MediaWiki REL1_32
SearchResultSetTest.php
Go to the documentation of this file.
1<?php
2
9 public function testIterate() {
10 $result = SearchResult::newFromTitle( Title::newMainPage() );
11 $resultSet = new MockSearchResultSet( [ $result ] );
12 $this->assertEquals( 1, $resultSet->numRows() );
13 $count = 0;
14 foreach ( $resultSet as $iterResult ) {
15 $this->assertEquals( $result, $iterResult );
16 $count++;
17 }
18 $this->assertEquals( 1, $count );
19
20 $this->hideDeprecated( 'SearchResultSet::rewind' );
21 $this->hideDeprecated( 'SearchResultSet::next' );
22 $resultSet->rewind();
23 $count = 0;
24 while ( false !== ( $iterResult = $resultSet->next() ) ) {
25 $this->assertEquals( $result, $iterResult );
26 $count++;
27 }
28 $this->assertEquals( 1, $count );
29 }
30
35 public function testDelayedResultAugment() {
36 $result = SearchResult::newFromTitle( Title::newMainPage() );
37 $resultSet = new MockSearchResultSet( [ $result ] );
38 $resultSet->augmentResult( $result );
39 $this->assertEquals( [], $result->getExtensionData() );
40 $resultSet->setAugmentedData( 'foo', [
41 $result->getTitle()->getArticleID() => 'bar'
42 ] );
43 $this->assertEquals( [ 'foo' => 'bar' ], $result->getExtensionData() );
44 }
45
51 public function testHasMoreResults() {
52 $result = SearchResult::newFromTitle( Title::newMainPage() );
53 $resultSet = new MockSearchResultSet( array_fill( 0, 3, $result ) );
54 $this->assertEquals( 3, count( $resultSet ) );
55 $this->assertFalse( $resultSet->hasMoreResults() );
56 $resultSet->shrink( 3 );
57 $this->assertFalse( $resultSet->hasMoreResults() );
58 $resultSet->shrink( 2 );
59 $this->assertTrue( $resultSet->hasMoreResults() );
60 }
61}
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
testHasMoreResults()
SearchResultSet::shrink SearchResultSet::count SearchResultSet::hasMoreResults.
testDelayedResultAugment()
SearchResultSet::augmentResult SearchResultSet::setAugmentedData.
testIterate()
SearchResultSet::getIterator SearchResultSet::next SearchResultSet::rewind.