|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leogout\Bundle\SeoBundle\Tests\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Leogout\Bundle\SeoBundle\Model\MetaTag; |
|
6
|
|
|
use Leogout\Bundle\SeoBundle\Tests\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Description of MetaTagTest. |
|
10
|
|
|
* |
|
11
|
|
|
* @author: leogout |
|
12
|
|
|
*/ |
|
13
|
|
|
class MetaTagTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
View Code Duplication |
public function testRenderName() |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
$metaTag = new MetaTag(); |
|
18
|
|
|
$metaTag |
|
19
|
|
|
->setType(MetaTag::NAME_TYPE) |
|
20
|
|
|
->setTagName('keywords') |
|
21
|
|
|
->setContent('your, tags'); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertEquals( |
|
24
|
|
|
'<meta name="keywords" content="your, tags" />', |
|
25
|
|
|
$metaTag->render() |
|
26
|
|
|
); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
View Code Duplication |
public function testRenderProperty() |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$metaTag = new MetaTag(); |
|
32
|
|
|
$metaTag |
|
33
|
|
|
->setType(MetaTag::PROPERTY_TYPE) |
|
34
|
|
|
->setTagName('og:title') |
|
35
|
|
|
->setContent('My awesome site'); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertEquals( |
|
38
|
|
|
'<meta property="og:title" content="My awesome site" />', |
|
39
|
|
|
$metaTag->render() |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
View Code Duplication |
public function testRenderHttpEquiv() |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$metaTag = new MetaTag(); |
|
46
|
|
|
$metaTag |
|
47
|
|
|
->setType(MetaTag::HTTP_EQUIV_TYPE) |
|
48
|
|
|
->setTagName('Cache-Control') |
|
49
|
|
|
->setContent('no-cache'); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals( |
|
52
|
|
|
'<meta http-equiv="Cache-Control" content="no-cache" />', |
|
53
|
|
|
$metaTag->render() |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
View Code Duplication |
public function testRenderEmptyString() |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
$metaTag = new MetaTag(); |
|
60
|
|
|
$metaTag |
|
61
|
|
|
->setType(MetaTag::PROPERTY_TYPE) |
|
62
|
|
|
->setTagName('og:determiner') |
|
63
|
|
|
->setContent('') |
|
64
|
|
|
; |
|
65
|
|
|
|
|
66
|
|
|
// This is a valid use case, according to the opengraph specs an empty string is a valid value for determiner. |
|
67
|
|
|
$this->assertEquals( |
|
68
|
|
|
'<meta property="og:determiner" content="" />', |
|
69
|
|
|
$metaTag->render() |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testRenderNothing() |
|
74
|
|
|
{ |
|
75
|
|
|
$metaTag = new MetaTag(); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertEquals('', $metaTag->render()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @expectedException \InvalidArgumentException |
|
82
|
|
|
* @expectedExceptionMessage Meta tag of type "unknownType" doesn't exist. Existing types are: name, property and http-equiv. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function testSetUnknownType() |
|
85
|
|
|
{ |
|
86
|
|
|
$metaTag = new MetaTag(); |
|
87
|
|
|
$metaTag->setType('unknownType'); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
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.