Unverified Commit 6312fcbe authored by alexpott's avatar alexpott

Issue #2870448 by vaplas, naveenvalecha, yogeshmpawar, dawehner, alexpott:...

Issue #2870448 by vaplas, naveenvalecha, yogeshmpawar, dawehner, alexpott: Convert web tests to browser tests for file module
parent 6bf15d5f
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
@trigger_error('The ' . __NAMESPACE__ . '\FileFieldTestBase is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\file\Functional\FileFieldTestBase. See https://www.drupal.org/node/2969361.', E_USER_DEPRECATED);
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\file\FileInterface; use Drupal\file\FileInterface;
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
@trigger_error('The ' . __NAMESPACE__ . '\FileManagedTestBase is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\file\Functional\FileManagedTestBase. See https://www.drupal.org/node/2969361.', E_USER_DEPRECATED);
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
use Drupal\file\FileInterface; use Drupal\file\FileInterface;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
/** /**
* Tests for download/file transfer functions. * Tests for download/file transfer functions.
...@@ -26,16 +26,17 @@ public function testPublicFileTransfer() { ...@@ -26,16 +26,17 @@ public function testPublicFileTransfer() {
// encoded. // encoded.
$filename = $GLOBALS['base_url'] . '/' . \Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath() . '/' . rawurlencode($file->getFilename()); $filename = $GLOBALS['base_url'] . '/' . \Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath() . '/' . rawurlencode($file->getFilename());
$this->assertEqual($filename, $url, 'Correctly generated a URL for a created file.'); $this->assertEqual($filename, $url, 'Correctly generated a URL for a created file.');
$this->drupalHead($url); $http_client = $this->getHttpClient();
$this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the created file.'); $response = $http_client->head($url);
$this->assertEquals(200, $response->getStatusCode(), 'Confirmed that the generated URL is correct by downloading the created file.');
// Test generating a URL to a shipped file (i.e. a file that is part of // Test generating a URL to a shipped file (i.e. a file that is part of
// Drupal core, a module or a theme, for example a JavaScript file). // Drupal core, a module or a theme, for example a JavaScript file).
$filepath = 'core/assets/vendor/jquery/jquery.min.js'; $filepath = 'core/assets/vendor/jquery/jquery.min.js';
$url = file_create_url($filepath); $url = file_create_url($filepath);
$this->assertEqual($GLOBALS['base_url'] . '/' . $filepath, $url, 'Correctly generated a URL for a shipped file.'); $this->assertEqual($GLOBALS['base_url'] . '/' . $filepath, $url, 'Correctly generated a URL for a shipped file.');
$this->drupalHead($url); $response = $http_client->head($url);
$this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.'); $this->assertEquals(200, $response->getStatusCode(), 'Confirmed that the generated URL is correct by downloading the shipped file.');
} }
/** /**
...@@ -71,17 +72,18 @@ protected function doPrivateFileTransferTest() { ...@@ -71,17 +72,18 @@ protected function doPrivateFileTransferTest() {
$this->assertResponse(200, 'Correctly allowed access to a file when file_test provides headers.'); $this->assertResponse(200, 'Correctly allowed access to a file when file_test provides headers.');
// Test that the file transferred correctly. // Test that the file transferred correctly.
$this->assertEqual($contents, $this->content, 'Contents of the file are correct.'); $this->assertSame($contents, $this->getSession()->getPage()->getContent(), 'Contents of the file are correct.');
$http_client = $this->getHttpClient();
// Deny access to all downloads via a -1 header. // Deny access to all downloads via a -1 header.
file_test_set_return('download', -1); file_test_set_return('download', -1);
$this->drupalHead($url); $response = $http_client->head($url, ['http_errors' => FALSE]);
$this->assertResponse(403, 'Correctly denied access to a file when file_test sets the header to -1.'); $this->assertSame(403, $response->getStatusCode(), 'Correctly denied access to a file when file_test sets the header to -1.');
// Try non-existent file. // Try non-existent file.
$url = file_create_url('private://' . $this->randomMachineName()); $url = file_create_url('private://' . $this->randomMachineName());
$this->drupalHead($url); $response = $http_client->head($url, ['http_errors' => FALSE]);
$this->assertResponse(404, 'Correctly returned 404 response for a non-existent file.'); $this->assertSame(404, $response->getStatusCode(), 'Correctly returned 404 response for a non-existent file.');
} }
/** /**
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\user\RoleInterface; use Drupal\user\RoleInterface;
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
...@@ -97,15 +97,17 @@ public function testNodeDisplay() { ...@@ -97,15 +97,17 @@ public function testNodeDisplay() {
// Test that fields appear as expected after during the preview. // Test that fields appear as expected after during the preview.
// Add a second file. // Add a second file.
$name = 'files[' . $field_name . '_1][]'; $name = 'files[' . $field_name . '_1][]';
$edit[$name] = \Drupal::service('file_system')->realpath($test_file->getFileUri()); $edit_upload[$name] = \Drupal::service('file_system')->realpath($test_file->getFileUri());
$this->drupalPostForm("node/$nid/edit", $edit_upload, t('Upload'));
// Uncheck the display checkboxes and go to the preview. // Uncheck the display checkboxes and go to the preview.
$edit[$field_name . '[0][display]'] = FALSE; $edit[$field_name . '[0][display]'] = FALSE;
$edit[$field_name . '[1][display]'] = FALSE; $edit[$field_name . '[1][display]'] = FALSE;
$this->drupalPostForm("node/$nid/edit", $edit, t('Preview')); $this->drupalPostForm(NULL, $edit, t('Preview'));
$this->clickLink(t('Back to content editing')); $this->clickLink(t('Back to content editing'));
$this->assertRaw($field_name . '[0][display]', 'First file appears as expected.'); $this->assertRaw($field_name . '[0][display]', 'First file appears as expected.');
$this->assertRaw($field_name . '[1][display]', 'Second file appears as expected.'); $this->assertRaw($field_name . '[1][display]', 'Second file appears as expected.');
$this->assertSession()->responseContains($field_name . '[1][description]', 'Description of second file appears as expected.');
} }
/** /**
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
/** /**
* Tests file formatter access. * Tests file formatter access.
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
...@@ -60,12 +60,12 @@ public function testFileFieldRSSContent() { ...@@ -60,12 +60,12 @@ public function testFileFieldRSSContent() {
$this->drupalGet('rss.xml'); $this->drupalGet('rss.xml');
$uploaded_filename = str_replace('public://', '', $node_file->getFileUri()); $uploaded_filename = str_replace('public://', '', $node_file->getFileUri());
$selector = sprintf( $selector = sprintf(
'enclosure[url="%s"][length="%s"][type="%s"]', 'enclosure[@url="%s"][@length="%s"][@type="%s"]',
file_create_url("public://$uploaded_filename", ['absolute' => TRUE]), file_create_url("public://$uploaded_filename", ['absolute' => TRUE]),
$node_file->getSize(), $node_file->getSize(),
$node_file->getMimeType() $node_file->getMimeType()
); );
$this->assertTrue(!empty($this->cssSelect($selector)), 'File field RSS enclosure is displayed when viewing the RSS feed.'); $this->assertNotNull($this->getSession()->getDriver()->find('xpath', $selector), 'File field RSS enclosure is displayed when viewing the RSS feed.');
} }
} }
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
...@@ -187,25 +187,4 @@ public function testFileRemoval() { ...@@ -187,25 +187,4 @@ public function testFileRemoval() {
$this->assertText('Article ' . $node->getTitle() . ' has been updated.'); $this->assertText('Article ' . $node->getTitle() . ' has been updated.');
} }
/**
* Test the validation message is displayed only once for ajax uploads.
*/
public function testAJAXValidationMessage() {
$field_name = strtolower($this->randomMachineName());
$this->createFileField($field_name, 'node', 'article');
$this->drupalGet('node/add/article');
/** @var \Drupal\file\FileInterface $image_file */
$image_file = $this->getTestFile('image');
$edit = [
'files[' . $field_name . '_0]' => $this->container->get('file_system')->realpath($image_file->getFileUri()),
'title[0][value]' => $this->randomMachineName(),
];
$this->drupalPostAjaxForm(NULL, $edit, $field_name . '_0_upload_button');
$elements = $this->xpath('//div[contains(@class, :class)]', [
':class' => 'messages--error',
]);
$this->assertEqual(count($elements), 1, 'Ajax validation messages are displayed once.');
}
} }
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
...@@ -127,7 +127,7 @@ public function testFileListingPages() { ...@@ -127,7 +127,7 @@ public function testFileListingPages() {
$usage = $this->sumUsages($file_usage->listUsage($file)); $usage = $this->sumUsages($file_usage->listUsage($file));
$this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage); $this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage);
$result = $this->xpath("//td[contains(@class, 'views-field-status') and contains(text(), :value)]", [':value' => t('Temporary')]); $result = $this->xpath("//td[contains(@class, 'views-field-status') and contains(text(), :value)]", [':value' => 'Temporary']);
$this->assertEqual(1, count($result), 'Unused file marked as temporary.'); $this->assertEqual(1, count($result), 'Unused file marked as temporary.');
// Test file usage page. // Test file usage page.
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\Core\Entity\Plugin\Validation\Constraint\ReferenceAccessConstraint; use Drupal\Core\Entity\Plugin\Validation\Constraint\ReferenceAccessConstraint;
use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Render\FormattableMarkup;
...@@ -81,8 +81,11 @@ public function testPrivateFile() { ...@@ -81,8 +81,11 @@ public function testPrivateFile() {
$edit['title[0][value]'] = $this->randomMachineName(); $edit['title[0][value]'] = $this->randomMachineName();
$this->drupalPostForm('node/add/' . $type_name, $edit, t('Save')); $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save'));
$new_node = $this->drupalGetNodeByTitle($edit['title[0][value]']); $new_node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$edit[$field_name . '[0][fids]'] = $node_file->id();
$this->drupalPostForm('node/' . $new_node->id() . '/edit', $edit, t('Save')); // Can't use drupalPostForm() to set hidden fields.
$this->drupalGet('node/' . $new_node->id() . '/edit');
$this->getSession()->getPage()->find('css', 'input[name="' . $field_name . '[0][fids]"]')->setValue($node_file->id());
$this->getSession()->getPage()->pressButton(t('Save'));
// Make sure the form submit failed - we stayed on the edit form. // Make sure the form submit failed - we stayed on the edit form.
$this->assertUrl('node/' . $new_node->id() . '/edit'); $this->assertUrl('node/' . $new_node->id() . '/edit');
// Check that we got the expected constraint form error. // Check that we got the expected constraint form error.
...@@ -92,8 +95,11 @@ public function testPrivateFile() { ...@@ -92,8 +95,11 @@ public function testPrivateFile() {
// that access is still denied. // that access is still denied.
$edit = []; $edit = [];
$edit['title[0][value]'] = $this->randomMachineName(); $edit['title[0][value]'] = $this->randomMachineName();
$edit[$field_name . '[0][fids]'] = $node_file->id(); // Can't use drupalPostForm() to set hidden fields.
$this->drupalPostForm('node/add/' . $type_name, $edit, t('Save')); $this->drupalGet('node/add/' . $type_name);
$this->getSession()->getPage()->find('css', 'input[name="title[0][value]"]')->setValue($edit['title[0][value]']);
$this->getSession()->getPage()->find('css', 'input[name="' . $field_name . '[0][fids]"]')->setValue($node_file->id());
$this->getSession()->getPage()->pressButton(t('Save'));
$new_node = $this->drupalGetNodeByTitle($edit['title[0][value]']); $new_node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertTrue(empty($new_node), 'Node was not created.'); $this->assertTrue(empty($new_node), 'Node was not created.');
$this->assertUrl('node/add/' . $type_name); $this->assertUrl('node/add/' . $type_name);
...@@ -144,9 +150,7 @@ public function testPrivateFile() { ...@@ -144,9 +150,7 @@ public function testPrivateFile() {
$this->drupalGet($file_url); $this->drupalGet($file_url);
$this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the temporary file.'); $this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the temporary file.');
// Close the prior connection and remove the session cookie. // Close the prior connection and remove the session cookie.
$this->curlClose(); $this->getSession()->reset();
$this->curlCookies = [];
$this->cookies = [];
$this->drupalGet($file_url); $this->drupalGet($file_url);
$this->assertResponse(403, 'Confirmed that another anonymous user cannot access the temporary file.'); $this->assertResponse(403, 'Confirmed that another anonymous user cannot access the temporary file.');
...@@ -174,9 +178,7 @@ public function testPrivateFile() { ...@@ -174,9 +178,7 @@ public function testPrivateFile() {
$this->drupalGet($file_url); $this->drupalGet($file_url);
$this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the file whose references were removed.'); $this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the file whose references were removed.');
// Close the prior connection and remove the session cookie. // Close the prior connection and remove the session cookie.
$this->curlClose(); $this->getSession()->reset();
$this->curlCookies = [];
$this->cookies = [];
$this->drupalGet($file_url); $this->drupalGet($file_url);
$this->assertResponse(403, 'Confirmed that another anonymous user cannot access the file whose references were removed.'); $this->assertResponse(403, 'Confirmed that another anonymous user cannot access the file whose references were removed.');
...@@ -197,9 +199,7 @@ public function testPrivateFile() { ...@@ -197,9 +199,7 @@ public function testPrivateFile() {
$this->drupalGet($file_url); $this->drupalGet($file_url);
$this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the permanent file that is referenced by a published node.'); $this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the permanent file that is referenced by a published node.');
// Close the prior connection and remove the session cookie. // Close the prior connection and remove the session cookie.
$this->curlClose(); $this->getSession()->reset();
$this->curlCookies = [];
$this->cookies = [];
$this->drupalGet($file_url); $this->drupalGet($file_url);
$this->assertResponse(200, 'Confirmed that another anonymous user also has access to the permanent file that is referenced by a published node.'); $this->assertResponse(200, 'Confirmed that another anonymous user also has access to the permanent file that is referenced by a published node.');
...@@ -224,9 +224,7 @@ public function testPrivateFile() { ...@@ -224,9 +224,7 @@ public function testPrivateFile() {
$this->drupalGet($file_url); $this->drupalGet($file_url);
$this->assertResponse(403, 'Confirmed that the anonymous uploader cannot access the permanent file when it is referenced by an unpublished node.'); $this->assertResponse(403, 'Confirmed that the anonymous uploader cannot access the permanent file when it is referenced by an unpublished node.');
// Close the prior connection and remove the session cookie. // Close the prior connection and remove the session cookie.
$this->curlClose(); $this->getSession()->reset();
$this->curlCookies = [];
$this->cookies = [];
$this->drupalGet($file_url); $this->drupalGet($file_url);
$this->assertResponse(403, 'Confirmed that another anonymous user cannot access the permanent file when it is referenced by an unpublished node.'); $this->assertResponse(403, 'Confirmed that another anonymous user cannot access the permanent file when it is referenced by an unpublished node.');
} }
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Render\BubbleableMetadata;
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
/** /**
* Tests the file uploading functions. * Tests the file uploading functions.
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
use Drupal\Tests\TestFileCreationTrait;
/** /**
* Tests the _file_save_upload_from_form() function. * Tests the _file_save_upload_from_form() function.
...@@ -13,6 +14,10 @@ ...@@ -13,6 +14,10 @@
*/ */
class SaveUploadFormTest extends FileManagedTestBase { class SaveUploadFormTest extends FileManagedTestBase {
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
}
/** /**
* Modules to enable. * Modules to enable.
* *
...@@ -445,17 +450,22 @@ public function testCombinedErrorMessages() { ...@@ -445,17 +450,22 @@ public function testCombinedErrorMessages() {
/** @var \Drupal\Core\File\FileSystemInterface $file_system */ /** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system'); $file_system = \Drupal::service('file_system');
// Can't use drupalPostForm() for set nonexistent fields.
$this->drupalGet('file-test/save_upload_from_form_test');
$client = $this->getSession()->getDriver()->getClient();
$submit_xpath = $this->assertSession()->buttonExists('Submit')->getXpath();
$form = $client->getCrawler()->filterXPath($submit_xpath)->form();
$edit = [ $edit = [
'files[file_test_upload][]' => [
$file_system->realpath($this->phpfile->uri),
$file_system->realpath($textfile->uri),
],
'allow_all_extensions' => FALSE, 'allow_all_extensions' => FALSE,
'is_image_file' => TRUE, 'is_image_file' => TRUE,
'extensions' => 'jpeg', 'extensions' => 'jpeg',
]; ];
$edit += $form->getPhpValues();
$files['files']['file_test_upload'][0] = $file_system->realpath($this->phpfile->uri);
$files['files']['file_test_upload'][1] = $file_system->realpath($textfile->uri);
$client->request($form->getMethod(), $form->getUri(), $edit, $files);
$this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.'); $this->assertResponse(200, 'Received a 200 response for posted test file.');
$this->assertRaw(t('Epic upload FAIL!'), 'Found the failure message.'); $this->assertRaw(t('Epic upload FAIL!'), 'Found the failure message.');
......
<?php <?php
namespace Drupal\file\Tests; namespace Drupal\Tests\file\Functional;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
use Drupal\Tests\TestFileCreationTrait;
/** /**
* Tests the file_save_upload() function. * Tests the file_save_upload() function.
...@@ -10,6 +11,11 @@ ...@@ -10,6 +11,11 @@
* @group file * @group file
*/ */
class SaveUploadTest extends FileManagedTestBase { class SaveUploadTest extends FileManagedTestBase {
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
}
/** /**
* Modules to enable. * Modules to enable.
* *
......
<?php <?php
namespace Drupal\file\Tests\Update; namespace Drupal\Tests\file\Functional\Update;
use Drupal\system\Tests\Update\UpdatePathTestBase; use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/** /**
* Tests File update path. * Tests File update path.
...@@ -21,8 +21,8 @@ class FileUpdateTest extends UpdatePathTestBase { ...@@ -21,8 +21,8 @@ class FileUpdateTest extends UpdatePathTestBase {
*/ */
protected function setDatabaseDumpFiles() { protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [ $this->databaseDumpFiles = [
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../tests/fixtures/update/drupal-8.file_formatters_update_2677990.php', __DIR__ . '/../../../../tests/fixtures/update/drupal-8.file_formatters_update_2677990.php',
]; ];
} }
......
<?php <?php
namespace Drupal\file\Tests\Views; namespace Drupal\Tests\file\Functional\Views;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
use Drupal\views\Tests\ViewTestBase; use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Views; use Drupal\views\Views;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
......
<?php
namespace Drupal\Tests\file\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
use Drupal\Tests\file\Functional\FileFieldCreationTrait;
use Drupal\Tests\TestFileCreationTrait;
/**
* Tests validation functions such as file type, max file size, max size per
* node, and required.
*
* @group file
*/
class FileFieldValidateTest extends JavascriptTestBase {
use FileFieldCreationTrait;
use TestFileCreationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'file'];
/**
* Test 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);