<?php
namespace Drupal\filter\Tests;
use Drupal\simpletest\WebTestBase;
class FilterAPITest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'API',
'description' => 'Test the behavior of the API of the Filter module.',
'group' => 'Filter',
);
}
function setUp() {
parent::setUp();
$filtered_html_format = entity_create('filter_format', array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'filters' => array(
'filter_url' => array(
'weight' => -1,
'status' => 1,
),
'filter_html' => array(
'status' => 1,
),
),
));
$filtered_html_format
->save();
$full_html_format = entity_create('filter_format', array(
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => array(
'filter_htmlcorrector' => array(
'weight' => 10,
'status' => 1,
),
),
));
$full_html_format
->save();
}
function testCheckMarkup() {
$text = "Text with <marquee>evil content and</marquee> a URL: http://drupal.org!";
$expected_filtered_text = "Text with evil content and a URL: <a href=\"http://drupal.org\">http://drupal.org</a>!";
$expected_filter_text_without_html_generators = "Text with evil content and a URL: http://drupal.org!";
$this
->assertIdentical(check_markup($text, 'filtered_html', '', FALSE, array()), $expected_filtered_text, 'Expected filter result.');
$this
->assertIdentical(check_markup($text, 'filtered_html', '', FALSE, array(
FILTER_TYPE_MARKUP_LANGUAGE,
)), $expected_filter_text_without_html_generators, 'Expected filter result when skipping FILTER_TYPE_MARKUP_LANGUAGE filters.');
$this
->assertIdentical(check_markup($text, 'filtered_html', '', FALSE, array(
FILTER_TYPE_HTML_RESTRICTOR,
FILTER_TYPE_MARKUP_LANGUAGE,
)), $expected_filter_text_without_html_generators, 'Expected filter result when skipping FILTER_TYPE_MARKUP_LANGUAGE filters, even when trying to disable filters of the FILTER_TYPE_HTML_RESTRICTOR type.');
}
function testFilterFormatAPI() {
$this
->assertEqual(filter_get_filter_types_by_format('filtered_html'), array(
FILTER_TYPE_HTML_RESTRICTOR,
FILTER_TYPE_MARKUP_LANGUAGE,
), 'filter_get_filter_types_by_format() works as expected for the filtered_html format.');
$this
->assertEqual(filter_get_filter_types_by_format('full_html'), array(
FILTER_TYPE_HTML_RESTRICTOR,
), 'filter_get_filter_types_by_format() works as expected for the full_html format.');
}
}