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;
|
2021-10-12 19:30:58 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2018-07-19 10:48:17 +00:00
|
|
|
use MWException;
|
|
|
|
use RequestContext;
|
|
|
|
use WANObjectCache;
|
2018-07-18 10:37:17 +00:00
|
|
|
|
2021-10-12 19:30:58 +00:00
|
|
|
class DecisionsTest extends MediaWikiIntegrationTestCase {
|
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() {
|
2024-07-27 07:21:32 +00:00
|
|
|
$this->overrideConfigValues( [
|
|
|
|
'CookieWarningEnabled' => true,
|
|
|
|
'CookieWarningGeoIPLookup' => 'php',
|
|
|
|
'CookieWarningForCountryCodes' => [ 'EU' => 'European Union' ],
|
2018-07-18 10:37:17 +00:00
|
|
|
] );
|
|
|
|
|
|
|
|
$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(
|
2024-07-27 07:40:08 +00:00
|
|
|
$this->getServiceContainer()->getService( 'CookieWarning.Config' ),
|
2018-07-18 10:37:17 +00:00
|
|
|
$geoLocation,
|
2021-03-30 18:24:32 +00:00
|
|
|
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ),
|
2024-07-27 07:40:08 +00:00
|
|
|
$this->getServiceContainer()->getUserOptionsLookup()
|
2018-07-18 10:37:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$cookieWarningDecisions->shouldShowCookieWarning( RequestContext::getMain() );
|
|
|
|
$cookieWarningDecisions->shouldShowCookieWarning( RequestContext::getMain() );
|
|
|
|
}
|
|
|
|
}
|