Completed
Push — master ( b362d7...ee34ad )
by mw
7s
created

EchoNotificationsManagerTest::testCanConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace SMW\Notifications\Tests;
4
5
use SMW\Notifications\EchoNotificationsManager;
6
use SMW\Notifications\ValueChange\ChangeNotifications;
7
use SMW\DIWikiPage;
8
9
/**
10
 * @covers \SMW\Notifications\EchoNotificationsManager
11
 * @group semantic-notifications
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.0
15
 *
16
 * @author mwjames
17
 */
18
class EchoNotificationsManagerTest extends \PHPUnit_Framework_TestCase {
19
20
	public function testAddNotificationsDefinitions() {
21
22
		$instance = new EchoNotificationsManager();
23
24
		$notifications = array();
25
		$notificationCategories = array();
26
		$icons = array();
27
28
		$instance->addNotificationsDefinitions(
29
			$notifications,
30
			$notificationCategories,
31
			$icons
32
		);
33
34
		$this->assertArrayHasKey(
35
			ChangeNotifications::VALUE_CHANGE,
36
			$notifications
37
		);
38
39
		$this->assertArrayHasKey(
40
			ChangeNotifications::SPECIFICATION_CHANGE,
41
			$notifications
42
		);
43
44
		$this->assertArrayHasKey(
45
			ChangeNotifications::VALUE_CHANGE,
46
			$notificationCategories
47
		);
48
49
		$this->assertArrayHasKey(
50
			ChangeNotifications::SPECIFICATION_CHANGE,
51
			$notificationCategories
52
		);
53
54
		$this->assertArrayHasKey(
55
			ChangeNotifications::VALUE_CHANGE,
56
			$icons
57
		);
58
59
		$this->assertArrayHasKey(
60
			ChangeNotifications::SPECIFICATION_CHANGE. '-property',
61
			$icons
62
		);
63
64
		$this->assertArrayHasKey(
65
			ChangeNotifications::SPECIFICATION_CHANGE . '-category',
66
			$icons
67
		);
68
	}
69
70
	public function testAddDefaultOptions() {
71
72
		$instance = new EchoNotificationsManager();
73
74
		$defaultOptions = array();
75
76
		$instance->addDefaultOptions(
77
			$defaultOptions
78
		);
79
80
		$this->assertArrayHasKey(
81
			'echo-subscriptions-web-' . ChangeNotifications::VALUE_CHANGE,
82
			$defaultOptions
83
		);
84
	}
85
86
	public function testGetNotificationsBundle() {
87
88
		$extra = array(
89
			'subject' => DIWikiPage::newFromText( 'Foo' ),
90
			'revid'   => 1001
91
		);
92
93
		$echoEvent = $this->getMockBuilder( \EchoEvent::class )
94
			->disableOriginalConstructor()
95
			->getMock();
96
97
		$echoEvent->expects( $this->once() )
98
			->method( 'getType' )
99
			->will( $this->returnValue( ChangeNotifications::VALUE_CHANGE ) );
100
101
		$echoEvent->expects( $this->once() )
102
			->method( 'getExtra' )
103
			->will( $this->returnValue( $extra ) );
104
105
		$instance = new EchoNotificationsManager();
106
107
		$bundleString = '';
108
109
		$instance->getNotificationsBundle(
110
			$echoEvent,
111
			$bundleString
112
		);
113
114
		$this->assertSame(
115
			'Foo#0#1001',
116
			$bundleString
117
		);
118
	}
119
120
	public function testCreateEvent() {
121
122
		$agent = $this->getMockBuilder( \User::class )
123
			->disableOriginalConstructor()
124
			->getMock();
125
126
		$title = $this->getMockBuilder( \Title::class )
127
			->disableOriginalConstructor()
128
			->getMock();
129
130
		$event = array(
131
			'agent' => $agent,
132
			'title' => $title,
133
			'type'  => ChangeNotifications::VALUE_CHANGE
134
		);
135
136
		$instance = new EchoNotificationsManager();
137
138
		$this->assertInstanceOf(
139
			\EchoEvent::class,
140
			$instance->createEvent( $event )
141
		);
142
	}
143
144
}
145