2016-09-15 21:07:08 +00:00
< ? php
/**
2018-01-24 00:24:33 +00:00
* @ covers CookieWarningHooks
2016-09-15 21:07:08 +00:00
* @ group Database
*/
class CookieWarningHooksTest extends MediaWikiLangTestCase {
protected function setUp () {
parent :: setUp ();
MessageCache :: singleton () -> enable ();
}
/**
* @ dataProvider providerOnSkinTemplateOutputPageBeforeExec
*/
public function testOnSkinTemplateOutputPageBeforeExec ( $enabled , $morelinkConfig ,
$morelinkCookieWarningMsg , $morelinkCookiePolicyMsg , $expectedLink
) {
2016-09-14 15:23:11 +00:00
$this -> setMwGlobals ( [
2016-09-15 21:07:08 +00:00
'wgCookieWarningEnabled' => $enabled ,
'wgCookieWarningMoreUrl' => $morelinkConfig ,
Add option to limit the cookie warning to specific regions
With this change, CookieWarning gets two new ways to limit the warning
bar to users of specific (configurable) regions. Based on the geo location
service (which can be configured, too, defaults to freegeoip.net), the
extension will try to get the region of the user (based on the IP address)
and checks it against the configured regions.
With the configuration variable $wgCookieWarningGeoIPLookup, the wiki sysadmin
can configure, if the lookup should be done with PHP (the timeout for the
request is hardcoded to 2 sedonds max), which will save the paylod sent to
the user, or with JavaScript, which will be asynchronous.
Deactivating this feature is easily done by simply setting the configured regions
to false, instead of an object.
Bug: T145780
Change-Id: I4d9371b8608ef270c11c42bdb3a773675977ab3a
2016-09-16 19:18:49 +00:00
'wgCookieWarningForCountryCodes' => false ,
2016-09-14 15:23:11 +00:00
] );
2016-09-15 21:07:08 +00:00
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 ,
2016-09-17 22:02:05 +00:00
'<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>' );
2016-09-15 21:07:08 +00:00
// @codingStandardsIgnoreEnd
}
$this -> assertEquals ( $expected , $headElement );
}
public function providerOnSkinTemplateOutputPageBeforeExec () {
2016-09-14 15:23:11 +00:00
return [
[
2016-09-15 21:07:08 +00:00
// $wgCookieWarningEnabled
true ,
// $wgCookieWarningMoreUrl
'' ,
// MediaWiki:Cookiewarning-more-link
false ,
// MediaWiki:Cookie-policy-link
false ,
// expected cookie warning link (when string), nothing if false
'' ,
2016-09-14 15:23:11 +00:00
],
[
2016-09-15 21:07:08 +00:00
false ,
'' ,
false ,
false ,
false ,
2016-09-14 15:23:11 +00:00
],
[
2016-09-15 21:07:08 +00:00
true ,
'http://google.de' ,
false ,
false ,
2016-11-04 16:47:15 +00:00
' <a href="http://google.de">More information</a>' ,
2016-09-14 15:23:11 +00:00
],
[
2016-09-15 21:07:08 +00:00
true ,
'' ,
'http://google.de' ,
false ,
2016-11-04 16:47:15 +00:00
' <a href="http://google.de">More information</a>' ,
2016-09-14 15:23:11 +00:00
],
[
2016-09-15 21:07:08 +00:00
true ,
'' ,
false ,
'http://google.de' ,
2016-11-04 16:47:15 +00:00
' <a href="http://google.de">More information</a>' ,
2016-09-14 15:23:11 +00:00
],
2016-09-15 21:07:08 +00:00
// the config should be the used, if set (no matter if the messages are used or not)
2016-09-14 15:23:11 +00:00
[
2016-09-15 21:07:08 +00:00
true ,
'http://google.de' ,
false ,
'http://google123.de' ,
2016-11-04 16:47:15 +00:00
' <a href="http://google.de">More information</a>' ,
2016-09-14 15:23:11 +00:00
],
[
2016-09-15 21:07:08 +00:00
true ,
'http://google.de' ,
'http://google1234.de' ,
'http://google123.de' ,
2016-11-04 16:47:15 +00:00
' <a href="http://google.de">More information</a>' ,
2016-09-14 15:23:11 +00:00
],
[
2016-09-15 21:07:08 +00:00
true ,
'' ,
'http://google.de' ,
'http://google123.de' ,
2016-11-04 16:47:15 +00:00
' <a href="http://google.de">More information</a>' ,
2016-09-14 15:23:11 +00:00
],
];
2016-09-15 21:07:08 +00:00
}
}