'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",
);
}
- 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',
);
}
- /**
- * @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( [
--- /dev/null
+<?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 )
+ )
+ );
+ }
+}
--- /dev/null
+<?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 );
+ }
+}
--- /dev/null
+<?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'
+ );
+ }
+}
--- /dev/null
+<?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'
+ );
+ }
+}