Completed
Branch master (0b86d9)
by Léo
02:17
created

TwitterSeoGeneratorTest::testRenderNothing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Leogout\Bundle\SeoBundle\Tests\Seo\Twitter;
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\Seo\Twitter\TwitterSeoGenerator;
9
use Leogout\Bundle\SeoBundle\Seo\Twitter\TwitterSeoInterface;
10
use Leogout\Bundle\SeoBundle\Tests\TestCase;
11
12
/**
13
 * Description of TwitterSeoGeneratorTest.
14
 *
15
 * @author: leogout
16
 */
17
class TwitterSeoGeneratorTest extends TestCase
18
{
19
    /**
20
     * @var TwitterSeoGenerator
21
     */
22
    protected $generator;
23
24
    protected function setUp()
25
    {
26
        $this->generator = new TwitterSeoGenerator(new TagBuilder(new TagFactory()));
27
    }
28
29
    public function testTitle()
30
    {
31
        $this->generator->setTitle('Awesome | Site');
32
33
        $this->assertEquals(
34
            '<meta name="twitter:title" content="Awesome | Site" />',
35
            $this->generator->render()
36
        );
37
38
        $this->assertInstanceOf(
39
            MetaTag::class, $this->generator->getTitle()
40
        );
41
    }
42
43
    public function testDescription()
44
    {
45
        $this->generator->setDescription('My awesome site is so cool!');
46
47
        $this->assertEquals(
48
            '<meta name="twitter:description" content="My awesome site is so cool!" />',
49
            $this->generator->render()
50
        );
51
52
        $this->assertInstanceOf(
53
            MetaTag::class, $this->generator->getDescription()
54
        );
55
    }
56
57
    public function testImage()
58
    {
59
        $this->generator->setImage('http://images.com/poney/12');
60
61
        $this->assertEquals(
62
            '<meta name="twitter:image" content="http://images.com/poney/12" />',
63
            $this->generator->render()
64
        );
65
66
        $this->assertInstanceOf(
67
            MetaTag::class, $this->generator->getImage()
68
        );
69
    }
70
71
    public function testCard()
72
    {
73
        $this->generator->setCard('summary');
74
75
        $this->assertEquals(
76
            '<meta name="twitter:card" content="summary" />',
77
            $this->generator->render()
78
        );
79
    }
80
81
    public function testSite()
82
    {
83
        $this->generator->setSite('@leogoutt');
84
85
        $this->assertEquals(
86
            '<meta name="twitter:site" content="@leogoutt" />',
87
            $this->generator->render()
88
        );
89
    }
90
91 View Code Duplication
    public function testFromResource()
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...
92
    {
93
        $resource = $this->getMockBuilder(TwitterSeoInterface::class)->getMock();
94
95
        $resource->method('getSeoTitle')->willReturn('Awesome site');
96
        $resource->method('getSeoDescription')->willReturn('My awesome site is so cool!');
97
        $resource->method('getSeoImage')->willReturn('http://images.com/poney/12');
98
99
        $this->generator->fromResource($resource);
100
101
        $this->assertEquals(
102
            "<meta name=\"twitter:title\" content=\"Awesome site\" />\n".
103
            "<meta name=\"twitter:description\" content=\"My awesome site is so cool!\" />\n".
104
            "<meta name=\"twitter:image\" content=\"http://images.com/poney/12\" />",
105
            $this->generator->render()
106
        );
107
    }
108
109
    public function testRenderNothing()
110
    {
111
        $this->assertEquals(
112
            '',
113
            $this->generator->render()
114
        );
115
    }
116
}
117