Merge "Add semantic tags to license info text"
[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 * phpcs:disable Generic.Files.LineLength
30 * @expectedException MWException
31 * @expectedExceptionMessage Filter names may not contain '_'. Use the naming convention: 'lowercase'
32 * phpcs:enable
33 */
34 public function testReservedCharacter() {
35 $filter = new MockChangesListFilter(
36 [
37 'group' => $this->group,
38 'name' => 'some_name',
39 'priority' => 1,
40 ]
41 );
42 }
43
44 /**
45 * @expectedException MWException
46 * @expectedExceptionMessage Two filters in a group cannot have the same name: 'somename'
47 */
48 public function testDuplicateName() {
49 new MockChangesListFilter(
50 [
51 'group' => $this->group,
52 'name' => 'somename',
53 'priority' => 1,
54 ]
55 );
56
57 new MockChangesListFilter(
58 [
59 'group' => $this->group,
60 'name' => 'somename',
61 'priority' => 2,
62 ]
63 );
64 }
65
66 /**
67 * @expectedException MWException
68 * @expectedExceptionMessage Supersets can only be defined for filters in the same group
69 */
70 public function testSetAsSupersetOf() {
71 $groupA = $this->getGroup(
72 [
73 'name' => 'groupA',
74 'filters' => [
75 [
76 'name' => 'foo',
77 ],
78 [
79 'name' => 'bar',
80 ]
81 ],
82 ]
83 );
84
85 $groupB = $this->getGroup(
86 [
87 'name' => 'groupB',
88 'filters' => [
89 [
90 'name' => 'baz',
91 ],
92 ],
93 ]
94 );
95
96 $foo = TestingAccessWrapper::newFromObject( $groupA->getFilter( 'foo' ) );
97
98 $bar = $groupA->getFilter( 'bar' );
99
100 $baz = $groupB->getFilter( 'baz' );
101
102 $foo->setAsSupersetOf( $bar );
103 $this->assertArrayEquals( [
104 [
105 'group' => 'groupA',
106 'filter' => 'bar',
107 ],
108 ],
109 $foo->subsetFilters,
110 /** ordered= */ false,
111 /** named= */ true
112 );
113
114 $foo->setAsSupersetOf( $baz );
115 }
116 }