1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Notifications\Tests\ChangeNotification; |
4
|
|
|
|
5
|
|
|
use SMW\Notifications\ChangeNotification\NotificationGroupsLocator; |
6
|
|
|
use SMW\Notifications\DataValues\NotificationGroupValue; |
7
|
|
|
use SMW\DIWikiPage; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers \SMW\Notifications\ChangeNotification\NotificationGroupsLocator |
11
|
|
|
* @group semantic-notifications |
12
|
|
|
* |
13
|
|
|
* @license GNU GPL v2+ |
14
|
|
|
* @since 1.0 |
15
|
|
|
* |
16
|
|
|
* @author mwjames |
17
|
|
|
*/ |
18
|
|
|
class NotificationGroupsLocatorTest extends \PHPUnit_Framework_TestCase { |
19
|
|
|
|
20
|
|
|
private $store; |
21
|
|
|
|
22
|
|
|
protected function setUp() { |
23
|
|
|
|
24
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
25
|
|
|
->disableOriginalConstructor() |
26
|
|
|
->getMockForAbstractClass(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testCanConstruct() { |
30
|
|
|
|
31
|
|
|
$this->assertInstanceOf( |
32
|
|
|
NotificationGroupsLocator::class, |
33
|
|
|
new NotificationGroupsLocator( $this->store ) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testGetSpecialGroupOnSpecificationChange() { |
38
|
|
|
|
39
|
|
|
$instance = new NotificationGroupsLocator( |
40
|
|
|
$this->store |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$this->assertArrayHasKey( |
44
|
|
|
NotificationGroupValue::SPECIAL_GROUP, |
45
|
|
|
$instance->getSpecialGroupOnSpecificationChange() |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetNotificationsToGroupListAsCallback() { |
50
|
|
|
|
51
|
|
|
$instance = new NotificationGroupsLocator( |
52
|
|
|
$this->store |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$subSemanticDataMatch = array(); |
56
|
|
|
|
57
|
|
|
$this->assertInstanceOf( |
58
|
|
|
'\Closure', |
59
|
|
|
$instance->getNotificationsToGroupListAsCallback( $subSemanticDataMatch ) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testFindNotificationsToGroupListOnEmptyValues() { |
64
|
|
|
|
65
|
|
|
$this->store->expects( $this->once() ) |
66
|
|
|
->method( 'getPropertyValues' ) |
67
|
|
|
->will( $this->returnValue( array() ) ); |
68
|
|
|
|
69
|
|
|
$dataItem = $this->getMockBuilder( '\SMW\DIWikiPage' ) |
70
|
|
|
->disableOriginalConstructor() |
71
|
|
|
->getMock(); |
72
|
|
|
|
73
|
|
|
$instance = new NotificationGroupsLocator( |
74
|
|
|
$this->store |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$subSemanticDataMatch = array(); |
78
|
|
|
|
79
|
|
|
$this->assertEmpty( |
80
|
|
|
$instance->findNotificationsToGroupList( $dataItem, $subSemanticDataMatch ) |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testFindNotificationsToGroupListOnSubSemanticDataReference() { |
85
|
|
|
|
86
|
|
|
$subSemanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
87
|
|
|
->disableOriginalConstructor() |
88
|
|
|
->getMock(); |
89
|
|
|
|
90
|
|
|
$subSemanticData->expects( $this->once() ) |
91
|
|
|
->method( 'getPropertyValues' ) |
92
|
|
|
->will( $this->returnValue( array( 'Bar' ) ) ); |
93
|
|
|
|
94
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
95
|
|
|
->disableOriginalConstructor() |
96
|
|
|
->getMock(); |
97
|
|
|
|
98
|
|
|
$semanticData->expects( $this->once() ) |
99
|
|
|
->method( 'findSubSemanticData' ) |
100
|
|
|
->with( $this->equalTo( 'Foo' ) ) |
101
|
|
|
->will( $this->returnValue( $subSemanticData ) ); |
102
|
|
|
|
103
|
|
|
$this->store->expects( $this->once() ) |
104
|
|
|
->method( 'getSemanticData' ) |
105
|
|
|
->will( $this->returnValue( $semanticData ) ); |
106
|
|
|
|
107
|
|
|
$this->store->expects( $this->once() ) |
108
|
|
|
->method( 'getPropertyValues' ) |
109
|
|
|
->will( $this->returnValue( array() ) ); |
110
|
|
|
|
111
|
|
|
$dataItem = DIWikiPage::newFromText( __METHOD__ ); |
112
|
|
|
|
113
|
|
|
$instance = new NotificationGroupsLocator( |
114
|
|
|
$this->store |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
$subSemanticDataMatch = array( |
118
|
|
|
$dataItem->getHash() => array( 'Foo' ) |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$this->assertEquals( |
122
|
|
|
array( 'Bar' ), |
123
|
|
|
$instance->findNotificationsToGroupList( $dataItem, $subSemanticDataMatch ) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
} |
128
|
|
|
|