summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/changes/ChangesListFilterTest.php
blob: 039658e2cfb5a2662b83e99c26e54416fdffdbc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php

use Wikimedia\TestingAccessWrapper;

/**
 * @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' => [],
			]
		);
	}

	/**
	 * phpcs:disable Generic.Files.LineLength
	 * @expectedException MWException
	 * @expectedExceptionMessage Filter names may not contain '_'.  Use the naming convention: 'lowercase'
	 * phpcs:enable
	 */
	public function testReservedCharacter() {
		$filter = new MockChangesListFilter(
			[
				'group' => $this->group,
				'name' => 'some_name',
				'priority' => 1,
			]
		);
	}

	/**
	 * @expectedException MWException
	 * @expectedExceptionMessage Two filters in a group cannot have the same name: 'somename'
	 */
	public function testDuplicateName() {
		new MockChangesListFilter(
			[
				'group' => $this->group,
				'name' => 'somename',
				'priority' => 1,
			]
		);

		new MockChangesListFilter(
			[
				'group' => $this->group,
				'name' => 'somename',
				'priority' => 2,
			]
		);
	}

	/**
	 * @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 );
	}
}