You are here

public function IntegrationTest::checkCdfFormat in Acquia Content Hub 8

Ensures the CDF output is present for expected formats.

Parameters

\Drupal\node\NodeInterface $entity: The entity to be used.

1 call to IntegrationTest::checkCdfFormat()
IntegrationTest::testFramework in tests/src/Functional/IntegrationTest.php
Tests various operations via the Acquia Content Hub admin UI.

File

tests/src/Functional/IntegrationTest.php, line 248

Class

IntegrationTest
Tests the overall functionality of the Acquia Content Hub module.

Namespace

Drupal\Tests\acquia_contenthub\Functional

Code

public function checkCdfFormat(NodeInterface $entity) {
  $output = $this
    ->drupalGetCdf('acquia-contenthub-cdf/' . $entity
    ->getEntityTypeId() . '/' . $entity
    ->id());
  $this
    ->assertSession()
    ->statusCodeEquals(200, 'Accept acquia_contenthub_cdf format.');
  $this
    ->assertEquals($output['entities']['0']['uuid'], $entity
    ->uuid(), 'CDF is present for acquia_contenthub_cdf format.');
  $output = $this
    ->drupalGetWithFormat('acquia-contenthub-cdf/' . $entity
    ->getEntityTypeId() . '/' . $entity
    ->id(), 'html');
  $output = Json::decode($output);
  $this
    ->assertSession()
    ->statusCodeEquals(200, 'Accept html format (browser default).');
  $this
    ->assertEquals($output['entities']['0']['uuid'], $entity
    ->uuid(), 'CDF is present for html format.');
  $output = $this
    ->drupalGetWithFormat('acquia-contenthub-cdf/' . $entity
    ->getEntityTypeId() . '/' . $entity
    ->id(), 'json');
  $output = Json::decode($output);
  $this
    ->assertSession()
    ->statusCodeEquals(200, 'Accept json format.');
  $this
    ->assertEquals($output['entities']['0']['uuid'], $entity
    ->uuid(), 'CDF is present for json format.');
  $output = $this
    ->drupalGet('acquia-contenthub-cdf/' . $entity
    ->getEntityTypeId() . '/' . $entity
    ->id());
  $output = Json::decode($output);
  $this
    ->assertSession()
    ->statusCodeEquals(200, 'Accept default format (json is default for tests).');
  $this
    ->assertEquals($output['entities']['0']['uuid'], $entity
    ->uuid(), 'CDF is present for default format.');
  $this
    ->drupalGetWithFormat('acquia-contenthub-cdf/' . $entity
    ->getEntityTypeId() . '/' . $entity
    ->id(), 'xml');
  $this
    ->assertSession()
    ->statusCodeEquals(406, 'A 406 response was returned when XML was requested.');
}