You are here

public function FileManagedTestBase::assertFileUnchanged in Drupal 8

Same name in this branch
  1. 8 core/modules/file/src/Tests/FileManagedTestBase.php \Drupal\file\Tests\FileManagedTestBase::assertFileUnchanged()
  2. 8 core/modules/file/tests/src/Functional/FileManagedTestBase.php \Drupal\Tests\file\Functional\FileManagedTestBase::assertFileUnchanged()

Asserts that two files have the same values (except timestamp).

Parameters

\Drupal\file\FileInterface $before: File object to compare.

\Drupal\file\FileInterface $after: File object to compare.

File

core/modules/file/src/Tests/FileManagedTestBase.php, line 102

Class

FileManagedTestBase
Base class for file tests that use the file_test module to test uploads and hooks.

Namespace

Drupal\file\Tests

Code

public function assertFileUnchanged(FileInterface $before, FileInterface $after) {
  $this
    ->assertEqual($before
    ->id(), $after
    ->id(), t('File id is the same: %file1 == %file2.', [
    '%file1' => $before
      ->id(),
    '%file2' => $after
      ->id(),
  ]), 'File unchanged');
  $this
    ->assertEqual($before
    ->getOwner()
    ->id(), $after
    ->getOwner()
    ->id(), t('File owner is the same: %file1 == %file2.', [
    '%file1' => $before
      ->getOwner()
      ->id(),
    '%file2' => $after
      ->getOwner()
      ->id(),
  ]), 'File unchanged');
  $this
    ->assertEqual($before
    ->getFilename(), $after
    ->getFilename(), t('File name is the same: %file1 == %file2.', [
    '%file1' => $before
      ->getFilename(),
    '%file2' => $after
      ->getFilename(),
  ]), 'File unchanged');
  $this
    ->assertEqual($before
    ->getFileUri(), $after
    ->getFileUri(), t('File path is the same: %file1 == %file2.', [
    '%file1' => $before
      ->getFileUri(),
    '%file2' => $after
      ->getFileUri(),
  ]), 'File unchanged');
  $this
    ->assertEqual($before
    ->getMimeType(), $after
    ->getMimeType(), t('File MIME type is the same: %file1 == %file2.', [
    '%file1' => $before
      ->getMimeType(),
    '%file2' => $after
      ->getMimeType(),
  ]), 'File unchanged');
  $this
    ->assertEqual($before
    ->getSize(), $after
    ->getSize(), t('File size is the same: %file1 == %file2.', [
    '%file1' => $before
      ->getSize(),
    '%file2' => $after
      ->getSize(),
  ]), 'File unchanged');
  $this
    ->assertEqual($before
    ->isPermanent(), $after
    ->isPermanent(), t('File status is the same: %file1 == %file2.', [
    '%file1' => $before
      ->isPermanent(),
    '%file2' => $after
      ->isPermanent(),
  ]), 'File unchanged');
}