diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/UploadFail.php b/core/modules/media_library/tests/src/FunctionalJavascript/UploadFail.php index 6992a03624..e6503471d0 100644 --- a/core/modules/media_library/tests/src/FunctionalJavascript/UploadFail.php +++ b/core/modules/media_library/tests/src/FunctionalJavascript/UploadFail.php @@ -4,6 +4,7 @@ use Behat\Mink\Exception\ElementNotFoundException; use Drupal\Core\File\Exception\FileNotExistsException; +use Drupal\Core\File\FileSystemInterface; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; use Drupal\media\Entity\Media; use Drupal\Tests\TestFileCreationTrait; @@ -58,6 +59,8 @@ public function testManyConsecutiveUploads() { // Visit a node create page and open the media library. $this->drupalGet('node/add/basic_page'); + $database = $this->container->get('database'); + $count = 0; // Upload then remove an image 100x to see if/when it fails. while ($count < 100) { @@ -65,11 +68,17 @@ public function testManyConsecutiveUploads() { $this->assertElementExistsAfterWait('css', '.media-library-menu', 10000, "Media library menu did not appear on iteration $count"); $this->waitForText('Add or select media', 10000, "Text 'Add or select media' not appear on iteration $count"); $this->clickTypeTab('Four'); - $new_filename = uniqid() . '.jpg'; + $new_filename = uniqid(time()) . '.jpg'; $new_filepath = $file_system->realpath('public://') . '/' . $new_filename; - copy($file_system->realpath($jpg_image->uri), $new_filepath); + $file_system->copy($file_system->realpath($jpg_image->uri), $new_filepath); $this->waitForFieldExists('Add files', 10000, "Did not find 'Add files' on iteration $count"); + $media_count = $database->select('file_managed')->countQuery()->execute()->fetchField(); + $this->assertEquals($count, $media_count); $page->attachFileToField('Add files', $new_filepath); + $this->assertTrue($page->waitFor(10, function () use ($database, $count) { + $media_count = $database->select('file_managed')->countQuery()->execute()->fetchField(); + return ($count + 1) === intval($media_count); + }), "The file_managed table wasn't updated iteration $count"); $this->waitForText('Alternative text', 10000, "Alternative text field not found on iteration $count"); $field = $page->findField('Alternative text'); $this->assertTrue(!empty($field), "Alt text label found but not the field on iteration $count"); @@ -86,6 +95,8 @@ public function testManyConsecutiveUploads() { $this->assertElementExistsAfterWait('css', '[name="field_twin_media-0-media-library-remove-button"]', 10000, "Media remove button not found on iteration $count")->click(); $this->waitForText('2 media items remaining', 10000, "'2 media items remaining' not found on iteration $count"); $count++; + // Delete temporary file. + $file_system->delete($new_filepath); usleep(10000); }