MediaWiki  1.29.2
ChangesListBooleanFilterTest.php
Go to the documentation of this file.
1 <?php
2 
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, false, 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, false, true
107  );
108  }
109 
111  $groupA = new ChangesListBooleanFilterGroup( [
112  'name' => 'groupA',
113  'priority' => 1,
114  'filters' => [],
115  ] );
116 
117  $foo = new ChangesListBooleanFilter( [
118  'name' => 'hidefoo',
119  'group' => $groupA,
120  'label' => 'foo-label',
121  'description' => 'foo-description',
122  'default' => true,
123  'showHide' => 'showhidefoo',
124  'priority' => 2,
125  ] );
126 
127  $this->assertEquals(
128  true,
129  $foo->isFeatureAvailableOnStructuredUi(),
130  'Same filter appears on both'
131  );
132 
133  // Should only be legacy ones that haven't been ported yet
134  $bar = new ChangesListBooleanFilter( [
135  'name' => 'hidebar',
136  'default' => true,
137  'group' => $groupA,
138  'showHide' => 'showhidebar',
139  'priority' => 2,
140  ] );
141 
142  $this->assertEquals(
143  false,
144  $bar->isFeatureAvailableOnStructuredUi(),
145  'Only on unstructured UI'
146  );
147 
148  $baz = new ChangesListBooleanFilter( [
149  'name' => 'hidebaz',
150  'default' => true,
151  'group' => $groupA,
152  'showHide' => 'showhidebaz',
153  'isReplacedInStructuredUi' => true,
154  'priority' => 2,
155  ] );
156 
157  $this->assertEquals(
158  true,
159  $baz->isFeatureAvailableOnStructuredUi(),
160  'Legacy filter does not appear directly in new UI, but equivalent ' .
161  'does and is marked with isReplacedInStructuredUi'
162  );
163  }
164 }
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:1498
ChangesListBooleanFilter
An individual filter in a boolean group.
Definition: ChangesListBooleanFilter.php:32
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWikiTestCase
Definition: MediaWikiTestCase.php:13
ChangesListBooleanFilterTest\testGetJsData
testGetJsData()
Definition: ChangesListBooleanFilterTest.php:7
ChangesListBooleanFilterTest
ChangesListBooleanFilter.
Definition: ChangesListBooleanFilterTest.php:6
ChangesListBooleanFilterTest\testIsFeatureAvailableOnStructuredUi
testIsFeatureAvailableOnStructuredUi()
Definition: ChangesListBooleanFilterTest.php:110
ChangesListBooleanFilterGroup
If the group is active, any unchecked filters will translate to hide parameters in the URL.
Definition: ChangesListBooleanFilterGroup.php:10