You are here

public function FileNormalizeTest::testNormalize in Zircon Profile 8

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

Tests the normalize function.

File

core/modules/hal/src/Tests/FileNormalizeTest.php, line 60
Contains \Drupal\hal\Tests\FileNormalizeTest.

Class

FileNormalizeTest
Tests that file entities can be normalized in HAL.

Namespace

Drupal\hal\Tests

Code

public function testNormalize() {
  $file_params = array(
    'filename' => 'test_1.txt',
    'uri' => 'public://test_1.txt',
    'filemime' => 'text/plain',
    'status' => FILE_STATUS_PERMANENT,
  );

  // Create a new file entity.
  $file = entity_create('file', $file_params);
  file_put_contents($file
    ->getFileUri(), 'hello world');
  $file
    ->save();
  $expected_array = array(
    'uri' => array(
      array(
        'value' => file_create_url($file
          ->getFileUri()),
      ),
    ),
  );
  $normalized = $this->serializer
    ->normalize($file, $this->format);
  $this
    ->assertEqual($normalized['uri'], $expected_array['uri'], 'URI is normalized.');
}