RCFilters: Test abstract class func directly, not in subclass tests
authorMatthew Flaschen <mflaschen@wikimedia.org>
Thu, 16 Mar 2017 00:15:16 +0000 (20:15 -0400)
committerMatthew Flaschen <mflaschen@wikimedia.org>
Thu, 16 Mar 2017 03:43:26 +0000 (23:43 -0400)
Change-Id: I8f526975bbf0a5392b69d239bc9db9771c99cdd9

tests/common/TestsAutoLoader.php
tests/phpunit/includes/changes/ChangesListBooleanFilterGroupTest.php
tests/phpunit/includes/changes/ChangesListBooleanFilterTest.php
tests/phpunit/includes/changes/ChangesListFilterGroupTest.php [new file with mode: 0644]
tests/phpunit/includes/changes/ChangesListFilterTest.php [new file with mode: 0644]
tests/phpunit/mocks/MockChangesListFilter.php [new file with mode: 0644]
tests/phpunit/mocks/MockChangesListFilterGroup.php [new file with mode: 0644]

index ebd3c53..2a4c43f 100644 (file)
@@ -160,6 +160,8 @@ $wgAutoloadClasses += [
        'MockDjVuHandler' => "$testDir/phpunit/mocks/media/MockDjVuHandler.php",
        'MockOggHandler' => "$testDir/phpunit/mocks/media/MockOggHandler.php",
        'MockMediaHandlerFactory' => "$testDir/phpunit/mocks/media/MockMediaHandlerFactory.php",
        'MockDjVuHandler' => "$testDir/phpunit/mocks/media/MockDjVuHandler.php",
        'MockOggHandler' => "$testDir/phpunit/mocks/media/MockOggHandler.php",
        'MockMediaHandlerFactory' => "$testDir/phpunit/mocks/media/MockMediaHandlerFactory.php",
+       'MockChangesListFilter' => "$testDir/phpunit/mocks/MockChangesListFilter.php",
+       'MockChangesListFilterGroup' => "$testDir/phpunit/mocks/MockChangesListFilterGroup.php",
        'MockWebRequest' => "$testDir/phpunit/mocks/MockWebRequest.php",
        'MediaWiki\\Session\\DummySessionBackend'
                => "$testDir/phpunit/mocks/session/DummySessionBackend.php",
        'MockWebRequest' => "$testDir/phpunit/mocks/MockWebRequest.php",
        'MediaWiki\\Session\\DummySessionBackend'
                => "$testDir/phpunit/mocks/session/DummySessionBackend.php",
index 0db3a49..d98311f 100644 (file)
@@ -19,33 +19,6 @@ class ChangesListBooleanFilterGroupTest extends MediaWikiTestCase {
                );
        }
 
                );
        }
 
