Commit d436dfef authored by Michael Oehlhof's avatar Michael Oehlhof Committed by Wouter Wolters
Browse files

[TASK] Add unit tests for HtmlParser->getFirstTag() and getFirstTagName()

Resolves: #69265
Releases: master
Change-Id: Ic4c221fc5d541ed42109ac9666b272e9f52c80c5
Reviewed-on: http://review.typo3.org/42843

Reviewed-by: Alexander Opitz's avatarAlexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz's avatarAlexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
parent df7378c4
......@@ -336,6 +336,74 @@ class HtmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
return $this->subject->HTMLcleaner($content, $config[0], $config[1], $config[2], $config[3]);
}
/**
* Data provider for getFirstTag
*
* @return array
*/
public function getFirstTagDataProvider() {
return array(
array('<body><span></span></body>',
'<body>'),
);
}
/**
* Returns the first tag in $str
* Actually everything from the beginning of the $str is returned, so you better make sure the tag is the first thing...
*
* @test
* @dataProvider getFirstTagDataProvider
*
* @param string $str HTML string with tags
* @param string $expected The expected result.
*/
public function getFirstTag($str, $expected) {
$this->assertEquals($expected, $this->subject->getFirstTag($str));
}
/**
* Data provider for getFirstTagName
*
* @return array
*/
public function getFirstTagNameDataProvider() {
return array(
array('<body><span></span></body>',
FALSE,
'BODY'),
array('<body><span></span></body>',
TRUE,
'body'),
array('<div class="test"><span></span></div>',
FALSE,
'DIV'),
array('<div><span class="test"></span></div>',
FALSE,
'DIV'),
array('<br /><span class="test"></span>',
FALSE,
'BR'),
array('<img src="test.jpg" />',
FALSE,
'IMG'),
);
}
/**
* Returns the NAME of the first tag in $str
*
* @test
* @dataProvider getFirstTagNameDataProvider
*
* @param string $str HTML tag (The element name MUST be separated from the attributes by a space character! Just *whitespace* will not do)
* @param bool $preserveCase If set, then the tag is NOT converted to uppercase by case is preserved.
* @param string $expected The expected result.
*/
public function getFirstTagName($str, $preserveCase, $expected) {
$this->assertEquals($expected, $this->subject->getFirstTagName($str, $preserveCase));
}
/**
* @return array
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment