3 use Wikimedia\TestingAccessWrapper
;
6 * @covers ChangesListStringOptionsFilterGroup
8 class ChangesListStringOptionsFilterGroupTest
extends MediaWikiTestCase
{
10 * @expectedException MWException
12 public function testIsFullCoverage() {
13 $falseGroup = TestingAccessWrapper
::newFromObject(
14 new ChangesListStringOptionsFilterGroup( [
17 'isFullCoverage' => false,
18 'queryCallable' => function () {
25 $falseGroup->isFullCoverage
28 // Should throw due to missing isFullCoverage
29 $undefinedFullCoverageGroup = new ChangesListStringOptionsFilterGroup( [
30 'name' => 'othergroup',
36 * @param array $filterDefinitions Array of filter definitions
37 * @param array $expectedValues Array of values callback should receive
38 * @param string $input Value in URL
40 * @dataProvider provideModifyQuery
42 public function testModifyQuery( $filterDefinitions, $expectedValues, $input ) {
43 $queryCallable = function (
53 ) use ( $expectedValues ) {
63 'isFullCoverage' => true,
64 'filters' => $filterDefinitions,
65 'queryCallable' => $queryCallable,
68 $this->modifyQueryHelper( $groupDefinition, $input );
71 public function provideModifyQuery() {
88 'foo;bar;BaZ;invalid',
93 [ 'baz', 'foo', 'goo' ],
100 * @param array $filterDefinitions Array of filter definitions
101 * @param string $input Value in URL
102 * @param string $message Message thrown by exception
104 * @dataProvider provideNoOpModifyQuery
106 public function testNoOpModifyQuery( $filterDefinitions, $input, $message ) {
107 $noFiltersAllowedCallable = function (
116 $actualSelectedValues
118 throw new MWException( $message );
124 'isFullCoverage' => true,
125 'filters' => $filterDefinitions,
126 'queryCallable' => $noFiltersAllowedCallable,
129 $this->modifyQueryHelper( $groupDefinition, $input );
133 'Test successfully completed without calling queryCallable'
137 public function provideNoOpModifyQuery() {
152 'disallowed1;disallowed3',
153 'The queryCallable should not be called if there are no filters',
159 'The queryCallable should not be called if no filters are selected',
165 'The queryCallable should not be called if no valid filters are selected',
170 protected function getSpecialPage() {
171 return $this->getMockBuilder( 'ChangesListSpecialPage' )
172 ->setConstructorArgs( [
173 'ChangesListSpecialPage',
176 ->getMockForAbstractClass();
180 * @param array $groupDefinition Group definition
181 * @param string $input Value in URL
183 * @dataProvider provideModifyQuery
185 protected function modifyQueryHelper( $groupDefinition, $input ) {
186 $ctx = $this->createMock( 'IContextSource' );
187 $dbr = $this->createMock( 'IDatabase' );
188 $tables = $fields = $conds = $query_options = $join_conds = [];
190 $group = new ChangesListStringOptionsFilterGroup( $groupDefinition );
192 $specialPage = $this->getSpecialPage();
206 public function testGetJsData() {
208 'name' => 'some-group',
209 'title' => 'some-group-title',
212 'isFullCoverage' => false,
213 'queryCallable' => function () {
218 'label' => 'foo-label',
219 'description' => 'foo-description',
224 'label' => 'bar-label',
225 'description' => 'bar-description',
231 $group = new ChangesListStringOptionsFilterGroup( $definition );
233 $this->assertArrayEquals(
235 'name' => 'some-group',
236 'title' => 'some-group-title',
237 'type' => ChangesListStringOptionsFilterGroup
::TYPE
,
240 'fullCoverage' => false,
244 'label' => 'bar-label',
245 'description' => 'bar-description',
253 'label' => 'foo-label',
254 'description' => 'foo-description',
272 /** ordered= */ false,