Completed
Push — develop ( dc46fb...584c3c )
by Mathieu
01:44
created

PageTest::testRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 59
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 18
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 59
rs 9.6666

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
class PageTest extends \PHPUnit\Framework\TestCase
3
{
4
    public function testLanguage()
5
    {
6
        $page = new \Suricate\Page();
7
        $page->setLanguage('fr_FR');
8
        $this->assertAttributeEquals('fr_FR', 'language', $page);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertAttributeEquals() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3338 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

8
        /** @scrutinizer ignore-deprecated */ $this->assertAttributeEquals('fr_FR', 'language', $page);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
9
    }
10
11
    public function testEncoding()
12
    {
13
        $page = new \Suricate\Page();
14
        $page->setEncoding('iso-8859-1');
15
        $this->assertAttributeEquals('iso-8859-1', 'encoding', $page);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertAttributeEquals() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3338 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

15
        /** @scrutinizer ignore-deprecated */ $this->assertAttributeEquals('iso-8859-1', 'encoding', $page);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
16
    }
17
18
    public function testTitle()
19
    {
20
        $page = new \Suricate\Page();
21
        $page->setTitle('My great webpage');
22
        $this->assertAttributeEquals('My great webpage', 'title', $page);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertAttributeEquals() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3338 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
        /** @scrutinizer ignore-deprecated */ $this->assertAttributeEquals('My great webpage', 'title', $page);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
23
    }
24
25
    public function testAddStylesheet()
26
    {
27
        $page = new \Suricate\Page();
28
        $page->addStylesheet('stylesheet-ref', '/my.css');
29
30
        $reflector = new ReflectionClass(get_class($page));
31
        $property = $reflector->getProperty('stylesheets');
32
        $property->setAccessible(true);
33
34
        $this->assertEquals(
35
            $property->getValue($page),
36
            [
37
                'stylesheet-ref' => ['url' => '/my.css', 'media' => 'all'],
38
            ]
39
        );
40
        $this->assertNotEquals(
41
            $property->getValue($page),
42
            [
43
                'another-stylesheet' => ['url' => '/my-2.css', 'media' => 'all'],
44
            ]
45
        );
46
    }
47
48
    public function testRender()
49
    {
50
        $page = new \Suricate\Page();
51
        $this->assertEquals('<!DOCTYPE html>
52
<html lang="en">
53
<head>
54
<title></title>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
56
</head>
57
<body>
58
</body>
59
</html>', $page->render());
60
61
        $page->setTitle('My Pageé');
62
        $this->assertEquals('<!DOCTYPE html>
63
<html lang="en">
64
<head>
65
<title>My Page&eacute;</title>
66
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
67
</head>
68
<body>
69
</body>
70
</html>', $page->render());
71
72
        $page->addHtmlClass('class1');
73
        $page->addHtmlClass('class2');
74
75
        $this->assertEquals('<!DOCTYPE html>
76
<html lang="en" class="class1 class2">
77
<head>
78
<title>My Page&eacute;</title>
79
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
80
</head>
81
<body>
82
</body>
83
</html>', $page->render());
84
85
        $page->addScript('script-id', 'http://scripturl.com');
86
        $page->addRss('rss-id', 'http://rssurl.com', 'RSS is not dead !');
87
        $page->addStylesheet('css-id', 'http://cssurl.com');
88
        $page->addMeta('metaname', 'metacontent');
89
        $page->addMetaProperty('metapropertyname', 'metapropertycontent');
90
        $page->addMetaLink('metalinkname', 'metalinktype', 'metalinkhref');
91
92
        $this->assertEquals('<!DOCTYPE html>
93
<html lang="en" class="class1 class2">
94
<head>
95
<title>My Page&eacute;</title>
96
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
97
<meta name="metaname" content="metacontent"/>
98
<meta property="metapropertyname" content="metapropertycontent"/>
99
<link rel="metalinktype" href="metalinkhref"/>
100
<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all"/>
101
<script type="text/javascript" src="http://scripturl.com"></script>
102
<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" media="RSS is not dead !"/>
103
</head>
104
<body>
105
</body>
106
</html>', $page->render());
107
    }
108
}
109