From 6ecc3fd4fcff51e81b3df9e3141c3500fad3cc4b Mon Sep 17 00:00:00 2001 From: Paladox Date: Thu, 14 Nov 2019 14:10:56 +0000 Subject: [PATCH] Fix tests to be compatible with master again Also fix tests relying on MessageCache. MessageCache is enabled in setup, however, as setMwGlobals is resetting services, it gets disabled again. Instead of setting the configuration to enable the use of database messages, let's enable the message cache after the last reset of services. Change-Id: Iff670def50ab15054099f7a1ca3adc119bd877ce --- composer.json | 2 +- includes/Decisions.php | 2 +- tests/phpunit/includes/HooksTest.php | 22 ++++++++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index bf0b315..0bf76a9 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "require-dev": { "jakub-onderka/php-parallel-lint": "1.0.0", - "mediawiki/mediawiki-codesniffer": "26.0.0", + "mediawiki/mediawiki-codesniffer": "28.0.0", "jakub-onderka/php-console-highlighter": "0.3.2", "mediawiki/minus-x": "0.3.1" }, diff --git a/includes/Decisions.php b/includes/Decisions.php index b0b9b46..4629e8a 100644 --- a/includes/Decisions.php +++ b/includes/Decisions.php @@ -13,7 +13,7 @@ class Decisions { private $geoLocation; private $cache; - const CACHE_KEY = 'cookieWarningIpLookupCache:'; + private const CACHE_KEY = 'cookieWarningIpLookupCache:'; /** * @param Config $config diff --git a/tests/phpunit/includes/HooksTest.php b/tests/phpunit/includes/HooksTest.php index 6881d9d..a20cd5c 100644 --- a/tests/phpunit/includes/HooksTest.php +++ b/tests/phpunit/includes/HooksTest.php @@ -2,12 +2,14 @@ namespace CookieWarning\Tests; +use CommentStoreComment; use CookieWarning\GeoLocation; use CookieWarning\Hooks; use DerivativeContext; use FauxRequest; +use MediaWiki\MediaWikiServices; +use MediaWiki\Revision\SlotRecord; use MediaWikiLangTestCase; -use MessageCache; use RequestContext; use SkinTemplate; use Title; @@ -19,13 +21,6 @@ use WikitextContent; * @group Database */ class HooksTest extends MediaWikiLangTestCase { - /** - * @throws \MWException - */ - protected function setUp() { - parent::setUp(); - MessageCache::singleton()->enable(); - } /** * @dataProvider providerOnSkinTemplateOutputPageBeforeExec @@ -41,17 +36,20 @@ class HooksTest extends MediaWikiLangTestCase { 'wgCookieWarningForCountryCodes' => false, 'wgUseMediaWikiUIEverywhere' => true, ] ); + MediaWikiServices::getInstance()->getMessageCache()->enable(); if ( $morelinkCookieWarningMsg ) { $title = Title::newFromText( 'cookiewarning-more-link', NS_MEDIAWIKI ); $wikiPage = WikiPage::factory( $title ); - $wikiPage->doEditContent( new WikitextContent( $morelinkCookieWarningMsg ), - "CookieWarning test" ); + $pageUpdater = $wikiPage->newPageUpdater( \User::newFromName( 'UTSysop' ) ); + $pageUpdater->setContent( SlotRecord::MAIN, new WikitextContent( $morelinkCookieWarningMsg ) ); + $pageUpdater->saveRevision( CommentStoreComment::newUnsavedComment( 'CookieWarning test' ) ); } if ( $morelinkCookiePolicyMsg ) { $title = Title::newFromText( 'cookie-policy-link', NS_MEDIAWIKI ); $wikiPage = WikiPage::factory( $title ); - $wikiPage->doEditContent( new WikitextContent( $morelinkCookiePolicyMsg ), - "CookieWarning test" ); + $pageUpdater = $wikiPage->newPageUpdater( \User::newFromName( 'UTSysop' ) ); + $pageUpdater->setContent( SlotRecord::MAIN, new WikitextContent( $morelinkCookiePolicyMsg ) ); + $pageUpdater->saveRevision( CommentStoreComment::newUnsavedComment( 'CookieWarning test' ) ); } $sk = new SkinTemplate(); $tpl = new \SkinFallbackTemplate();