diff --git a/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php b/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php index b1060ccf90..29cf02beb0 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php @@ -79,26 +79,19 @@ public function getRemoteFilePath($path) { } try { - $remotePath = $this->getWebDriverSession()->file(array('file' => base64_encode(file_get_contents($tempFilename)))); + $remotePath = $this->getWebDriverSession()->file(['file' => base64_encode(file_get_contents($tempFilename))]); - // If no path is returned the file upload failed silently. In this - // case it is possible Selenium was not used but another web driver - // such as PhantomJS. - // @todo Support other drivers when (if) they get remote file transfer - // capability. + // If no path is returned the file upload failed silently. if (empty($remotePath)) { throw new UnknownError(); } } catch (\Exception $e) { - // Catch any error so we can still clean up the temporary archive. - } - - unlink($tempFilename); - - if (isset($e)) { throw $e; } + finally { + unlink($tempFilename); + } return $remotePath; } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Tests/DrupalSelenium2DriverTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Tests/DrupalSelenium2DriverTest.php index 97380c657a..ddd956ddb0 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Tests/DrupalSelenium2DriverTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Tests/DrupalSelenium2DriverTest.php @@ -3,10 +3,10 @@ namespace Drupal\FunctionalJavascriptTests\Tests; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\entity_test\Entity\EntityTest; use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; use Drupal\FunctionalJavascriptTests\JavascriptTestBase; -use Drupal\node\Entity\Node; -use Drupal\Tests\image\Kernel\ImageFieldCreationTrait; +use Drupal\Tests\file\Functional\FileFieldCreationTrait; use Drupal\Tests\TestFileCreationTrait; /** @@ -17,8 +17,8 @@ */ class DrupalSelenium2DriverTest extends JavascriptTestBase { - use ImageFieldCreationTrait; use TestFileCreationTrait; + use FileFieldCreationTrait; /** * {@inheritdoc} @@ -28,7 +28,7 @@ class DrupalSelenium2DriverTest extends JavascriptTestBase { /** * {@inheritdoc} */ - protected static $modules = ['node', 'image', 'field_ui']; + protected static $modules = ['file', 'field_ui', 'entity_test']; /** * WebDriver. @@ -51,12 +51,12 @@ protected function setUp() { parent::setUp(); $this->webDriver = $this->getSession()->getDriver(); $this->fileSystem = \Drupal::service('file_system'); - - $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); $storage_settings = ['cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED]; - $field_settings = ['alt_field_required' => 0]; - $this->createImageField('images', 'article', $storage_settings, $field_settings); - $this->drupalLogin($this->drupalCreateUser(['access content', 'create article content'])); + $this->createFileField('field_file', 'entity_test', 'entity_test', $storage_settings); + $this->drupalLogin($this->drupalCreateUser([ + 'administer entity_test content', + 'access content', + ])); } /** @@ -65,30 +65,29 @@ protected function setUp() { * @covers ::getRemoteFilePath */ public function testGetRemoteFilePath() { + $entity = EntityTest::create(); + $entity->save(); - $this->drupalGet('node/add/article'); - $this->xpath('//input[@name="title[0][value]"]')[0]->setValue('Test'); - $multiple_field = $this->xpath('//input[@multiple]')[0]; - - $images = array_slice($this->getTestFiles('image'), 0, 3); - + $files = array_slice($this->getTestFiles('text'), 0, 3); $real_paths = []; - foreach ($images as $image) { - $real_paths[] = $this->fileSystem->realpath($image->uri); + foreach ($files as $file) { + $real_paths[] = $this->fileSystem->realpath($file->uri); } - $remote_paths = []; foreach ($real_paths as $path) { $remote_paths[] = $this->webDriver->getRemoteFilePath($path); } + + // Tests that upload remote files works with remote path. + $this->drupalGet($entity->toUrl('edit-form')); + $multiple_field = $this->xpath('//input[@multiple]')[0]; $multiple_field->setValue(implode("\n", $remote_paths)); $this->getSession()->getPage()->findButton('Save')->click(); - $node = Node::load(1); - $this->assertNotEmpty($node->images); + $entity = EntityTest::load($entity->id()); + $this->assertNotEmpty($entity->field_file); - // Tests that upload remote files not works without getRemoteFilePath(). - $this->drupalGet('node/add/article'); - $this->xpath('//input[@name="title[0][value]"]')[0]->setValue('Test'); + // Tests that upload remote files not works without remote path. + $this->drupalGet($entity->toUrl('edit-form')); $multiple_field = $this->xpath('//input[@multiple]')[0]; try { $multiple_field->setValue(implode("\n", $real_paths));