YamlFormEntityReferenceItemNormalizerTest.php in YAML Form 8
File
src/Tests/YamlFormEntityReferenceItemNormalizerTest.php
View source
<?php
namespace Drupal\yamlform\Tests;
use Drupal\node\Entity\Node;
class YamlFormEntityReferenceItemNormalizerTest extends YamlFormTestBase {
protected static $modules = [
'system',
'block',
'node',
'user',
'yamlform',
'yamlform_node',
'yamlform_test',
'hal',
'serialization',
];
public function testYamlFormEntityReferenceItemNormalization() {
$node = $this
->drupalCreateNode([
'type' => 'yamlform',
]);
$yamlform_field = 'yamlform';
$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();
$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']);
$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);
}
}