You are here

public function YamlFormEntityReferenceItemNormalizerTest::testYamlFormEntityReferenceItemNormalization in YAML Form 8

Tests the normalization of a node with a form entity reference.

File

src/Tests/YamlFormEntityReferenceItemNormalizerTest.php, line 33

Class

YamlFormEntityReferenceItemNormalizerTest
Tests the normalization of yamlform entity reference items.

Namespace

Drupal\yamlform\Tests

Code

public function testYamlFormEntityReferenceItemNormalization() {

  // Create node.
  $node = $this
    ->drupalCreateNode([
    'type' => 'yamlform',
  ]);
  $yamlform_field = 'yamlform';

  // Set yamlform field to reference the contact form and add data.
  $node->{$yamlform_field}->target_id = 'contact';
  $node->{$yamlform_field}->default_data = 'name: Please enter your name\\r\\nemail: Please enter a valid email address';
  $node->{$yamlform_field}->status = 1;
  $node
    ->save();

  // Normalize the node.
  $serializer = $this->container
    ->get('serializer');
  $normalized = $serializer
    ->normalize($node, 'hal_json');
  $this
    ->assertEqual($node->{$yamlform_field}->default_data, $normalized[$yamlform_field][0]['default_data']);
  $this
    ->assertEqual($node->{$yamlform_field}->status, $normalized[$yamlform_field][0]['status']);

  // Denormalize the node.
  $new_node = $serializer
    ->denormalize($normalized, Node::class, 'hal_json');
  $this
    ->assertEqual($node->{$yamlform_field}->default_data, $new_node->{$yamlform_field}->default_data);
  $this
    ->assertEqual($node->{$yamlform_field}->status, $new_node->{$yamlform_field}->status);
}