Same name in other branches
- 8.x-1.x tests/src/Functional/EntityCloneFileTest.php \Drupal\Tests\entity_clone\Functional\EntityCloneFileTest::testFileEntityClone()
Test file entity clone.
Fichier
-
tests/
src/ Functional/ EntityCloneFileTest.php, line 62
Classe
- EntityCloneFileTest
- Create a filer and test a clone.
Namespace
Drupal\Tests\entity_clone\FunctionalCode
public function testFileEntityClone() {
/** @var \Drupal\file\FileInterface $file */
$file = File::create([
'uid' => 1,
'filename' => 'druplicon.txt',
'uri' => 'public://druplicon.txt',
'filemime' => 'text/plain',
'status' => FileInterface::STATUS_PERMANENT,
]);
file_put_contents($file->getFileUri(), 'hello world');
$file->save();
$this->drupalGet('entity_clone/file/' . $file->id());
$this->submitForm([], $this->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->assertEquals($file->getFileUri(), 'public://druplicon_0.txt', 'The stored file is also cloned.');
}