1 | <?php |
||
7 | class ActionScheduler_Action_Test extends ActionScheduler_UnitTestCase { |
||
8 | public function test_set_schedule() { |
||
9 | $time = as_get_datetime_object(); |
||
10 | $schedule = new ActionScheduler_SimpleSchedule($time); |
||
11 | $action = new ActionScheduler_Action('my_hook', array(), $schedule); |
||
12 | $this->assertEquals( $schedule, $action->get_schedule() ); |
||
13 | } |
||
14 | |||
15 | public function test_null_schedule() { |
||
16 | $action = new ActionScheduler_Action('my_hook'); |
||
17 | $this->assertInstanceOf( 'ActionScheduler_NullSchedule', $action->get_schedule() ); |
||
18 | } |
||
19 | |||
20 | public function test_set_hook() { |
||
21 | $action = new ActionScheduler_Action('my_hook'); |
||
22 | $this->assertEquals( 'my_hook', $action->get_hook() ); |
||
23 | } |
||
24 | |||
25 | public function test_args() { |
||
26 | $action = new ActionScheduler_Action('my_hook'); |
||
27 | $this->assertEmpty($action->get_args()); |
||
28 | |||
29 | $action = new ActionScheduler_Action('my_hook', array(5,10,15)); |
||
30 | $this->assertEqualSets(array(5,10,15), $action->get_args()); |
||
31 | } |
||
32 | |||
33 | public function test_set_group() { |
||
34 | $action = new ActionScheduler_Action('my_hook', array(), NULL, 'my_group'); |
||
35 | $this->assertEquals('my_group', $action->get_group()); |
||
36 | } |
||
37 | |||
38 | public function test_execute() { |
||
39 | $mock = new MockAction(); |
||
40 | |||
41 | $random = md5(rand()); |
||
42 | add_action( $random, array( $mock, 'action' ) ); |
||
43 | |||
44 | $action = new ActionScheduler_Action( $random, array($random) ); |
||
45 | $action->execute(); |
||
46 | |||
47 | remove_action( $random, array( $mock, 'action' ) ); |
||
48 | |||
49 | $this->assertEquals( 1, $mock->get_call_count() ); |
||
50 | $events = $mock->get_events(); |
||
51 | $event = reset($events); |
||
52 | $this->assertEquals( $random, reset($event['args']) ); |
||
53 | } |
||
54 | } |
||
55 |