RCFilters: Test abstract class func directly, not in subclass tests
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / ChangesListBooleanFilterTest.php
1 <?php
2
3 /**
4 * @covers ChangesListBooleanFilter
5 */
6 class ChangesListBooleanFilterTest extends MediaWikiTestCase {
7 public function testGetJsData() {
8 $group = new ChangesListBooleanFilterGroup( [
9 'name' => 'group',
10 'priority' => 2,
11 'filters' => [],
12 ] );
13
14 $definition = [
15 'group' => $group,
16 'label' => 'main-label',
17 'description' => 'main-description',
18 'default' => 1,
19 'priority' => 1,
20 ];
21
22 $fooFilter = new ChangesListBooleanFilter(
23 $definition + [ 'name' => 'hidefoo' ]
24 );
25
26 $barFilter = new ChangesListBooleanFilter(
27 $definition + [ 'name' => 'hidebar' ]
28 );
29
30 $bazFilter = new ChangesListBooleanFilter(
31 $definition + [ 'name' => 'hidebaz' ]
32 );
33
34 $fooFilter->conflictsWith(
35 $barFilter,
36 'foo-bar-global-conflict',
37 'foo-conflicts-bar',
38 'bar-conflicts-foo'
39 );
40
41 $fooFilter->setAsSupersetOf( $bazFilter, 'foo-superset-of-baz' );
42
43 $fooData = $fooFilter->getJsData();
44 $this->assertArrayEquals(
45 [
46 'name' => 'hidefoo',
47 'label' => 'main-label',
48 'description' => 'main-description',
49 'default' => 1,
50 'priority' => 1,
51 'cssClass' => null,
52 'conflicts' => [
53 [
54 'group' => 'group',
55 'filter' => 'hidebar',
56 'globalDescription' => 'foo-bar-global-conflict',
57 'contextDescription' => 'foo-conflicts-bar',
58 ]
59 ],
60 'subset' => [
61 [
62 'group' => 'group',
63 'filter' => 'hidebaz',
64 ],
65
66 ],
67 'messageKeys' => [
68 'main-label',
69 'main-description',
70 'foo-bar-global-conflict',
71 'foo-conflicts-bar',
72 ],
73 ],
74 $fooData,
75 /** ordered= */ false,
76 /** named= */ true
77 );
78
79 $barData = $barFilter->getJsData();
80 $this->assertArrayEquals(
81 [
82 'name' => 'hidebar',
83 'label' => 'main-label',
84 'description' => 'main-description',
85 'default' => 1,
86 'priority' => 1,
87 'cssClass' => null,
88 'conflicts' => [
89 [
90 'group' => 'group',
91 'filter' => 'hidefoo',
92 'globalDescription' => 'foo-bar-global-conflict',
93 'contextDescription' => 'bar-conflicts-foo',
94 ]
95 ],
96 'subset' => [],
97 'messageKeys' => [
98 'main-label',
99 'main-description',
100 'foo-bar-global-conflict',
101 'bar-conflicts-foo',
102 ],
103 ],
104 $barData,
105 /** ordered= */ false,
106 /** named= */ true
107 );
108 }
109
110 public function testIsFeatureAvailableOnStructuredUi() {
111 $specialPage = $this->getMockBuilder( 'ChangesListSpecialPage' )
112 ->setConstructorArgs( [
113 'ChangesListSpecialPage',
114 '',
115 ] )
116 ->getMockForAbstractClass();
117
118 $groupA = new ChangesListBooleanFilterGroup( [
119 'name' => 'groupA',
120 'priority' => 1,
121 'filters' => [],
122 ] );
123
124 $foo = new ChangesListBooleanFilter( [
125 'name' => 'hidefoo',
126 'group' => $groupA,
127 'label' => 'foo-label',
128 'description' => 'foo-description',
129 'default' => true,
130 'showHide' => 'showhidefoo',
131 'priority' => 2,
132 ] );
133
134 $this->assertEquals(
135 true,
136 $foo->isFeatureAvailableOnStructuredUi( $specialPage ),
137 'Same filter appears on both'
138 );
139
140 // Should only be legacy ones that haven't been ported yet
141 $bar = new ChangesListBooleanFilter( [
142 'name' => 'hidebar',
143 'default' => true,
144 'group' => $groupA,
145 'showHide' => 'showhidebar',
146 'priority' => 2,
147 ] );
148
149 $this->assertEquals(
150 false,
151 $bar->isFeatureAvailableOnStructuredUi( $specialPage ),
152 'Only on unstructured UI'
153 );
154
155 $baz = new ChangesListBooleanFilter( [
156 'name' => 'hidebaz',
157 'default' => true,
158 'group' => $groupA,
159 'showHide' => 'showhidebaz',
160 'isReplacedInStructuredUi' => true,
161 'priority' => 2,
162 ] );
163
164 $this->assertEquals(
165 true,
166 $baz->isFeatureAvailableOnStructuredUi( $specialPage ),
167 'Legacy filter does not appear directly in new UI, but equivalent ' .
168 'does and is marked with isReplacedInStructuredUi'
169 );
170 }
171 }