public function WebformEntityReferenceItemNormalizerTest::testWebformEntityReferenceItemNormalization in Webform 8.5
Same name and namespace in other branches
- 6.x tests/src/Functional/WebformEntityReferenceItemNormalizerTest.php \Drupal\Tests\webform\Functional\WebformEntityReferenceItemNormalizerTest::testWebformEntityReferenceItemNormalization()
Tests the normalization of a node with a webform entity reference.
File
- tests/
src/ Functional/ WebformEntityReferenceItemNormalizerTest.php, line 24
Class
- WebformEntityReferenceItemNormalizerTest
- Tests the normalization of webform entity reference items.
Namespace
Drupal\Tests\webform\FunctionalCode
public function testWebformEntityReferenceItemNormalization() {
// Create node.
$node = $this
->drupalCreateNode([
'type' => 'webform',
]);
$webform_field = 'webform';
// Set webform field to reference the contact webform and add data.
$node->{$webform_field}->target_id = 'contact';
$node->{$webform_field}->default_data = 'name: Please enter your name\\r\\nemail: Please enter a valid email address';
$node->{$webform_field}->status = 1;
$node
->save();
// Normalize the node.
$serializer = $this->container
->get('serializer');
$normalized = $serializer
->normalize($node, 'hal_json');
$this
->assertEqual($node->{$webform_field}->default_data, $normalized[$webform_field][0]['default_data']);
$this
->assertEqual($node->{$webform_field}->status, $normalized[$webform_field][0]['status']);
// Denormalize the node.
$new_node = $serializer
->denormalize($normalized, Node::class, 'hal_json');
$this
->assertEqual($node->{$webform_field}->default_data, $new_node->{$webform_field}->default_data);
$this
->assertEqual($node->{$webform_field}->status, $new_node->{$webform_field}->status);
}