Skip to content

Commit

Permalink
Remove search functionality, refs 75 (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Mar 29, 2020
1 parent dab4204 commit bd7180d
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 219 deletions.
9 changes: 0 additions & 9 deletions SemanticInterlanguageLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,4 @@ public static function onExtensionFunction() {
$hookRegistry->register();
}

/**
* @since 1.3
*
* @return string|null
*/
public static function getVersion() {
return SIL_VERSION;
}

}
73 changes: 0 additions & 73 deletions src/HookRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ private function addCallbackHandlers( $store, $cache, $cacheKeyProvider ) {
};

$this->registerInterlanguageParserHooks( $interlanguageLinksLookup );
$this->registerSpecialSearchHooks( $interlanguageLinksLookup );
}

private function registerInterlanguageParserHooks( InterlanguageLinksLookup $interlanguageLinksLookup ) {
Expand Down Expand Up @@ -265,77 +264,5 @@ private function registerInterlanguageParserHooks( InterlanguageLinksLookup $int
};
}

private function registerSpecialSearchHooks( InterlanguageLinksLookup $interlanguageLinksLookup ) {

$searchResultModifier = new SearchResultModifier(
new LanguageResultMatchFinder( $interlanguageLinksLookup )
);

/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SpecialSearchProfiles
*/
$this->handlers['SpecialSearchProfiles'] = function ( array &$profiles ) use ( $searchResultModifier ) {

$searchResultModifier->addSearchProfile(
$profiles
);

return true;
};

/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SpecialSearchProfileForm
*/
$this->handlers['SpecialSearchProfileForm'] = function ( $search, &$form, $profile, $term, $opts ) use ( $searchResultModifier ) {

$searchResultModifier->addSearchProfileForm(
$search,
$profile,
$form,
$opts
);

return true;
};

/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SpecialSearchPowerBox
*/
$this->handlers['SpecialSearchPowerBox'] = function ( &$showSections, $term, $opts ) use ( $searchResultModifier ) {

$searchResultModifier->addLanguageFilterToPowerBox(
$GLOBALS['wgRequest'],
$showSections
);

return true;
};

/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SpecialSearchSetupEngine
*/
$this->handlers['SpecialSearchSetupEngine'] = function ( \SpecialSearch $search, $profile, \SearchEngine $searchEngine ) use ( $searchResultModifier ) {

if ( $search->getContext()->getRequest()->getVal( 'nsflag') ) {
$searchEngine->setNamespaces( \SearchEngine::defaultNamespaces() );
}

return true;
};

/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/SpecialSearchResults
*/
$this->handlers['SpecialSearchResults'] = function ( $term, &$titleMatches, &$textMatches ) use ( $searchResultModifier ) {

$searchResultModifier->applyLanguageFilterToResultMatches(
$GLOBALS['wgRequest'],
$titleMatches,
$textMatches
);

return true;
};
}

}
8 changes: 6 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
die( 'The Semantic MediaWiki test autoloader is not available' );
}

