Debian Codegraph @

tests/phpunit/integration/includes/search/SearchSuggestionSetIntegrationTest.php

raw symbols SCIP
1 <?php
2
3 /**
4 * Test for filter utilities.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 */
21
22 use MediaWiki\Title\Title;
23
24 class SearchSuggestionSetIntegrationTest extends MediaWikiIntegrationTestCase {
25 /** @return iterable */
26 public static function provideTitles(): iterable {
27 $mainspaceTitle1 = Title::makeTitle( NS_MAIN, 'Title' );
28 $mainspaceTitle1->resetArticleID( 10 );
29 yield 'Array of 1 Title with NS:0' => [ [ $mainspaceTitle1 ], 1 ];
30
31 $mainspaceTitle2 = Title::makeTitle( NS_MAIN, 'Title1' );
32 $mainspaceTitle2->resetArticleID( 20 );
33 $mainspaceTitle3 = Title::makeTitle( NS_MAIN, 'Title2' );
34 $mainspaceTitle3->resetArticleID( 30 );
35 yield 'Array of 2 Titles with NS:0' => [
36 [ $mainspaceTitle2, $mainspaceTitle3 ],
37 2
38 ];
39
40 $talkTitle = Title::makeTitle( NS_TALK, 'Test' );
41 $talkTitle->resetArticleID( 40 );
42 yield 'Array of another Title with NS:1' => [ [ $talkTitle ], 1 ];
43 }
44
45 /**
46 * NOTE: This is made an integration test because SearchSuggestion::fromText()
47 * calls Title::isValid() when following the execution and that tries to
48 * access MediaWiki services to get a Title Parser object which is not possible
49 * in a unit test as services are not available. That's why this ends up being
50 * an integration test instead.
51 *
52 * @covers \SearchSuggestionSet::fromTitles
53 * @dataProvider provideTitles
54 */
55 public function testFromTitles( array $titles, $expected ): void {
56 $actual = SearchSuggestionSet::fromTitles( $titles );
57
58 $this->assertSame( $expected, $actual->getSize() );
59 $this->assertInstanceOf( SearchSuggestionSet::class, $actual );
60 $this->assertCount( $expected, $actual->getSuggestions() );
61 }
62 }