Merge "Change Title::getPreviousRevisionID (and next) to ignore PRIMARY"
[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 // @codingStandardsIgnoreStart
44 /**
45 * @expectedException MWException
46 * @expectedExceptionMessage Two filters in a group cannot have the same name: 'somename'
47 */
48 // @codingStandardsIgnoreEnd
49 public function testDuplicateName() {
50 new MockChangesListFilter(
51 [
52 'group' => $this->group,
53 'name' => 'somename',
54 'priority' => 1,
55 ]
56 );
57
58 new MockChangesListFilter(
59 [
60 'group' => $this->group,
61 'name' => 'somename',
62 'priority' => 2,
63 ]
64 );
65 }
66
67 /**
68 * @expectedException MWException
69 * @expectedExceptionMessage Supersets can only be defined for filters in the same group
70 */
71 public function testSetAsSupersetOf() {
72 $groupA = $this->getGroup(
73 [
74 'name' => 'groupA',
75 'filters' => [
76 [
77 'name' => 'foo',
78 ],
79 [
80 'name' => 'bar',
81 ]
82 ],
83 ]
84 );
85
86 $groupB = $this->getGroup(
87 [
88 'name' => 'groupB',
89 'filters' => [
90 [
91 'name' => 'baz',
92 ],
93 ],
94 ]
95 );
96
97 $foo = TestingAccessWrapper::newFromObject( $groupA->getFilter( 'foo' ) );
98
99 $bar = $groupA->getFilter( 'bar' );
100
101 $baz = $groupB->getFilter( 'baz' );
102
103 $foo->setAsSupersetOf( $bar );
104 $this->assertArrayEquals( [
105 [
106 'group' => 'groupA',
107 'filter' => 'bar',
108 ],
109 ],
110 $foo->subsetFilters,
111 /** ordered= */ false,
112 /** named= */ true
113 );
114
115 $foo->setAsSupersetOf( $baz );
116 }
117 }