|
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/widgets'); |
|
40
|
|
|
$edit = [ |
|
41
|
|
|
'table[871dbf77-012e-41cb-b32a-ada353d2de35][form][submit_text]' => 'Different', |
|
42
|
|
|
]; |
|
43
|
|
|
$this->drupalPostForm(NULL, $edit, 'Finish'); |
|
44
|
|
|
$this->drupalGet('/entity-browser/iframe/test_entity_browser_iframe'); |
|
45
|
|
|
$this->assertRaw('Different'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Tests entity browser token support for upload widget. |
|
50
|
|
|
*/ |
|
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', |
|
55
|
|
|
]); |
|
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')); |
|
60
|
|
|
$edit = [ |
|
61
|
|
|
'files[upload][]' => $this->container->get('file_system')->realpath($image->uri), |
|
62
|
|
|
]; |
|
63
|
|
|
$this->drupalPostForm(NULL, $edit, 'Select files'); |
|
64
|
|
|
|
|
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.'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|