Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPCS: tests/phpunit/procedural_api/wc_get_scheduled_actions_Test.php #1197

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@
<exclude-pattern>lib/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<rule ref="PEAR.NamingConventions.ValidClassName">
<exclude-pattern>tests/phpunit/procedural_api/wc_get_scheduled_actions_Test.php</exclude-pattern>
</rule>

<rule ref="Squiz.Commenting.FunctionComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
</ruleset>
163 changes: 97 additions & 66 deletions tests/phpunit/procedural_api/wc_get_scheduled_actions_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,97 +4,128 @@
* Class as_get_scheduled_actions_Test
*/
class as_get_scheduled_actions_Test extends ActionScheduler_UnitTestCase {
/** @var array<int, string> */
private $hooks = array();

/** @var array<int, string> */
private $args = array();

/** @var array<int, string> */
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++ ) {
$this->hooks[ $i ] = md5( wp_rand() );
$this->args[ $i ] = md5( wp_rand() );
$this->groups[ $i ] = md5( wp_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 );
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);
$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);
$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);
$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);
$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 );
}
}

Loading