2009-10-13 03:44:41 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-10-13 03:44:41 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2013-03-11 21:06:20 +01:00
|
|
|
class SS_HTML4ValueTest extends SapphireTest {
|
2009-10-13 03:44:41 +02:00
|
|
|
public function testInvalidHTMLSaving() {
|
2013-03-11 21:06:20 +01:00
|
|
|
$value = new SS_HTML4Value();
|
|
|
|
|
2009-10-13 03:44:41 +02:00
|
|
|
$invalid = array (
|
|
|
|
'<p>Enclosed Value</p></p>' => '<p>Enclosed Value</p>',
|
2012-10-16 00:59:30 +02:00
|
|
|
'<meta content="text/html"></meta>' => '<meta content="text/html">',
|
2012-09-14 07:31:12 +02:00
|
|
|
'<p><div class="example"></div></p>' => '<p></p><div class="example"></div>',
|
|
|
|
'<html><html><body><falsetag "attribute=""attribute""">' => '<falsetag></falsetag>',
|
2009-10-13 03:44:41 +02:00
|
|
|
'<body<body<body>/bodu>/body>' => '/bodu>/body>'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($invalid as $input => $expected) {
|
|
|
|
$value->setContent($input);
|
|
|
|
$this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be saved');
|
|
|
|
}
|
|
|
|
}
|
2012-10-16 00:59:30 +02:00
|
|
|
|
|
|
|
public function testUtf8Saving() {
|
2013-03-11 21:06:20 +01:00
|
|
|
$value = new SS_HTML4Value();
|
|
|
|
|
2012-10-16 00:59:30 +02:00
|
|
|
$value->setContent('<p>ö ß ā い 家</p>');
|
|
|
|
$this->assertEquals('<p>ö ß ā い 家</p>', $value->getContent());
|
|
|
|
}
|
|
|
|
|
2009-10-13 03:44:41 +02:00
|
|
|
public function testInvalidHTMLTagNames() {
|
2013-03-11 21:06:20 +01:00
|
|
|
$value = new SS_HTML4Value();
|
|
|
|
|
2012-09-14 07:31:12 +02:00
|
|
|
$invalid = array(
|
2009-10-13 03:44:41 +02:00
|
|
|
'<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);
|
2012-10-16 00:59:30 +02:00
|
|
|
$this->assertEquals(
|
2009-10-13 03:44:41 +02:00
|
|
|
'test-link',
|
|
|
|
$value->getElementsByTagName('a')->item(0)->getAttribute('href'),
|
|
|
|
'Link data can be extraced from malformed HTML'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 07:03:29 +02:00
|
|
|
public function testMixedNewlines() {
|
2013-03-11 21:06:20 +01:00
|
|
|
$value = new SS_HTML4Value();
|
|
|
|
|
2012-09-14 07:31:12 +02:00
|
|
|
$value->setContent("<p>paragraph</p>\n<ul><li>1</li>\r\n</ul>");
|
2010-10-19 07:03:29 +02:00
|
|
|
$this->assertEquals(
|
2012-09-14 07:31:12 +02:00
|
|
|
"<p>paragraph</p>\n<ul><li>1</li>\n</ul>",
|
2010-10-19 07:03:29 +02:00
|
|
|
$value->getContent(),
|
|
|
|
'Newlines get converted'
|
|
|
|
);
|
|
|
|
}
|
2012-10-16 00:59:30 +02:00
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|