|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\embed\Tests; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Tests the administrative UI. |
|
7
|
|
|
* |
|
8
|
|
|
* @group embed |
|
9
|
|
|
*/ |
|
10
|
|
|
class EmbedButtonAdminTest extends EmbedTestBase { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Tests the embed_button administration functionality. |
|
14
|
|
|
*/ |
|
15
|
|
|
public function testEmbedButtonAdmin() { |
|
16
|
|
|
// Ensure proper access to the Embed settings page. |
|
17
|
|
|
$this->drupalGet('admin/config/content/embed'); |
|
18
|
|
|
$this->assertResponse(403); |
|
19
|
|
|
|
|
20
|
|
|
$this->drupalLogin($this->adminUser); |
|
21
|
|
|
$this->drupalGet('admin/config/content/embed'); |
|
22
|
|
|
$this->assertResponse(200); |
|
23
|
|
|
|
|
24
|
|
|
// Add embed button. |
|
25
|
|
|
$this->clickLink('Add embed button'); |
|
26
|
|
|
$button_id = strtolower($this->randomMachineName()); |
|
27
|
|
|
$button_label = $this->randomMachineName(); |
|
28
|
|
|
$edit = [ |
|
29
|
|
|
'id' => $button_id, |
|
30
|
|
|
'label' => $button_label, |
|
31
|
|
|
'type_id' => 'embed_test_default', |
|
32
|
|
|
]; |
|
33
|
|
|
$this->drupalPostForm(NULL, $edit, 'Save'); |
|
34
|
|
|
// Ensure that the newly created button is listed. |
|
35
|
|
|
$this->drupalGet('admin/config/content/embed'); |
|
36
|
|
|
$this->assertText($button_label, 'Test embed_button appears on the list page'); |
|
37
|
|
|
|
|
38
|
|
|
// Edit embed button. |
|
39
|
|
|
$this->drupalGet('admin/config/content/embed/button/manage/' . $button_id); |
|
40
|
|
|
$new_button_label = $this->randomMachineName(); |
|
41
|
|
|
$edit = [ |
|
42
|
|
|
'label' => $new_button_label, |
|
43
|
|
|
]; |
|
44
|
|
|
$this->drupalPostForm(NULL, $edit, 'Save'); |
|
45
|
|
|
// Ensure that name and label has been changed. |
|
46
|
|
|
$this->drupalGet('admin/config/content/embed'); |
|
47
|
|
|
$this->assertText($new_button_label, 'New label appears on the list page'); |
|
48
|
|
|
$this->assertNoText($button_label, 'Old label does not appears on the list page'); |
|
49
|
|
|
|
|
50
|
|
|
// Delete embed button. |
|
51
|
|
|
$this->drupalGet('admin/config/content/embed/button/manage/' . $button_id . '/delete'); |
|
52
|
|
|
$this->drupalPostForm(NULL, [], 'Delete'); |
|
53
|
|
|
// Ensure that the deleted embed button no longer exists. |
|
54
|
|
|
$this->drupalGet('admin/config/content/embed/button/manage/' . $button_id); |
|
55
|
|
|
$this->assertResponse(404, 'Deleted embed button no longer exists.'); |
|
56
|
|
|
// Ensure that the deleted button is no longer listed. |
|
57
|
|
|
$this->drupalGet('admin/config/content/embed'); |
|
58
|
|
|
$this->assertNoText($button_label, 'Test embed_button does not appears on the list page'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testButtonValidation() { |
|
62
|
|
|
$this->drupalLogin($this->adminUser); |
|
63
|
|
|
$button_id = strtolower($this->randomMachineName()); |
|
64
|
|
|
$edit = [ |
|
65
|
|
|
'id' => $button_id, |
|
66
|
|
|
'label' => $this->randomMachineName(), |
|
67
|
|
|
'type_id' => 'embed_test_aircraft', |
|
68
|
|
|
]; |
|
69
|
|
|
$this->drupalPostAjaxForm('admin/config/content/embed/button/add', $edit, 'type_id'); |
|
70
|
|
|
$this->assertFieldByName('type_settings[aircraft_type]', 'fixed-wing'); |
|
71
|
|
|
|
|
72
|
|
|
$edit['type_settings[aircraft_type]'] = 'invalid'; |
|
73
|
|
|
$this->drupalPostForm(NULL, $edit, 'Save'); |
|
74
|
|
|
$this->assertText('Cannot select invalid aircraft type.'); |
|
75
|
|
|
|
|
76
|
|
|
$edit['type_settings[aircraft_type]'] = 'helicopters'; |
|
77
|
|
|
$this->drupalPostForm(NULL, $edit, 'Save'); |
|
78
|
|
|
$this->assertText('Helicopters are just rotorcraft.'); |
|
79
|
|
|
|
|
80
|
|
|
$this->drupalGet('admin/config/content/embed/button/manage/' . $button_id); |
|
81
|
|
|
$this->assertFieldByName('type_settings[aircraft_type]', 'rotorcraft'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testCKEditorButtonConflict() { |
|
85
|
|
|
$this->drupalLogin($this->adminUser); |
|
86
|
|
|
$this->drupalGet('admin/config/content/embed/button/add'); |
|
87
|
|
|
|
|
88
|
|
|
$button_label = $this->randomMachineName(); |
|
89
|
|
|
$edit = array( |
|
90
|
|
|
'id' => 'DrupalImage', |
|
91
|
|
|
'label' => $button_label, |
|
92
|
|
|
'type_id' => 'embed_test_default', |
|
93
|
|
|
); |
|
94
|
|
|
$this->drupalPostForm(NULL, $edit, 'Save'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|