Newer
Older
Angie Byron
committed
<?php
/**
* @file
* Definition of \Drupal\editor\Tests\EditorAdminTest.
*/
namespace Drupal\editor\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests administration of text editors.
*/
class EditorAdminTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('filter', 'editor');
public static function getInfo() {
return array(
'name' => 'Text editor administration',
'description' => 'Tests administration of text editors.',
'group' => 'Text Editor',
);
}
function setUp() {
parent::setUp();
Angie Byron
committed
// Add text format.
$filtered_html_format = entity_create('filter_format', array(
Angie Byron
committed
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(),
Angie Byron
committed
));
$filtered_html_format->save();
Angie Byron
committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Create admin user.
$this->admin_user = $this->drupalCreateUser(array('administer filters'));
}
function testWithoutEditorAvailable() {
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/config/content/formats/filtered_html');
// Ensure the form field order is correct.
$roles_pos = strpos($this->drupalGetContent(), 'Roles');
$editor_pos = strpos($this->drupalGetContent(), 'Text editor');
$filters_pos = strpos($this->drupalGetContent(), 'Enabled filters');
$this->assertTrue($roles_pos < $editor_pos && $editor_pos < $filters_pos, '"Text Editor" select appears in the correct location of the text format configuration UI.');
// Verify the <select>.
$select = $this->xpath('//select[@name="editor"]');
$select_is_disabled = $this->xpath('//select[@name="editor" and @disabled="disabled"]');
$options = $this->xpath('//select[@name="editor"]/option');
$this->assertTrue(count($select) === 1, 'The Text Editor select exists.');
$this->assertTrue(count($select_is_disabled) === 1, 'The Text Editor select is disabled.');
$this->assertTrue(count($options) === 1, 'The Text Editor select has only one option.');
$this->assertTrue(((string) $options[0]) === 'None', 'Option 1 in the he Text Editor select is "None".');
$this->assertRaw(t('This option is disabled because no modules that provide a text editor are currently enabled.'), 'Description for select present that tells users to install a text editor module.');
// Make a text editor available.
module_enable(array('editor_test'));
$this->rebuildContainer();
$this->resetAll();
$this->drupalGet('admin/config/content/formats/filtered_html');
// Verify the <select> when a text editor is available.
$select = $this->xpath('//select[@name="editor"]');
$select_is_disabled = $this->xpath('//select[@name="editor" and @disabled="disabled"]');
$options = $this->xpath('//select[@name="editor"]/option');
$this->assertTrue(count($select) === 1, 'The Text Editor select exists.');
$this->assertTrue(count($select_is_disabled) === 0, 'The Text Editor select is not disabled.');
$this->assertTrue(count($options) === 2, 'The Text Editor select has two options.');
$this->assertTrue(((string) $options[0]) === 'None', 'Option 1 in the he Text Editor select is "None".');
$this->assertTrue(((string) $options[1]) === 'Unicorn Editor', 'Option 2 in the he Text Editor select is "Unicorn Editor".');
$this->assertTrue(((string) $options[0]['selected']) === 'selected', 'Option 1 ("None") is selected.');
// Ensure the none option is selected
$this->assertNoRaw(t('This option is disabled because no modules that provide a text editor are currently enabled.'), 'Description for select absent that tells users to install a text editor module.');
// Select the "Unicorn Editor" editor and click the "Configure" button.
$edit = array(
'editor' => 'unicorn',
);
$this->drupalPostAjax(NULL, $edit, 'editor_configure');
$unicorn_setting_foo = $this->xpath('//input[@name="editor_settings[foo]" and @type="text" and @value="bar"]');
$this->assertTrue(count($unicorn_setting_foo), "Unicorn Editor's settings form is present.");
$options = $this->xpath('//select[@name="editor"]/option');
// Now configure the setting to another value.
$edit['editor_settings[foo]'] = 'baz';
$this->drupalPost(NULL, $edit, t('Save configuration'));
// Verify the editor configuration is saved correctly.
$editor = editor_load('filtered_html');
$this->assertIdentical($editor->editor, 'unicorn', 'The text editor is configured correctly.');
$this->assertIdentical($editor->settings['foo'], 'baz', 'The text editor settings are stored correctly.');
$this->assertIdentical($editor->settings['ponies too'], true, 'The text editor defaults are retrieved correctly.');
$this->assertIdentical($editor->settings['rainbows'], true, 'The text editor defaults added by hook_editor_settings_defaults() are retrieved correctly.');
$this->assertIdentical($editor->settings['sparkles'], false, 'The text editor defaults modified by hook_editor_settings_defaults_alter() are retrieved correctly.');
$this->drupalGet('admin/config/content/formats/filtered_html');
$select = $this->xpath('//select[@name="editor"]');
$select_is_disabled = $this->xpath('//select[@name="editor" and @disabled="disabled"]');
$options = $this->xpath('//select[@name="editor"]/option');
$this->assertTrue(count($select) === 1, 'The Text Editor select exists.');
$this->assertTrue(count($select_is_disabled) === 0, 'The Text Editor select is not disabled.');
$this->assertTrue(count($options) === 2, 'The Text Editor select has two options.');
$this->assertTrue(((string) $options[1]['selected']) === 'selected', 'Option 2 ("Unicorn Editor") is selected.');
}
}