b7bf839328f5b96cb0abc24c66433a4fa8c6ac72
[yaffs-website] / web / modules / contrib / entity_browser / tests / src / FunctionalJavascript / UploadWidgetTest.php
1 <?php
2
3 namespace Drupal\Tests\entity_browser\FunctionalJavascript;
4
5 use Drupal\user\Entity\Role;
6
7 /**
8  * Tests the Upload Widget.
9  *
10  * @group entity_browser
11  */
12 class UploadWidgetTest extends EntityBrowserJavascriptTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function setUp() {
18     parent::setUp();
19
20     // Grant permission to this user to use also the EB page we are testing.
21     /** @var \Drupal\user\RoleInterface $role */
22     $role = Role::load('authenticated');
23     $this->grantPermissions($role, ['access test_entity_browser_standalone_upload entity browser pages']);
24
25   }
26
27   /**
28    * Tests Entity Browser upload widget.
29    */
30   public function testUploadWidget() {
31
32     /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */
33     $browser = $this->container->get('entity_type.manager')
34       ->getStorage('entity_browser')
35       ->load('test_entity_browser_standalone_upload');
36
37     $page = $this->getSession()->getPage();
38
39     // Make sure the test file is not present beforehand.
40     $this->assertFileNotExists('public://druplicon.png');
41
42     // Go to the widget standalone page and test the upload.
43     $this->drupalGet($browser->getDisplay()->path());
44     $page->attachFileToField('edit-upload-upload', \Drupal::root() . '/core/misc/druplicon.png');
45     $this->waitForAjaxToFinish();
46     $this->assertSession()->fieldExists('druplicon.png');
47     $page->pressButton('Select files');
48     $this->assertSession()->statusCodeEquals(200);
49
50     // Check if the file was correctly uploaded to the EB destination.
51     $this->assertFileExists('public://druplicon.png');
52
53     // Now change upload location and submit label and check again.
54     $widget = $browser->getWidget('2dc1ab07-2f8f-42c9-aab7-7eef7f8b7d87');
55     $config = $widget->getConfiguration();
56     $config['settings']['upload_location'] = 'public://some_location';
57     $config['settings']['submit_text'] = 'Fancy submit';
58     $widget->setConfiguration($config);
59     $browser->save();
60
61     $this->drupalGet($browser->getDisplay()->path());
62     $page->attachFileToField('edit-upload-upload', \Drupal::root() . '/core/misc/druplicon.png');
63     $this->waitForAjaxToFinish();
64     $this->assertSession()->fieldExists('druplicon.png');
65     $page->pressButton('Fancy submit');
66     $this->assertSession()->statusCodeEquals(200);
67
68     // Check if the file was correctly uploaded to the EB destination.
69     $this->assertFileExists('public://some_location/druplicon.png');
70
71   }
72
73 }