Merge "RCFilters: Don't allow underscore in filter or group names"
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / ChangesListFilterTest.php
1 <?php
2
3 /**
4 * @covers ChangesListFilter
5 */
6 class ChangesListFilterTest extends MediaWikiTestCase {
7 protected $group;
8
9 public function setUp() {
10 $this->group = $this->getGroup( [ 'name' => 'group' ] );
11
12 parent::setUp();
13 }
14
15 protected function getGroup( $groupDefinition ) {
16 return new MockChangesListFilterGroup(
17 $groupDefinition + [
18 'isFullCoverage' => true,
19 'type' => 'some_type',
20 'name' => 'group',
21 'filters' => [],
22 ]
23 );
24
25 }
26
27 // @codingStandardsIgnoreStart
28 /**
29 * @expectedException MWException
30 * @expectedExceptionMessage Filter names may not contain '_'. Use the naming convention: 'lowercase'
31 */
32 // @codingStandardsIgnoreEnd
33 public function testReservedCharacter() {
34 $filter = new MockChangesListFilter(
35 [
36 'group' => $this->group,
37 'name' => 'some_name',
38 'priority' => 1,
39 ]
40 );
41 }
42
43 /**
44 * @expectedException MWException
45 * @expectedExceptionMessage Supersets can only be defined for filters in the same group
46 */
47 public function testSetAsSupersetOf() {
48 $groupA = $this->getGroup(
49 [
50 'name' => 'groupA',
51 'filters' => [
52 [
53 'name' => 'foo',
54 ],
55 [
56 'name' => 'bar',
57 ]
58 ],
59 ]
60 );
61
62 $groupB = $this->getGroup(
63 [
64 'name' => 'groupB',
65 'filters' => [
66 [
67 'name' => 'baz',
68 ],
69 ],
70 ]
71 );
72
73 $foo = TestingAccessWrapper::newFromObject( $groupA->getFilter( 'foo' ) );
74
75 $bar = $groupA->getFilter( 'bar' );
76
77 $baz = $groupB->getFilter( 'baz' );
78
79 $foo->setAsSupersetOf( $bar );
80 $this->assertArrayEquals( [
81 [
82 'group' => 'groupA',
83 'filter' => 'bar',
84 ],
85 ],
86 $foo->subsetFilters,
87 /** ordered= */ false,
88 /** named= */ true
89 );
90
91 $foo->setAsSupersetOf( $baz );
92 }
93 }