You are here

public function EntityCloneFileTest::testFileEntityClone in Entity Clone 8

Test file entity clone.

File

tests/src/Functional/EntityCloneFileTest.php, line 57

Class

EntityCloneFileTest
Create a filer and test a clone.

Namespace

Drupal\Tests\entity_clone\Functional

Code

public function testFileEntityClone() {

  /** @var \Drupal\file\FileInterface $file */
  $file = File::create([
    'uid' => 1,
    'filename' => 'druplicon.txt',
    'uri' => 'public://druplicon.txt',
    'filemime' => 'text/plain',
    'status' => FILE_STATUS_PERMANENT,
  ]);
  file_put_contents($file
    ->getFileUri(), 'hello world');
  $file
    ->save();
  $this
    ->drupalPostForm('entity_clone/file/' . $file
    ->id(), [], t('Clone'));
  $files = \Drupal::entityTypeManager()
    ->getStorage('file')
    ->loadByProperties([
    'filename' => 'druplicon.txt - Cloned',
  ]);
  $file = reset($files);
  $this
    ->assertInstanceOf(File::class, $file, 'Test file cloned found in database.');
  $this
    ->assertEqual($file
    ->getFileUri(), 'public://druplicon_0.txt', 'The stored file is also cloned.');
}