Helpers   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _assertEqualsXmlFile() 0 18 2
A toXml() 0 4 1
A getDocumentBody() 0 3 1
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