OgSeoGeneratorTest::testFromResource()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace Leogout\Bundle\SeoBundle\Tests\Seo\Og;
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\Og\OgSeoGenerator;
9
use Leogout\Bundle\SeoBundle\Seo\Og\OgSeoInterface;
10
use Leogout\Bundle\SeoBundle\Tests\TestCase;
11
12
/**
13
 * Description of OgSeoGeneratorTest.
14
 *
15
 * @author: leogout
16
 */
17
class OgSeoGeneratorTest extends TestCase
18
{
19
    /**
20
     * @var OgSeoGenerator
21
     */
22
    protected $generator;
23
24
    protected function setUp()
25
    {
26
        $this->generator = new OgSeoGenerator(new TagBuilder(new TagFactory()));
27
    }
28
29
    public function testTitle()
30
    {
31
        $this->generator->setTitle('Awesome | Site');
32
33
        $this->assertEquals(
34
            '<meta name="og: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="og: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="og: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 testType()
72
    {
73
        $this->generator->setType('website');
74
75
        $this->assertEquals(
76
            '<meta name="og:type" content="website" />',
77
            $this->generator->render()
78
        );
79
    }
80
81 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...
82
    {
83
        $resource = $this->getMockBuilder(OgSeoInterface::class)->getMock();
84
85
        $resource->method('getSeoTitle')->willReturn('Awesome site');
86
        $resource->method('getSeoDescription')->willReturn('My awesome site is so cool!');
87
        $resource->method('getSeoImage')->willReturn('http://images.com/poney/12');
88
89
        $this->generator->fromResource($resource);
90
91
        $this->assertEquals(
92
            "<meta name=\"og:title\" content=\"Awesome site\" />\n".
93
            "<meta name=\"og:description\" content=\"My awesome site is so cool!\" />\n".
94
            "<meta name=\"og:image\" content=\"http://images.com/poney/12\" />",
95
            $this->generator->render()
96
        );
97
    }
98
99
    public function testRenderNothing()
100
    {
101
        $this->assertEquals(
102
            '',
103
            $this->generator->render()
104
        );
105
    }
106
}
107