4 * @covers ChangesListStringOptionsFilterGroup
6 class ChangesListStringOptionsFilterGroupTest
extends MediaWikiTestCase
{
8 * @expectedException MWException
10 public function testIsFullCoverage() {
11 $falseGroup = TestingAccessWrapper
::newFromObject(
12 new ChangesListStringOptionsFilterGroup( [
15 'isFullCoverage' => false,
16 'queryCallable' => function () {
23 $falseGroup->isFullCoverage
26 // Should throw due to missing isFullCoverage
27 $undefinedFullCoverageGroup = new ChangesListStringOptionsFilterGroup( [
28 'name' => 'othergroup',
34 * @param array $filterDefinitions Array of filter definitions
35 * @param array $expectedValues Array of values callback should receive
36 * @param string $input Value in URL
38 * @dataProvider provideModifyQuery
40 public function testModifyQuery( $filterDefinitions, $expectedValues, $input ) {
43 $queryCallable = function (
53 ) use ( $self, $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->getMock( 'IContextSource' );
187 $dbr = $this->getMock( '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,