5546de8739ce9a05b95ae69ae7e4699814b792b4
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / ChangesListFilterTest.php
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4
5 /**
6 * @covers ChangesListFilter
7 */
8 class ChangesListFilterTest extends MediaWikiTestCase {
9 protected $group;
10
11 public function setUp() {
12 $this->group = $this->getGroup( [ 'name' => 'group' ] );
13
14 parent::setUp();
15 }
16
17 protected function getGroup( $groupDefinition ) {
18 return new MockChangesListFilterGroup(
19 $groupDefinition + [
20 'isFullCoverage' => true,
21 'type' => 'some_type',
22 'name' => 'group',
23 'filters' => [],
24 ]
25 );
26
27 }
28
29 // @codingStandardsIgnoreStart
30 /**
31 * @expectedException MWException
32 * @expectedExceptionMessage Filter names may not contain '_'. Use the naming convention: 'lowercase'
33 */
34 // @codingStandardsIgnoreEnd
35 public function testReservedCharacter() {
36 $filter = new MockChangesListFilter(
37 [
38 'group' => $this->group,
39 'name' => 'some_name',
40 'priority' => 1,
41 ]
42 );
43 }
44
45 // @codingStandardsIgnoreStart
46 /**
47 * @expectedException MWException
48 * @expectedExceptionMessage Two filters in a group cannot have the same name: 'somename'
49 */
50 // @codingStandardsIgnoreEnd
51 public function testDuplicateName() {
52 new MockChangesListFilter(
53 [
54 'group' => $this->group,
55 'name' => 'somename',
56 'priority' => 1,
57 ]
58 );
59
60 new MockChangesListFilter(
61 [
62 'group' => $this->group,
63 'name' => 'somename',
64 'priority' => 2,
65 ]
66 );
67 }
68
69 /**
70 * @expectedException MWException
71 * @expectedExceptionMessage Supersets can only be defined for filters in the same group
72 */
73 public function testSetAsSupersetOf() {
74 $groupA = $this->getGroup(
75 [
76 'name' => 'groupA',
77 'filters' => [
78 [
79 'name' => 'foo',
80 ],
81 [
82 'name' => 'bar',
83 ]
84 ],
85 ]
86 );
87
88 $groupB = $this->getGroup(
89 [
90 'name' => 'groupB',
91 'filters' => [
92 [
93 'name' => 'baz',
94 ],
95 ],
96 ]
97 );
98
99 $foo = TestingAccessWrapper::newFromObject( $groupA->getFilter( 'foo' ) );
100
101 $bar = $groupA->getFilter( 'bar' );
102
103 $baz = $groupB->getFilter( 'baz' );
104
105 $foo->setAsSupersetOf( $bar );
106 $this->assertArrayEquals( [
107 [
108 'group' => 'groupA',
109 'filter' => 'bar',
110 ],
111 ],
112 $foo->subsetFilters,
113 /** ordered= */ false,
114 /** named= */ true
115 );
116
117 $foo->setAsSupersetOf( $baz );
118 }
119 }