View source
<?php
namespace Drupal\Tests\inline_form_errors\Functional;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
class FormErrorHandlerFileUploadTest extends BrowserTestBase {
public static $modules = [
'node',
'file',
'field_ui',
'inline_form_errors',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
NodeType::create([
'type' => 'page',
'name' => 'page',
])
->save();
FieldStorageConfig::create([
'entity_type' => 'node',
'field_name' => 'field_ief_file',
'type' => 'file',
'cardinality' => 1,
])
->save();
FieldConfig::create([
'field_name' => 'field_ief_file',
'label' => 'field_ief_file',
'entity_type' => 'node',
'bundle' => 'page',
'required' => TRUE,
'settings' => [
'file_extensions' => 'png gif jpg jpeg',
],
])
->save();
EntityFormDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'page',
'mode' => 'default',
'status' => TRUE,
])
->setComponent('field_ief_file', [
'type' => 'file_generic',
'settings' => [],
])
->save();
EntityViewDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'page',
'mode' => 'default',
'status' => TRUE,
'label' => 'hidden',
'type' => 'file_default',
])
->save();
$account = $this
->drupalCreateUser([
'access content',
'access administration pages',
'administer nodes',
'create page content',
]);
$this
->drupalLogin($account);
}
public function testFileUploadErrors() {
$this
->drupalGet('node/add/page');
$edit = [
'edit-title-0-value' => $this
->randomString(),
];
$this
->submitForm($edit, t('Save'));
$error_text = $this
->getSession()
->getPage()
->find('css', '.field--name-field-ief-file .form-item--error-message')
->getText();
$this
->assertEquals('field_ief_file field is required.', $error_text);
}
}