Commit fe124202 authored by Alex Pott's avatar Alex Pott
Browse files

Revert "Issue #2863416 by zviryatko, Jo Fitzgerald, michielnugter: Convert web...

Revert "Issue #2863416 by zviryatko, Jo Fitzgerald, michielnugter: Convert web tests to browser tests for filter module"

This reverts commit 589eede1.
parent 420db4ce
Loading
Loading
Loading
Loading
+11 −11
Changes for core/modules/filter/src/Tests/FilterAdminTest.php: 11 added lines, 11 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\filter\Functional;
namespace Drupal\filter\Tests;

use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\filter\Entity\FilterFormat;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
use Drupal\simpletest\WebTestBase;
use Drupal\user\RoleInterface;

/**
@@ -15,7 +15,7 @@
 *
 * @group filter
 */
class FilterAdminTest extends BrowserTestBase {
class FilterAdminTest extends WebTestBase {

  /**
   * {@inheritdoc}
@@ -142,7 +142,7 @@ public function testFormatAdmin() {
    $edit_link = $this->xpath('//a[@href=:href]', [
      ':href' => \Drupal::url('entity.filter_format.edit_form', ['filter_format' => $format_id])
    ]);
    $this->assertNotEmpty($edit_link, format_string('Link href %href found.',
    $this->assertTrue($edit_link, format_string('Link href %href found.',
      ['%href' => 'admin/config/content/formats/manage/' . $format_id]
    ));
    $this->drupalGet('admin/config/content/formats/manage/' . $format_id);
@@ -218,7 +218,7 @@ public function testFilterAdmin() {
      ':first' => 'filters[' . $first_filter . '][weight]',
      ':second' => 'filters[' . $second_filter . '][weight]',
    ]);
    $this->assertNotEmpty($elements, 'Order confirmed in admin interface.');
    $this->assertTrue(!empty($elements), 'Order confirmed in admin interface.');

    // Reorder filters.
    $edit = [];
@@ -234,7 +234,7 @@ public function testFilterAdmin() {
      ':first' => 'filters[' . $second_filter . '][weight]',
      ':second' => 'filters[' . $first_filter . '][weight]',
    ]);
    $this->assertNotEmpty($elements, 'Reorder confirmed in admin interface.');
    $this->assertTrue(!empty($elements), 'Reorder confirmed in admin interface.');

    $filter_format = FilterFormat::load($restricted);
    foreach ($filter_format->filters() as $filter_name => $filter) {
@@ -260,9 +260,9 @@ public function testFilterAdmin() {
    $format = FilterFormat::load($edit['format']);
    $this->assertNotNull($format, 'Format found in database.');
    $this->drupalGet('admin/config/content/formats/manage/' . $format->id());
    $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', RoleInterface::AUTHENTICATED_ID);
    $this->assertFieldByName('filters[' . $second_filter . '][status]', TRUE);
    $this->assertFieldByName('filters[' . $first_filter . '][status]', TRUE);
    $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', '', 'Role found.');
    $this->assertFieldByName('filters[' . $second_filter . '][status]', '', 'Line break filter found.');
    $this->assertFieldByName('filters[' . $first_filter . '][status]', '', 'URL filter found.');

    // Disable new filter.
    $this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', [], t('Disable'));
@@ -297,8 +297,8 @@ public function testFilterAdmin() {
    $this->assertText(t('Basic page @title has been created.', ['@title' => $edit['title[0][value]']]), 'Filtered node created.');

    // Verify that the creation message contains a link to a node.
    $view_link = $this->xpath('//div[contains(@class, "messages")]//a[contains(@href, :href)]', [':href' => 'node/']);
    $this->assertNotEmpty($view_link, 'The message area contains a link to a node');
    $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
    $this->assert(isset($view_link), 'The message area contains a link to a node');

    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
    $this->assertTrue($node, 'Node found in database.');
+25 −17
Changes for core/modules/filter/src/Tests/FilterFormTest.php: 25 added lines, 17 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\filter\Functional;
namespace Drupal\filter\Tests;

use Drupal\Component\Utility\SafeMarkup;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
use Drupal\simpletest\WebTestBase;

/**
 * Tests form elements with associated text formats.
 *
 * @group filter
 */
class FilterFormTest extends BrowserTestBase {
class FilterFormTest extends WebTestBase {

