function FileFieldValidateTest::testAssertFileExistsDeprecation
Tests deprecation of the assertFileExists and assertFileNotExists methods.
@group legacy
@todo the expectedDeprecation annotation does not work if tests are marked skipped.
See also
https://github.com/symfony/symfony/pull/25757
File
-
core/
modules/ file/ tests/ src/ Functional/ FileFieldValidateTest.php, line 209
Class
- FileFieldValidateTest
- Tests validation functions such as file type, max file size, max size per node, and required.
Namespace
Drupal\Tests\file\FunctionalCode
public function testAssertFileExistsDeprecation() {
if (RunnerVersion::getMajor() == 6) {
$this->addExpectedDeprecationMessage('Passing a File entity as $file argument to FileFieldTestBase::assertFileExists is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Instead, pass the File entity URI via File::getFileUri(). See https://www.drupal.org/node/3057326');
$this->addExpectedDeprecationMessage('Passing a File entity as $file argument to FileFieldTestBase::assertFileNotExists is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Instead, pass the File entity URI via File::getFileUri(). See https://www.drupal.org/node/3057326');
}
else {
$this->markTestSkipped('This test does not work in PHPUnit 7+ since assertFileExists only accepts string arguments for $file');
}
$node_storage = $this->container
->get('entity.manager')
->getStorage('node');
$type_name = 'article';
$field_name = 'file_test';
$this->createFileField($field_name, 'node', $type_name);
$test_file = $this->getTestFile('image');
// Disable extension checking.
$this->updateFileField($field_name, $type_name, [
'file_extensions' => '',
]);
// Check that the file can be uploaded with no extension checking.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node_storage->resetCache([
$nid,
]);
$node = $node_storage->load($nid);
$node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file);
unlink($node_file->getFileUri());
$this->assertFileNotExists($node_file);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.