Skip to content

Commit

Permalink
Merge pull request #1197 from crstauf/phpcstests/wc_get_scheduled_act…
Browse files Browse the repository at this point in the history
…ions_Test.php

PHPCS: `tests/phpunit/procedural_api/wc_get_scheduled_actions_Test.php`
  • Loading branch information
barryhughes authored Oct 8, 2024
2 parents 3f1fb42 + 9a2f0f9 commit 3f0a480
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 66 deletions.
4 changes: 4 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<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>
Expand Down
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 );
}
}

0 comments on commit 3f0a480

Please sign in to comment.