  /**
   * Modules to enable for this test.
@@ -173,10 +173,13 @@ protected function doFilterFormTestAsNonAdmin() {
   *
   * @param string $id
   *   The HTML ID of the select element.
   *
   * @return bool
   *   TRUE if the assertion passed; FALSE otherwise.
   */
  protected function assertNoSelect($id) {
    $select = $this->xpath('//select[@id=:id]', [':id' => $id]);
    $this->assertEmpty($select, SafeMarkup::format('Field @id does not exist.', [
    return $this->assertFalse($select, SafeMarkup::format('Field @id does not exist.', [
      '@id' => $id,
    ]));
  }
@@ -196,13 +199,14 @@ protected function assertNoSelect($id) {
   */
  protected function assertOptions($id, array $expected_options, $selected) {
    $select = $this->xpath('//select[@id=:id]', [':id' => $id]);
    $this->assertNotEmpty($select, SafeMarkup::format('Field @id exists.', [
    $select = reset($select);
    $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Field @id exists.', [
      '@id' => $id,
    ]));
    $select = reset($select);
    $found_options = $select->findAll('css', 'option');

    $found_options = $this->getAllOptions($select);
    foreach ($found_options as $found_key => $found_option) {
      $expected_key = array_search($found_option->getValue(), $expected_options);
      $expected_key = array_search($found_option->attributes()->value, $expected_options);
      if ($expected_key !== FALSE) {
        $this->pass(SafeMarkup::format('Option @option for field @id exists.', [
          '@option' => $expected_options[$expected_key],
@@ -220,15 +224,17 @@ protected function assertOptions($id, array $expected_options, $selected) {
        '@option' => $expected_option,
        '@id' => $id,
      ]));
      $passed = FALSE;
    }
    foreach ($found_options as $found_option) {
      $this->fail(SafeMarkup::format('Option @option for field @id does not exist.', [
        '@option' => $found_option->getValue(),
        '@option' => $found_option->attributes()->value,
        '@id' => $id,
      ]));
      $passed = FALSE;
    }

    $this->assertOptionSelected($id, $selected);
    return $passed && $this->assertOptionSelected($id, $selected);
  }

  /**
@@ -247,13 +253,14 @@ protected function assertRequiredSelectAndOptions($id, array $options) {
    $select = $this->xpath('//select[@id=:id and contains(@required, "required")]', [
      ':id' => $id,
    ]);
    $this->assertNotEmpty($select, SafeMarkup::format('Required field @id exists.', [
    $select = reset($select);
    $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Required field @id exists.', [
      '@id' => $id,
    ]));
    // A required select element has a "- Select -" option whose key is an empty
    // string.
    $options[] = '';
    $this->assertOptions($id, $options, '');
    return $passed && $this->assertOptions($id, $options, '');
  }

  /**
@@ -269,7 +276,8 @@ protected function assertEnabledTextarea($id) {
    $textarea = $this->xpath('//textarea[@id=:id and not(contains(@disabled, "disabled"))]', [
      ':id' => $id,
    ]);
    $this->assertNotEmpty($textarea, SafeMarkup::format('Enabled field @id exists.', [
    $textarea = reset($textarea);
    return $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Enabled field @id exists.', [
      '@id' => $id,
    ]));
  }
@@ -287,17 +295,17 @@ protected function assertDisabledTextarea($id) {
    $textarea = $this->xpath('//textarea[@id=:id and contains(@disabled, "disabled")]', [
      ':id' => $id,
    ]);
    $this->assertNotEmpty($textarea, SafeMarkup::format('Disabled field @id exists.', [
    $textarea = reset($textarea);
    $passed = $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Disabled field @id exists.', [
      '@id' => $id,
    ]));
    $textarea = reset($textarea);
    $expected = 'This field has been disabled because you do not have sufficient permissions to edit it.';
    $this->assertEqual($textarea->getText(), $expected, SafeMarkup::format('Disabled textarea @id hides text in an inaccessible text format.', [
    $passed = $passed && $this->assertEqual((string) $textarea, $expected, SafeMarkup::format('Disabled textarea @id hides text in an inaccessible text format.', [
      '@id' => $id,
    ]));
    // Make sure the text format select is not shown.
    $select_id = str_replace('value', 'format--2', $id);
    $this->assertNoSelect($select_id);
    return $passed && $this->assertNoSelect($select_id);
  }

}
+4 −4
Changes for core/modules/filter/src/Tests/FilterFormatAccessTest.php: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\filter\Functional;
namespace Drupal\filter\Tests;

use Drupal\Component\Utility\Unicode;
use Drupal\Core\Access\AccessResult;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
use Drupal\simpletest\WebTestBase;

/**
 * Tests access to text formats.
@@ -13,7 +13,7 @@
 * @group Access
 * @group filter
 */
class FilterFormatAccessTest extends BrowserTestBase {
class FilterFormatAccessTest extends WebTestBase {

  /**
   * Modules to enable.
@@ -151,7 +151,7 @@ public function testFormatPermissions() {
    ]);
    $options = [];
    foreach ($elements as $element) {
      $options[$element->getValue()] = $element;
      $options[(string) $element['value']] = $element;
    }
    $this->assertTrue(isset($options[$this->allowedFormat->id()]), 'The allowed text format appears as an option when adding a new node.');
    $this->assertFalse(isset($options[$this->disallowedFormat->id()]), 'The disallowed text format does not appear as an option when adding a new node.');
+10 −12
Changes for core/modules/filter/src/Tests/FilterHtmlImageSecureTest.php: 10 added lines, 12 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\filter\Functional;
namespace Drupal\filter\Tests;

use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\simpletest\WebTestBase;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\TestFileCreationTrait;

/**
 * Tests restriction of IMG tags in HTML input.
 *
 * @group filter
 */
class FilterHtmlImageSecureTest extends BrowserTestBase {
class FilterHtmlImageSecureTest extends WebTestBase {

  use CommentTestTrait;
  use TestFileCreationTrait;

  /**
   * Modules to enable.
@@ -92,7 +90,7 @@ public function testImageSource() {
    $title_text = t('This image has been removed. For security reasons, only images from the local domain are allowed.');

    // Put a test image in the files directory.
    $test_images = $this->getTestFiles('image');
    $test_images = $this->drupalGetTestFiles('image');
    $test_image = $test_images[0]->filename;

    // Put a test image in the files directory with special filename.
@@ -143,14 +141,14 @@ public function testImageSource() {
      foreach ($this->xpath('//img[@testattribute="' . hash('sha256', $image) . '"]') as $element) {
        $found = TRUE;
        if ($converted == $red_x_image) {
          $this->assertEqual($element->getAttribute('src'), $red_x_image);
          $this->assertEqual($element->getAttribute('alt'), $alt_text);
          $this->assertEqual($element->getAttribute('title'), $title_text);
          $this->assertEqual($element->getAttribute('height'), '16');
          $this->assertEqual($element->getAttribute('width'), '16');
          $this->assertEqual((string) $element['src'], $red_x_image);
          $this->assertEqual((string) $element['alt'], $alt_text);
          $this->assertEqual((string) $element['title'], $title_text);
          $this->assertEqual((string) $element['height'], '16');
          $this->assertEqual((string) $element['width'], '16');
        }
        else {
          $this->assertEqual($element->getAttribute('src'), $converted);
          $this->assertEqual((string) $element['src'], $converted);
        }
      }
      $this->assertTrue($found, format_string('@image was found.', ['@image' => $image]));
+1 −1
Changes for core/modules/filter/tests/filter_test_plugin/src/Plugin/Filter/FilterSparkles.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
 * This filter does not do anything, but enabling of its module is done in a
 * test.
 *
 * @see \Drupal\Tests\filter\Functional\FilterFormTest::testFilterForm()
 * @see \Drupal\filter\Tests\FilterFormTest::testFilterForm()
 *
 * @Filter(
 *   id = "filter_sparkles",