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