if ( !class_exists( 'SemanticInterlanguageLinks' ) || ( $version = SemanticInterlanguageLinks::getVersion() ) === null ) {
if ( !class_exists( 'SemanticInterlanguageLinks' ) || !defined( 'SIL_VERSION' ) ) {
die( "\nSemantic Interlanguage Links is not available, please check your Composer or LocalSettings.\n" );
}

print sprintf( "\n%-27s%s\n", "Semantic Interlanguage Links: ", $version );
if ( !defined( 'SMW_PHPUNIT_FIRST_COLUMN_WIDTH' ) ) {
define( 'SMW_PHPUNIT_FIRST_COLUMN_WIDTH', 30 );
}

print sprintf( "\n%-27s%s\n", "Semantic Interlanguage Links: ", SIL_VERSION );

$autoloader = require $autoloaderClassPath;
$autoloader->addPsr4( 'SIL\\Tests\\', __DIR__ . '/phpunit/Unit' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class LanguageFilterCategoryViewerIntegrationTest extends MwDBaseUnitTestCase {
private $pageCreator;
private $subjects = [];

protected function setUp() {
protected function setUp() : void {
parent::setUp();

$this->pageCreator = UtilityFactory::getInstance()->newpageCreator();
}

protected function tearDown() {
protected function tearDown() : void {

UtilityFactory::getInstance()
->newPageDeleter()
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/Integration/ParserFunctionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ParserFunctionIntegrationTest extends MwDBaseUnitTestCase {
private $semanticDataValidator;
private $subjects = [];

protected function setUp() {
protected function setUp() : void {
parent::setUp();

$this->markTestSkipped(
Expand Down Expand Up @@ -58,7 +58,7 @@ protected function setUp() {
};
}

protected function tearDown() {
protected function tearDown() : void {

UtilityFactory::getInstance()->newPageDeleter()->doDeletePoolOfPages( $this->subjects );
unset( $GLOBALS['wgHooks']['InterwikiLoadPrefix'] );
Expand Down
127 changes: 0 additions & 127 deletions tests/phpunit/Unit/HookRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ public function testRegister() {
$this->doTestInitProperties( $instance );
$this->doTestSQLStoreBeforeDeleteSubjectCompletes( $instance );
$this->doTestSQLStoreBeforeChangeTitleComplete( $instance );

$this->doTestSpecialSearchProfiles( $instance );
$this->doTestSpecialSearchProfileForm( $instance );
$this->doTestSpecialSearchResults( $instance );
$this->doTestSpecialSearchSetupEngine( $instance );
$this->doTestSpecialSearchPowerBox( $instance );
}

public function testOnBeforeConfigCompletion() {
Expand Down Expand Up @@ -283,127 +277,6 @@ public function doTestSQLStoreBeforeChangeTitleComplete( $instance ) {
);
}

public function doTestSpecialSearchProfiles( $instance ) {

$handler = 'SpecialSearchProfiles';
$profiles = [];

$this->assertTrue(
$instance->isRegistered( $handler )
);

$this->assertThatHookIsExcutable(
$instance->getHandlerFor( $handler ),
[ &$profiles ]
);
}

public function doTestSpecialSearchProfileForm( $instance ) {

$handler = 'SpecialSearchProfileForm';

$search = $this->getMockBuilder( '\SpecialSearch' )
->disableOriginalConstructor()
->getMock();

$form = '';
$profile = '';
$term = '';
$opts = [];

$this->assertTrue(
$instance->isRegistered( $handler )
);

$this->assertThatHookIsExcutable(
$instance->getHandlerFor( $handler ),
[ $search, &$form, $profile, $term, $opts ]
);
}

public function doTestSpecialSearchResults( $instance ) {

$handler = 'SpecialSearchResults';

$search = $this->getMockBuilder( '\SpecialSearch' )
->disableOriginalConstructor()
->getMock();

$titleMatches = false;
$textMatches = false;

$this->assertTrue(
$instance->isRegistered( $handler )
);

$this->assertThatHookIsExcutable(
$instance->getHandlerFor( $handler ),
[ $search, &$titleMatches, &$textMatches ]
);
}

public function doTestSpecialSearchSetupEngine( $instance ) {

$handler = 'SpecialSearchSetupEngine';

$profile = [];

$request = $this->getMockBuilder( '\WebRequest' )
->disableOriginalConstructor()
->getMock();

$request->expects( $this->once() )
->method( 'getVal' )
->will( $this->returnValue( true ) );

$context = $this->getMockBuilder( '\RequestContext' )
->disableOriginalConstructor()
->getMock();

$context->expects( $this->once() )
->method( 'getRequest' )
->will( $this->returnValue( $request ) );

$search = $this->getMockBuilder( '\SpecialSearch' )
->disableOriginalConstructor()
->getMock();

$search->expects( $this->once() )
->method( 'getContext' )
->will( $this->returnValue( $context ) );

$searchEngine = $this->getMockBuilder( '\SearchEngine' )
->disableOriginalConstructor()
->getMock();

$searchEngine->expects( $this->once() )
->method( 'setNamespaces' );

$this->assertTrue(
$instance->isRegistered( $handler )
);

$this->assertThatHookIsExcutable(
$instance->getHandlerFor( $handler ),
[ $search, $profile, $searchEngine ]
);
}

public function doTestSpecialSearchPowerBox( $instance ) {

$handler = 'SpecialSearchPowerBox';
$showSections = [];

$this->assertTrue(
$instance->isRegistered( $handler )
);

$this->assertThatHookIsExcutable(
$instance->getHandlerFor( $handler ),
[ &$showSections, '', [] ]
);
}

private function assertThatHookIsExcutable( \Closure $handler, $arguments ) {
$this->assertInternalType(
'boolean',
Expand Down
4 changes: 0 additions & 4 deletions tests/phpunit/Unit/LanguageLinkAnnotatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ public function testCanAddAnnotation() {
->disableOriginalConstructor()
->getMock();

$parserData->expects( $this->any() )
->method( 'canModifySemanticData' )
->will( $this->returnValue( false ) );

// SMW 3.0
$parserData->expects( $this->any() )
->method( 'canUse' )
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/Unit/Search/MappedSearchResultSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
*/
class MappedSearchResultSetTest extends \PHPUnit_Framework_TestCase {

protected function setUp() : void {
$this->markTestSkipped( 'The each() function is deprecated. This message will be suppressed on further calls' );
}

public function testCanConstruct() {

$searchMatches = [];
Expand Down

0 comments on commit bd7180d

Please sign in to comment.