Completed
Push — master ( b51747...8ab68d )
by Mathieu
21s queued 11s
created

PageTest::testRender()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 70
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 60
nc 1
nop 0
dl 0
loc 70
rs 8.8727
c 1
b 0
f 1

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
        $language = 'fr_FR';
7
        $page = new \Suricate\Page();
8
        $page->setLanguage($language);
9
        $this->assertSame($language, $page->getLanguage());
10
    }
11
12
    public function testEncoding()
13
    {
14
        $encoding = 'iso-8859-1';
15
16
        $page = new \Suricate\Page();
17
        $page->setEncoding($encoding);
18
        $this->assertSame($encoding, $page->getEncoding());
19
    }
20
21
    public function testTitle()
22
    {
23
        $title = 'My great webpage';
24
25
        $page = new \Suricate\Page();
26
        $page->setTitle($title);
27
        $this->assertSame($title, $page->getTitle());
28
    }
29
30
    public function testAddStylesheet()
31
    {
32
        $page = new \Suricate\Page();
33
        $page->addStylesheet('stylesheet-ref', '/my.css');
34
35
        $reflector = new ReflectionClass(get_class($page));
36
        $property = $reflector->getProperty('stylesheets');
37
        $property->setAccessible(true);
38
39
        $this->assertEquals($property->getValue($page), [
40
            'stylesheet-ref' => ['url' => '/my.css', 'media' => 'all']
41
        ]);
42
        $this->assertNotEquals($property->getValue($page), [
43
            'another-stylesheet' => ['url' => '/my-2.css', 'media' => 'all']
44
        ]);
45
    }
46
47
    public function testRender()
48
    {
49
        $page = new \Suricate\Page();
50
        $this->assertEquals(
51
            '<!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>',
60
            $page->render()
61
        );
62
63
        $page->setTitle('My Pageé');
64
        $this->assertEquals(
65
            '<!DOCTYPE html>
66
<html lang="en">
67
<head>
68
<title>My Page&eacute;</title>
69
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
70
</head>
71
<body>
72
</body>
73
</html>',
74
            $page->render()
75
        );
76
77
        $page->addHtmlClass('class1');
78
        $page->addHtmlClass('class2');
79
80
        $this->assertEquals(
81
            '<!DOCTYPE html>
82
<html lang="en" class="class1 class2">
83
<head>
84
<title>My Page&eacute;</title>
85
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
86
</head>
87
<body>
88
</body>
89
</html>',
90
            $page->render()
91
        );
92
93
        $page->addScript('script-id', 'http://scripturl.com');
94
        $page->addRss('rss-id', 'http://rssurl.com', 'RSS is not dead !');
95
        $page->addStylesheet('css-id', 'http://cssurl.com');
96
        $page->addMeta('metaname', 'metacontent');
97
        $page->addMetaProperty('metapropertyname', 'metapropertycontent');
98
        $page->addMetaLink('metalinkname', 'metalinktype', 'metalinkhref');
99
100
        $this->assertEquals(
101
            '<!DOCTYPE html>
102
<html lang="en" class="class1 class2">
103
<head>
104
<title>My Page&eacute;</title>
105
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
106
<meta name="metaname" content="metacontent"/>
107
<meta property="metapropertyname" content="metapropertycontent"/>
108
<link rel="metalinktype" href="metalinkhref"/>
109
<link rel="stylesheet" id="css-id" href="http://cssurl.com" type="text/css" media="all"/>
110
<script type="text/javascript" src="http://scripturl.com"></script>
111
<link rel="alternate" id="rss-id" href="http://rssurl.com" type="application/rss+xml" media="RSS is not dead !"/>
112
</head>
113
<body>
114
</body>
115
</html>',
116
            $page->render()
117
        );
118
    }
119
}
120