protected function jQueryUiFilterUnitTest::assertFilteredString in jQuery UI filter 8.2
Asserts multiple filter output expectations for multiple input strings.
$tests = array(
'Input string' => array(
'<p>Input string</p>' => TRUE,
'Input string<br' => FALSE,
),
);
Parameters
FilterInterface $filter: A input filter object.
array $tests: An associative array, whereas each key is an arbitrary input string and each value is again an associative array whose keys are filter output strings and whose values are Booleans indicating whether the output is expected or not.
For example:
1 call to jQueryUiFilterUnitTest::assertFilteredString()
- jQueryUiFilterUnitTest::testMatchingPatterns in src/
Tests/ jQueryUiFilterUnitTest.php - Tests the matching patterns.
File
- src/
Tests/ jQueryUiFilterUnitTest.php, line 138 - Definition of Drupal\jquery_ui_filter\Tests\jQueryUiFilterUnitTest.
Class
- jQueryUiFilterUnitTest
- Tests jQuery UI filter.
Namespace
Drupal\jquery_ui_filter\TestsCode
protected function assertFilteredString(FilterInterface $filter, array $tests) {
foreach ($tests as $source => $tasks) {
$result = $filter
->process($source, $filter)
->getProcessedText();
foreach ($tasks as $value => $is_expected) {
// Not using assertIdentical, since combination with strpos() is hard to grok.
if ($is_expected) {
$success = $this
->assertTrue(strpos($result, $value) !== FALSE, new FormattableMarkup('@source: @value found. Filtered result: @result.', [
'@source' => var_export($source, TRUE),
'@value' => var_export($value, TRUE),
'@result' => var_export($result, TRUE),
]));
}
else {
$success = $this
->assertTrue(strpos($result, $value) === FALSE, new FormattableMarkup('@source: @value not found. Filtered result: @result.', [
'@source' => var_export($source, TRUE),
'@value' => var_export($value, TRUE),
'@result' => var_export($result, TRUE),
]));
}
if (!$success) {
$this
->verbose('Source:<pre>' . Html::escape(var_export($source, TRUE)) . '</pre>' . '<hr />' . 'Result:<pre>' . Html::escape(var_export($result, TRUE)) . '</pre>' . '<hr />' . ($is_expected ? 'Expected:' : 'Not expected:') . '<pre>' . Html::escape(var_export($value, TRUE)) . '</pre>');
}
}
}
}