|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace spec\Sylius\Bundle\CoreBundle\Sitemap\Provider; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\Collection; |
|
15
|
|
|
use PhpSpec\ObjectBehavior; |
|
16
|
|
|
use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository; |
|
17
|
|
|
use Sylius\Bundle\CoreBundle\Sitemap\Factory\SitemapUrlFactoryInterface; |
|
18
|
|
|
use Sylius\Bundle\CoreBundle\Sitemap\Model\ChangeFrequency; |
|
19
|
|
|
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface; |
|
20
|
|
|
use Sylius\Bundle\CoreBundle\Sitemap\Provider\UrlProviderInterface; |
|
21
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
22
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class ProductUrlProviderSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function let(ProductRepository $repository, RouterInterface $router, SitemapUrlFactoryInterface $sitemapUrlFactory) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->beConstructedWith($repository, $router, $sitemapUrlFactory); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function it_is_initializable() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldHaveType('Sylius\Bundle\CoreBundle\Sitemap\Provider\ProductUrlProvider'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_implements_provider_interface() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->shouldImplement(UrlProviderInterface::class); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_generates_urls( |
|
45
|
|
|
$repository, |
|
46
|
|
|
$router, |
|
47
|
|
|
$sitemapUrlFactory, |
|
48
|
|
|
Collection $products, |
|
49
|
|
|
\Iterator $iterator, |
|
50
|
|
|
ProductInterface $product, |
|
51
|
|
|
SitemapUrlInterface $sitemapUrl, |
|
52
|
|
|
\DateTime $now |
|
53
|
|
|
) { |
|
54
|
|
|
$repository->findAll()->willReturn($products); |
|
55
|
|
|
$products->getIterator()->willReturn($iterator); |
|
56
|
|
|
$iterator->valid()->willReturn(true, false); |
|
57
|
|
|
$iterator->next()->shouldBeCalled(); |
|
58
|
|
|
$iterator->rewind()->shouldBeCalled(); |
|
59
|
|
|
|
|
60
|
|
|
$iterator->current()->willReturn($product); |
|
61
|
|
|
$product->getUpdatedAt()->willReturn($now); |
|
62
|
|
|
|
|
63
|
|
|
$router->generate($product, [], true)->willReturn('http://sylius.org/t-shirt'); |
|
64
|
|
|
$sitemapUrlFactory->createNew()->willReturn($sitemapUrl); |
|
65
|
|
|
|
|
66
|
|
|
$sitemapUrl->setLocalization('http://sylius.org/t-shirt')->shouldBeCalled(); |
|
67
|
|
|
$sitemapUrl->setLastModification($now)->shouldBeCalled(); |
|
68
|
|
|
$sitemapUrl->setChangeFrequency(ChangeFrequency::always())->shouldBeCalled(); |
|
69
|
|
|
$sitemapUrl->setPriority(0.5)->shouldBeCalled(); |
|
70
|
|
|
|
|
71
|
|
|
$this->generate(); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|