diff --git a/core/modules/editor/src/Tests/EditorAdminTest.php b/core/modules/editor/src/Tests/EditorAdminTest.php index 26fb9d19df1ea7d2c4eb0c53dce9d4f456eb19a5..e133a26fb5f2386d72383856f00ee68a34f3a261 100644 --- a/core/modules/editor/src/Tests/EditorAdminTest.php +++ b/core/modules/editor/src/Tests/EditorAdminTest.php @@ -23,6 +23,13 @@ class EditorAdminTest extends WebTestBase { */ public static $modules = array('filter', 'editor'); + /** + * A user with the 'administer filters' permission. + * + * @var \Drupal\user\UserInterface + */ + protected $adminUser; + protected function setUp() { parent::setUp(); @@ -36,14 +43,14 @@ protected function setUp() { $filtered_html_format->save(); // Create admin user. - $this->admin_user = $this->drupalCreateUser(array('administer filters')); + $this->adminUser = $this->drupalCreateUser(array('administer filters')); } /** * Tests an existing format without any editors available. */ public function testNoEditorAvailable() { - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); $this->drupalGet('admin/config/content/formats/manage/filtered_html'); // Ensure the form field order is correct. @@ -68,7 +75,7 @@ public function testNoEditorAvailable() { */ public function testAddEditorToExistingFormat() { $this->enableUnicornEditor(); - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); $this->drupalGet('admin/config/content/formats/manage/filtered_html'); $edit = $this->selectUnicornEditor(); // Configure Unicorn Editor's setting to another value. @@ -82,7 +89,7 @@ public function testAddEditorToExistingFormat() { */ public function testAddEditorToNewFormat() { $this->enableUnicornEditor(); - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); $this->drupalGet('admin/config/content/formats/add'); // Configure the text format name. $edit = array( diff --git a/core/modules/editor/src/Tests/EditorLoadingTest.php b/core/modules/editor/src/Tests/EditorLoadingTest.php index 910f6faab9dcd0048b5f1f692e4fbaf48d1c1d87..f0b8877a878aaddc542cb66e96c31b87ebeeca3c 100644 --- a/core/modules/editor/src/Tests/EditorLoadingTest.php +++ b/core/modules/editor/src/Tests/EditorLoadingTest.php @@ -23,6 +23,27 @@ class EditorLoadingTest extends WebTestBase { */ public static $modules = array('filter', 'editor', 'editor_test', 'node'); + /** + * An untrusted user, with access to the 'plain_text' format. + * + * @var \Drupal\user\UserInterface + */ + protected $untrustedUser; + + /** + * A normal user with additional access to the 'filtered_html' format. + * + * @var \Drupal\user\UserInterface + */ + protected $normalUser; + + /** + * A privileged user with additional access to the 'full_html' format. + * + * @var \Drupal\user\UserInterface + */ + protected $privilegedUser; + protected function setUp() { parent::setUp(); @@ -48,13 +69,10 @@ protected function setUp() { 'name' => 'Article', )); - // Create 3 users, each with access to different text formats: - // - "untrusted": plain_text - // - "normal": plain_text, filtered_html - // - "privileged": plain_text, filtered_html, full_html - $this->untrusted_user = $this->drupalCreateUser(array('create article content', 'edit any article content')); - $this->normal_user = $this->drupalCreateUser(array('create article content', 'edit any article content', 'use text format filtered_html')); - $this->privileged_user = $this->drupalCreateUser(array('create article content', 'edit any article content', 'use text format filtered_html', 'use text format full_html')); + // Create 3 users, each with access to different text formats. + $this->untrustedUser = $this->drupalCreateUser(array('create article content', 'edit any article content')); + $this->normalUser = $this->drupalCreateUser(array('create article content', 'edit any article content', 'use text format filtered_html')); + $this->privilegedUser = $this->drupalCreateUser(array('create article content', 'edit any article content', 'use text format filtered_html', 'use text format full_html')); } /** @@ -71,19 +89,19 @@ public function testLoading() { // The normal user: // - has access to 2 text formats; // - doesn't have access to the full_html text format, so: no text editor. - $this->drupalLogin($this->normal_user); + $this->drupalLogin($this->normalUser); $this->drupalGet('node/add/article'); list( , $editor_settings_present, $editor_js_present, $body, $format_selector) = $this->getThingsToCheck(); $this->assertFalse($editor_settings_present, 'No Text Editor module settings.'); $this->assertFalse($editor_js_present, 'No Text Editor JavaScript.'); $this->assertTrue(count($body) === 1, 'A body field exists.'); $this->assertTrue(count($format_selector) === 0, 'No text format selector exists on the page because the user only has access to a single format.'); - $this->drupalLogout($this->normal_user); + $this->drupalLogout($this->normalUser); - // The normal user: + // The privileged user: // - has access to 2 text formats (and the fallback format); // - does have access to the full_html text format, so: Unicorn text editor. - $this->drupalLogin($this->privileged_user); + $this->drupalLogin($this->privilegedUser); $this->drupalGet('node/add/article'); list($settings, $editor_settings_present, $editor_js_present, $body, $format_selector) = $this->getThingsToCheck(); $expected = array('formats' => array('full_html' => array( @@ -100,7 +118,7 @@ public function testLoading() { $this->assertTrue(count($format_selector) === 1, 'A single text format selector exists on the page.'); $specific_format_selector = $this->xpath('//select[contains(@class, "filter-list") and contains(@class, "editor") and @data-editor-for="edit-body-0-value"]'); $this->assertTrue(count($specific_format_selector) === 1, 'A single text format selector exists on the page and has the "editor" class and a "data-editor-for" attribute with the correct value.'); - $this->drupalLogout($this->privileged_user); + $this->drupalLogout($this->privilegedUser); // Also associate a text editor with the "Plain Text" text format. $editor = entity_create('editor', array( @@ -112,7 +130,7 @@ public function testLoading() { // The untrusted user: // - has access to 1 text format (plain_text); // - has access to the plain_text text format, so: Unicorn text editor. - $this->drupalLogin($this->untrusted_user); + $this->drupalLogin($this->untrustedUser); $this->drupalGet('node/add/article'); list($settings, $editor_settings_present, $editor_js_present, $body, $format_selector) = $this->getThingsToCheck(); $expected = array('formats' => array('plain_text' => array( diff --git a/core/modules/editor/src/Tests/EditorSecurityTest.php b/core/modules/editor/src/Tests/EditorSecurityTest.php index 6a19d3e696b2103ee1c6b95d2dcae9adc8823323..f63fce292ef557457e9d3ed936588354dac4a531 100644 --- a/core/modules/editor/src/Tests/EditorSecurityTest.php +++ b/core/modules/editor/src/Tests/EditorSecurityTest.php @@ -51,14 +51,14 @@ class EditorSecurityTest extends WebTestBase { * * @var \Drupal\user\UserInterface */ - protected $untrusted_user; + protected $untrustedUser; /** * User with access to Restricted HTML text format with text editor. * * @var \Drupal\user\UserInterface */ - protected $normal_user; + protected $normalUser; /** * User with access to Restricted HTML text format, dangerous tags allowed @@ -66,14 +66,14 @@ class EditorSecurityTest extends WebTestBase { * * @var \Drupal\user\UserInterface */ - protected $trusted_user; + protected $trustedUser; /** * User with access to all text formats and text editors. * * @var \Drupal\user\UserInterface */ - protected $privileged_user; + protected $privilegedUser; protected function setUp() { parent::setUp(); @@ -176,22 +176,22 @@ protected function setUp() { // - "privileged": restricted_without_editor, restricted_with_editor, // restricted_plus_dangerous_tag_with_editor, // unrestricted_without_editor and unrestricted_with_editor - $this->untrusted_user = $this->drupalCreateUser(array( + $this->untrustedUser = $this->drupalCreateUser(array( 'create article content', 'edit any article content', 'use text format restricted_without_editor', )); - $this->normal_user = $this->drupalCreateUser(array( + $this->normalUser = $this->drupalCreateUser(array( 'create article content', 'edit any article content', 'use text format restricted_with_editor', )); - $this->trusted_user = $this->drupalCreateUser(array( + $this->trustedUser = $this->drupalCreateUser(array( 'create article content', 'edit any article content', 'use text format restricted_plus_dangerous_tag_with_editor', )); - $this->privileged_user = $this->drupalCreateUser(array( + $this->privilegedUser = $this->drupalCreateUser(array( 'create article content', 'edit any article content', 'use text format restricted_without_editor', @@ -204,11 +204,11 @@ protected function setUp() { // Create an "article" node for each possible text format, with the same // sample content, to do our tests on. $samples = array( - array('author' => $this->untrusted_user->id(), 'format' => 'restricted_without_editor'), - array('author' => $this->normal_user->id(), 'format' => 'restricted_with_editor'), - array('author' => $this->trusted_user->id(), 'format' => 'restricted_plus_dangerous_tag_with_editor'), - array('author' => $this->privileged_user->id(), 'format' => 'unrestricted_without_editor'), - array('author' => $this->privileged_user->id(), 'format' => 'unrestricted_with_editor'), + array('author' => $this->untrustedUser->id(), 'format' => 'restricted_without_editor'), + array('author' => $this->normalUser->id(), 'format' => 'restricted_with_editor'), + array('author' => $this->trustedUser->id(), 'format' => 'restricted_plus_dangerous_tag_with_editor'), + array('author' => $this->privilegedUser->id(), 'format' => 'unrestricted_without_editor'), + array('author' => $this->privilegedUser->id(), 'format' => 'unrestricted_with_editor'), ); foreach ($samples as $sample) { $this->drupalCreateNode(array( @@ -234,8 +234,8 @@ function testInitialSecurity() { // No text editor => no XSS filtering. 'value' => self::$sampleContent, 'users' => array( - $this->untrusted_user, - $this->privileged_user, + $this->untrustedUser, + $this->privilegedUser, ), ), array( @@ -244,8 +244,8 @@ function testInitialSecurity() { // Text editor => XSS filtering. 'value' => self::$sampleContentSecured, 'users' => array( - $this->normal_user, - $this->privileged_user, + $this->normalUser, + $this->privilegedUser, ), ), array( @@ -254,8 +254,8 @@ function testInitialSecurity() { // Text editor => XSS filtering. 'value' => self::$sampleContentSecuredEmbedAllowed, 'users' => array( - $this->trusted_user, - $this->privileged_user, + $this->trustedUser, + $this->privilegedUser, ), ), array( @@ -264,7 +264,7 @@ function testInitialSecurity() { // No text editor => no XSS filtering. 'value' => self::$sampleContent, 'users' => array( - $this->privileged_user, + $this->privilegedUser, ), ), array( @@ -273,7 +273,7 @@ function testInitialSecurity() { // Text editor, no security filter => no XSS filtering. 'value' => self::$sampleContent, 'users' => array( - $this->privileged_user, + $this->privilegedUser, ), ), ); @@ -389,7 +389,7 @@ function testSwitchingSecurity() { // - switch to every other text format/editor // - assert the XSS-filtered values that we get from the server $value_original_attribute = String::checkPlain(self::$sampleContent); - $this->drupalLogin($this->privileged_user); + $this->drupalLogin($this->privilegedUser); foreach ($expected as $case) { $this->drupalGet('node/' . $case['node_id'] . '/edit'); @@ -422,7 +422,7 @@ function testSwitchingSecurity() { */ function testEditorXssFilterOverride() { // First: the Standard text editor XSS filter. - $this->drupalLogin($this->normal_user); + $this->drupalLogin($this->normalUser); $this->drupalGet('node/2/edit'); $dom_node = $this->xpath('//textarea[@id="edit-body-0-value"]'); $this->assertIdentical(self::$sampleContentSecured, (string) $dom_node[0], 'The value was filtered by the Standard text editor XSS filter.'); diff --git a/core/modules/editor/src/Tests/QuickEditIntegrationLoadingTest.php b/core/modules/editor/src/Tests/QuickEditIntegrationLoadingTest.php index cce6e04c6bf2c0fd56eafe27297cfe0dbc86fb53..c4b81eadcdf47b91e374a8b6883bfd71323cb37a 100644 --- a/core/modules/editor/src/Tests/QuickEditIntegrationLoadingTest.php +++ b/core/modules/editor/src/Tests/QuickEditIntegrationLoadingTest.php @@ -29,7 +29,7 @@ class QuickEditIntegrationLoadingTest extends WebTestBase { * * @var array */ - protected static $basic_permissions = array('access content', 'create article content', 'use text format filtered_html', 'access contextual links'); + protected static $basicPermissions = array('access content', 'create article content', 'use text format filtered_html', 'access contextual links'); protected function setUp() { parent::setUp(); @@ -74,9 +74,9 @@ public function testUsersWithoutPermission() { // - the 'access in-place editing' permission // - the 'edit any article content' permission (necessary to edit node 1) $users = array( - $this->drupalCreateUser(static::$basic_permissions), - $this->drupalCreateUser(array_merge(static::$basic_permissions, array('edit any article content'))), - $this->drupalCreateUser(array_merge(static::$basic_permissions, array('access in-place editing'))) + $this->drupalCreateUser(static::$basicPermissions), + $this->drupalCreateUser(array_merge(static::$basicPermissions, array('edit any article content'))), + $this->drupalCreateUser(array_merge(static::$basicPermissions, array('access in-place editing'))) ); // Now test with each of the 3 users with insufficient permissions. @@ -98,7 +98,7 @@ public function testUsersWithoutPermission() { * Test loading of untransformed text when a user does have access to it. */ public function testUserWithPermission() { - $user = $this->drupalCreateUser(array_merge(static::$basic_permissions, array('edit any article content', 'access in-place editing'))); + $user = $this->drupalCreateUser(array_merge(static::$basicPermissions, array('edit any article content', 'access in-place editing'))); $this->drupalLogin($user); $this->drupalGet('node/1'); diff --git a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php index ee43da06668ff7c926176b64aaacf4e105aaa0d0..28b0f4b6a684828917a94d34d6de9096844faf59 100644 --- a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php +++ b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php @@ -62,7 +62,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase { * * @var string */ - protected $field_name; + protected $fieldName; protected function setUp() { parent::setUp(); @@ -71,9 +71,9 @@ protected function setUp() { $this->installSchema('system', 'url_alias'); // Create a field. - $this->field_name = 'field_textarea'; + $this->fieldName = 'field_textarea'; $this->createFieldWithStorage( - $this->field_name, 'text', 1, 'Long text field', + $this->fieldName, 'text', 1, 'Long text field', // Instance settings. array(), // Widget type & settings. @@ -132,22 +132,22 @@ public function testEditorSelection() { // Create an entity with values for this text field. $entity = entity_create('entity_test'); - $entity->{$this->field_name}->value = 'Hello, world!'; - $entity->{$this->field_name}->format = 'filtered_html'; + $entity->{$this->fieldName}->value = 'Hello, world!'; + $entity->{$this->fieldName}->format = 'filtered_html'; $entity->save(); // Editor selection w/ cardinality 1, text format w/o associated text editor. - $this->assertEqual('form', $this->getSelectedEditor($entity->id(), $this->field_name), "With cardinality 1, and the filtered_html text format, the 'form' editor is selected."); + $this->assertEqual('form', $this->getSelectedEditor($entity->id(), $this->fieldName), "With cardinality 1, and the filtered_html text format, the 'form' editor is selected."); // Editor selection w/ cardinality 1, text format w/ associated text editor. - $entity->{$this->field_name}->format = 'full_html'; + $entity->{$this->fieldName}->format = 'full_html'; $entity->save(); - $this->assertEqual('editor', $this->getSelectedEditor($entity->id(), $this->field_name), "With cardinality 1, and the full_html text format, the 'editor' editor is selected."); + $this->assertEqual('editor', $this->getSelectedEditor($entity->id(), $this->fieldName), "With cardinality 1, and the full_html text format, the 'editor' editor is selected."); // Editor selection with text processing, cardinality >1 $this->fields->field_textarea_field_storage->cardinality = 2; $this->fields->field_textarea_field_storage->save(); - $this->assertEqual('form', $this->getSelectedEditor($entity->id(), $this->field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected."); + $this->assertEqual('form', $this->getSelectedEditor($entity->id(), $this->fieldName), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected."); } /** @@ -161,13 +161,13 @@ public function testMetadata() { // Create an entity with values for the field. $entity = entity_create('entity_test'); - $entity->{$this->field_name}->value = 'Test'; - $entity->{$this->field_name}->format = 'full_html'; + $entity->{$this->fieldName}->value = 'Test'; + $entity->{$this->fieldName}->format = 'full_html'; $entity->save(); $entity = entity_load('entity_test', $entity->id()); // Verify metadata. - $items = $entity->getTranslation(LanguageInterface::LANGCODE_NOT_SPECIFIED)->get($this->field_name); + $items = $entity->getTranslation(LanguageInterface::LANGCODE_NOT_SPECIFIED)->get($this->fieldName); $metadata = $this->metadataGenerator->generateFieldMetadata($items, 'default'); $expected = array( 'access' => TRUE, @@ -199,15 +199,15 @@ public function testAttachments() { public function testGetUntransformedTextCommand() { // Create an entity with values for the field. $entity = entity_create('entity_test'); - $entity->{$this->field_name}->value = 'Test'; - $entity->{$this->field_name}->format = 'full_html'; + $entity->{$this->fieldName}->value = 'Test'; + $entity->{$this->fieldName}->format = 'full_html'; $entity->save(); $entity = entity_load('entity_test', $entity->id()); // Verify AJAX response. $controller = new EditorController(); $request = new Request(); - $response = $controller->getUntransformedText($entity, $this->field_name, LanguageInterface::LANGCODE_NOT_SPECIFIED, 'default'); + $response = $controller->getUntransformedText($entity, $this->fieldName, LanguageInterface::LANGCODE_NOT_SPECIFIED, 'default'); $expected = array( array( 'command' => 'editorGetUntransformedText',