EchoNotificationsManagerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 127
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInitNotificationsDefinitions() 0 49 1
A testAddDefaultOptions() 0 15 1
A testGetNotificationsBundle() 0 33 1
A testCreateEvent() 0 23 1
1
<?php
2
3
namespace SMW\Notifications\Tests;
4
5
use SMW\Notifications\EchoNotificationsManager;
6
use SMW\Notifications\ChangeNotification\ChangeNotificationFilter;
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 testInitNotificationsDefinitions() {
21
22
		$instance = new EchoNotificationsManager();
23
24
		$notifications = array();
25
		$notificationCategories = array();
26
		$icons = array();
27
28
		$instance->initNotificationsDefinitions(
29
			$notifications,
30
			$notificationCategories,
31
			$icons
32
		);
33
34
		$this->assertArrayHasKey(
35
			ChangeNotificationFilter::VALUE_CHANGE,
36
			$notifications
37
		);
38
39
		$this->assertArrayHasKey(
40
			ChangeNotificationFilter::SPECIFICATION_CHANGE,
41
			$notifications
42
		);
43
44
		$this->assertArrayHasKey(
45
			ChangeNotificationFilter::VALUE_CHANGE,
46
			$notificationCategories
47
		);
48
49
		$this->assertArrayHasKey(
50
			ChangeNotificationFilter::SPECIFICATION_CHANGE,
51
			$notificationCategories
52
		);
53
54
		$this->assertArrayHasKey(
55
			ChangeNotificationFilter::VALUE_CHANGE,
56
			$icons
57
		);
58
59
		$this->assertArrayHasKey(
60
			ChangeNotificationFilter::SPECIFICATION_CHANGE . '-property',
61
			$icons
62
		);
63
64
		$this->assertArrayHasKey(
65
			ChangeNotificationFilter::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-' . ChangeNotificationFilter::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( ChangeNotificationFilter::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'  => ChangeNotificationFilter::VALUE_CHANGE
134
		);
135
136
		$instance = new EchoNotificationsManager();
137
138
		$this->assertInstanceOf(
139
			\EchoEvent::class,
140
			$instance->createEvent( $event )
141
		);
142
	}
143
144
}
145