mediawiki-extensions-Cookie.../tests/phpunit/includes/DecisionsTest.php
Florian Schmidt 6634e8c829 Enable GeoLocation service being replaced by other providers
Making GeoLocation an interface makes it easier to replace the underlying implementation
from the current Http backed method.

Change-Id: I2beb97772fd74ab08b2214c08d82dbc1ebfcdcd2
2019-11-21 17:31:23 +01:00

44 lines
1.2 KiB
PHP

<?php
namespace CookieWarning\Tests;
use ConfigException;
use CookieWarning\Decisions;
use CookieWarning\GeoLocation;
use HashBagOStuff;
use MediaWiki\MediaWikiServices;
use MediaWikiTestCase;
use MWException;
use RequestContext;
use WANObjectCache;
class DecisionsTest extends MediaWikiTestCase {
/**
* @covers \CookieWarning\Decisions::shouldShowCookieWarning()
* @throws ConfigException
* @throws MWException
*/
public function testShouldNotCallGeoLocationMultiple() {
$this->setMwGlobals( [
'wgCookieWarningEnabled' => true,
'wgCookieWarningGeoIPLookup' => 'php',
'wgCookieWarningForCountryCodes' => [ 'EU' => 'European Union' ],
] );
$geoLocation = $this->getMockBuilder( GeoLocation::class )
->disableOriginalConstructor()
->getMock();
$geoLocation->method( 'locate' )->willReturn( 'EU' );
$geoLocation->expects( $this->once() )->method( 'locate' );
$cookieWarningDecisions = new Decisions(
MediaWikiServices::getInstance()->getService( 'CookieWarning.Config' ),
$geoLocation,
new WANObjectCache( [ 'cache' => new HashBagOStuff() ] )
);
$cookieWarningDecisions->shouldShowCookieWarning( RequestContext::getMain() );
$cookieWarningDecisions->shouldShowCookieWarning( RequestContext::getMain() );
}
}