function SearchByPageUnitTest::testStripTags in Search by Page 8
Tests the search_by_page_strip_tags function.
File
- tests/
src/ Unit/ SearchByPageUnitTest.php, line 84 - Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com
Class
- SearchByPageUnitTest
- Unit tests for Search by Page functions.
Namespace
Drupal\Tests\search_by_page\UnitCode
function testStripTags() {
$env = 1;
$test_string = '<div>This is a test. <tag1>This should be removed</tag1> <tag2>This should also be removed</tag2> This should be left. <tag1>This should not be here</tag1><tag1 some="attribute">This although with attributes, should also be removed</tag1></div>';
// Try excluding some tags.
\Drupal::service('search_by_page.settings')
->setSetting('exclude_tags', $env, 'tag1 tag2');
$result = search_by_page_strip_tags($test_string, $env);
$this
->assertEquals($result, '<div>This is a test. This should be left. </div>', 'search_by_page_strip_tags() is working correctly.');
// Try not excluding any tags.
\Drupal::service('search_by_page.settings')
->setSetting('exclude_tags', $env, '');
$result = search_by_page_strip_tags($test_string, $env);
$this
->assertEquals($result, $test_string, 'search_by_page_strip_tags() with no tags to strip is working correctly.');
}