You are here

public function FieldClearingNodeTest::testFieldClearing in Acquia Content Hub 8

Configure content hub node form.

File

tests/src/Functional/FieldClearingNodeTest.php, line 53

Class

FieldClearingNodeTest
Test that Acquia Content Hub respects Field Сlearing.

Namespace

Drupal\Tests\acquia_contenthub\Functional

Code

public function testFieldClearing() {
  $this->adminRole = $this
    ->createAdminRole('administrator', 'Administrator');
  $this
    ->drupalLogin($this->adminUser);

  // Create Article Node.
  $entity = $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'Test Title',
    'body' => [
      [
        'value' => 'Test Body',
        'format' => filter_default_format(),
      ],
    ],
  ]);
  $this
    ->configureContentHubContentTypes('node', [
    'article',
  ]);

  // Rendering the CDF, we can see the "Body" Field.
  $output = $this
    ->drupalGetCdf('acquia-contenthub-cdf/' . $entity
    ->getEntityTypeId() . '/' . $entity
    ->id(), [
    'query' => [
      'include_references' => 'true',
    ],
  ]);
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Check the base fields in CDF.
  $this
    ->assertEquals($output['entities']['0']['uuid'], $entity
    ->uuid());
  $this
    ->assertEquals($output['entities']['0']['attributes']['title']['value']['en'], 'Test Title');

  // Check the body in CDF.
  $json_body = $output['entities']['0']['attributes']['body']['value']['en'][0];
  $body = Json::decode($json_body);
  $this
    ->assertEquals($body['value'], 'Test Body');

  // Now modify article "Body" Field to have clear it.
  $node_edit_url = 'node/' . $entity
    ->id() . '/edit';
  $edit = [];
  $edit['body[0][value]'] = '';
  $this
    ->drupalPostForm($node_edit_url, $edit, $this
    ->t('Save'));

  // Rendering the CDF, we can see the "Body" Field.
  $output = $this
    ->drupalGetCdf('acquia-contenthub-cdf/' . $entity
    ->getEntityTypeId() . '/' . $entity
    ->id(), [
    'query' => [
      'include_references' => 'true',
    ],
  ]);
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Check the base fields in CDF.
  $this
    ->assertEquals($output['entities']['0']['uuid'], $entity
    ->uuid());
  $this
    ->assertEquals($output['entities']['0']['attributes']['title']['value']['en'], 'Test Title');

  // Check the body in CDF.
  $json_body = $output['entities']['0']['attributes']['body']['value']['en'];
  $body = Json::decode($json_body);
  $this
    ->assertEquals($body, NULL);
}