DrupalSelenium2DriverTest.php 2.0 KB

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