1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\SitemapBundle\Tests; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
6
|
|
|
use Victoire\Bundle\PageBundle\Entity\BasePage; |
7
|
|
|
use Victoire\Bundle\PageBundle\Entity\Page; |
8
|
|
|
use Victoire\Bundle\SeoBundle\Entity\PageSeo; |
9
|
|
|
use Victoire\Tests\Functional\VictoireWebTestCase; |
10
|
|
|
|
11
|
|
|
class SitemapTest extends VictoireWebTestCase |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
protected function setUp() |
14
|
|
|
{ |
15
|
|
|
parent::setUp(); |
16
|
|
|
$this->resetSchema(); |
17
|
|
|
$this->loadFixtures(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testPageIndexation() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/* @var BasePage $homepage */ |
23
|
|
|
$homepage = $this->entityManager->getRepository('VictoirePageBundle:BasePage')->findOneByHomepage('en'); |
|
|
|
|
24
|
|
|
|
25
|
|
|
//English first |
26
|
|
|
$pageSeo = new PageSeo(); |
27
|
|
|
$pageSeo->setCurrentLocale('en'); |
28
|
|
|
$pageSeo->setSitemapIndexed(false); |
29
|
|
|
$pageSeo->setSitemapPriority(0.8); |
30
|
|
|
$this->entityManager->persist($pageSeo); |
31
|
|
|
|
32
|
|
|
$page = new Page(); |
33
|
|
|
$page->setCurrentLocale('en'); |
34
|
|
|
$page->setName('Indexed page'); |
35
|
|
|
$page->setSeo($pageSeo); |
36
|
|
|
$page->setParent($homepage); |
37
|
|
|
$this->entityManager->persist($page); |
38
|
|
|
|
39
|
|
|
//French |
40
|
|
|
$page->setCurrentLocale('fr'); |
41
|
|
|
$page->setName('Page indexée'); |
42
|
|
|
$pageSeo->setCurrentLocale('fr'); |
43
|
|
|
$pageSeo->setSitemapIndexed(true); |
44
|
|
|
$pageSeo->setSitemapPriority(0.3); |
45
|
|
|
|
46
|
|
|
$this->entityManager->flush(); |
47
|
|
|
$this->resetViewsReference(); |
48
|
|
|
|
49
|
|
|
$englishAssertions = [ |
50
|
|
|
[ |
51
|
|
|
'loc' => '/en/', |
52
|
|
|
'changefreq' => 'monthly', |
53
|
|
|
'priority' => '0.5', |
54
|
|
|
], |
55
|
|
|
[ |
56
|
|
|
'loc' => '/en/english-test', |
57
|
|
|
'changefreq' => 'monthly', |
58
|
|
|
'priority' => '0.5', |
59
|
|
|
], |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
$frenchAssertions = [ |
63
|
|
|
[ |
64
|
|
|
'loc' => '/fr/', |
65
|
|
|
'changefreq' => 'monthly', |
66
|
|
|
'priority' => '0.5', |
67
|
|
|
], |
68
|
|
|
[ |
69
|
|
|
'loc' => '/fr/test', |
70
|
|
|
'changefreq' => 'monthly', |
71
|
|
|
'priority' => '0.5', |
72
|
|
|
], |
73
|
|
|
[ |
74
|
|
|
'loc' => '/fr/page-indexee', |
75
|
|
|
'changefreq' => 'monthly', |
76
|
|
|
'priority' => '0.3', |
77
|
|
|
], |
78
|
|
|
]; |
79
|
|
|
|
80
|
|
|
$englishPages = $this->getSitemapPages('en'); |
81
|
|
|
$this->runAssertions($englishPages, $englishAssertions); |
82
|
|
|
|
83
|
|
|
$frenchPages = $this->getSitemapPages('fr'); |
84
|
|
|
$this->runAssertions($frenchPages, $frenchAssertions); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return Crawler |
89
|
|
|
*/ |
90
|
|
|
private function getSitemapPages($locale = 'en') |
91
|
|
|
{ |
92
|
|
|
$client = $this->createClient(); |
93
|
|
|
$this->logIn($client, ['ROLE_ADMIN']); |
94
|
|
|
$client->request('GET', '/'.$locale.'/sitemap.xml'); |
95
|
|
|
|
96
|
|
|
return $client->getCrawler()->filter('urlset > url'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param Crawler $pages |
101
|
|
|
* @param array $assertions |
102
|
|
|
*/ |
103
|
|
|
private function runAssertions(Crawler $pages, array $assertions) |
104
|
|
|
{ |
105
|
|
|
foreach ($assertions as $i => $v) { |
106
|
|
|
$this->assertStringEndsWith($assertions[$i]['loc'], $pages->eq($i)->filter('loc')->text()); |
107
|
|
|
$this->assertEquals($assertions[$i]['changefreq'], $pages->eq($i)->filter('changefreq')->text()); |
108
|
|
|
$this->assertEquals($assertions[$i]['priority'], $pages->eq($i)->filter('priority')->text()); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|