2018-07-18 10:37:17 +00:00
|
|
|
<?php
|
|
|
|
|
2018-07-19 10:48:17 +00:00
|
|
|
namespace CookieWarning\Tests;
|
|
|
|
|
|
|
|
use ConfigException;
|
|
|
|
use CookieWarning\Decisions;
|
|
|
|
use CookieWarning\GeoLocation;
|
|
|
|
use HashBagOStuff;
|
2018-07-18 10:37:17 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2018-07-19 10:48:17 +00:00
|
|
|
use MediaWikiTestCase;
|
|
|
|
use MWException;
|
|
|
|
use RequestContext;
|
|
|
|
use WANObjectCache;
|
2018-07-18 10:37:17 +00:00
|
|
|
|
2018-07-19 10:48:17 +00:00
|
|
|
class DecisionsTest extends MediaWikiTestCase {
|
2018-07-18 10:37:17 +00:00
|
|
|
/**
|
2018-07-19 10:48:17 +00:00
|
|
|
* @covers \CookieWarning\Decisions::shouldShowCookieWarning()
|
2018-07-18 10:37:17 +00:00
|
|
|
* @throws ConfigException
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
|
|
|
public function testShouldNotCallGeoLocationMultiple() {
|
|
|
|
$this->setMwGlobals( [
|
|
|
|
'wgCookieWarningEnabled' => true,
|
|
|
|
'wgCookieWarningGeoIPLookup' => 'php',
|
|
|
|
'wgCookieWarningForCountryCodes' => [ 'EU' => 'European Union' ],
|
|
|
|
] );
|
|
|
|
|
|
|
|
$geoLocation = $this->getMockBuilder( GeoLocation::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2018-11-04 15:15:42 +00:00
|
|
|
$geoLocation->method( 'locate' )->willReturn( 'EU' );
|
2018-07-18 10:37:17 +00:00
|
|
|
|
|
|
|
$geoLocation->expects( $this->once() )->method( 'locate' );
|
2018-07-19 10:48:17 +00:00
|
|
|
$cookieWarningDecisions = new Decisions(
|
2018-07-18 10:37:17 +00:00
|
|
|
MediaWikiServices::getInstance()->getService( 'CookieWarning.Config' ),
|
|
|
|
$geoLocation,
|
2021-03-30 18:24:32 +00:00
|
|
|
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
|
|
|
|
MediaWikiServices::getInstance()->getUserOptionsLookup()
|
2018-07-18 10:37:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$cookieWarningDecisions->shouldShowCookieWarning( RequestContext::getMain() );
|
|
|
|
$cookieWarningDecisions->shouldShowCookieWarning( RequestContext::getMain() );
|
|
|
|
}
|
|
|
|
}
|