1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Leogout\Bundle\SeoBundle\Tests\Seo\Basic; |
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\Model\TitleTag; |
9
|
|
|
use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator; |
10
|
|
|
use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoInterface; |
11
|
|
|
use Leogout\Bundle\SeoBundle\Tests\TestCase; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Description of BasicSeoGeneratorTest. |
15
|
|
|
* |
16
|
|
|
* @author: leogout |
17
|
|
|
*/ |
18
|
|
|
class BasicSeoGeneratorTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var BasicSeoGenerator |
22
|
|
|
*/ |
23
|
|
|
protected $generator; |
24
|
|
|
|
25
|
|
|
protected function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->generator = new BasicSeoGenerator(new TagBuilder(new TagFactory())); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testTitle() |
31
|
|
|
{ |
32
|
|
|
$this->generator->setTitle('Awesome site'); |
33
|
|
|
|
34
|
|
|
$this->assertEquals( |
35
|
|
|
'<title>Awesome site</title>', |
36
|
|
|
$this->generator->render() |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$this->assertInstanceOf( |
40
|
|
|
TitleTag::class, $this->generator->getTitle() |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function testDescription() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->generator->setDescription('My awesome site is so cool!'); |
47
|
|
|
|
48
|
|
|
$this->assertEquals( |
49
|
|
|
'<meta name="description" content="My awesome site is so cool!" />', |
50
|
|
|
$this->generator->render() |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf( |
54
|
|
|
MetaTag::class, $this->generator->getDescription() |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function testKeywords() |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$this->generator->setKeywords('awesome, cool'); |
61
|
|
|
|
62
|
|
|
$this->assertEquals( |
63
|
|
|
'<meta name="keywords" content="awesome, cool" />', |
64
|
|
|
$this->generator->render() |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$this->assertInstanceOf( |
68
|
|
|
MetaTag::class, $this->generator->getKeywords() |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testCanonical() |
73
|
|
|
{ |
74
|
|
|
$this->generator->setCanonical('http://127.0.0.1:8000'); |
75
|
|
|
|
76
|
|
|
$this->assertEquals( |
77
|
|
|
'<link href="http://127.0.0.1:8000" rel="canonical" />', |
78
|
|
|
$this->generator->render() |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testRobots() |
83
|
|
|
{ |
84
|
|
|
$this->generator->setRobots(true, true); |
85
|
|
|
|
86
|
|
|
$this->assertEquals( |
87
|
|
|
'<meta name="robots" content="index, follow" />', |
88
|
|
|
$this->generator->render() |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$this->generator->setRobots(false, false); |
92
|
|
|
|
93
|
|
|
$this->assertEquals( |
94
|
|
|
'<meta name="robots" content="noindex, nofollow" />', |
95
|
|
|
$this->generator->render() |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$this->generator->setRobots(true, false); |
99
|
|
|
|
100
|
|
|
$this->assertEquals( |
101
|
|
|
'<meta name="robots" content="index, nofollow" />', |
102
|
|
|
$this->generator->render() |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$this->generator->setRobots(false, true); |
106
|
|
|
|
107
|
|
|
$this->assertEquals( |
108
|
|
|
'<meta name="robots" content="noindex, follow" />', |
109
|
|
|
$this->generator->render() |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
View Code Duplication |
public function testFromResource() |
|
|
|
|
114
|
|
|
{ |
115
|
|
|
$resource = $this->getMockBuilder(BasicSeoInterface::class)->getMock(); |
116
|
|
|
|
117
|
|
|
$resource->method('getSeoTitle')->willReturn('Awesome site'); |
118
|
|
|
$resource->method('getSeoDescription')->willReturn('My awesome site is so cool!'); |
119
|
|
|
$resource->method('getSeoKeywords')->willReturn('awesome, cool'); |
120
|
|
|
|
121
|
|
|
$this->generator->fromResource($resource); |
122
|
|
|
|
123
|
|
|
$this->assertEquals( |
124
|
|
|
"<title>Awesome site</title>\n". |
125
|
|
|
"<meta name=\"description\" content=\"My awesome site is so cool!\" />\n". |
126
|
|
|
"<meta name=\"keywords\" content=\"awesome, cool\" />", |
127
|
|
|
$this->generator->render() |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function testRenderNothing() |
132
|
|
|
{ |
133
|
|
|
$this->assertEquals( |
134
|
|
|
'', |
135
|
|
|
$this->generator->render() |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
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.