protected function SearchApiUnitTest::checkHtmlFilter in Search API 7
Tests the functionality of the "HTML filter" processor.
1 call to SearchApiUnitTest::checkHtmlFilter()
- SearchApiUnitTest::testUnits in ./
search_api.test - Tests the functionality of several components of the module.
File
- ./
search_api.test, line 1067 - Contains the SearchApiWebTest and the SearchApiUnitTest classes.
Class
- SearchApiUnitTest
- Class with unit tests testing small fragments of the Search API.
Code
protected function checkHtmlFilter() {
$orig = <<<END
This is <em lang="en" title =
"something">a test</em>.<h3>Header</h3>
How to write <strong>links to <em>other sites</em></strong>: <a href="URL" title="MOUSEOVER TEXT">TEXT</a>.
< signs can be <A HREF="http://example.com/topic/html-escapes" TITLE = 'HTML "escapes"'
TARGET = '_blank'>escaped</A> with "&lt;".
<img src = "foo.png" alt = "someone's image" />
END;
$tags = <<<END
em = 1.5
strong = 2
h3 = 3
END;
$processed1 = array(
array(
'value' => 'This',
'score' => 1,
),
array(
'value' => 'is',
'score' => 1,
),
array(
'value' => 'something',
'score' => 1.5,
),
array(
'value' => 'a',
'score' => 1.5,
),
array(
'value' => 'test',
'score' => 1.5,
),
array(
'value' => 'Header',
'score' => 3,
),
array(
'value' => 'How',
'score' => 1,
),
array(
'value' => 'to',
'score' => 1,
),
array(
'value' => 'write',
'score' => 1,
),
array(
'value' => 'links',
'score' => 2,
),
array(
'value' => 'to',
'score' => 2,
),
array(
'value' => 'other',
'score' => 3,
),
array(
'value' => 'sites',
'score' => 3,
),
array(
'value' => '<a',
'score' => 1,
),
array(
'value' => 'href="URL"',
'score' => 1,
),
array(
'value' => 'title="MOUSEOVER',
'score' => 1,
),
array(
'value' => 'TEXT">TEXT</a>',
'score' => 1,
),
array(
'value' => '<',
'score' => 1,
),
array(
'value' => 'signs',
'score' => 1,
),
array(
'value' => 'can',
'score' => 1,
),
array(
'value' => 'be',
'score' => 1,
),
array(
'value' => 'HTML',
'score' => 1,
),
array(
'value' => '"escapes"',
'score' => 1,
),
array(
'value' => 'escaped',
'score' => 1,
),
array(
'value' => 'with',
'score' => 1,
),
array(
'value' => '"<"',
'score' => 1,
),
array(
'value' => 'someone\'s',
'score' => 1,
),
array(
'value' => 'image',
'score' => 1,
),
);
$items = array(
1 => array(
'name' => array(
'type' => 'text',
'original_type' => 'text',
'value' => $orig,
),
'search_api_language' => array(
'type' => 'string',
'original_type' => 'string',
'value' => LANGUAGE_NONE,
),
),
);
$tmp = $items;
$processor = new SearchApiHtmlFilter($this->index, array(
'fields' => array(
'name' => 'name',
),
'title' => TRUE,
'alt' => TRUE,
'tags' => $tags,
));
$processor
->preprocessIndexItems($tmp);
$processor = new SearchApiTokenizer($this->index, array(
'fields' => array(
'name' => 'name',
),
'spaces' => '[\\s.:]',
'ignorable' => '',
));
$processor
->preprocessIndexItems($tmp);
$this
->assertEqual($tmp[1]['name']['value'], $processed1, 'Text was correctly processed.');
}