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