3 namespace Drupal\embed\Tests;
6 * Tests the administrative UI.
10 class EmbedButtonAdminTest extends EmbedTestBase {
13 * Tests the embed_button administration functionality.
15 public function testEmbedButtonAdmin() {
16 // Ensure proper access to the Embed settings page.
17 $this->drupalGet('admin/config/content/embed');
18 $this->assertResponse(403);
20 $this->drupalLogin($this->adminUser);
21 $this->drupalGet('admin/config/content/embed');
22 $this->assertResponse(200);
25 $this->clickLink('Add embed button');
26 $button_id = strtolower($this->randomMachineName());
27 $button_label = $this->randomMachineName();
30 'label' => $button_label,
31 'type_id' => 'embed_test_default',
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');
39 $this->drupalGet('admin/config/content/embed/button/manage/' . $button_id);
40 $new_button_label = $this->randomMachineName();
42 'label' => $new_button_label,
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');
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');
61 public function testButtonValidation() {
62 $this->drupalLogin($this->adminUser);
63 $button_id = strtolower($this->randomMachineName());
66 'label' => $this->randomMachineName(),
67 'type_id' => 'embed_test_aircraft',
69 $this->drupalPostAjaxForm('admin/config/content/embed/button/add', $edit, 'type_id');
70 $this->assertFieldByName('type_settings[aircraft_type]', 'fixed-wing');
72 $edit['type_settings[aircraft_type]'] = 'invalid';
73 $this->drupalPostForm(NULL, $edit, 'Save');
74 $this->assertText('Cannot select invalid aircraft type.');
76 $edit['type_settings[aircraft_type]'] = 'helicopters';
77 $this->drupalPostForm(NULL, $edit, 'Save');
78 $this->assertText('Helicopters are just rotorcraft.');
80 $this->drupalGet('admin/config/content/embed/button/manage/' . $button_id);
81 $this->assertFieldByName('type_settings[aircraft_type]', 'rotorcraft');