MediaWiki  1.29.1
ParserOutputSearchDataExtractorTest.php
Go to the documentation of this file.
1 <?php
2 
4 
10 
11  public function testGetCategories() {
12  $categories = [
13  'Foo_bar' => 'Bar',
14  'New_page' => ''
15  ];
16 
17  $parserOutput = new ParserOutput( '', [], $categories );
18 
19  $searchDataExtractor = new ParserOutputSearchDataExtractor();
20 
21  $this->assertEquals(
22  [ 'Foo bar', 'New page' ],
23  $searchDataExtractor->getCategories( $parserOutput )
24  );
25  }
26 
27  public function testGetExternalLinks() {
29 
30  $parserOutput->addExternalLink( 'https://foo' );
31  $parserOutput->addExternalLink( 'https://bar' );
32 
33  $searchDataExtractor = new ParserOutputSearchDataExtractor();
34 
35  $this->assertEquals(
36  [ 'https://foo', 'https://bar' ],
37  $searchDataExtractor->getExternalLinks( $parserOutput )
38  );
39  }
40 
41  public function testGetOutgoingLinks() {
43 
44  $parserOutput->addLink( Title::makeTitle( NS_MAIN, 'Foo_bar' ), 1 );
45  $parserOutput->addLink( Title::makeTitle( NS_HELP, 'Contents' ), 2 );
46 
47  $searchDataExtractor = new ParserOutputSearchDataExtractor();
48 
49  // this indexes links with db key
50  $this->assertEquals(
51  [ 'Foo_bar', 'Help:Contents' ],
52  $searchDataExtractor->getOutgoingLinks( $parserOutput )
53  );
54  }
55 
56  public function testGetTemplates() {
57  $title = Title::makeTitle( NS_TEMPLATE, 'Cite_news' );
58 
60  $parserOutput->addTemplate( $title, 10, 100 );
61 
62  $searchDataExtractor = new ParserOutputSearchDataExtractor();
63 
64  $this->assertEquals(
65  [ 'Template:Cite news' ],
66  $searchDataExtractor->getTemplates( $parserOutput )
67  );
68  }
69 
70 }
ParserOutput
Definition: ParserOutput.php:24
NS_HELP
const NS_HELP
Definition: Defines.php:74
ParserOutputSearchDataExtractorTest\testGetOutgoingLinks
testGetOutgoingLinks()
Definition: ParserOutputSearchDataExtractorTest.php:41
ParserOutputSearchDataExtractorTest\testGetExternalLinks
testGetExternalLinks()
Definition: ParserOutputSearchDataExtractorTest.php:27
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
NS_TEMPLATE
const NS_TEMPLATE
Definition: Defines.php:72
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
NS_MAIN
const NS_MAIN
Definition: Defines.php:62
MediaWiki\Search\ParserOutputSearchDataExtractor
Extracts data from ParserOutput for indexing in the search engine.
Definition: ParserOutputSearchDataExtractor.php:29
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
ParserOutputSearchDataExtractorTest\testGetCategories
testGetCategories()
Definition: ParserOutputSearchDataExtractorTest.php:11
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:514
ParserOutputSearchDataExtractorTest\testGetTemplates
testGetTemplates()
Definition: ParserOutputSearchDataExtractorTest.php:56
ParserOutputSearchDataExtractorTest
Search MediaWiki\Search\ParserOutputSearchDataExtractor.
Definition: ParserOutputSearchDataExtractorTest.php:9
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
$parserOutput
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context $parserOutput
Definition: hooks.txt:1049