function FileMoveTest::testNormal

Same name in other branches
  1. 9 core/modules/image/tests/src/Functional/FileMoveTest.php \Drupal\Tests\image\Functional\FileMoveTest::testNormal()
  2. 9 core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php \Drupal\KernelTests\Core\File\FileMoveTest::testNormal()
  3. 8.9.x core/modules/image/tests/src/Functional/FileMoveTest.php \Drupal\Tests\image\Functional\FileMoveTest::testNormal()
  4. 8.9.x core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php \Drupal\KernelTests\Core\File\FileMoveTest::testNormal()
  5. 10 core/modules/image/tests/src/Kernel/FileMoveTest.php \Drupal\Tests\image\Kernel\FileMoveTest::testNormal()
  6. 10 core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php \Drupal\KernelTests\Core\File\FileMoveTest::testNormal()
  7. 11.x core/modules/image/tests/src/Kernel/FileMoveTest.php \Drupal\Tests\image\Kernel\FileMoveTest::testNormal()
  8. 11.x core/tests/Drupal/KernelTests/Core/File/FileMoveTest.php \Drupal\KernelTests\Core\File\FileMoveTest::testNormal()

Move a normal file.

File

modules/simpletest/tests/file.test, line 1807

Class

FileMoveTest
Move related tests

Code

function testNormal() {
    $contents = $this->randomName(10);
    $source = $this->createFile(NULL, $contents);
    $desired_filepath = 'public://' . $this->randomName();
    // Clone the object so we don't have to worry about the function changing
    // our reference copy.
    $result = file_move(clone $source, $desired_filepath, FILE_EXISTS_ERROR);
    // Check the return status and that the contents changed.
    $this->assertTrue($result, 'File moved successfully.');
    $this->assertFalse(file_exists($source->uri));
    $this->assertEqual($contents, file_get_contents($result->uri), 'Contents of file correctly written.');
    // Check that the correct hooks were called.
    $this->assertFileHooksCalled(array(
        'move',
        'load',
        'update',
    ));
    // Make sure we got the same file back.
    $this->assertEqual($source->fid, $result->fid, format_string("Source file id's' %fid is unchanged after move.", array(
        '%fid' => $source->fid,
    )));
    // Reload the file from the database and check that the changes were
    // actually saved.
    $loaded_file = file_load($result->fid, TRUE);
    $this->assertTrue($loaded_file, 'File can be loaded from the database.');
    $this->assertFileUnchanged($result, $loaded_file);
}

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