[Sitemap] Remove sitemap support

This commit is contained in:
Arminek 2016-11-25 14:14:08 +01:00
parent 492a0d3a72
commit 4ce64fce2f
32 changed files with 0 additions and 1588 deletions

View file

@ -1,55 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Controller;
use Sylius\Bundle\CoreBundle\Sitemap\Builder\SitemapBuilderInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Renderer\SitemapRendererInterface;
use Symfony\Component\HttpFoundation\Response;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class SitemapController
{
/**
* @var SitemapRendererInterface
*/
private $sitemapRenderer;
/**
* @var SitemapBuilderInterface
*/
private $sitemapBuilder;
/**
* @param SitemapRendererInterface $sitemapRenderer
* @param SitemapBuilderInterface $sitemapBuilder
*/
public function __construct(SitemapRendererInterface $sitemapRenderer, SitemapBuilderInterface $sitemapBuilder)
{
$this->sitemapRenderer = $sitemapRenderer;
$this->sitemapBuilder = $sitemapBuilder;
}
/**
* @return Response
*/
public function showAction()
{
$sitemap = $this->sitemapBuilder->build();
$response = new Response($this->sitemapRenderer->render($sitemap));
$response->headers->set('Content-Type', 'application/xml');
return $response;
}
}

View file

@ -27,7 +27,6 @@
<import resource="services/order_processing.xml" />
<import resource="services/pricing.xml" />
<import resource="services/promotion.xml" />
<import resource="services/sitemap.xml" />
<import resource="services/state_resolvers.xml" />
<import resource="services/taxation.xml" />
<import resource="services/templating.xml" />

View file

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius.controller.sitemap" class="Sylius\Bundle\CoreBundle\Controller\SitemapController">
<argument type="service" id="sylius.sitemap_renderer"/>
<argument type="service" id="sylius.sitemap_builder" />
</service>
<service id="sylius.sitemap_renderer.twig_adapter" class="Sylius\Bundle\CoreBundle\Sitemap\Renderer\TwigAdapter">
<argument type="service" id="templating" />
<argument>%sylius.sitemap_template%</argument>
</service>
<service id="sylius.sitemap_renderer" class="Sylius\Bundle\CoreBundle\Sitemap\Renderer\SitemapRenderer">
<argument type="service" id="sylius.sitemap_renderer.twig_adapter" />
</service>
<service id="sylius.sitemap_factory" class="Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapFactory" />
<service id="sylius.sitemap_url_factory" class="Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapUrlFactory" />
<service id="sylius.sitemap_builder" class="Sylius\Bundle\CoreBundle\Sitemap\Builder\SitemapBuilder">
<argument type="service" id="sylius.sitemap_factory" />
</service>
<service id="sylius.sitemap_provider.product" class="Sylius\Bundle\CoreBundle\Sitemap\Provider\ProductUrlProvider" >
<argument type="service" id="sylius.repository.product" />
<argument type="service" id="router" />
<argument type="service" id="sylius.sitemap_url_factory" />
<tag name="sylius.sitemap_provider" />
</service>
</services>
</container>

View file

@ -1,63 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Builder;
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapFactoryInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Provider\UrlProviderInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapBuilder implements SitemapBuilderInterface
{
/**
* @var SitemapFactoryInterface
*/
private $sitemapFactory;
/**
* @var array
*/
private $providers = [];
/**
* @param SitemapFactoryInterface $sitemapFactory
*/
public function __construct(SitemapFactoryInterface $sitemapFactory)
{
$this->sitemapFactory = $sitemapFactory;
}
/**
* {@inheritdoc}
*/
public function addProvider(UrlProviderInterface $provider)
{
$this->providers[] = $provider;
}
/**
* {@inheritdoc}
*/
public function build()
{
$sitemap = $this->sitemapFactory->createNew();
$urls = [];
foreach ($this->providers as $provider) {
$urls = array_merge($urls, $provider->generate());
}
$sitemap->setUrls($urls);
return $sitemap;
}
}

View file

@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Builder;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Provider\UrlProviderInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface SitemapBuilderInterface
{
/**
* @param UrlProviderInterface $provider
*/
public function addProvider(UrlProviderInterface $provider);
/**
* @return SitemapInterface
*/
public function build();
}

