MediaWiki  1.33.0
RefreshLinksJobTest.php
Go to the documentation of this file.
1 <?php
3 
14 
15  public function setUp() {
16  parent::setUp();
17 
18  $this->tablesUsed[] = 'page';
19  $this->tablesUsed[] = 'revision';
20 
21  $this->tablesUsed[] = 'pagelinks';
22  $this->tablesUsed[] = 'categorylinks';
23  }
24 
31  private function createPage( $name, array $content ) {
33  $page = WikiPage::factory( $title );
34 
35  $updater = $page->newPageUpdater( $this->getTestUser()->getUser() );
36 
37  foreach ( $content as $slot => $cnt ) {
38  $updater->setContent( $slot, $cnt );
39  }
40 
41  $updater->saveRevision( CommentStoreComment::newUnsavedComment( 'Test' ) );
42 
43  return $page;
44  }
45 
46  // TODO: test multi-page
47  // TODO: test recursive
48  // TODO: test partition
49 
50  public function testRunForSinglePage() {
51  MediaWikiServices::getInstance()->getSlotRoleRegistry()->defineRoleWithModel(
52  'aux',
54  );
55 
56  $mainContent = new WikitextContent( 'MAIN [[Kittens]]' );
57  $auxContent = new WikitextContent( 'AUX [[Category:Goats]]' );
58  $page = $this->createPage( __METHOD__, [ 'main' => $mainContent, 'aux' => $auxContent ] );
59 
60  // clear state
61  $parserCache = MediaWikiServices::getInstance()->getParserCache();
62  $parserCache->deleteOptionsKey( $page );
63 
64  $this->db->delete( 'pagelinks', '*', __METHOD__ );
65  $this->db->delete( 'categorylinks', '*', __METHOD__ );
66 
67  // run job
68  $job = new RefreshLinksJob( $page->getTitle(), [ 'parseThreshold' => 0 ] );
69  $job->run();
70 
71  // assert state
72  $options = ParserOptions::newCanonical( 'canonical' );
73  $out = $parserCache->get( $page, $options );
74  $this->assertNotFalse( $out, 'parser cache entry' );
75 
76  $text = $out->getText();
77  $this->assertContains( 'MAIN', $text );
78  $this->assertContains( 'AUX', $text );
79 
80  $this->assertSelect(
81  'pagelinks',
82  'pl_title',
83  [ 'pl_from' => $page->getId() ],
84  [ [ 'Kittens' ] ]
85  );
86  $this->assertSelect(
87  'categorylinks',
88  'cl_to',
89  [ 'cl_from' => $page->getId() ],
90  [ [ 'Goats' ] ]
91  );
92  }
93 
94 }
RefreshLinksJobTest\createPage
createPage( $name, array $content)
Definition: RefreshLinksJobTest.php:31
CommentStoreComment\newUnsavedComment
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
Definition: CommentStoreComment.php:66
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:180
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:780
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:235
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
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
RefreshLinksJobTest\setUp
setUp()
Definition: RefreshLinksJobTest.php:15
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MediaWikiTestCase\assertSelect
assertSelect( $table, $fields, $condition, array $expectedRows, array $options=[], array $join_conds=[])
Asserts that the given database query yields the rows given by $expectedRows.
Definition: MediaWikiTestCase.php:2000
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
MediaWikiTestCase\getDefaultWikitextNS
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
Definition: MediaWikiTestCase.php:2211
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:36
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
RefreshLinksJob
Job to update link tables for pages.
Definition: RefreshLinksJob.php:39
ParserOptions\newCanonical
static newCanonical( $context=null, $userLang=null)
Creates a "canonical" ParserOptions object.
Definition: ParserOptions.php:1064
RefreshLinksJobTest
RefreshLinksJob.
Definition: RefreshLinksJobTest.php:13
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1985
$job
if(count( $args)< 1) $job
Definition: recompressTracked.php:49
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$updater
$page->newPageUpdater($user) $updater
Definition: pageupdater.txt:63
$content
$content
Definition: pageupdater.txt:72
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
RefreshLinksJobTest\testRunForSinglePage
testRunForSinglePage()
Definition: RefreshLinksJobTest.php:50