Completed
Push — master ( 60669a...da1289 )
by Daniel
05:37 queued 02:49
created

SS_HTML5ValueTest::testInvalidHTMLParsing()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.4286
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
/**
3
 * @package framework
4
 * @subpackage tests
5
 */
6
class SS_HTML5ValueTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    public function testInvalidHTMLParsing()
9
    {
10
        $value = new SS_HTML5Value();
11
12
        $invalid = array(
13
            '<p>Enclosed Value</p></p>'                              => '<p>Enclosed Value</p><p></p>',
14
            '<meta content="text/html"></meta>'                      => '<meta content="text/html">',
15
            '<p><div class="example"></div></p>'                     => '<p></p><div class="example"></div><p></p>'
16
        );
17
        
18
        foreach ($invalid as $input => $expected) {
19
            $value->setContent($input);
20
            $this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be parsed');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SS_HTML5ValueTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
        }
22
    }
23
24
    public function testUtf8Saving()
25
    {
26
        $value = new SS_HTML5Value();
27
28
        $value->setContent('<p>ö ß ā い 家</p>');
29
        $this->assertEquals('<p>ö ß ā い 家</p>', $value->getContent());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SS_HTML5ValueTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
    }
31
32
    public function testWhitespaceHandling()
33
    {
34
        $value = new SS_HTML5Value();
35
36
        $value->setContent('<p></p> <p></p>');
37
        $this->assertEquals('<p></p> <p></p>', $value->getContent());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SS_HTML5ValueTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
    }
39
40
    public function testInvalidHTMLTagNames()
41
    {
42
        $value = new SS_HTML5Value();
43
44
        $invalid = array(
45
            '<p><div><a href="test-link"></p></div>',
46
            '<html><div><a href="test-link"></a></a></html_>'
47
        );
48
        
49
        foreach ($invalid as $input) {
50
            $value->setContent($input);
51
52
            $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SS_HTML5ValueTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
                'test-link',
54
                $value->getElementsByTagName('a')->item(0)->getAttribute('href'),
0 ignored issues
show
Documentation Bug introduced by
The method getElementsByTagName does not exist on object<SS_HTML5Value>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
55
                'Link data can be extraced from malformed HTML'
56
            );
57
        }
58
    }
59
60
    public function testMixedNewlines()
61
    {
62
        $value = new SS_HTML5Value();
63
64
        $value->setContent("<p>paragraph</p>\n<ul><li>1</li>\r\n</ul>");
65
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SS_HTML5ValueTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
            "<p>paragraph</p>\n<ul><li>1</li>\n</ul>",
67
            $value->getContent(),
68
            'Newlines get converted'
69
        );
70
    }
71
}
72