public function DenormalizeTest::testMarkFieldForDeletion

Test that a field set to an empty array is different than an empty field.

File

drupal/core/modules/hal/lib/Drupal/hal/Tests/DenormalizeTest.php, line 89
Contains \Drupal\hal\Tests\DenormalizeTest.

Class

DenormalizeTest
Test the HAL normalizer's denormalize function.

Namespace

Drupal\hal\Tests

Code

public function testMarkFieldForDeletion() {
  $no_field_data = array(
    '_links' => array(
      'type' => array(
        'href' => url('rest/type/entity_test/entity_test', array(
          'absolute' => TRUE,
        )),
      ),
    ),
  );
  $no_field_denormalized = $this->serializer
    ->denormalize($no_field_data, $this->entityClass, $this->format);
  $no_field_value = $no_field_denormalized->field_test_text
    ->getValue();
  $empty_field_data = array(
    '_links' => array(
      'type' => array(
        'href' => url('rest/type/entity_test/entity_test', array(
          'absolute' => TRUE,
        )),
      ),
    ),
    'field_test_text' => array(),
  );
  $empty_field_denormalized = $this->serializer
    ->denormalize($empty_field_data, $this->entityClass, $this->format);
  $empty_field_value = $empty_field_denormalized->field_test_text
    ->getValue();
  $this
    ->assertTrue(!empty($no_field_value) && empty($empty_field_value), 'A field set to an empty array in the data is structured differently than an empty field.');
}