class FileFieldValidateTest in Drupal 10
Same name in this branch
- 10 core/modules/file/tests/src/Functional/FileFieldValidateTest.php \Drupal\Tests\file\Functional\FileFieldValidateTest
- 10 core/modules/file/tests/src/FunctionalJavascript/FileFieldValidateTest.php \Drupal\Tests\file\FunctionalJavascript\FileFieldValidateTest
Same name and namespace in other branches
- 8 core/modules/file/tests/src/FunctionalJavascript/FileFieldValidateTest.php \Drupal\Tests\file\FunctionalJavascript\FileFieldValidateTest
- 9 core/modules/file/tests/src/FunctionalJavascript/FileFieldValidateTest.php \Drupal\Tests\file\FunctionalJavascript\FileFieldValidateTest
Tests validation functions such as file type, max file size, max size per node, and required.
@group file
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase
- class \Drupal\Tests\file\FunctionalJavascript\FileFieldValidateTest uses FileFieldCreationTrait, TestFileCreationTrait
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase
Expanded class hierarchy of FileFieldValidateTest
File
- core/
modules/ file/ tests/ src/ FunctionalJavascript/ FileFieldValidateTest.php, line 15
Namespace
Drupal\Tests\file\FunctionalJavascriptView source
class FileFieldValidateTest extends WebDriverTestBase {
use FileFieldCreationTrait;
use TestFileCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'file',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests the validation message is displayed only once for ajax uploads.
*/
public function testAjaxValidationMessage() {
$field_name = strtolower($this
->randomMachineName());
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this
->createFileField($field_name, 'node', 'article', [], [
'file_extensions' => 'txt',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'access content',
'create article content',
]));
$page = $this
->getSession()
->getPage();
$this
->drupalGet('node/add/article');
$image_file = current($this
->getTestFiles('image'));
$image_path = $this->container
->get('file_system')
->realpath($image_file->uri);
$page
->attachFileToField('files[' . $field_name . '_0]', $image_path);
$elements = $page
->waitFor(10, function () use ($page) {
return $page
->findAll('css', '.messages--error');
});
$this
->assertCount(1, $elements, 'Ajax validation messages are displayed once.');
}
}