Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick477 committed Jun 22, 2018
1 parent 633781f commit c6a6b2c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
16 changes: 16 additions & 0 deletions src/Sitemap/Provider/PageUrlProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace BitBag\SyliusCmsPlugin\Sitemap\Provider;
Expand Down Expand Up @@ -136,6 +144,7 @@ private function getLocaleCodes(): array
if (null === $this->channelLocaleCodes) {
/** @var ChannelInterface $channel */
$channel = $this->channelContext->getChannel();

$this->channelLocaleCodes = $channel->getLocales()->map(function (LocaleInterface $locale) {
return $locale->getCode();
})->toArray();
Expand All @@ -152,30 +161,37 @@ private function getLocaleCodes(): array
private function createPageUrl(PageInterface $page): SitemapUrlInterface
{
$pageUrl = $this->sitemapUrlFactory->createNew();

$pageUrl->setChangeFrequency(ChangeFrequency::daily());
$pageUrl->setPriority(0.7);

if ($page->getUpdatedAt()) {
$pageUrl->setLastModification($page->getUpdatedAt());
} elseif ($page->getCreatedAt()) {
$pageUrl->setLastModification($page->getCreatedAt());
}

/** @var PageTranslationInterface $translation */
foreach ($this->getTranslations($page) as $translation) {
if (!$translation->getLocale()) {
continue;
}

if (!$this->localeInLocaleCodes($translation)) {
continue;
}

$location = $this->router->generate('bitbag_sylius_cms_plugin_shop_page_show', [
'slug' => $translation->getSlug(),
'_locale' => $translation->getLocale(),
]);

if ($translation->getLocale() === $this->localeContext->getLocaleCode()) {
$pageUrl->setLocalization($location);

continue;
}

$pageUrl->addAlternative($location, $translation->getLocale());
}

Expand Down
16 changes: 13 additions & 3 deletions tests/Api/Sitemap/Provider/AbstractTestController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Api\Sitemap\Provider;

use Lakion\ApiTestCase\XmlApiTestCase;
Expand All @@ -12,7 +22,6 @@

abstract class AbstractTestController extends XmlApiTestCase
{

/**
* @var ChannelInterface
*/
Expand All @@ -35,8 +44,10 @@ abstract class AbstractTestController extends XmlApiTestCase

/**
* @before
*
* {@inheritdoc}
*/
public function setupDatabase()
public function setupDatabase(): void
{
parent::setUpDatabase();

Expand Down Expand Up @@ -68,5 +79,4 @@ public function setupDatabase()
$this->getEntityManager()->persist($this->channel);
$this->getEntityManager()->flush();
}

}
18 changes: 14 additions & 4 deletions tests/Api/Sitemap/Provider/SitemapPageControllerApiLocalesTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Api\Sitemap\Provider;

use BitBag\SyliusCmsPlugin\Entity\Page;

class SitemapPageControllerApiLocalesTest extends AbstractTestController
{

/**
* @before
*
* {@inheritdoc}
*/
public function setUpDatabase()
public function setUpDatabase(): void
{
parent::setUpDatabase();

Expand Down Expand Up @@ -63,11 +74,10 @@ public function setUpDatabase()
$this->getEntityManager()->flush();
}

public function testShowActionResponse()
public function testShowActionResponse(): void
{
$this->client->request('GET', '/sitemap/cms_pages.xml');
$response = $this->client->getResponse();
$this->assertResponse($response, 'show_sitemap_pages_locale');
}

}
20 changes: 16 additions & 4 deletions tests/Api/Sitemap/Provider/SitemapPageControllerApiTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Api\Sitemap\Provider;

use BitBag\SyliusCmsPlugin\Entity\Page;

class SitemapPageControllerApiTest extends AbstractTestController
{

/**
* @before
*
* {@inheritdoc}
*/
public function setUpDatabase()
public function setUpDatabase(): void
{
parent::setUpDatabase();

Expand All @@ -20,12 +31,14 @@ public function setUpDatabase()
$page->setCode('test-code');
$page->setSlug('test');
$this->getEntityManager()->persist($page);

$page = new Page();
$page->setCurrentLocale('en_US');
$page->setName('Mock');
$page->setCode('mock-code');
$page->setSlug('mock');
$this->getEntityManager()->persist($page);

$page = new Page();
$page->setCurrentLocale('en_US');
$page->setName('Test 2');
Expand All @@ -36,11 +49,10 @@ public function setUpDatabase()
$this->getEntityManager()->flush();
}

public function testShowActionResponse()
public function testShowActionResponse(): void
{
$this->client->request('GET', '/sitemap/cms_pages.xml');
$response = $this->client->getResponse();
$this->assertResponse($response, 'show_sitemap_pages');
}

}

0 comments on commit c6a6b2c

Please sign in to comment.