X-Git-Url: https://git.heureux-cyclage.org/index.php?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fsearch%2FSearchEngineTest.php;h=9711eabb31350afa03940d3318d10a2c4fcbfdae;hb=925fe0df015458a330d320c9f1a0014d32ff8866;hp=c74c8939017c8aafc0c476e596358c1d9c77331c;hpb=3b24efab270e0f8d768ee3d390e25ae5259da431;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index c74c893901..9711eabb31 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -121,7 +121,63 @@ class SearchEngineTest extends MediaWikiLangTestCase { $this->assertEquals( [ 'Smithee' ], $this->fetchIds( $this->search->searchText( 'smithee' ) ), - "Plain search failed" ); + "Plain search" ); + } + + public function testWildcardSearch() { + $res = $this->search->searchText( 'smith*' ); + $this->assertEquals( + [ 'Smithee' ], + $this->fetchIds( $res ), + "Search with wildcards" ); + + $res = $this->search->searchText( 'smithson*' ); + $this->assertEquals( + [], + $this->fetchIds( $res ), + "Search with wildcards must not find unrelated articles" ); + + $res = $this->search->searchText( 'smith* smithee' ); + $this->assertEquals( + [ 'Smithee' ], + $this->fetchIds( $res ), + "Search with wildcards can be combined with simple terms" ); + + $res = $this->search->searchText( 'smith* "one who smiths"' ); + $this->assertEquals( + [ 'Smithee' ], + $this->fetchIds( $res ), + "Search with wildcards can be combined with phrase search" ); + } + + public function testPhraseSearch() { + $res = $this->search->searchText( '"smithee is one who smiths"' ); + $this->assertEquals( + [ 'Smithee' ], + $this->fetchIds( $res ), + "Search a phrase" ); + + $res = $this->search->searchText( '"smithee is who smiths"' ); + $this->assertEquals( + [], + $this->fetchIds( $res ), + "Phrase search is not sloppy, search terms must be adjacent" ); + + $res = $this->search->searchText( '"is smithee one who smiths"' ); + $this->assertEquals( + [], + $this->fetchIds( $res ), + "Phrase search is ordered" ); + } + + public function testPhraseSearchHighlight() { + $phrase = "smithee is one who smiths"; + $res = $this->search->searchText( "\"$phrase\"" ); + $match = $res->next(); + $snippet = "A " . $phrase . ""; + $this->assertStringStartsWith( $snippet, + $match->getTextSnippet( $res->termMatches() ), + "Highlight a phrase search" ); } public function testTextPowerSearch() { @@ -132,7 +188,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { 'Talk:Not Main Page', ], $this->fetchIds( $this->search->searchText( 'smithee' ) ), - "Power search failed" ); + "Power search" ); } public function testTitleSearch() { @@ -142,7 +198,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { 'Smithee', ], $this->fetchIds( $this->search->searchTitle( 'smithee' ) ), - "Title search failed" ); + "Title search" ); } public function testTextTitlePowerSearch() { @@ -154,7 +210,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { 'Talk:Smithee', ], $this->fetchIds( $this->search->searchTitle( 'smithee' ) ), - "Title power search failed" ); + "Title power search" ); } /**