Issue #2863416 by zviryatko, Jo Fitzgerald, michielnugter: Convert web tests to browser tests for filter module
							parent
							
								
									1815dfddf8
								
							
						
					
					
						commit
						26ad8f8529
					
				| 
						 | 
				
			
			@ -11,7 +11,7 @@ use Drupal\filter\Plugin\FilterBase;
 | 
			
		|||
 * This filter does not do anything, but enabling of its module is done in a
 | 
			
		||||
 * test.
 | 
			
		||||
 *
 | 
			
		||||
 * @see \Drupal\filter\Tests\FilterFormTest::testFilterForm()
 | 
			
		||||
 * @see \Drupal\Tests\filter\Functional\FilterFormTest::testFilterForm()
 | 
			
		||||
 *
 | 
			
		||||
 * @Filter(
 | 
			
		||||
 *   id = "filter_sparkles",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,13 +1,13 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Drupal\filter\Tests;
 | 
			
		||||
namespace Drupal\Tests\filter\Functional;
 | 
			
		||||
 | 
			
		||||
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\simpletest\WebTestBase;
 | 
			
		||||
use Drupal\Tests\BrowserTestBase;
 | 
			
		||||
use Drupal\user\RoleInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ use Drupal\user\RoleInterface;
 | 
			
		|||
 *
 | 
			
		||||
 * @group filter
 | 
			
		||||
 */
 | 
			
		||||
class FilterAdminTest extends WebTestBase {
 | 
			
		||||
class FilterAdminTest extends BrowserTestBase {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * {@inheritdoc}
 | 
			
		||||
| 
						 | 
				
			
			@ -142,7 +142,7 @@ class FilterAdminTest extends WebTestBase {
 | 
			
		|||
    $edit_link = $this->xpath('//a[@href=:href]', [
 | 
			
		||||
      ':href' => \Drupal::url('entity.filter_format.edit_form', ['filter_format' => $format_id])
 | 
			
		||||
    ]);
 | 
			
		||||
    $this->assertTrue($edit_link, format_string('Link href %href found.',
 | 
			
		||||
    $this->assertNotEmpty($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 @@ class FilterAdminTest extends WebTestBase {
 | 
			
		|||
      ':first' => 'filters[' . $first_filter . '][weight]',
 | 
			
		||||
      ':second' => 'filters[' . $second_filter . '][weight]',
 | 
			
		||||
    ]);
 | 
			
		||||
    $this->assertTrue(!empty($elements), 'Order confirmed in admin interface.');
 | 
			
		||||
    $this->assertNotEmpty($elements, 'Order confirmed in admin interface.');
 | 
			
		||||
 | 
			
		||||
    // Reorder filters.
 | 
			
		||||
    $edit = [];
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +234,7 @@ class FilterAdminTest extends WebTestBase {
 | 
			
		|||
      ':first' => 'filters[' . $second_filter . '][weight]',
 | 
			
		||||
      ':second' => 'filters[' . $first_filter . '][weight]',
 | 
			
		||||
    ]);
 | 
			
		||||
    $this->assertTrue(!empty($elements), 'Reorder confirmed in admin interface.');
 | 
			
		||||
    $this->assertNotEmpty($elements, 'Reorder confirmed in admin interface.');
 | 
			
		||||
 | 
			
		||||
    $filter_format = FilterFormat::load($restricted);
 | 
			
		||||
    foreach ($filter_format->filters() as $filter_name => $filter) {
 | 
			
		||||
| 
						 | 
				
			
			@ -260,9 +260,9 @@ class FilterAdminTest extends WebTestBase {
 | 
			
		|||
    $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 . ']', '', 'Role found.');
 | 
			
		||||
    $this->assertFieldByName('filters[' . $second_filter . '][status]', '', 'Line break filter found.');
 | 
			
		||||
    $this->assertFieldByName('filters[' . $first_filter . '][status]', '', 'URL filter found.');
 | 
			
		||||
    $this->assertFieldByName('roles[' . RoleInterface::AUTHENTICATED_ID . ']', RoleInterface::AUTHENTICATED_ID);
 | 
			
		||||
    $this->assertFieldByName('filters[' . $second_filter . '][status]', TRUE);
 | 
			
		||||
    $this->assertFieldByName('filters[' . $first_filter . '][status]', TRUE);
 | 
			
		||||
 | 
			
		||||
    // Disable new filter.
 | 
			
		||||
    $this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', [], t('Disable'));
 | 
			
		||||
| 
						 | 
				
			
			@ -297,8 +297,8 @@ class FilterAdminTest extends WebTestBase {
 | 
			
		|||
    $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[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
 | 
			
		||||
    $this->assert(isset($view_link), 'The message area 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');
 | 
			
		||||
 | 
			
		||||
    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
 | 
			
		||||
    $this->assertTrue($node, 'Node found in database.');
 | 
			
		||||
| 
						 | 
				
			
			@ -1,17 +1,17 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Drupal\filter\Tests;
 | 
			
		||||
namespace Drupal\Tests\filter\Functional;
 | 
			
		||||
 | 
			
		||||
use Drupal\Component\Utility\SafeMarkup;
 | 
			
		||||
use Drupal\filter\Entity\FilterFormat;
 | 
			
		||||
use Drupal\simpletest\WebTestBase;
 | 
			
		||||
use Drupal\Tests\BrowserTestBase;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Tests form elements with associated text formats.
 | 
			
		||||
 *
 | 
			
		||||
 * @group filter
 | 
			
		||||
 */
 | 
			
		||||
class FilterFormTest extends WebTestBase {
 | 
			
		||||
class FilterFormTest extends BrowserTestBase {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Modules to enable for this test.
 | 
			
		||||
| 
						 | 
				
			
			@ -173,13 +173,10 @@ class FilterFormTest extends WebTestBase {
 | 
			
		|||
   *
 | 
			
		||||
   * @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]);
 | 
			
		||||
    return $this->assertFalse($select, SafeMarkup::format('Field @id does not exist.', [
 | 
			
		||||
    $this->assertEmpty($select, SafeMarkup::format('Field @id does not exist.', [
 | 
			
		||||
      '@id' => $id,
 | 
			
		||||
    ]));
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -199,14 +196,13 @@ class FilterFormTest extends WebTestBase {
 | 
			
		|||
   */
 | 
			
		||||
  protected function assertOptions($id, array $expected_options, $selected) {
 | 
			
		||||
    $select = $this->xpath('//select[@id=:id]', [':id' => $id]);
 | 
			
		||||
    $select = reset($select);
 | 
			
		||||
    $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Field @id exists.', [
 | 
			
		||||
    $this->assertNotEmpty($select, SafeMarkup::format('Field @id exists.', [
 | 
			
		||||
      '@id' => $id,
 | 
			
		||||
    ]));
 | 
			
		||||
 | 
			
		||||
    $found_options = $this->getAllOptions($select);
 | 
			
		||||
    $select = reset($select);
 | 
			
		||||
    $found_options = $select->findAll('css', 'option');
 | 
			
		||||
    foreach ($found_options as $found_key => $found_option) {
 | 
			
		||||
      $expected_key = array_search($found_option->attributes()->value, $expected_options);
 | 
			
		||||
      $expected_key = array_search($found_option->getValue(), $expected_options);
 | 
			
		||||
      if ($expected_key !== FALSE) {
 | 
			
		||||
        $this->pass(SafeMarkup::format('Option @option for field @id exists.', [
 | 
			
		||||
          '@option' => $expected_options[$expected_key],
 | 
			
		||||
| 
						 | 
				
			
			@ -224,17 +220,15 @@ class FilterFormTest extends WebTestBase {
 | 
			
		|||
        '@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->attributes()->value,
 | 
			
		||||
        '@option' => $found_option->getValue(),
 | 
			
		||||
        '@id' => $id,
 | 
			
		||||
      ]));
 | 
			
		||||
      $passed = FALSE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return $passed && $this->assertOptionSelected($id, $selected);
 | 
			
		||||
    $this->assertOptionSelected($id, $selected);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			@ -253,14 +247,13 @@ class FilterFormTest extends WebTestBase {
 | 
			
		|||
    $select = $this->xpath('//select[@id=:id and contains(@required, "required")]', [
 | 
			
		||||
      ':id' => $id,
 | 
			
		||||
    ]);
 | 
			
		||||
    $select = reset($select);
 | 
			
		||||
    $passed = $this->assertTrue($select instanceof \SimpleXMLElement, SafeMarkup::format('Required field @id exists.', [
 | 
			
		||||
    $this->assertNotEmpty($select, SafeMarkup::format('Required field @id exists.', [
 | 
			
		||||
      '@id' => $id,
 | 
			
		||||
    ]));
 | 
			
		||||
    // A required select element has a "- Select -" option whose key is an empty
 | 
			
		||||
    // string.
 | 
			
		||||
    $options[] = '';
 | 
			
		||||
    return $passed && $this->assertOptions($id, $options, '');
 | 
			
		||||
    $this->assertOptions($id, $options, '');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			@ -276,8 +269,7 @@ class FilterFormTest extends WebTestBase {
 | 
			
		|||
    $textarea = $this->xpath('//textarea[@id=:id and not(contains(@disabled, "disabled"))]', [
 | 
			
		||||
      ':id' => $id,
 | 
			
		||||
    ]);
 | 
			
		||||
    $textarea = reset($textarea);
 | 
			
		||||
    return $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Enabled field @id exists.', [
 | 
			
		||||
    $this->assertNotEmpty($textarea, SafeMarkup::format('Enabled field @id exists.', [
 | 
			
		||||
      '@id' => $id,
 | 
			
		||||
    ]));
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -295,17 +287,17 @@ class FilterFormTest extends WebTestBase {
 | 
			
		|||
    $textarea = $this->xpath('//textarea[@id=:id and contains(@disabled, "disabled")]', [
 | 
			
		||||
      ':id' => $id,
 | 
			
		||||
    ]);
 | 
			
		||||
    $textarea = reset($textarea);
 | 
			
		||||
    $passed = $this->assertTrue($textarea instanceof \SimpleXMLElement, SafeMarkup::format('Disabled field @id exists.', [
 | 
			
		||||
    $this->assertNotEmpty($textarea, 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.';
 | 
			
		||||
    $passed = $passed && $this->assertEqual((string) $textarea, $expected, SafeMarkup::format('Disabled textarea @id hides text in an inaccessible text format.', [
 | 
			
		||||
    $this->assertEqual($textarea->getText(), $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);
 | 
			
		||||
    return $passed && $this->assertNoSelect($select_id);
 | 
			
		||||
    $this->assertNoSelect($select_id);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,11 +1,11 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Drupal\filter\Tests;
 | 
			
		||||
namespace Drupal\Tests\filter\Functional;
 | 
			
		||||
 | 
			
		||||
use Drupal\Component\Utility\Unicode;
 | 
			
		||||
use Drupal\Core\Access\AccessResult;
 | 
			
		||||
use Drupal\filter\Entity\FilterFormat;
 | 
			
		||||
use Drupal\simpletest\WebTestBase;
 | 
			
		||||
use Drupal\Tests\BrowserTestBase;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Tests access to text formats.
 | 
			
		||||
| 
						 | 
				
			
			@ -13,7 +13,7 @@ use Drupal\simpletest\WebTestBase;
 | 
			
		|||
 * @group Access
 | 
			
		||||
 * @group filter
 | 
			
		||||
 */
 | 
			
		||||
class FilterFormatAccessTest extends WebTestBase {
 | 
			
		||||
class FilterFormatAccessTest extends BrowserTestBase {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Modules to enable.
 | 
			
		||||
| 
						 | 
				
			
			@ -151,7 +151,7 @@ class FilterFormatAccessTest extends WebTestBase {
 | 
			
		|||
    ]);
 | 
			
		||||
    $options = [];
 | 
			
		||||
    foreach ($elements as $element) {
 | 
			
		||||
      $options[(string) $element['value']] = $element;
 | 
			
		||||
      $options[$element->getValue()] = $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.');
 | 
			
		||||
| 
						 | 
				
			
			@ -1,20 +1,22 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Drupal\filter\Tests;
 | 
			
		||||
namespace Drupal\Tests\filter\Functional;
 | 
			
		||||
 | 
			
		||||
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 WebTestBase {
 | 
			
		||||
class FilterHtmlImageSecureTest extends BrowserTestBase {
 | 
			
		||||
 | 
			
		||||
  use CommentTestTrait;
 | 
			
		||||
  use TestFileCreationTrait;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Modules to enable.
 | 
			
		||||
| 
						 | 
				
			
			@ -90,7 +92,7 @@ class FilterHtmlImageSecureTest extends WebTestBase {
 | 
			
		|||
    $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->drupalGetTestFiles('image');
 | 
			
		||||
    $test_images = $this->getTestFiles('image');
 | 
			
		||||
    $test_image = $test_images[0]->filename;
 | 
			
		||||
 | 
			
		||||
    // Put a test image in the files directory with special filename.
 | 
			
		||||
| 
						 | 
				
			
			@ -141,14 +143,14 @@ class FilterHtmlImageSecureTest extends WebTestBase {
 | 
			
		|||
      foreach ($this->xpath('//img[@testattribute="' . hash('sha256', $image) . '"]') as $element) {
 | 
			
		||||
        $found = TRUE;
 | 
			
		||||
        if ($converted == $red_x_image) {
 | 
			
		||||
          $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');
 | 
			
		||||
          $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');
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
          $this->assertEqual((string) $element['src'], $converted);
 | 
			
		||||
          $this->assertEqual($element->getAttribute('src'), $converted);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      $this->assertTrue($found, format_string('@image was found.', ['@image' => $image]));
 | 
			
		||||
		Loading…
	
		Reference in New Issue