mediawiki-extensions-Cookie.../tests/phpunit/includes/CookieWarningHooksTest.php
Florian Schmidt 2fa9bb87b0 Unbreak geolocation tests
The freegeoip.net service is shutdown since... a while.

There's currently no alternative, apart from ones where you need an API
key. As I don't want to provide an API key in the CI, and this is a
release branch, I simply remove the tests. The same will most likely be
done in master, but I need to think about removing this feature
altogether, if untested.

Change-Id: I1c5783aae290af5fdcb39f44ac1e832fa5edb6db
2021-01-05 19:39:32 +01:00

121 lines
3.2 KiB
PHP

<?php
/**
* @covers CookieWarningHooks
* @group Database
*/
class CookieWarningHooksTest extends MediaWikiLangTestCase {
protected function setUp() {
parent::setUp();
MessageCache::singleton()->enable();
}
/**
* @dataProvider providerOnSkinTemplateOutputPageBeforeExec
*/
public function testOnSkinTemplateOutputPageBeforeExec( $enabled, $morelinkConfig,
$morelinkCookieWarningMsg, $morelinkCookiePolicyMsg, $expectedLink
) {
$this->setMwGlobals( [
'wgCookieWarningEnabled' => $enabled,
'wgCookieWarningMoreUrl' => $morelinkConfig,
'wgCookieWarningForCountryCodes' => false,
] );
if ( $morelinkCookieWarningMsg ) {
$title = Title::newFromText( 'cookiewarning-more-link', NS_MEDIAWIKI );
$wikiPage = WikiPage::factory( $title );
$wikiPage->doEditContent( new WikitextContent( $morelinkCookieWarningMsg ),
"CookieWarning test" );
}
if ( $morelinkCookiePolicyMsg ) {
$title = Title::newFromText( 'cookie-policy-link', NS_MEDIAWIKI );
$wikiPage = WikiPage::factory( $title );
$wikiPage->doEditContent( new WikitextContent( $morelinkCookiePolicyMsg ),
"CookieWarning test" );
}
$sk = new SkinTemplate();
$tpl = new CookieWarningTestTemplate();
CookieWarningHooks::onSkinTemplateOutputPageBeforeExec( $sk, $tpl );
$headElement = '';
if ( isset( $tpl->data['headelement'] ) ) {
$headElement = $tpl->data['headelement'];
}
if ( $expectedLink === false ) {
$expected = '';
} else {
// @codingStandardsIgnoreStart Generic.Files.LineLength
$expected =
str_replace( '$1', $expectedLink,
'<div class="mw-cookiewarning-container"><div class="mw-cookiewarning-text"><span>Cookies help us deliver our services. By using our services, you agree to our use of cookies.</span>$1<form method="POST"><input name="disablecookiewarning" class="mw-cookiewarning-dismiss" type="submit" value="OK"/></form></div></div>' );
// @codingStandardsIgnoreEnd
}
$this->assertEquals( $expected, $headElement );
}
public function providerOnSkinTemplateOutputPageBeforeExec() {
return [
[
// $wgCookieWarningEnabled
true,
// $wgCookieWarningMoreUrl
'',
// MediaWiki:Cookiewarning-more-link
false,
// MediaWiki:Cookie-policy-link
false,
// expected cookie warning link (when string), nothing if false
'',
],
[
false,
'',
false,
false,
false,
],
[
true,
'http://google.de',
false,
false,
'&#160;<a href="http://google.de">More information</a>',
],
[
true,
'',
'http://google.de',
false,
'&#160;<a href="http://google.de">More information</a>',
],
[
true,
'',
false,
'http://google.de',
'&#160;<a href="http://google.de">More information</a>',
],
// the config should be the used, if set (no matter if the messages are used or not)
[
true,
'http://google.de',
false,
'http://google123.de',
'&#160;<a href="http://google.de">More information</a>',
],
[
true,
'http://google.de',
'http://google1234.de',
'http://google123.de',
'&#160;<a href="http://google.de">More information</a>',
],
[
true,
'',
'http://google.de',
'http://google123.de',
'&#160;<a href="http://google.de">More information</a>',
],
];
}
}