diff --git a/core/modules/hal/tests/src/Kernel/FileFieldNormalizeTest.php b/core/modules/hal/tests/src/Kernel/FileFieldNormalizeTest.php index e122658..06dff16 100644 --- a/core/modules/hal/tests/src/Kernel/FileFieldNormalizeTest.php +++ b/core/modules/hal/tests/src/Kernel/FileFieldNormalizeTest.php @@ -1,8 +1,4 @@ serializer = $this->container->get('serializer'); + } + + + /** + * Tests CRUD operations for the file entity. + */ + public function testCrudFile() { + $entity_type = 'file'; + + // Enables the REST service for 'file' entity type. + $this->enableService('entity:' . $entity_type, 'POST', 'hal_json'); + //$this->enableService('entity:' . $entity_type, 'GET'); + //$this->enableService('entity:' . $entity_type, 'PATCH'); + + $file_contents = 'hello world'; + $data = base64_encode($file_contents); + + $file = File::create([ + 'filename' => 'default.txt', + 'filemime' => 'text/plain', + ]); + + $normalized_data = $this->serializer->normalize($file, 'hal_json'); + $normalized_data['data'][0]['value'] = $data; + + // Remove non-accessible fields. + unset($normalized_data['status']); + unset($normalized_data['changed']); + + $serialized = $this->serializer->serialize($normalized_data, 'hal_json'); + + // POST method must be allowed for the current entity type. + $permissions[] = 'restful post entity:' . $entity_type; + + // Create the user. + $account = $this->drupalCreateUser($permissions); + + $this->drupalLogin($account); + $this->httpRequest('entity/' . $entity_type, 'POST', $serialized, 'application/hal+json'); + $this->assertResponse(201); + } + +} +