3 namespace Drupal\entity_browser\Tests;
5 use Drupal\file\Entity\File;
6 use Drupal\simpletest\WebTestBase;
9 * Tests the entity browser UI.
11 * @group entity_browser
13 class EntityBrowserUITest extends WebTestBase {
20 public static $modules = [
21 'entity_browser_test',
28 * Tests entity browser UI.
30 public function testEntityBrowserUI() {
31 $account = $this->drupalCreateUser([
32 'administer entity browsers',
33 'access test_entity_browser_iframe entity browser pages',
35 $this->drupalLogin($account);
36 // Go to the entity browser iframe link.
37 $this->drupalGet('/entity-browser/iframe/test_entity_browser_iframe');
38 $this->assertRaw('Select');
39 $this->drupalGet('/admin/config/content/entity_browser/test_entity_browser_iframe/widgets');
41 'table[871dbf77-012e-41cb-b32a-ada353d2de35][form][submit_text]' => 'Different',
43 $this->drupalPostForm(NULL, $edit, 'Finish');
44 $this->drupalGet('/entity-browser/iframe/test_entity_browser_iframe');
45 $this->assertRaw('Different');
49 * Tests entity browser token support for upload widget.
51 public function testEntityBrowserToken() {
52 $this->container->get('module_installer')->install(['token', 'file']);
53 $account = $this->drupalCreateUser([
54 'access test_entity_browser_token entity browser pages',
56 $this->drupalLogin($account);
57 // Go to the entity browser iframe link.
58 $this->drupalGet('/entity-browser/iframe/test_entity_browser_token');
59 $image = current($this->drupalGetTestFiles('image'));
61 'files[upload][]' => $this->container->get('file_system')->realpath($image->uri),
63 $this->drupalPostForm(NULL, $edit, 'Select files');
65 $file = File::load(1);
66 // Test entity browser token that has upload location configured to
67 // public://[current-user:account-name]/.
68 $this->assertEqual($file->getFileUri(), 'public://' . $account->getUsername() . '/' . $file->getFilename(), 'Image has the correct uri.');