You are here

class AkamaiClientV3Test in Akamai 8.3

@coversDefaultClass \Drupal\akamai\Plugin\Client\AkamaiClientV3

@group Akamai

Hierarchy

Expanded class hierarchy of AkamaiClientV3Test

File

tests/src/Unit/AkamaiClientV3Test.php, line 15

Namespace

Drupal\Tests\akamai\Unit
View source
class AkamaiClientV3Test extends UnitTestCase {

  /**
   * Creates a client to test.
   *
   * @param array $config
   *   An array of client configuration.
   *
   * @return \Drupal\akamai\Plugin\Client\AkamaiClientV3
   *   An AkamaiClient to test.
   */
  protected function getClient(array $config = []) {

    // Ensure some sane defaults.
    $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();

    // Create stub for response class.
    $response_stub = $this
      ->getMockBuilder('GuzzleHttp\\Psr7\\Response')
      ->disableOriginalConstructor()
      ->setMethods([
      'getStatusCode',
    ])
      ->getMock();
    $response_stub
      ->method('getStatusCode')
      ->willReturn(201);

    // Create stub for the Akamai Client class.
    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();
  }

  /**
   * Tests creation of a purge payload body.
   *
   * @covers ::createPurgeBody
   */
  public function testCreatePurgeBody() {
    $urls = [
      '/node/11',
    ];

    // URL type (default).
    $expected = (object) [
      'objects' => $urls,
    ];
    $akamai_client = $this
      ->getClient();
    $this
      ->assertEquals($expected, $akamai_client
      ->createPurgeBody($urls));

    // URL type (default) with hostname setting enabled.
    $expected = (object) [
      'objects' => $urls,
      'hostname' => 'http://example.com',
    ];
    $akamai_client = $this
      ->getClient([
      'purge_urls_with_hostname' => TRUE,
    ]);
    $this
      ->assertEquals($expected, $akamai_client
      ->createPurgeBody($urls));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AkamaiClientV3Test::getClient protected function Creates a client to test.
AkamaiClientV3Test::testCreatePurgeBody public function Tests creation of a purge payload body.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340