Merge "AutoLoader: Use require_once rather than require"
[mediawiki.git] / tests / phpunit / includes / cache / LinkCacheTestTrait.php
blob6872d00e14387dd6cbbf6f51e6ebe87c9fa2ff5a
1 <?php
3 use MediaWiki\Linker\LinkTarget;
4 use MediaWiki\MediaWikiServices;
5 use MediaWiki\Page\PageReference;
7 /**
8 * A trait providing utility functions for testing LinkCache.
9 * This trait is intended to be used on subclasses of
10 * MediaWikiIntegrationTestCase.
12 * @stable to use
13 * @since 1.37
16 trait LinkCacheTestTrait {
18 /**
19 * Force information about a page into the cache, pretending it exists.
21 * @param int $id Page's ID
22 * @param LinkTarget|PageReference $page The page to set cached info for.
23 * @param int $len Text's length
24 * @param int|null $redir Whether the page is a redirect
25 * @param int $revision Latest revision's ID
26 * @param string|null $model Latest revision's content model ID
27 * @param string|null $lang Language code of the page, if not the content language
29 public function addGoodLinkObject(
30 $id, $page, $len = -1, $redir = null, $revision = 0, $model = null, $lang = null
31 ) {
32 MediaWikiServices::getInstance()->getLinkCache()->addGoodLinkObjFromRow( $page, (object)[
33 'page_id' => (int)$id,
34 'page_namespace' => $page->getNamespace(),
35 'page_title' => $page->getDBkey(),
36 'page_len' => (int)$len,
37 'page_is_redirect' => (int)$redir,
38 'page_latest' => (int)$revision,
39 'page_content_model' => $model ? (string)$model : null,
40 'page_lang' => $lang ? (string)$lang : null,
41 'page_is_new' => 0,
42 'page_touched' => '',
43 ] );