File "wc_get_scheduled_actions_Test.php"

Full Path: /home/vantageo/public_html/cache/cache/cache/cache/cache/.wp-cli/wp-content/plugins/mailchimp-for-woocommerce_bk/includes/vendor/action-scheduler/tests/phpunit/procedural_api/wc_get_scheduled_actions_Test.php
File size: 2.56 KB
MIME-type: text/x-php
Charset: utf-8

<?php

/**
 * Class as_get_scheduled_actions_Test
 */
class as_get_scheduled_actions_Test extends ActionScheduler_UnitTestCase {
	private $hooks = array();
	private $args = array();
	private $groups = array();

	public function setUp() {
		parent::setUp();

		$store = ActionScheduler::store();

		for ( $i = 0 ; $i < 10 ; $i++ ) {
			$this->hooks[$i] = md5(rand());
			$this->args[$i] = md5(rand());
			$this->groups[$i] = md5(rand());
		}

		for ( $i = 0 ; $i < 10 ; $i++ ) {
			for ( $j = 0 ; $j < 10 ; $j++  ) {
				$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( $j - 3 . 'days') );
				$group = $this->groups[ ( $i + $j ) % 10 ];
				$action = new ActionScheduler_Action( $this->hooks[$i], array($this->args[$j]), $schedule, $group );
				$store->save_action( $action );
			}
		}
	}

	public function test_date_queries() {
		$actions = as_get_scheduled_actions(array(
			'date' => as_get_datetime_object(gmdate('Y-m-d 00:00:00')),
			'per_page' => -1,
		), 'ids');
		$this->assertCount(30, $actions);

		$actions = as_get_scheduled_actions(array(
			'date' => as_get_datetime_object(gmdate('Y-m-d 00:00:00')),
			'date_compare' => '>=',
			'per_page' => -1,
		), 'ids');
		$this->assertCount(70, $actions);
	}

	public function test_hook_queries() {
		$actions = as_get_scheduled_actions(array(
			'hook' => $this->hooks[2],
			'per_page' => -1,
		), 'ids');
		$this->assertCount(10, $actions);

		$actions = as_get_scheduled_actions(array(
			'hook' => $this->hooks[2],
			'date' => as_get_datetime_object(gmdate('Y-m-d 00:00:00')),
			'per_page' => -1,
		), 'ids');
		$this->assertCount(3, $actions);
	}

	public function test_args_queries() {
		$actions = as_get_scheduled_actions(array(
			'args' => array($this->args[5]),
			'per_page' => -1,
		), 'ids');
		$this->assertCount(10, $actions);

		$actions = as_get_scheduled_actions(array(
			'args' => array($this->args[5]),
			'hook' => $this->hooks[3],
			'per_page' => -1,
		), 'ids');
		$this->assertCount(1, $actions);

		$actions = as_get_scheduled_actions(array(
			'args' => array($this->args[5]),
			'hook' => $this->hooks[3],
			'date' => as_get_datetime_object(gmdate('Y-m-d 00:00:00')),
			'per_page' => -1,
		), 'ids');
		$this->assertCount(0, $actions);
	}

	public function test_group_queries() {
		$actions = as_get_scheduled_actions(array(
			'group' => $this->groups[1],
			'per_page' => -1,
		), 'ids');
		$this->assertCount(10, $actions);

		$actions = as_get_scheduled_actions(array(
			'group' => $this->groups[1],
			'hook' => $this->hooks[9],
			'per_page' => -1,
		), 'ids');
		$this->assertCount(1, $actions);
	}
}