View file

@ -1,28 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Exception;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class SitemapUrlNotFoundException extends \Exception
{
/**
* {@inheritdoc}
*/
public function __construct(SitemapUrlInterface $sitemapUrl, \Exception $previousException = null)
{
parent::__construct(sprintf('Sitemap url %s not found', $sitemapUrl->getLocalization()), 0, $previousException);
}
}

View file

@ -1,28 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Factory;
use Sylius\Bundle\CoreBundle\Sitemap\Model\Sitemap;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapFactory implements SitemapFactoryInterface
{
/**
* {@inheritdoc}
*/
public function createNew()
{
return new Sitemap();
}
}

View file

@ -1,25 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Factory;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface SitemapFactoryInterface
{
/**
* @return SitemapInterface
*/
public function createNew();
}

View file

@ -1,28 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Factory;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrl;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapUrlFactory implements SitemapUrlFactoryInterface
{
/**
* {@inheritdoc}
*/
public function createNew()
{
return new SitemapUrl();
}
}

View file

@ -1,25 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Factory;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface SitemapUrlFactoryInterface
{
/**
* @return SitemapUrlInterface
*/
public function createNew();
}

View file

@ -1,95 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Model;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class ChangeFrequency
{
/**
* @var string
*/
private $value;
/**
* @param string $changeFrequency
*/
private function __construct($changeFrequency)
{
$this->value = $changeFrequency;
}
/**
* @return string
*/
public function __toString()
{
return $this->value;
}
/**
* @return ChangeFrequency
*/
public static function always()
{
return new self('always');
}
/**
* @return ChangeFrequency
*/
public static function hourly()
{
return new self('hourly');
}
/**
* @return ChangeFrequency
*/
public static function daily()
{
return new self('daily');
}
/**
* @return ChangeFrequency
*/
public static function weekly()
{
return new self('weekly');
}
/**
* @return ChangeFrequency
*/
public static function monthly()
{
return new self('monthly');
}
/**
* @return ChangeFrequency
*/
public static function yearly()
{
return new self('yearly');
}
/**
* @return ChangeFrequency
*/
public static function never()
{
return new self('never');
}
}

View file

@ -1,104 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Model;
use Sylius\Bundle\CoreBundle\Sitemap\Exception\SitemapUrlNotFoundException;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class Sitemap implements SitemapInterface
{
/**
* @var array
*/
private $urls = [];
/**
* @var string
*/
private $localization;
/**
* @var \DateTime
*/
private $lastModification;
/**
* {@inheritdoc}
*/
public function setUrls(array $urls)
{
$this->urls = $urls;
}
/**
* {@inheritdoc}
*/
public function getUrls()
{
return $this->urls;
}
/**
* {@inheritdoc}
*/
public function addUrl(SitemapUrlInterface $url)
{
$this->urls[] = $url;
}
/**
* {@inheritdoc}
*/
public function removeUrl(SitemapUrlInterface $url)
{
$key = array_search($url, $this->urls, true);
if (false === $key) {
throw new SitemapUrlNotFoundException($url);
}
unset($this->urls[$key]);
}
/**
* {@inheritdoc}
*/
public function setLocalization($localization)
{
$this->localization = $localization;
}
/**
* {@inheritdoc}
*/
public function getLocalization()
{
return $this->localization;
}
/**
* {@inheritdoc}
*/
public function setLastModification(\DateTime $lastModification)
{
$this->lastModification = $lastModification;
}
/**
* {@inheritdoc}
*/
public function getLastModification()
{
return $this->lastModification;
}
}

View file

@ -1,58 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Model;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface SitemapInterface
{
/**
* @return SitemapUrlInterface[]
*/
public function getUrls();
/**
* @param SitemapUrlInterface[] $urlSet
*/
public function setUrls(array $urlSet);
/**
* @param SitemapUrlInterface $url
*/
public function addUrl(SitemapUrlInterface $url);
/**
* @param SitemapUrlInterface $url
*/
public function removeUrl(SitemapUrlInterface $url);
/**
* @return string
*/
public function getLocalization();
/**
* @param string $localization
*/
public function setLocalization($localization);
/**
* @return \DateTime
*/
public function getLastModification();
/**
* @param \DateTime $lastModification
*/
public function setLastModification(\DateTime $lastModification);
}

