You are here

public function FileManagedUnitTestBase::assertFileUnchanged in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php \Drupal\Tests\file\Kernel\FileManagedUnitTestBase::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.

14 calls to FileManagedUnitTestBase::assertFileUnchanged()
CopyTest::testExistingError in core/modules/file/tests/src/Kernel/CopyTest.php
Test that copying over an existing file fails when instructed to do so.
CopyTest::testExistingRename in core/modules/file/tests/src/Kernel/CopyTest.php
Test renaming when copying over a file that already exists.
CopyTest::testExistingReplace in core/modules/file/tests/src/Kernel/CopyTest.php
Test replacement when copying over a file that already exists.
CopyTest::testNormal in core/modules/file/tests/src/Kernel/CopyTest.php
Test file copying in the normal, base case.
MoveTest::testExistingError in core/modules/file/tests/src/Kernel/MoveTest.php
Test that moving onto an existing file fails when instructed to do so.

... See full list

File

core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php, line 110

Class

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

Namespace

Drupal\Tests\file\Kernel

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');
}