3 use MediaWiki\Linker\LinkTarget
;
4 use MediaWiki\MediaWikiServices
;
5 use MediaWiki\Page\PageReference
;
8 * A trait providing utility functions for testing LinkCache.
9 * This trait is intended to be used on subclasses of
10 * MediaWikiIntegrationTestCase.
16 trait LinkCacheTestTrait
{
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
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,