You are here

public function DenormalizeTest::testPatchDenormalization in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/hal/src/Tests/DenormalizeTest.php \Drupal\hal\Tests\DenormalizeTest::testPatchDenormalization()

Verifies that the denormalized entity is correct in the PATCH context.

File

core/modules/hal/src/Tests/DenormalizeTest.php, line 191
Contains \Drupal\hal\Tests\DenormalizeTest.

Class

DenormalizeTest
Tests that entities can be denormalized from HAL.

Namespace

Drupal\hal\Tests

Code

public function testPatchDenormalization() {
  $data = array(
    '_links' => array(
      'type' => array(
        'href' => Url::fromUri('base:rest/type/entity_test/entity_test', array(
          'absolute' => TRUE,
        ))
          ->toString(),
      ),
    ),
    'field_test_text' => array(
      array(
        'value' => $this
          ->randomMachineName(),
        'format' => 'full_html',
      ),
    ),
  );
  $denormalized = $this->serializer
    ->denormalize($data, $this->entityClass, $this->format, array(
    'request_method' => 'patch',
  ));

  // Check that the one field got populated as expected.
  $this
    ->assertEqual($data['field_test_text'], $denormalized
    ->get('field_test_text')
    ->getValue());

  // Check the custom property that contains the list of fields to merge.
  $this
    ->assertEqual($denormalized->_restSubmittedFields, [
    'field_test_text',
  ]);
}