|
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() |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
$this->tagBuilder->addMeta('keywords', MetaTag::NAME_TYPE, 'keywords', ['foo', 'bar'], false); |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
$this->tagBuilder->addMeta('keywords', MetaTag::NAME_TYPE, 'lang', ['en', 'nl']); |
|
|
|
|
|
|
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
|
|
|
|
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.