WebformEntityReferenceItemNormalizerTest.php in Webform 8.5
File
tests/src/Functional/WebformEntityReferenceItemNormalizerTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional;
use Drupal\node\Entity\Node;
class WebformEntityReferenceItemNormalizerTest extends WebformBrowserTestBase {
public static $modules = [
'rest',
'serialization',
'hal',
'webform',
'webform_node',
];
public function testWebformEntityReferenceItemNormalization() {
$node = $this
->drupalCreateNode([
'type' => 'webform',
]);
$webform_field = 'webform';
$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();
$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']);
$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);
}
}