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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Behat\Context\Ui\Shop; |
15
|
|
|
|
16
|
|
|
use Behat\Behat\Context\Context; |
17
|
|
|
use Sylius\Behat\Page\Shop\HomePageInterface; |
18
|
|
|
use Sylius\Component\Locale\Context\LocaleNotFoundException; |
19
|
|
|
use Webmozart\Assert\Assert; |
20
|
|
|
|
21
|
|
|
final class LocaleContext implements Context |
22
|
|
|
{ |
23
|
|
|
/** @var HomePageInterface */ |
24
|
|
|
private $homePage; |
25
|
|
|
|
26
|
|
|
public function __construct(HomePageInterface $homePage) |
27
|
|
|
{ |
28
|
|
|
$this->homePage = $homePage; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @Given I switched the shop's locale to :locale |
33
|
|
|
* @Given I have switched to the :locale locale |
34
|
|
|
* @When I switch to the :locale locale |
35
|
|
|
* @When I change my locale to :locale |
36
|
|
|
*/ |
37
|
|
|
public function iSwitchTheLocaleToTheLocale(string $locale): void |
38
|
|
|
{ |
39
|
|
|
$this->homePage->open(); |
40
|
|
|
$this->homePage->switchLocale($locale); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @When I show homepage with the locale :localeCode |
45
|
|
|
*/ |
46
|
|
|
public function iShowHomepageWithTheLocale(string $localeCode): void |
47
|
|
|
{ |
48
|
|
|
$this->homePage->tryToOpen(['_locale' => $localeCode]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @Then I should shop using the :locale locale |
53
|
|
|
* @Then I should still shop using the :locale locale |
54
|
|
|
*/ |
55
|
|
|
public function iShouldShopUsingTheLocale($locale) |
56
|
|
|
{ |
57
|
|
|
Assert::same($this->homePage->getActiveLocale(), $locale); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Then I should be able to shop using the :locale locale |
62
|
|
|
* @Then the store should be available in the :locale locale |
63
|
|
|
*/ |
64
|
|
|
public function iShouldBeAbleToShopUsingTheLocale($locale) |
65
|
|
|
{ |
66
|
|
|
Assert::oneOf($locale, $this->homePage->getAvailableLocales()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Then I should not be able to shop using the :locale locale |
71
|
|
|
* @Then the store should not be available in the :locale locale |
72
|
|
|
*/ |
73
|
|
|
public function iShouldNotBeAbleToShopUsingTheLocale($locale) |
74
|
|
|
{ |
75
|
|
|
if (in_array($locale, $this->homePage->getAvailableLocales(), true)) { |
76
|
|
|
throw new \InvalidArgumentException(sprintf( |
77
|
|
|
'Expected "%s" not to be in "%s"', |
78
|
|
|
$locale, |
79
|
|
|
implode('", "', $this->homePage->getAvailableLocales()) |
80
|
|
|
)); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @Then I should not be able to shop without default locale |
86
|
|
|
*/ |
87
|
|
|
public function iShouldNotBeAbleToShop() |
88
|
|
|
{ |
89
|
|
|
try { |
90
|
|
|
$this->homePage->tryToOpen(); |
91
|
|
|
|
92
|
|
|
throw new \Exception('The page should not be able to open.'); |
93
|
|
|
} catch (LocaleNotFoundException $e) { |
|
|
|
|
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|