| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Title\Title; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class FauxSearchResultSetTest extends MediaWikiUnitTestCase { |
| 10 |
|
| 11 |
public function testConstruct() { |
| 12 |
$titles = array_map( [ $this, 'getTitleMock' ], [ 'Foo', 'Bar', 'Baz' ] ); |
| 13 |
$rs = new FauxSearchResultSet( $titles ); |
| 14 |
$titleTexts = []; |
| 15 |
foreach ( $rs as $result ) { |
| 16 |
|
| 17 |
$titleTexts[] = $result->getTitle()->getPrefixedText(); |
| 18 |
} |
| 19 |
$this->assertSame( [ 'Foo', 'Bar', 'Baz' ], $titleTexts ); |
| 20 |
$this->assertSame( $titles, $rs->extractTitles() ); |
| 21 |
} |
| 22 |
|
| 23 |
public function testGetTotalHits() { |
| 24 |
$titles = array_map( [ $this, 'getTitleMock' ], [ 'Foo', 'Bar', 'Baz' ] ); |
| 25 |
$rs = new FauxSearchResultSet( $titles ); |
| 26 |
$this->assertSame( 3, $rs->getTotalHits() ); |
| 27 |
$this->assertFalse( $rs->hasMoreResults() ); |
| 28 |
|
| 29 |
$rs = new FauxSearchResultSet( $titles, 5 ); |
| 30 |
$this->assertCount( 3, $rs ); |
| 31 |
$this->assertSame( 5, $rs->getTotalHits() ); |
| 32 |
$this->assertTrue( $rs->hasMoreResults() ); |
| 33 |
|
| 34 |
$rs = new FauxSearchResultSet( $titles, 3 ); |
| 35 |
$this->assertFalse( $rs->hasMoreResults() ); |
| 36 |
$rs = new FauxSearchResultSet( $titles, 1 ); |
| 37 |
$this->assertSame( 3, $rs->getTotalHits() ); |
| 38 |
$this->assertFalse( $rs->hasMoreResults() ); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
private function getTitleMock( $titleText ) { |
| 46 |
$title = $this->getMockBuilder( Title::class ) |
| 47 |
->disableOriginalConstructor() |
| 48 |
->onlyMethods( [ 'getPrefixedText' ] ) |
| 49 |
->getMock(); |
| 50 |
$title->method( 'getPrefixedText' )->willReturn( $titleText ); |
| 51 |
return $title; |
| 52 |
} |
| 53 |
|
| 54 |
} |