Mercurial > hg > cmmr2012-drupal-site
diff core/tests/Drupal/FunctionalJavascriptTests/Tests/DrupalSelenium2DriverTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/tests/Drupal/FunctionalJavascriptTests/Tests/DrupalSelenium2DriverTest.php Thu May 09 15:34:47 2019 +0100 @@ -0,0 +1,68 @@ +<?php + +namespace Drupal\FunctionalJavascriptTests\Tests; + +use Drupal\entity_test\Entity\EntityTest; +use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\Tests\file\Functional\FileFieldCreationTrait; +use Drupal\Tests\TestFileCreationTrait; + +/** + * Tests the DrupalSelenium2Driver methods. + * + * @coversDefaultClass \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver + * @group javascript + */ +class DrupalSelenium2DriverTest extends WebDriverTestBase { + + use TestFileCreationTrait; + use FileFieldCreationTrait; + + /** + * {@inheritdoc} + */ + protected static $modules = ['file', 'field_ui', 'entity_test']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $storage_settings = ['cardinality' => 3]; + $this->createFileField('field_file', 'entity_test', 'entity_test', $storage_settings); + $this->drupalLogin($this->drupalCreateUser([ + 'administer entity_test content', + 'access content', + ])); + } + + /** + * Tests uploading remote files. + */ + public function testGetRemoteFilePath() { + $web_driver = $this->getSession()->getDriver(); + $file_system = \Drupal::service('file_system'); + $entity = EntityTest::create(); + $entity->save(); + + $files = array_slice($this->getTestFiles('text'), 0, 3); + $real_paths = []; + foreach ($files as $file) { + $real_paths[] = $file_system->realpath($file->uri); + } + $remote_paths = []; + foreach ($real_paths as $path) { + $remote_paths[] = $web_driver->uploadFileAndGetRemoteFilePath($path); + } + + // Tests that uploading multiple 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->assertSession()->assertWaitOnAjaxRequest(); + $this->getSession()->getPage()->findButton('Save')->click(); + $entity = EntityTest::load($entity->id()); + $this->assertCount(3, $entity->field_file); + } + +}