silverstripe-framework/tests/integration/HTMLValueTest.php
Sam Minnee f51f5bc958 BUGFIX Ensure that windows-style newlines ("\r\n") don't get converted to their XML entity representation through DOMDocument in SS_HTMLValue->setContent() (from r111878)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112935 467b73ca-7a2a-4603-9d3b-597d59a354a9
2010-10-19 05:03:29 +00:00

52 lines
1.5 KiB
PHP
Executable File

<?php
/**
* @package sapphire
* @subpackage tests
*/
class SS_HTMLValueTest extends SapphireTest {
public function testInvalidHTMLSaving() {
$value = new SS_HTMLValue();
$invalid = array (
'<p>Enclosed Value</p></p>' => '<p>Enclosed Value</p>',
'<p><div class="example"></div></p>' => '<p/><div class="example"/>',
'<html><html><body><falsetag "attribute=""attribute""">' => '<falsetag/>',
'<body<body<body>/bodu>/body>' => '/bodu&gt;/body&gt;'
);
foreach($invalid as $input => $expected) {
$value->setContent($input);
$this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be saved');
}
}
public function testInvalidHTMLTagNames() {
$value = new SS_HTMLValue();
$invalid = array (
'<p><div><a href="test-link"></p></div>',
'<html><div><a href="test-link"></a></a></html_>',
'""\'\'\'"""\'""<<<>/</<htmlbody><a href="test-link"<<>'
);
foreach($invalid as $input) {
$value->setContent($input);
$this->assertEquals (
'test-link',
$value->getElementsByTagName('a')->item(0)->getAttribute('href'),
'Link data can be extraced from malformed HTML'
);
}
}
public function testMixedNewlines() {
$value = new SS_HTMLValue();
$eol = PHP_EOL;
$value->setContent("<p>paragraph</p>{$eol}<ul><li>1</li>\r\n</ul>");
$this->assertEquals(
"<p>paragraph</p>{$eol}<ul><li>1</li>{$eol}</ul>",
$value->getContent(),
'Newlines get converted'
);
}
}