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\Seo\Basic\BasicSeoConfigurator; |
8
|
|
|
use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator; |
9
|
|
|
use Leogout\Bundle\SeoBundle\Seo\Twitter\TwitterSeoGenerator; |
10
|
|
|
use Leogout\Bundle\SeoBundle\Tests\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Description of BasicSeoConfiguratorTest. |
14
|
|
|
* |
15
|
|
|
* @author: leogout |
16
|
|
|
*/ |
17
|
|
|
class BasicSeoConfiguratorTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var BasicSeoGenerator |
21
|
|
|
*/ |
22
|
|
|
protected $generator; |
23
|
|
|
|
24
|
|
|
protected function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->generator = new BasicSeoGenerator(new TagBuilder(new TagFactory())); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @expectedException \Leogout\Bundle\SeoBundle\Exception\InvalidSeoGeneratorException |
31
|
|
|
* @expectedExceptionMessage Invalid seo generator passed to Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoConfigurator. Expected "Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator", but got "Leogout\Bundle\SeoBundle\Seo\Twitter\TwitterSeoGenerator". |
32
|
|
|
*/ |
33
|
|
|
public function testException() |
34
|
|
|
{ |
35
|
|
|
$invalidGenerator = new TwitterSeoGenerator(new TagBuilder(new TagFactory())); |
36
|
|
|
$configurator = new BasicSeoConfigurator([]); |
37
|
|
|
$configurator->configure($invalidGenerator); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function testTitle() |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$config = [ |
43
|
|
|
'title' => 'Awesome | Site' |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
$configurator = new BasicSeoConfigurator($config); |
47
|
|
|
$configurator->configure($this->generator); |
48
|
|
|
|
49
|
|
|
$this->assertEquals( |
50
|
|
|
'<title>Awesome | Site</title>', |
51
|
|
|
$this->generator->render() |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function testDescription() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$config = [ |
58
|
|
|
'description' => 'My awesome site is so cool!', |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
$configurator = new BasicSeoConfigurator($config); |
62
|
|
|
$configurator->configure($this->generator); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( |
65
|
|
|
'<meta name="description" content="My awesome site is so cool!" />', |
66
|
|
|
$this->generator->render() |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
View Code Duplication |
public function testKeywords() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$config = [ |
73
|
|
|
'keywords' => 'awesome, cool', |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
$configurator = new BasicSeoConfigurator($config); |
77
|
|
|
$configurator->configure($this->generator); |
78
|
|
|
|
79
|
|
|
$this->assertEquals( |
80
|
|
|
'<meta name="keywords" content="awesome, cool" />', |
81
|
|
|
$this->generator->render() |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
View Code Duplication |
public function testCanonical() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$config = [ |
88
|
|
|
'canonical' => 'http://127.0.0.1:8000', |
89
|
|
|
]; |
90
|
|
|
|
91
|
|
|
$configurator = new BasicSeoConfigurator($config); |
92
|
|
|
$configurator->configure($this->generator); |
93
|
|
|
|
94
|
|
|
$this->assertEquals( |
95
|
|
|
'<link href="http://127.0.0.1:8000" rel="canonical" />', |
96
|
|
|
$this->generator->render() |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testRobots() |
101
|
|
|
{ |
102
|
|
|
$config = [ |
103
|
|
|
'robots' => [ |
104
|
|
|
'index' => true, |
105
|
|
|
'follow' => true, |
106
|
|
|
], |
107
|
|
|
]; |
108
|
|
|
|
109
|
|
|
$configurator = new BasicSeoConfigurator($config); |
110
|
|
|
$configurator->configure($this->generator); |
111
|
|
|
|
112
|
|
|
$this->assertEquals( |
113
|
|
|
'<meta name="robots" content="index, follow" />', |
114
|
|
|
$this->generator->render() |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
View Code Duplication |
public function testNoConfig() |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$config = []; |
121
|
|
|
|
122
|
|
|
$configurator = new BasicSeoConfigurator($config); |
123
|
|
|
$configurator->configure($this->generator); |
124
|
|
|
|
125
|
|
|
$this->assertEquals( |
126
|
|
|
'', |
127
|
|
|
$this->generator->render() |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
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.