mediawiki-extensions-Cookie.../tests/phpunit/includes/DecisionsTest.php
Florian Schmidt 90d2e58096 Move classes into CookieWarning namespace
This should make the code a bit more structured and easier to navigate
through. It also removes some lines from extension.json as the autoload
classes list is replaced by an autoload namespaces property.

This also changes the minimum requirement of MediaWiki to 1.31 for this
extension to work.

Change-Id: I249ccc3035297c99202a5f83fcc8d3fda68b682c
2018-07-19 12:57:52 +02:00

45 lines
1.3 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( true );
$geoLocation->method( 'getCountryCode' )->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() );
}
}