1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lakion\SyliusCmsBundle\Tests\Behat\Context\Setup; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Context; |
6
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
7
|
|
|
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; |
8
|
|
|
use Sylius\Behat\Service\SharedStorageInterface; |
9
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
10
|
|
|
|
11
|
|
|
final class RouteContext implements Context |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var SharedStorageInterface |
15
|
|
|
*/ |
16
|
|
|
private $sharedStorage; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var ExampleFactoryInterface |
20
|
|
|
*/ |
21
|
|
|
private $routeExampleFactory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ObjectManager |
25
|
|
|
*/ |
26
|
|
|
private $routeManager; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var RepositoryInterface |
30
|
|
|
*/ |
31
|
|
|
private $staticContentRepository; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param SharedStorageInterface $sharedStorage |
35
|
|
|
* @param ExampleFactoryInterface $routeExampleFactory |
36
|
|
|
* @param ObjectManager $routeManager |
37
|
|
|
* @param RepositoryInterface $staticContentRepository |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
SharedStorageInterface $sharedStorage, |
41
|
|
|
ExampleFactoryInterface $routeExampleFactory, |
42
|
|
|
ObjectManager $routeManager, |
43
|
|
|
RepositoryInterface $staticContentRepository |
44
|
|
|
) { |
45
|
|
|
$this->sharedStorage = $sharedStorage; |
46
|
|
|
$this->routeExampleFactory = $routeExampleFactory; |
47
|
|
|
$this->routeManager = $routeManager; |
48
|
|
|
$this->staticContentRepository = $staticContentRepository; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @Given the store has route :name |
53
|
|
|
*/ |
54
|
|
|
public function theStoreHasRoute($name) |
55
|
|
|
{ |
56
|
|
|
$route = $this->routeExampleFactory->create(['name' => $name]); |
57
|
|
|
|
58
|
|
|
$this->routeManager->persist($route); |
59
|
|
|
$this->routeManager->flush(); |
60
|
|
|
$this->routeManager->clear(); |
61
|
|
|
|
62
|
|
|
$this->sharedStorage->set('route', $route); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @Given the store has routes :firstName and :secondName |
67
|
|
|
*/ |
68
|
|
|
public function theStoreHasRoutes(...$routesNames) |
69
|
|
|
{ |
70
|
|
|
foreach ($routesNames as $routesName) { |
71
|
|
|
$this->theStoreHasRoute($routesName); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @Given the store has route :name with :contentTitle as its content |
77
|
|
|
*/ |
78
|
|
|
public function theStoreHasRouteWithAsItsContent($name, $contentTitle) |
79
|
|
|
{ |
80
|
|
|
$content = $this->staticContentRepository->findOneBy(['title' => $contentTitle]); |
81
|
|
|
|
82
|
|
|
$route = $this->routeExampleFactory->create(['name' => $name, 'content' => $content]); |
83
|
|
|
|
84
|
|
|
$this->routeManager->persist($route); |
85
|
|
|
$this->routeManager->flush(); |
86
|
|
|
$this->routeManager->clear(); |
87
|
|
|
|
88
|
|
|
$this->sharedStorage->set('route', $route); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|