-       public function testAutoPriorities() {
-               $group = new ChangesListBooleanFilterGroup( [
-                       'name' => 'groupName',
-                       'priority' => 1,
-                       'filters' => [
-                               [ 'name' => 'hidefoo', 'default' => false, ],
-                               [ 'name' => 'hidebar', 'default' => false, ],
-                               [ 'name' => 'hidebaz', 'default' => false, ],
-                       ],
-               ] );
-
-               $filters = $group->getFilters();
-               $this->assertEquals(
-                       [
-                               -2,
-                               -3,
-                               -4,
-                       ],
-                       array_map(
-                               function ( $f ) {
-                                       return $f->getPriority();
-                               },
-                               array_values( $filters )
-                       )
-               );
-       }
-
        public function testGetJsData() {
                $definition = [
                        'name' => 'some-group',
        public function testGetJsData() {
                $definition = [
                        'name' => 'some-group',
index c715988..2c0c22d 100644 (file)
@@ -107,58 +107,6 @@ class ChangesListBooleanFilterTest extends MediaWikiTestCase {
                );
        }
 
                );
        }
 
-       /**
-        * @expectedException MWException
-        * @expectedExceptionMessage Supersets can only be defined for filters in the same group
-        */
-       public function testSetAsSupersetOf() {
-               $groupA = new ChangesListBooleanFilterGroup( [
-                       'name' => 'groupA',
-                       'priority' => 2,
-                       'filters' => [
-                               [
-                                       'name' => 'foo',
-                                       'default' => false,
-                               ],
-                               [
-                                       'name' => 'bar',
-                                       'default' => false,
-                               ]
-                       ],
-               ] );
-
-               $groupB = new ChangesListBooleanFilterGroup( [
-                       'name' => 'groupB',
-                       'priority' => 3,
-                       'filters' => [
-                               [
-                                       'name' => 'baz',
-                                       'default' => true,
-                               ],
-                       ],
-               ] );
-
-               $foo = TestingAccessWrapper::newFromObject( $groupA->getFilter( 'foo' ) );
-
-               $bar = $groupA->getFilter( 'bar' );
-
-               $baz = $groupB->getFilter( 'baz' );
-
-               $foo->setAsSupersetOf( $bar );
-               $this->assertArrayEquals( [
-                               [
-                                       'group' => 'groupA',
-                                       'filter' => 'bar',
-                               ],
-                       ],
-                       $foo->subsetFilters,
-                       /** ordered= */ false,
-                       /** named= */ true
-               );
-
-               $foo->setAsSupersetOf( $baz, 'some-message' );
-       }
-
        public function testIsFeatureAvailableOnStructuredUi() {
                $specialPage = $this->getMockBuilder( 'ChangesListSpecialPage' )
                        ->setConstructorArgs( [
        public function testIsFeatureAvailableOnStructuredUi() {
                $specialPage = $this->getMockBuilder( 'ChangesListSpecialPage' )
                        ->setConstructorArgs( [
diff --git a/tests/phpunit/includes/changes/ChangesListFilterGroupTest.php b/tests/phpunit/includes/changes/ChangesListFilterGroupTest.php
new file mode 100644 (file)
index 0000000..718d4b3
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * @covers ChangesListFilterGroup
+ */
+class ChangesListFilterGroupTest extends MediaWikiTestCase {
+       public function testAutoPriorities() {
+               $group = new MockChangesListFilterGroup(
+                       [
+                               'type' => 'some_type',
+                               'name' => 'groupName',
+                               'isFullCoverage' => true,
+                               'priority' => 1,
+                               'filters' => [
+                                       [ 'name' => 'hidefoo' ],
+                                       [ 'name' => 'hidebar' ],
+                                       [ 'name' => 'hidebaz' ],
+                               ],
+                       ]
+               );
+
+               $filters = $group->getFilters();
+               $this->assertEquals(
+                       [
+                               -2,
+                               -3,
+                               -4,
+                       ],
+                       array_map(
+                               function ( $f ) {
+                                       return $f->getPriority();
+                               },
+                               array_values( $filters )
+                       )
+               );
+       }
+}
diff --git a/tests/phpunit/includes/changes/ChangesListFilterTest.php b/tests/phpunit/includes/changes/ChangesListFilterTest.php
new file mode 100644 (file)
index 0000000..b63482f
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * @covers ChangesListFilter
+ */
+class ChangesListFilterTest extends MediaWikiTestCase {
+       protected $group;
+
+       public function setUp() {
+               $this->group = $this->getGroup( [ 'name' => 'group' ] );
+
+               parent::setUp();
+       }
+
+       protected function getGroup( $groupDefinition ) {
+               return new MockChangesListFilterGroup(
+                       $groupDefinition + [
+                               'isFullCoverage' => true,
+                               'type' => 'some_type',
+                               'name' => 'group',
+                               'filters' => [],
+                       ]
+               );
+
+       }
+
+       /**
+        * @expectedException MWException
+        * @expectedExceptionMessage Supersets can only be defined for filters in the same group
+        */
+       public function testSetAsSupersetOf() {
+               $groupA = $this->getGroup(
+                       [
+                               'name' => 'groupA',
+                               'filters' => [
+                                       [
+                                               'name' => 'foo',
+                                       ],
+                                       [
+                                               'name' => 'bar',
+                                       ]
+                               ],
+                       ]
+               );
+
+               $groupB =  $this->getGroup(
+                       [
+                               'name' => 'groupB',
+                               'filters' => [
+                                       [
+                                               'name' => 'baz',
+                                       ],
+                               ],
+                       ]
+               );
+
+               $foo = TestingAccessWrapper::newFromObject( $groupA->getFilter( 'foo' ) );
+
+               $bar = $groupA->getFilter( 'bar' );
+
+               $baz = $groupB->getFilter( 'baz' );
+
+               $foo->setAsSupersetOf( $bar );
+               $this->assertArrayEquals( [
+                               [
+                                       'group' => 'groupA',
+                                       'filter' => 'bar',
+                               ],
+                       ],
+                       $foo->subsetFilters,
+                       /** ordered= */ false,
+                       /** named= */ true
+               );
+
+               $foo->setAsSupersetOf( $baz );
+       }
+}
diff --git a/tests/phpunit/mocks/MockChangesListFilter.php b/tests/phpunit/mocks/MockChangesListFilter.php
new file mode 100644 (file)
index 0000000..cbf306e
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+class MockChangesListFilter extends ChangesListFilter {
+       public function displaysOnUnstructuredUi( ChangesListSpecialPage $specialPage ) {
+               throw new MWException(
+                       'Not implemented: If the test relies on this, put it one of the ' .
+                       'subclasses\' tests (e.g. ChangesListBooleanFilterTest) ' .
+                       'instead of testing the abstract class'
+               );
+       }
+}
diff --git a/tests/phpunit/mocks/MockChangesListFilterGroup.php b/tests/phpunit/mocks/MockChangesListFilterGroup.php
new file mode 100644 (file)
index 0000000..f2891ce
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+class MockChangesListFilterGroup extends ChangesListFilterGroup {
+       public function createFilter( array $filterDefinition ) {
+               return new MockChangesListFilter( $filterDefinition );
+       }
+
+       public function registerFilter( MockChangesListFilter $filter ) {
+               $this->filters[$filter->getName()] = $filter;
+       }
+
+       public function isPerGroupRequestParameter() {
+               throw new MWException(
+                       'Not implemented: If the test relies on this, put it one of the ' .
+                       'subclasses\' tests (e.g. ChangesListBooleanFilterGroupTest) ' .
+                       'instead of testing the abstract class'
+               );
+       }
+}