1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\Tests\media\FunctionalJavascript; |
4
|
|
|
|
5
|
|
|
use Drupal\FunctionalJavascriptTests\JavascriptTestBase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Ensures that embedding functionality works perfectly. |
9
|
|
|
* |
10
|
|
|
* @group media |
11
|
|
|
*/ |
12
|
|
|
class EmbedButtonTest extends JavascriptTestBase { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
public static $modules = [ |
18
|
|
|
'node', |
19
|
|
|
'path', |
20
|
|
|
'text', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function setUp() { |
27
|
|
|
parent::setUp(); |
28
|
|
|
// Manually installing modules to preserve the order. |
29
|
|
|
$this->installModule('media_embed_test'); |
30
|
|
|
$this->installModule('media'); |
31
|
|
|
$adminUser = $this->drupalCreateUser([ |
32
|
|
|
'access content', |
33
|
|
|
'use text format basic_html', |
34
|
|
|
'use text format full_html', |
35
|
|
|
'access media_embed entity browser pages', |
36
|
|
|
'view media', |
37
|
|
|
'create media', |
38
|
|
|
'update media', |
39
|
|
|
'update any media', |
40
|
|
|
'delete media', |
41
|
|
|
'delete any media', |
42
|
|
|
'access media overview', |
43
|
|
|
'create page content', |
44
|
|
|
'edit any page content', |
45
|
|
|
]); |
46
|
|
|
$this->drupalLogin($adminUser); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Tests that the entity embed dialog is working. |
51
|
|
|
*/ |
52
|
|
|
public function testMediaEmbedDialog() { |
53
|
|
|
// Find the button and click it to see if the modal opens. |
54
|
|
|
$this->drupalGet('node/add/page'); |
55
|
|
|
$this->find('.cke_button__media')->click(); |
56
|
|
|
$this->wait(); |
57
|
|
|
$this->assertSession()->pageTextContains('Select media to embed'); |
58
|
|
|
|
59
|
|
|
// Test for the button in the basic_html editor. |
60
|
|
|
$this->drupalGet('entity-embed/dialog/basic_html/media'); |
61
|
|
|
$this->assertEquals(200, $this->getSession()->getStatusCode()); |
62
|
|
|
$this->assertSession()->pageTextContains('Select media to embed'); |
63
|
|
|
|
64
|
|
|
// Test for the button in the full_html editor. |
65
|
|
|
$this->drupalGet('entity-embed/dialog/full_html/media'); |
66
|
|
|
$this->assertEquals(200, $this->getSession()->getStatusCode()); |
67
|
|
|
$this->assertSession()->pageTextContains('Select media to embed'); |
68
|
|
|
|
69
|
|
|
$this->drupalGet('entity-browser/iframe/media_embed'); |
70
|
|
|
$this->assertEquals(200, $this->getSession()->getStatusCode()); |
71
|
|
|
$filter = $this->getSession()->getPage()->find('css', 'input[name="name"]'); |
72
|
|
|
$this->assertTrue($filter, "Found filter"); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Installs the module using module_handler service. |
77
|
|
|
* |
78
|
|
|
* @param string $module_name |
79
|
|
|
* Name of the module to install. |
80
|
|
|
*/ |
81
|
|
|
public function installModule($module_name) { |
82
|
|
|
if (!$this->container->get('module_handler')->moduleExists($module_name)) { |
83
|
|
|
$this->container->get('module_installer')->install(array($module_name)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Wait for AJAX. |
89
|
|
|
*/ |
90
|
|
|
protected function wait() { |
91
|
|
|
$this->getSession()->wait(20000, '(0 === jQuery.active)'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Find an element based on a CSS selector. |
96
|
|
|
* |
97
|
|
|
* @param string $css_selector |
98
|
|
|
* A css selector to find an element for. |
99
|
|
|
* |
100
|
|
|
* @return \Behat\Mink\Element\NodeElement|null |
101
|
|
|
* The found element or null. |
102
|
|
|
*/ |
103
|
|
|
protected function find($css_selector) { |
104
|
|
|
return $this->getSession()->getPage()->find('css', $css_selector); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|