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 Sylius\Behat\Context\Setup; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
16
|
|
|
use Sylius\Bundle\ThemeBundle\Factory\ThemeFactoryInterface; |
17
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
18
|
|
|
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface; |
19
|
|
|
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; |
20
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
21
|
|
|
use Sylius\Component\Core\Test\Services\SharedStorageInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Kamil Kokot <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
final class ThemeContext implements Context |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var SharedStorageInterface |
30
|
|
|
*/ |
31
|
|
|
private $sharedStorage; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ThemeRepositoryInterface |
35
|
|
|
*/ |
36
|
|
|
private $themeRepository; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var ThemeFactoryInterface |
40
|
|
|
*/ |
41
|
|
|
private $themeFactory; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var ChannelRepositoryInterface |
45
|
|
|
*/ |
46
|
|
|
private $channelRepository; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var ObjectManager |
50
|
|
|
*/ |
51
|
|
|
private $channelManager; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param SharedStorageInterface $sharedStorage |
55
|
|
|
* @param ThemeRepositoryInterface $themeRepository |
56
|
|
|
* @param ThemeFactoryInterface $themeFactory |
57
|
|
|
* @param ChannelRepositoryInterface $channelRepository |
58
|
|
|
* @param ObjectManager $channelManager |
59
|
|
|
*/ |
60
|
|
|
public function __construct( |
61
|
|
|
SharedStorageInterface $sharedStorage, |
62
|
|
|
ThemeRepositoryInterface $themeRepository, |
63
|
|
|
ThemeFactoryInterface $themeFactory, |
64
|
|
|
ChannelRepositoryInterface $channelRepository, |
65
|
|
|
ObjectManager $channelManager |
66
|
|
|
) { |
67
|
|
|
$this->sharedStorage = $sharedStorage; |
68
|
|
|
$this->themeRepository = $themeRepository; |
69
|
|
|
$this->themeFactory = $themeFactory; |
70
|
|
|
$this->channelRepository = $channelRepository; |
71
|
|
|
$this->channelManager = $channelManager; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @Given the store has :themeName theme |
76
|
|
|
*/ |
77
|
|
|
public function storeHasTheme($themeName) |
78
|
|
|
{ |
79
|
|
|
$theme = $this->themeFactory->createNamed($themeName); |
80
|
|
|
$theme->setTitle($themeName); |
81
|
|
|
$theme->setPath(sys_get_temp_dir() . '/theme-' . $theme->getCode() . time() . '/'); |
82
|
|
|
|
83
|
|
|
if (!file_exists($theme->getPath())) { |
84
|
|
|
mkdir($theme->getPath(), 0777, true); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$this->themeRepository->add($theme); |
88
|
|
|
$this->sharedStorage->set('theme', $theme); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @Given channel :channel uses :theme theme |
93
|
|
|
*/ |
94
|
|
|
public function channelUsesTheme(ChannelInterface $channel, ThemeInterface $theme) |
95
|
|
|
{ |
96
|
|
|
$channel->setTheme($theme); |
97
|
|
|
|
98
|
|
|
$this->channelManager->flush(); |
99
|
|
|
|
100
|
|
|
$this->sharedStorage->set('channel', $channel); |
101
|
|
|
$this->sharedStorage->set('theme', $theme); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @Given channel :channel does not use any theme |
106
|
|
|
*/ |
107
|
|
|
public function channelDoesNotUseAnyTheme(ChannelInterface $channel) |
108
|
|
|
{ |
109
|
|
|
$channel->setTheme(null); |
110
|
|
|
|
111
|
|
|
$this->channelManager->flush(); |
112
|
|
|
|
113
|
|
|
$this->sharedStorage->set('channel', $channel); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @Given /^(this theme) changes homepage template contents to "([^"]+)"$/ |
118
|
|
|
*/ |
119
|
|
|
public function themeChangesHomepageTemplateContents(ThemeInterface $theme, $contents) |
120
|
|
|
{ |
121
|
|
|
$file = rtrim($theme->getPath(), '/') . '/SyliusWebBundle/views/Frontend/Homepage/main.html.twig'; |
122
|
|
|
$dir = dirname($file); |
123
|
|
|
|
124
|
|
|
if (!file_exists($dir)) { |
125
|
|
|
mkdir($dir, 0777, true); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
file_put_contents($file, $contents); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|