function JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid

Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()
Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()
  2. 9 core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()
  3. 8.9.x core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()
  4. 8.9.x core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()
  5. 11.x core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Unit\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()
  6. 11.x core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testDenormalizeUuid()

Ensures only valid UUIDs can be specified.

@covers ::denormalize @dataProvider denormalizeUuidProvider

Parameters

string $id: The input UUID. May be invalid.

bool $expect_exception: Whether to expect an exception.

File

core/modules/jsonapi/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php, line 214

Class

JsonApiDocumentTopLevelNormalizerTest
@coversDefaultClass \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\Normalizer

Code

public function testDenormalizeUuid($id, $expect_exception) : void {
    $data['data'] = isset($id) ? [
        'type' => 'node--article',
        'id' => $id,
    ] : [
        'type' => 'node--article',
    ];
    if ($expect_exception) {
        $this->expectException(UnprocessableEntityHttpException::class);
        $this->expectExceptionMessage('IDs should be properly generated and formatted UUIDs as described in RFC 4122.');
    }
    $denormalized = $this->normalizer
        ->denormalize($data, NULL, 'api_json', [
        'resource_type' => new ResourceType('node', 'article', FieldableEntityInterface::class),
    ]);
    if (isset($id)) {
        $this->assertSame($id, $denormalized['uuid']);
    }
    else {
        $this->assertArrayNotHasKey('uuid', $denormalized);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.