Test Failed
Push — master ( abf703...9671b2 )
by Jonathan
04:24 queued 01:11
created

ActionScheduler_Action_Test   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 3
1
<?php
2
3
/**
4
 * Class ActionScheduler_Action_Test
5
 * @group actions
6
 */
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