View file

@ -1,108 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Model;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class SitemapUrl implements SitemapUrlInterface
{
/**
* @var string
*/
private $localization;
/**
* @var \DateTime
*/
private $lastModification;
/**
* @var ChangeFrequency
*/
private $changeFrequency;
/**
* @var float
*/
private $priority;
/**
* {@inheritdoc}
*/
public function getLocalization()
{
return $this->localization;
}
/**
* {@inheritdoc}
*/
public function setLocalization($localization)
{
$this->localization = $localization;
}
/**
* {@inheritdoc}
*/
public function getLastModification()
{
return $this->lastModification;
}
/**
* {@inheritdoc}
*/
public function setLastModification(\DateTime $lastModification)
{
$this->lastModification = $lastModification;
}
/**
* {@inheritdoc}
*/
public function getChangeFrequency()
{
return (string) $this->changeFrequency;
}
/**
* {@inheritdoc}
*/
public function setChangeFrequency(ChangeFrequency $changeFrequency)
{
$this->changeFrequency = $changeFrequency;
}
/**
* {@inheritdoc}
*/
public function getPriority()
{
return $this->priority;
}
/**
* {@inheritdoc}
*/
public function setPriority($priority)
{
if (!is_numeric($priority) || 0 > $priority || 1 < $priority) {
throw new \InvalidArgumentException(sprintf(
'The value %s is not supported by the option priority, it must be a numeric between 0.0 and 1.0.', $priority
));
}
$this->priority = $priority;
}
}

View file

@ -1,58 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Model;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface SitemapUrlInterface
{
/**
* @return string
*/
public function getLocalization();
/**
* @param string $localization
*/
public function setLocalization($localization);
/**
* @return \DateTime
*/
public function getLastModification();
/**
* @param \DateTime $lastModification
*/
public function setLastModification(\DateTime $lastModification);
/**
* @return string
*/
public function getChangeFrequency();
/**
* @param ChangeFrequency $changeFrequency
*/
public function setChangeFrequency(ChangeFrequency $changeFrequency);
/**
* @return float
*/
public function getPriority();
/**
* @param float $priority
*/
public function setPriority($priority);
}

View file

@ -1,80 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Provider;
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapUrlFactoryInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Model\ChangeFrequency;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\Routing\RouterInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class ProductUrlProvider implements UrlProviderInterface
{
/**
* @var RepositoryInterface
*/
private $productRepository;
/**
* @var RouterInterface
*/
private $router;
/**
* @var SitemapUrlFactoryInterface
*/
private $sitemapUrlFactory;
/**
* @var array
*/
private $urls = [];
/**
* @param RepositoryInterface $productRepository
* @param RouterInterface $router
* @param SitemapUrlFactoryInterface $sitemapUrlFactory
*/
public function __construct(
RepositoryInterface $productRepository,
RouterInterface $router,
SitemapUrlFactoryInterface $sitemapUrlFactory
) {
$this->productRepository = $productRepository;
$this->router = $router;
$this->sitemapUrlFactory = $sitemapUrlFactory;
}
/**
* {@inheritdoc}
*/
public function generate()
{
$products = $this->productRepository->findAll();
foreach ($products as $product) {
$productUrl = $this->sitemapUrlFactory->createNew();
$localization = $this->router->generate('sylius_shop_product_show', ['slug' => $product->getSlug()], true);
$productUrl->setLastModification($product->getUpdatedAt());
$productUrl->setLocalization($localization);
$productUrl->setChangeFrequency(ChangeFrequency::always());
$productUrl->setPriority(0.5);
$this->urls[] = $productUrl;
}
return $this->urls;
}
}

View file

@ -1,23 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Provider;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface UrlProviderInterface
{
/**
* @return array
*/
public function generate();
}

View file

@ -1,29 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Renderer;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface RendererAdapterInterface
{
/**
* @param SitemapInterface $sitemap
*
* @return string The evaluated template as a string
*
* @throws \RuntimeException if the template cannot be rendered
*/
public function render(SitemapInterface $sitemap);
}

View file

