Completed
Push — 8.x-1.x ( 321310...2a7b34 )
by Janez
02:52
created

EntityBrowserUITest::testEntityBrowserToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 19
rs 9.4285
1
<?php
2
3
namespace Drupal\entity_browser\Tests;
4
5
use Drupal\file\Entity\File;
6
use Drupal\simpletest\WebTestBase;
7
8
/**
9
 * Tests the entity browser UI.
10
 *
11
 * @group entity_browser
12
 */
13
class EntityBrowserUITest extends WebTestBase {
14
15
  /**
16
   * Modules to enable.
17
   *
18
   * @var array
19
   */
20
  public static $modules = [
21
    'entity_browser_test',
22
    'ctools',
23
    'views',
24
    'block',
25
  ];
26
27
  /**
28
   * Tests entity browser UI.
29
   */
30
  public function testEntityBrowserUI() {
31
    $account = $this->drupalCreateUser([
32
      'administer entity browsers',
33
      'access test_entity_browser_iframe entity browser pages',
34
    ]);
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');
40
    $edit = [
41
      'submit_text' => 'Different',
42
    ];
43
    $this->drupalPostForm(NULL, $edit, 'Next');
44
    $this->drupalGet('/admin/config/content/entity_browser/test_entity_browser_iframe/widgets');
45
    $this->drupalPostForm(NULL, [], 'Finish');
46
    $this->drupalGet('/entity-browser/iframe/test_entity_browser_iframe');
47
    $this->assertRaw('Different');
48
  }
49
50
  /**
51
   * Tests entity browser token support for upload widget.
52
   */
53
  public function testEntityBrowserToken() {
54
    $this->container->get('module_installer')->install(['token', 'file']);
55
    $account = $this->drupalCreateUser([
56
      'access test_entity_browser_token entity browser pages',
57
    ]);
58
    $this->drupalLogin($account);
59
    // Go to the entity browser iframe link.
60
    $this->drupalGet('/entity-browser/iframe/test_entity_browser_token');
61
    $image = current($this->drupalGetTestFiles('image'));
62
    $edit = [
63
      'files[upload][]' => $this->container->get('file_system')->realpath($image->uri),
64
    ];
65
    $this->drupalPostForm(NULL, $edit, 'Select');
66
67
    $file = File::load(1);
68
    // Test entity browser token that has upload location configured to
69
    // public://[current-user:account-name]/
70
    $this->assertEqual($file->getFileUri(), 'public://' . $account->getUsername() . '/' . $file->getFilename(), 'Image has the correct uri.');
71
  }
72
73
}
74