|
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 Sylius\Component\Locale\Converter\LocaleNameConverterInterface; |
|
16
|
|
|
use Sylius\Component\Core\Test\Services\SharedStorageInterface; |
|
17
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
|
18
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class LocaleContext implements Context |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var SharedStorageInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $sharedStorage; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var FactoryInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $localeFactory; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var LocaleNameConverterInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $localeNameConverter; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var RepositoryInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
private $localeRepository; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param SharedStorageInterface $sharedStorage |
|
47
|
|
|
* @param FactoryInterface $localeFactory |
|
48
|
|
|
* @param LocaleNameConverterInterface $localeNameConverter |
|
49
|
|
|
* @param RepositoryInterface $localeRepository |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct( |
|
52
|
|
|
SharedStorageInterface $sharedStorage, |
|
53
|
|
|
FactoryInterface $localeFactory, |
|
54
|
|
|
LocaleNameConverterInterface $localeNameConverter, |
|
55
|
|
|
RepositoryInterface $localeRepository |
|
56
|
|
|
) { |
|
57
|
|
|
$this->localeFactory = $localeFactory; |
|
58
|
|
|
$this->localeRepository = $localeRepository; |
|
59
|
|
|
$this->localeNameConverter = $localeNameConverter; |
|
60
|
|
|
$this->sharedStorage = $sharedStorage; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @Given the store has locale :localeName |
|
65
|
|
|
*/ |
|
66
|
|
|
public function theStoreHasLocale($localeName) |
|
67
|
|
|
{ |
|
68
|
|
|
$locale = $this->localeFactory->createNew(); |
|
69
|
|
|
$locale->setCode($this->localeNameConverter->convertToCode($localeName)); |
|
70
|
|
|
|
|
71
|
|
|
$this->sharedStorage->set('locale', $locale); |
|
72
|
|
|
$this->localeRepository->add($locale); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @Given the store has disabled locale :localeName |
|
77
|
|
|
*/ |
|
78
|
|
|
public function theStoreHasDisabledLocale($localeName) |
|
79
|
|
|
{ |
|
80
|
|
|
$locale = $this->localeFactory->createNew(); |
|
81
|
|
|
$locale->setCode($this->localeNameConverter->convertToCode($localeName)); |
|
82
|
|
|
$locale->disable(); |
|
83
|
|
|
|
|
84
|
|
|
$this->sharedStorage->set('locale', $locale); |
|
85
|
|
|
$this->localeRepository->add($locale); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|