View source
<?php
namespace Drupal\Tests\akamai\Unit;
use Drupal\akamai\KeyProviderInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Tests\UnitTestCase;
use Psr\Log\LoggerInterface;
class AkamaiClientV3Test extends UnitTestCase {
protected function getClient(array $config = []) {
$config = $config + [
'version' => 'v3',
'domain' => [
'production' => TRUE,
'staging' => FALSE,
],
'action_v3' => [
'delete' => TRUE,
'invalidate' => FALSE,
],
'basepath' => 'http://example.com',
'timeout' => 300,
'purge_urls_with_hostname' => FALSE,
];
$logger = $this
->prophesize(LoggerInterface::class)
->reveal();
$edgegridclient = $this
->getMockBuilder('Akamai\\Open\\EdgeGrid\\Client')
->disableOriginalConstructor()
->setMethods(NULL)
->getMock();
$response_stub = $this
->getMockBuilder('GuzzleHttp\\Psr7\\Response')
->disableOriginalConstructor()
->setMethods([
'getStatusCode',
])
->getMock();
$response_stub
->method('getStatusCode')
->willReturn(201);
return $this
->getMockBuilder('Drupal\\akamai\\Plugin\\Client\\AkamaiClientV3')
->setConstructorArgs([
[],
'v3',
[],
$edgegridclient,
$this
->getConfigFactoryStub([
'akamai.settings' => $config,
]),
$logger,
$this
->prophesize(MessengerInterface::class)
->reveal(),
$this
->prophesize(KeyProviderInterface::class)
->reveal(),
])
->setMethods([
'getQueueLength',
'purgeRequest',
])
->getMock();
}
public function testCreatePurgeBody() {
$urls = [
'/node/11',
];
$expected = (object) [
'objects' => $urls,
];
$akamai_client = $this
->getClient();
$this
->assertEquals($expected, $akamai_client
->createPurgeBody($urls));
$expected = (object) [
'objects' => $urls,
'hostname' => 'http://example.com',
];
$akamai_client = $this
->getClient([
'purge_urls_with_hostname' => TRUE,
]);
$this
->assertEquals($expected, $akamai_client
->createPurgeBody($urls));
}
}