Completed
Pull Request — develop (#8)
by
unknown
07:18
created

testRenderMetaMultipleAsSingleTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Leogout\Bundle\SeoBundle\Tests\Builder;
4
5
use Leogout\Bundle\SeoBundle\Builder\TagBuilder;
6
use Leogout\Bundle\SeoBundle\Factory\TagFactory;
7
use Leogout\Bundle\SeoBundle\Model\MetaTag;
8
use Leogout\Bundle\SeoBundle\Tests\TestCase;
9
10
/**
11
 * Description of TagBuilderTest.
12
 *
13
 * @author: leogout
14
 */
15
class TagBuilderTest extends TestCase
16
{
17
    /**
18
     * @var TagBuilder
19
     */
20
    protected $tagBuilder;
21
22
    protected function setUp()
23
    {
24
        $this->tagBuilder = new TagBuilder(new TagFactory());
25
    }
26
27
    public function testRenderAll()
28
    {
29
        $this->tagBuilder->setTitle('Awesonme | Site');
30
        $this->tagBuilder->addMeta('keywords', MetaTag::NAME_TYPE, 'keywords', 'your, tags');
31
        $this->tagBuilder->addLink('rss',
32
            'http://symfony.com/blog',
33
            'alternate',
34
            'application/rss+xml',
35
            'RSS'
36
        );
37
38
        $this->assertEquals(
39
            "<title>Awesonme | Site</title>\n".
40
            "<meta name=\"keywords\" content=\"your, tags\" />\n".
41
            "<link href=\"http://symfony.com/blog\" rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" />",
42
            $this->tagBuilder->render()
43
        );
44
    }
45
46
    public function testRenderTitle()
47
    {
48
        $this->tagBuilder->setTitle('Awesonme | Site');
49
50
        $this->assertEquals(
51
            '<title>Awesonme | Site</title>',
52
            $this->tagBuilder->render()
53
        );
54
    }
55
56
    public function testRenderMeta()
57
    {
58
        $this->tagBuilder->addMeta('keywords', MetaTag::NAME_TYPE, 'title', 'Hello World');
59
60
        $this->assertEquals(
61
            '<meta name="title" content="Hello World" />',
62
            $this->tagBuilder->render()
63
        );
64
    }
65
66 View Code Duplication
    public function testRenderMetaMultipleAsSingleTag()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $this->tagBuilder->addMeta('keywords', MetaTag::NAME_TYPE, 'keywords',  ['foo', 'bar'], false);
0 ignored issues
show
Documentation introduced by
array('foo', 'bar') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
70
        $this->assertEquals(
71
            '<meta name="keywords" content="foo, bar" />',
72
            $this->tagBuilder->render()
73
        );
74
    }
75
76 View Code Duplication
    public function testRenderMetaMultipleAsSeparateTags()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        $this->tagBuilder->addMeta('keywords', MetaTag::NAME_TYPE, 'lang',  ['en', 'nl']);
0 ignored issues
show
Documentation introduced by
array('en', 'nl') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
80
        $this->assertEquals(
81
            '<meta name="lang" content="en" /><meta name="lang" content="nl" />',
82
            $this->tagBuilder->render()
83
        );
84
    }
85
86
    public function testRenderLink()
87
    {
88
        $this->tagBuilder->addLink('rss',
89
            'http://symfony.com/blog',
90
            'alternate',
91
            'application/rss+xml',
92
            'RSS'
93
        );
94
95
        $this->assertEquals(
96
            '<link href="http://symfony.com/blog" rel="alternate" type="application/rss+xml" title="RSS" />',
97
            $this->tagBuilder->render()
98
        );
99
    }
100
101
    public function testRenderNothing()
102
    {
103
        $this->assertEquals(
104
            '',
105
            $this->tagBuilder->render()
106
        );
107
    }
108
}
109