|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright (C) 2014 Michael Herold <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This program is free software; you can redistribute it and/or |
|
7
|
|
|
* modify it under the terms of the GNU General Public License |
|
8
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
9
|
|
|
* of the License, or (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License |
|
17
|
|
|
* along with this program; if not, write to the Free Software |
|
18
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Unit test utils for html |
|
23
|
|
|
*/ |
|
24
|
|
|
class Helpers extends PHPUnit_Framework_TestCase { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* |
|
28
|
|
|
* @param hemio\html\Interface_\HtmlCode $objHtml |
|
29
|
|
|
* @param string $strFile |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function _assertEqualsXmlFile(hemio\html\Interface_\HtmlCode $objHtml, $strFile) { |
|
32
|
|
|
$path = __DIR__ . DIRECTORY_SEPARATOR . $strFile; |
|
33
|
|
|
|
|
34
|
|
|
$actual = new DOMDocument; |
|
35
|
|
|
$actualString = (string) $objHtml; |
|
36
|
|
|
$actual->loadXML($actualString); |
|
37
|
|
|
|
|
38
|
|
|
if (!file_exists($path)) |
|
39
|
|
|
file_put_contents($path, /*'NEW-AUTOGENERATED' .*/ PHP_EOL . $actualString); |
|
40
|
|
|
|
|
41
|
|
|
$expected = new DOMDocument; |
|
42
|
|
|
$expected->load($path); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEqualXMLStructure($expected->documentElement, $actual->documentElement, true); |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
$this->assertEquals($this->toXml($expected), $this->toXml($actual)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function toXml(DOMDocument $obj) { |
|
51
|
|
|
$obj->normalizeDocument(); |
|
52
|
|
|
return str_replace(PHP_EOL, '', str_replace(' ', '', $obj->saveHTML())); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public static function getDocumentBody() { |
|
56
|
|
|
return (new hemio\html\Document(new hemio\html\Str('Title')))->getHtml()->getBody(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|