@ -1,42 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Renderer;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapRenderer implements SitemapRendererInterface
{
/**
* @var RendererAdapterInterface
*/
private $adapter;
/**
* @param RendererAdapterInterface $adapter
* @param array $configuration
*/
public function __construct(RendererAdapterInterface $adapter, array $configuration = [])
{
$this->adapter = $adapter;
}
/**
* {@inheritdoc}
*/
public function render(SitemapInterface $sitemap)
{
return $this->adapter->render($sitemap);
}
}

View file

@ -1,25 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Renderer;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface SitemapRendererInterface
{
/**
* @param SitemapInterface $sitemap
*/
public function render(SitemapInterface $sitemap);
}

View file

@ -1,50 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CoreBundle\Sitemap\Renderer;
use Sylius\Bundle\CoreBundle\Sitemap\Exception\TemplateNotFoundException;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
use Symfony\Component\Templating\EngineInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class TwigAdapter implements RendererAdapterInterface
{
/**
* @var EngineInterface
*/
private $twig;
/**
* @var string
*/
private $template;
/**
* @param EngineInterface $twig
* @param string $template
*/
public function __construct(EngineInterface $twig, $template)
{
$this->twig = $twig;
$this->template = $template;
}
/**
* {@inheritdoc}
*/
public function render(SitemapInterface $sitemap)
{
return $this->twig->render($this->template, ['url_set' => $sitemap->getUrls()]);
}
}

View file

@ -1,60 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Builder;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Sitemap\Builder\SitemapBuilder;
use Sylius\Bundle\CoreBundle\Sitemap\Builder\SitemapBuilderInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapFactoryInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Provider\UrlProviderInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapBuilderSpec extends ObjectBehavior
{
function let(SitemapFactoryInterface $sitemapFactory)
{
$this->beConstructedWith($sitemapFactory);
}
function it_is_initializable()
{
$this->shouldHaveType(SitemapBuilder::class);
}
function it_implements_sitemap_builder_interface()
{
$this->shouldImplement(SitemapBuilderInterface::class);
}
function it_builds_sitemap(
$sitemapFactory,
UrlProviderInterface $productUrlProvider,
UrlProviderInterface $staticUrlProvider,
SitemapInterface $sitemap,
SitemapUrlInterface $bookUrl,
SitemapUrlInterface $homePage
) {
$sitemapFactory->createNew()->willReturn($sitemap);
$this->addProvider($productUrlProvider);
$this->addProvider($staticUrlProvider);
$productUrlProvider->generate()->willReturn([$bookUrl]);
$staticUrlProvider->generate()->willReturn([$homePage]);
$sitemap->setUrls([$bookUrl, $homePage])->shouldBeCalled();
$this->build()->shouldReturn($sitemap);
}
}

View file

@ -1,38 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Exception;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Sitemap\Exception\SitemapUrlNotFoundException;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapUrlNotFoundExceptionSpec extends ObjectBehavior
{
function let(SitemapUrlInterface $sitemapUrl)
{
$sitemapUrl->getLocalization()->willReturn('http://sylius.org');
$this->beConstructedWith($sitemapUrl, null);
}
function it_is_an_exception()
{
$this->shouldHaveType(\Exception::class);
}
function it_is_initializable()
{
$this->shouldHaveType(SitemapUrlNotFoundException::class);
}
}

View file

@ -1,39 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Factory;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapFactory;
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapFactoryInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Model\Sitemap;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(SitemapFactory::class);
}
function it_implements_sitemap_factory_interface()
{
$this->shouldImplement(SitemapFactoryInterface::class);
}
function it_creates_empty_sitemap()
{
$this->createNew()->shouldBeLike(new Sitemap());
}
}

View file

@ -1,39 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Factory;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapUrlFactory;
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapUrlFactoryInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrl;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapUrlFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(SitemapUrlFactory::class);
}
function it_implements_sitemap_url_factory_interface()
{
$this->shouldImplement(SitemapUrlFactoryInterface::class);
}
function it_creates_empty_sitemap_url()
{
$this->createNew()->shouldBeLike(new SitemapUrl());
}
}

View file

