class EdgescapeTest in Akamai 8.3
Same name in this branch
- 8.3 tests/src/Functional/EdgescapeTest.php \Drupal\Tests\akamai\Functional\EdgescapeTest
- 8.3 tests/src/Unit/Helper/EdgescapeTest.php \Drupal\Tests\akamai\Unit\Helper\EdgescapeTest
Edgescape Helper Tests.
@group Akamai
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\akamai\Unit\Helper\EdgescapeTest
Expanded class hierarchy of EdgescapeTest
File
- tests/
src/ Unit/ Helper/ EdgescapeTest.php, line 15
Namespace
Drupal\Tests\akamai\Unit\HelperView source
class EdgescapeTest extends UnitTestCase {
/**
* Get a mock config factory.
*/
public function getConfigFactory($edgescapeEnabled = FALSE) {
$config = [
'edgescape_support' => $edgescapeEnabled,
];
return $this
->getConfigFactoryStub([
'akamai.settings' => $config,
]);
}
/**
* Get a mock request stack with request.
*/
public function getRequestStack($headerValue = NULL) {
$request = new Request();
if ($headerValue) {
$request->headers = new HeaderBag([
Edgescape::EDGESCAPE_HEADER => (string) $headerValue,
]);
}
$requestStack = $this
->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\RequestStack')
->disableOriginalConstructor()
->setMethods([
'getCurrentRequest',
])
->getMock();
$requestStack
->method('getCurrentRequest')
->willReturn($request);
return $requestStack;
}
/**
* Get an Edgescape header value.
*/
public function getEdgescapeHeaderValue($info = []) {
$info = $info + [
'georegion' => '263',
'country_code' => 'US',
'region_code' => 'MA',
'city' => 'CAMBRIDGE',
'dma' => '506',
'pmsa' => '1120',
'areacode' => '617',
'county' => 'MIDDLESEX',
'fips' => '25017',
'lat' => '42.3933',
'long' => '-71.1333',
'timezone' => 'EST',
'zip' => '02138-02142',
'continent' => 'NA',
'throughput' => 'vhigh',
'asnum' => '21399',
];
return http_build_query($info, '', ',');
}
/**
* Tests getEdgescapeHeaderValue creating a valid header value.
*/
public function testGetEdgescapeHeaderValue() {
$expected = 'georegion=263,country_code=US,region_code=MA,city=CAMBRIDGE,dma=506,pmsa=1120,areacode=617,county=MIDDLESEX,fips=25017,lat=42.3933,long=-71.1333,timezone=EST,zip=02138-02142,continent=NA,throughput=vhigh,asnum=21399';
$this
->assertSame($this
->getEdgescapeHeaderValue(), $expected);
}
/**
* Tests getInformationByType returns empty.
*/
public function testGetInformationByTypeReturnsEmpty() {
// Config false and header not present.
$config = $this
->getConfigFactory();
$requestStack = $this
->getRequestStack();
$helper = new Edgescape($config, $requestStack);
$this
->assertSame($helper
->getInformationByType('country_code'), '');
// Config false and header present.
$config = $this
->getConfigFactory();
$requestStack = $this
->getRequestStack($this
->getEdgescapeHeaderValue());
$helper = new Edgescape($config, $requestStack);
$this
->assertSame($helper
->getInformationByType('country_code'), '');
// Config true and header not present.
$config = $this
->getConfigFactory(TRUE);
$requestStack = $this
->getRequestStack();
$helper = new Edgescape($config, $requestStack);
$this
->assertSame($helper
->getInformationByType('country_code'), '');
}
/**
* Tests getInformationByType returns values.
*/
public function testGetInformationByTypeReturnsValues() {
// Config true and header present.
$config = $this
->getConfigFactory(TRUE);
$requestStack = $this
->getRequestStack($this
->getEdgescapeHeaderValue());
$helper = new Edgescape($config, $requestStack);
$this
->assertSame($helper
->getInformationByType('country_code'), 'US');
$this
->assertSame($helper
->getInformationByType('continent'), 'NA');
$this
->assertSame($helper
->getInformationByType('foo'), '');
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EdgescapeTest:: |
public | function | Get a mock config factory. | |
EdgescapeTest:: |
public | function | Get an Edgescape header value. | |
EdgescapeTest:: |
public | function | Get a mock request stack with request. | |
EdgescapeTest:: |
public | function | Tests getEdgescapeHeaderValue creating a valid header value. | |
EdgescapeTest:: |
public | function | Tests getInformationByType returns empty. | |
EdgescapeTest:: |
public | function | Tests getInformationByType returns values. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |