1 filter.test | FilterUnitTestCase::testImageAlignFilter() |
Tests the Image alignment filter (data-align).
File
- core/
modules/ filter/ tests/ filter.test, line 1784 - Tests for filter.module.
Class
- FilterUnitTestCase
- Unit tests for core filters.
Code
function testImageAlignFilter() {
// Set up dummy filter object.
$filter = new stdClass();
$filter->callback = '_filter_image_align';
$input = <<<EOF
<p><img src="foo.png" width="100" height="100" data-align="right" /></p>
<p><img src="foo.png" width="100" height="100" data-align="left" /></p>
<p><img src="foo.png" width="100" height="100" data-align="center" /></p>
<p><img src="foo.png" width="100" height="100" data-align="bottom" /></p>
<p><img src="foo.png" class="foo" data-align="right" /></p>
<blockquote data-align="left">
A quote
</blockquote>
<p class="foo" data-align="center">
Centered paragraph.
</p>
EOF;
$tests = array(
$input => array(
'<img src="foo.png" width="100" height="100" class="align-right" />' => TRUE,
'<img src="foo.png" width="100" height="100" class="align-left" />' => TRUE,
'<img src="foo.png" width="100" height="100" class="align-center" />' => TRUE,
// An unknown alignment (bottom) should be removed.
'<img src="foo.png" width="100" height="100" />' => TRUE,
'<img src="foo.png" width="100" height="100" class="align-bottom" />' => FALSE,
// The align class should be added to existing classes.
'<img src="foo.png" class="foo align-right" />' => TRUE,
// Align class also works on other elements, despite the filter name.
'<blockquote class="align-left">' => TRUE,
'<p class="foo align-center">' => TRUE,
// Ensure the temporarily wrapped body tag is stripped before output.
'<body>' => FALSE,
),
);
$this->assertFilteredString($filter, $tests);
}