summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/changes/ChangesListFilterGroupTest.php
blob: 6190516e684434427d78caaded812bbb0d9356d9 (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
<?php

/**
 * @covers ChangesListFilterGroup
 */
class ChangesListFilterGroupTest extends MediaWikiTestCase {
	/**
	 * phpcs:disable Generic.Files.LineLength
	 * @expectedException MWException
	 * @expectedExceptionMessage Group names may not contain '_'.  Use the naming convention: 'camelCase'
	 * phpcs:enable
	 */
	public function testReservedCharacter() {
		new MockChangesListFilterGroup(
			[
				'type' => 'some_type',
				'name' => 'group_name',
				'priority' => 1,
				'filters' => [],
			]
		);
	}

	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 )
			)
		);
	}

	// Get without warnings
	public function testGetFilter() {
		$group = new MockChangesListFilterGroup(
			[
				'type' => 'some_type',
				'name' => 'groupName',
				'isFullCoverage' => true,
				'priority' => 1,
				'filters' => [
					[ 'name' => 'foo' ],
				],
			]
		);

		$this->assertEquals(
			'foo',
			$group->getFilter( 'foo' )->getName()
		);

		$this->assertEquals(
			null,
			$group->getFilter( 'bar' )
		);
	}
}