Merge "Skin: Make skins aware of their registered skin name"
[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 'defaultHighlightColor' => null,
53 'conflicts' => [
54 [
55 'group' => 'group',
56 'filter' => 'hidebar',
57 'globalDescription' => 'foo-bar-global-conflict',
58 'contextDescription' => 'foo-conflicts-bar',
59 ]
60 ],
61 'subset' => [
62 [
63 'group' => 'group',
64 'filter' => 'hidebaz',
65 ],
66
67 ],
68 'messageKeys' => [
69 'main-label',
70 'main-description',
71 'foo-bar-global-conflict',
72 'foo-conflicts-bar',
73 ],
74 ],
75 $fooData,
76 /** ordered= */ false,
77 /** named= */ true
78 );
79
80 $barData = $barFilter->getJsData();
81 $this->assertArrayEquals(
82 [
83 'name' => 'hidebar',
84 'label' => 'main-label',
85 'description' => 'main-description',
86 'default' => 1,
87 'priority' => 1,
88 'cssClass' => null,
89 'defaultHighlightColor' => null,
90 'conflicts' => [
91 [
92 'group' => 'group',
93 'filter' => 'hidefoo',
94 'globalDescription' => 'foo-bar-global-conflict',
95 'contextDescription' => 'bar-conflicts-foo',
96 ]
97 ],
98 'subset' => [],
99 'messageKeys' => [
100 'main-label',
101 'main-description',
102 'foo-bar-global-conflict',
103 'bar-conflicts-foo',
104 ],
105 ],
106 $barData,
107 /** ordered= */ false,
108 /** named= */ true
109 );
110 }
111
112 public function testIsFeatureAvailableOnStructuredUi() {
113 $groupA = new ChangesListBooleanFilterGroup( [
114 'name' => 'groupA',
115 'priority' => 1,
116 'filters' => [],
117 ] );
118
119 $foo = new ChangesListBooleanFilter( [
120 'name' => 'hidefoo',
121 'group' => $groupA,
122 'label' => 'foo-label',
123 'description' => 'foo-description',
124 'default' => true,
125 'showHide' => 'showhidefoo',
126 'priority' => 2,
127 ] );
128
129 $this->assertEquals(
130 true,
131 $foo->isFeatureAvailableOnStructuredUi(),
132 'Same filter appears on both'
133 );
134
135 // Should only be legacy ones that haven't been ported yet
136 $bar = new ChangesListBooleanFilter( [
137 'name' => 'hidebar',
138 'default' => true,
139 'group' => $groupA,
140 'showHide' => 'showhidebar',
141 'priority' => 2,
142 ] );
143
144 $this->assertEquals(
145 false,
146 $bar->isFeatureAvailableOnStructuredUi(),
147 'Only on unstructured UI'
148 );
149
150 $baz = new ChangesListBooleanFilter( [
151 'name' => 'hidebaz',
152 'default' => true,
153 'group' => $groupA,
154 'showHide' => 'showhidebaz',
155 'isReplacedInStructuredUi' => true,
156 'priority' => 2,
157 ] );
158
159 $this->assertEquals(
160 true,
161 $baz->isFeatureAvailableOnStructuredUi(),
162 'Legacy filter does not appear directly in new UI, but equivalent ' .
163 'does and is marked with isReplacedInStructuredUi'
164 );
165 }
166 }