X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/tests/phpunit/includes/changes/ChangesListBooleanFilterTest.php diff --git a/tests/phpunit/includes/changes/ChangesListBooleanFilterTest.php b/tests/phpunit/includes/changes/ChangesListBooleanFilterTest.php new file mode 100644 index 00000000..000f0177 --- /dev/null +++ b/tests/phpunit/includes/changes/ChangesListBooleanFilterTest.php @@ -0,0 +1,164 @@ + 'group', + 'priority' => 2, + 'filters' => [], + ] ); + + $definition = [ + 'group' => $group, + 'label' => 'main-label', + 'description' => 'main-description', + 'default' => 1, + 'priority' => 1, + ]; + + $fooFilter = new ChangesListBooleanFilter( + $definition + [ 'name' => 'hidefoo' ] + ); + + $barFilter = new ChangesListBooleanFilter( + $definition + [ 'name' => 'hidebar' ] + ); + + $bazFilter = new ChangesListBooleanFilter( + $definition + [ 'name' => 'hidebaz' ] + ); + + $fooFilter->conflictsWith( + $barFilter, + 'foo-bar-global-conflict', + 'foo-conflicts-bar', + 'bar-conflicts-foo' + ); + + $fooFilter->setAsSupersetOf( $bazFilter, 'foo-superset-of-baz' ); + + $fooData = $fooFilter->getJsData(); + $this->assertArrayEquals( + [ + 'name' => 'hidefoo', + 'label' => 'main-label', + 'description' => 'main-description', + 'default' => 1, + 'priority' => 1, + 'cssClass' => null, + 'conflicts' => [ + [ + 'group' => 'group', + 'filter' => 'hidebar', + 'globalDescription' => 'foo-bar-global-conflict', + 'contextDescription' => 'foo-conflicts-bar', + ] + ], + 'subset' => [ + [ + 'group' => 'group', + 'filter' => 'hidebaz', + ], + + ], + 'messageKeys' => [ + 'main-label', + 'main-description', + 'foo-bar-global-conflict', + 'foo-conflicts-bar', + ], + ], + $fooData, + /** ordered= */ false, + /** named= */ true + ); + + $barData = $barFilter->getJsData(); + $this->assertArrayEquals( + [ + 'name' => 'hidebar', + 'label' => 'main-label', + 'description' => 'main-description', + 'default' => 1, + 'priority' => 1, + 'cssClass' => null, + 'conflicts' => [ + [ + 'group' => 'group', + 'filter' => 'hidefoo', + 'globalDescription' => 'foo-bar-global-conflict', + 'contextDescription' => 'bar-conflicts-foo', + ] + ], + 'subset' => [], + 'messageKeys' => [ + 'main-label', + 'main-description', + 'foo-bar-global-conflict', + 'bar-conflicts-foo', + ], + ], + $barData, + /** ordered= */ false, + /** named= */ true + ); + } + + public function testIsFeatureAvailableOnStructuredUi() { + $groupA = new ChangesListBooleanFilterGroup( [ + 'name' => 'groupA', + 'priority' => 1, + 'filters' => [], + ] ); + + $foo = new ChangesListBooleanFilter( [ + 'name' => 'hidefoo', + 'group' => $groupA, + 'label' => 'foo-label', + 'description' => 'foo-description', + 'default' => true, + 'showHide' => 'showhidefoo', + 'priority' => 2, + ] ); + + $this->assertEquals( + true, + $foo->isFeatureAvailableOnStructuredUi(), + 'Same filter appears on both' + ); + + // Should only be legacy ones that haven't been ported yet + $bar = new ChangesListBooleanFilter( [ + 'name' => 'hidebar', + 'default' => true, + 'group' => $groupA, + 'showHide' => 'showhidebar', + 'priority' => 2, + ] ); + + $this->assertEquals( + false, + $bar->isFeatureAvailableOnStructuredUi(), + 'Only on unstructured UI' + ); + + $baz = new ChangesListBooleanFilter( [ + 'name' => 'hidebaz', + 'default' => true, + 'group' => $groupA, + 'showHide' => 'showhidebaz', + 'isReplacedInStructuredUi' => true, + 'priority' => 2, + ] ); + + $this->assertEquals( + true, + $baz->isFeatureAvailableOnStructuredUi(), + 'Legacy filter does not appear directly in new UI, but equivalent ' . + 'does and is marked with isReplacedInStructuredUi' + ); + } +}