@ -1,63 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Model;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Sitemap\Model\ChangeFrequency;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class ChangeFrequencySpec extends ObjectBehavior
{
function it_initialize_with_always_value()
{
$this->beConstructedThrough('always');
$this->__toString()->shouldReturn('always');
}
function it_initialize_with_hourly_value()
{
$this->beConstructedThrough('hourly');
$this->__toString()->shouldReturn('hourly');
}
function it_initialize_with_daily_value()
{
$this->beConstructedThrough('daily');
$this->__toString()->shouldReturn('daily');
}
function it_initialize_with_weekly_value()
{
$this->beConstructedThrough('weekly');
$this->__toString()->shouldReturn('weekly');
}
function it_initialize_with_monthly_value()
{
$this->beConstructedThrough('monthly');
$this->__toString()->shouldReturn('monthly');
}
function it_initialize_with_yearly_value()
{
$this->beConstructedThrough('yearly');
$this->__toString()->shouldReturn('yearly');
}
function it_initialize_with_never_value()
{
$this->beConstructedThrough('never');
$this->__toString()->shouldReturn('never');
}
}

View file

@ -1,82 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Model;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Sitemap\Exception\SitemapUrlNotFoundException;
use Sylius\Bundle\CoreBundle\Sitemap\Model\Sitemap;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Sitemap::class);
}
function it_implements_sitemap_interface()
{
$this->shouldImplement(SitemapInterface::class);
}
function it_has_sitemap_urls()
{
$this->setUrls([]);
$this->getUrls()->shouldReturn([]);
}
function it_adds_url(SitemapUrlInterface $sitemapUrl)
{
$this->addUrl($sitemapUrl);
$this->getUrls()->shouldReturn([$sitemapUrl]);
}
function it_removes_url(
SitemapUrlInterface $sitemapUrl,
SitemapUrlInterface $productUrl,
SitemapUrlInterface $staticUrl
) {
$this->addUrl($sitemapUrl);
$this->addUrl($staticUrl);
$this->addUrl($productUrl);
$this->removeUrl($sitemapUrl);
$this->getUrls()->shouldReturn([1 => $staticUrl, 2 => $productUrl]);
}
function it_has_localization()
{
$this->setLocalization('http://sylius.org/sitemap1.xml');
$this->getLocalization()->shouldReturn('http://sylius.org/sitemap1.xml');
}
function it_has_last_modification_date(\DateTime $now)
{
$this->setLastModification($now);
$this->getLastModification()->shouldReturn($now);
}
function it_throws_sitemap_url_not_found_exception_if_cannot_find_url_to_remove(
SitemapUrlInterface $productUrl,
SitemapUrlInterface $staticUrl
) {
$this->addUrl($productUrl);
$staticUrl->getLocalization()->willReturn('http://sylius.org');
$this->shouldThrow(SitemapUrlNotFoundException::class)->during('removeUrl', [$staticUrl]);
}
}

View file

@ -1,71 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Model;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Sitemap\Model\ChangeFrequency;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrl;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapUrlSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(SitemapUrl::class);
}
function it_implements_sitemap_url_interface()
{
$this->shouldImplement(SitemapUrlInterface::class);
}
function it_has_localization()
{
$this->setLocalization('http://sylius.org/');
$this->getLocalization()->shouldReturn('http://sylius.org/');
}
function it_has_last_modification(\DateTime $now)
{
$this->setLastModification($now);
$this->getLastModification()->shouldReturn($now);
}
function it_has_change_frequency()
{
$this->setChangeFrequency(ChangeFrequency::always());
$this->getChangeFrequency()->shouldReturn('always');
}
function it_has_priority()
{
$this->setPriority(0.5);
$this->getPriority()->shouldReturn(0.5);
}
function it_throws_invalid_argument_exception_if_priority_wont_be_between_zero_and_one()
{
$this->shouldThrow(\InvalidArgumentException::class)->during('setPriority', array(-1));
$this->shouldThrow(\InvalidArgumentException::class)->during('setPriority', array(-0.5));
$this->shouldThrow(\InvalidArgumentException::class)->during('setPriority', array(2));
$this->shouldThrow(\InvalidArgumentException::class)->during('setPriority', array(1.1));
}
function it_throws_invalid_argument_exception_if_priority_will_be_not_a_number()
{
$this->shouldThrow(\InvalidArgumentException::class)->during('setPriority', array('Mike'));
$this->shouldThrow(\InvalidArgumentException::class)->during('setPriority', array(true));
}
}

View file

