Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/162190
Change subject: PrefixSearch: Add unit tests for StringPrefixSearch
......................................................................
PrefixSearch: Add unit tests for StringPrefixSearch
Change-Id: If0fa66b212f70ea39d2e7feec117930fcd1b9642
---
M includes/PrefixSearch.php
A tests/phpunit/includes/PrefixSearchTest.php
2 files changed, 156 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/90/162190/1
diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php
index 718750f..9511579 100644
--- a/includes/PrefixSearch.php
+++ b/includes/PrefixSearch.php
@@ -63,8 +63,7 @@
if ( $ns[0] == NS_MAIN ) {
$ns = $namespaces; // no explicit prefix, use
default namespaces
}
- return $this->searchBackend(
- $ns, $title->getText(), $limit );
+ return $this->searchBackend( $ns, $title->getText(),
$limit );
}
// Is this a namespace prefix?
diff --git a/tests/phpunit/includes/PrefixSearchTest.php
b/tests/phpunit/includes/PrefixSearchTest.php
new file mode 100644
index 0000000..5abf83e
--- /dev/null
+++ b/tests/phpunit/includes/PrefixSearchTest.php
@@ -0,0 +1,155 @@
+<?php
+/**
+ * @group Search
+ * @group Database
+ */
+class PrefixSearchTest extends MediaWikiTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ // Avoid special pages from extensions interferring with the
tests
+ $this->setMwGlobals( 'wgSpecialPages', array() );
+ }
+
+ protected function searchProvision( Array $results = null ) {
+ if ( $results === null ) {
+ $this->setMwGlobals( 'wgHooks', array() );
+ } else {
+ $this->setMwGlobals( 'wgHooks', array(
+ 'PrefixSearchBackend' => array(
+ function ( $namespaces, $search,
$limit, &$srchres ) use ( $results ) {
+ $srchres = $results;
+ return false;
+ }
+ ),
+ ) );
+ }
+ }
+
+ public function addDBData() {
+ $this->insertPage( 'Sandbox' );
+
+ $this->insertPage( 'Example' );
+ $this->insertPage( 'Example Bar' );
+ $this->insertPage( 'Example Foo' );
+ $this->insertPage( 'Example Foo/Bar' );
+ $this->insertPage( 'Example/Baz' );
+
+ $this->insertPage( 'Talk:Sandbox' );
+ $this->insertPage( 'Talk:Example' );
+
+ $this->insertPage( 'User:Example' );
+ }
+
+ /**
+ * @covers PrefixSearch::search
+ * @covers PrefixSearch::searchBackend
+ */
+ public function testSearch() {
+ $this->searchProvision( null );
+ $searcher = new StringPrefixSearch;
+ $results = $searcher->search( '', 3 );
+ $this->assertEquals(
+ array(),
+ $results,
+ 'Empty string'
+ );
+
+ $this->searchProvision( null );
+ $searcher = new StringPrefixSearch;
+ $results = $searcher->search( 'Ex', 3 );
+ $this->assertEquals(
+ array(
+ 'Example',
+ 'Example/Baz',
+ 'Example Bar',
+ ),
+ $results,
+ 'Main namespace with title prefix'
+ );
+
+ $this->searchProvision( null );
+ $searcher = new StringPrefixSearch;
+ $results = $searcher->search( 'Talk:', 3 );
+ $this->assertEquals(
+ array(
+ 'Talk:Example',
+ 'Talk:Sandbox',
+ ),
+ $results,
+ 'Talk namespace prefix'
+ );
+
+ $this->searchProvision( null );
+ $searcher = new StringPrefixSearch;
+ $results = $searcher->search( 'User:', 3 );
+ $this->assertEquals(
+ array(
+ 'User:Example',
+ ),
+ $results,
+ 'User namespace prefix'
+ );
+
+ $this->searchProvision( null );
+ $searcher = new StringPrefixSearch;
+ $results = $searcher->search( 'Special:', 3 );
+ $this->assertEquals(
+ array(
+ 'Special:ActiveUsers',
+ 'Special:AllMessages',
+ 'Special:AllMyFiles',
+ ),
+ $results,
+ 'Special namespace prefix'
+ );
+
+ $this->searchProvision( null );
+ $searcher = new StringPrefixSearch;
+ $results = $searcher->search( 'Special:Un', 3 );
+ $this->assertEquals(
+ array(
+ 'Special:Unblock',
+ 'Special:UncategorizedCategories',
+ 'Special:UncategorizedFiles',
+ ),
+ $results,
+ 'Special namespace with prefix'
+ );
+
+ $this->searchProvision( null );
+ $searcher = new StringPrefixSearch;
+ $results = $searcher->search( 'Special:EditWatchlist', 3 );
+ $this->assertEquals(
+ array(
+ 'Special:EditWatchlist',
+ ),
+ $results,
+ 'Special page name'
+ );
+
+ $this->searchProvision( null );
+ $searcher = new StringPrefixSearch;
+ $results = $searcher->search( 'Special:EditWatchlist/', 3 );
+ $this->assertEquals(
+ array(
+ 'Special:EditWatchlist/clear',
+ 'Special:EditWatchlist/raw',
+ ),
+ $results,
+ 'Special page subpages'
+ );
+
+ $this->searchProvision( null );
+ $searcher = new StringPrefixSearch;
+ $results = $searcher->search( 'Special:EditWatchlist/cl', 3 );
+ $this->assertEquals(
+ array(
+ 'Special:EditWatchlist/clear',
+ ),
+ $results,
+ 'Special page subpages with prefix'
+ );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/162190
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If0fa66b212f70ea39d2e7feec117930fcd1b9642
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits