comparison 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
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php
2
3 namespace Drupal\FunctionalJavascriptTests\Tests;
4
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
7 use Drupal\Tests\file\Functional\FileFieldCreationTrait;
8 use Drupal\Tests\TestFileCreationTrait;
9
10 /**
11 * Tests the DrupalSelenium2Driver methods.
12 *
13 * @coversDefaultClass \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver
14 * @group javascript
15 */
16 class DrupalSelenium2DriverTest extends WebDriverTestBase {
17
18 use TestFileCreationTrait;
19 use FileFieldCreationTrait;
20
21 /**
22 * {@inheritdoc}
23 */
24 protected static $modules = ['file', 'field_ui', 'entity_test'];
25
26 /**
27 * {@inheritdoc}
28 */
29 protected function setUp() {
30 parent::setUp();
31 $storage_settings = ['cardinality' => 3];
32 $this->createFileField('field_file', 'entity_test', 'entity_test', $storage_settings);
33 $this->drupalLogin($this->drupalCreateUser([
34 'administer entity_test content',
35 'access content',
36 ]));
37 }
38
39 /**
40 * Tests uploading remote files.
41 */
42 public function testGetRemoteFilePath() {
43 $web_driver = $this->getSession()->getDriver();
44 $file_system = \Drupal::service('file_system');
45 $entity = EntityTest::create();
46 $entity->save();
47
48 $files = array_slice($this->getTestFiles('text'), 0, 3);
49 $real_paths = [];
50 foreach ($files as $file) {
51 $real_paths[] = $file_system->realpath($file->uri);
52 }
53 $remote_paths = [];
54 foreach ($real_paths as $path) {
55 $remote_paths[] = $web_driver->uploadFileAndGetRemoteFilePath($path);
56 }
57
58 // Tests that uploading multiple remote files works with remote path.
59 $this->drupalGet($entity->toUrl('edit-form'));
60 $multiple_field = $this->xpath('//input[@multiple]')[0];
61 $multiple_field->setValue(implode("\n", $remote_paths));
62 $this->assertSession()->assertWaitOnAjaxRequest();
63 $this->getSession()->getPage()->findButton('Save')->click();
64 $entity = EntityTest::load($entity->id());
65 $this->assertCount(3, $entity->field_file);
66 }
67
68 }