@ -1,77 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Provider;
use Doctrine\Common\Collections\Collection;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository;
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapUrlFactoryInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Model\ChangeFrequency;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Provider\ProductUrlProvider;
use Sylius\Bundle\CoreBundle\Sitemap\Provider\UrlProviderInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Symfony\Component\Routing\RouterInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class ProductUrlProviderSpec extends ObjectBehavior
{
function let(ProductRepository $repository, RouterInterface $router, SitemapUrlFactoryInterface $sitemapUrlFactory)
{
$this->beConstructedWith($repository, $router, $sitemapUrlFactory);
}
function it_is_initializable()
{
$this->shouldHaveType(ProductUrlProvider::class);
}
function it_implements_provider_interface()
{
$this->shouldImplement(UrlProviderInterface::class);
}
function it_generates_urls(
$repository,
$router,
$sitemapUrlFactory,
Collection $products,
\Iterator $iterator,
ProductInterface $product,
SitemapUrlInterface $sitemapUrl,
\DateTime $now
) {
$repository->findAll()->willReturn($products);
$products->getIterator()->willReturn($iterator);
$iterator->valid()->willReturn(true, false);
$iterator->next()->shouldBeCalled();
$iterator->rewind()->shouldBeCalled();
$iterator->current()->willReturn($product);
$product->getUpdatedAt()->willReturn($now);
$product->getSlug()->willReturn('t-shirt');
$router->generate('sylius_shop_product_show', ['slug' => 't-shirt'], true)->willReturn('http://sylius.org/products/t-shirt');
$router->generate($product, [], true)->willReturn('http://sylius.org/products/t-shirt');
$sitemapUrlFactory->createNew()->willReturn($sitemapUrl);
$sitemapUrl->setLocalization('http://sylius.org/products/t-shirt')->shouldBeCalled();
$sitemapUrl->setLastModification($now)->shouldBeCalled();
$sitemapUrl->setChangeFrequency(ChangeFrequency::always())->shouldBeCalled();
$sitemapUrl->setPriority(0.5)->shouldBeCalled();
$this->generate();
}
}

View file

@ -1,46 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Renderer;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Renderer\RendererAdapterInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Renderer\SitemapRenderer;
use Sylius\Bundle\CoreBundle\Sitemap\Renderer\SitemapRendererInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class SitemapRendererSpec extends ObjectBehavior
{
function let(RendererAdapterInterface $adapter)
{
$this->beConstructedWith($adapter);
}
function it_is_initializable()
{
$this->shouldHaveType(SitemapRenderer::class);
}
function it_implements_sitemap_renderer_interface()
{
$this->shouldImplement(SitemapRendererInterface::class);
}
function it_renders_sitemap($adapter, SitemapInterface $sitemap)
{
$adapter->render($sitemap)->shouldBeCalled();
$this->render($sitemap);
}
}

View file

@ -1,48 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Renderer;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Renderer\RendererAdapterInterface;
use Sylius\Bundle\CoreBundle\Sitemap\Renderer\TwigAdapter;
use Symfony\Component\Templating\EngineInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class TwigAdapterSpec extends ObjectBehavior
{
function let(EngineInterface $twig)
{
$this->beConstructedWith($twig, '@SyliusCore/Sitemap/url_set.xml.twig');
}
function it_is_initializable()
{
$this->shouldHaveType(TwigAdapter::class);
}
function it_implements_renderer_adapter_interface()
{
$this->shouldImplement(RendererAdapterInterface::class);
}
function it_renders_sitemap($twig, SitemapInterface $sitemap, SitemapUrlInterface $productUrl)
{
$sitemap->getUrls()->willReturn([$productUrl]);
$twig->render('@SyliusCore/Sitemap/url_set.xml.twig', ['url_set' => [$productUrl]])->shouldBeCalled();
$this->render($sitemap);
}
}

View file

@ -1,30 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Tests\Controller;
use Lakion\ApiTestCase\XmlApiTestCase;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class SitemapControllerApiTest extends XmlApiTestCase
{
public function testShowActionResponse()
{
$this->loadFixturesFromFile('resources/product.yml');
$this->client->request('GET', '/sitemap.xml');
$response = $this->client->getResponse();
$this->assertResponse($response, 'sitemap/show_sitemap');
}
}