assertFileUnchanged example

// Check that the correct hooks were called.     $this->assertFileHooksCalled(['copy', 'insert']);

    $this->assertDifferentFile($source$result);
    $this->assertEquals($result->getFileUri()$desired_uri, 'The copied file entity has the desired filepath.');
    $this->assertFileExists($source->getFileUri());
    $this->assertFileExists($result->getFileUri());

    // Reload the file from the database and check that the changes were     // actually saved.     $this->assertFileUnchanged($result, File::load($result->id()));
  }

  /** * Tests renaming when copying over a file that already exists. * * @covers ::copy */
  public function testExistingRename() {
    // Setup a file to overwrite.     $contents = $this->randomMachineName(10);
    $source = $this->createFile(NULL, $contents);
    
// Check that the correct hooks were called.     $this->assertFileHooksCalled(['move', 'load', 'update']);

    // Make sure we got the same file back.     $this->assertEquals($source->id()$result->id()new FormattableMarkup("Source file id's' %fid is unchanged after move.", ['%fid' => $source->id()]));

    // Reload the file from the database and check that the changes were     // actually saved.     $loaded_file = File::load($result->id());
    $this->assertNotEmpty($loaded_file, 'File can be loaded from the database.');
    $this->assertFileUnchanged($result$loaded_file);
  }

  /** * Tests renaming when moving onto a file that already exists. * * @covers ::move */
  public function testExistingRename() {
    // Setup a file to overwrite.     $contents = $this->randomMachineName(10);
    $source = $this->createFile(NULL, $contents);
    
assert($stream_wrapper_manager instanceof StreamWrapperManagerInterface);
    $this->assertEquals('public', $stream_wrapper_manager::getScheme($result->getFileUri()), "File was placed in Drupal's files directory.");
    $this->assertEquals($filename, \Drupal::service('file_system')->basename($result->getFileUri()), 'File was named correctly.');
    $this->assertEquals($contentsfile_get_contents($result->getFileUri()), 'Contents of the file are correct.');
    $this->assertEquals('text/plain', $result->getMimeType(), 'A MIME type was set.');
    $this->assertTrue($result->isPermanent(), "The file's status was set to permanent.");

    // Check that the correct hooks were called.     $this->assertFileHooksCalled(['insert']);

    // Verify that what was returned is what's in the database.     $this->assertFileUnchanged($result, File::load($result->id()));
  }

  /** * Tests writeData() when renaming around an existing file. * * @covers ::writeData */
  public function testExistingRename() {
    // Setup a file to overwrite.     $existing = $this->createFile();
    $contents = $this->randomMachineName();

    
Home | Imprint | This part of the site doesn't use cookies.