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\Bundle\AddressingBundle\Factory\ZoneFactoryInterface; |
16
|
|
|
use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface; |
17
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
18
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Mateusz Zalewski <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ZoneContext implements Context |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
private $euMembers = [ |
29
|
|
|
'BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'IE', 'GR', 'ES', |
30
|
|
|
'FR', 'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT', 'NL', |
31
|
|
|
'AT', 'PL', 'PT', 'RO', 'SI', 'SK', 'FI', 'SE', 'GB', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var RepositoryInterface |
36
|
|
|
*/ |
37
|
|
|
private $zoneRepository; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var SettingsManagerInterface |
41
|
|
|
*/ |
42
|
|
|
private $settingsManager; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var ZoneFactoryInterface |
46
|
|
|
*/ |
47
|
|
|
private $zoneFactory; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param RepositoryInterface $zoneRepository |
51
|
|
|
* @param SettingsManagerInterface $settingsManager |
52
|
|
|
* @param ZoneFactoryInterface $zoneFactory |
53
|
|
|
*/ |
54
|
|
|
public function __construct(RepositoryInterface $zoneRepository, SettingsManagerInterface $settingsManager, ZoneFactoryInterface $zoneFactory) |
55
|
|
|
{ |
56
|
|
|
$this->zoneRepository = $zoneRepository; |
57
|
|
|
$this->settingsManager = $settingsManager; |
58
|
|
|
$this->zoneFactory = $zoneFactory; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Transform :zone zone |
63
|
|
|
* @Transform zone :zone |
64
|
|
|
*/ |
65
|
|
|
public function getZoneByCode($zone) |
66
|
|
|
{ |
67
|
|
|
$existingZone = $this->zoneRepository->findOneBy(['code' => $zone]); |
68
|
|
|
if (null === $existingZone) { |
69
|
|
|
throw new \InvalidArgumentException(sprintf('Zone with code "%s" does not exist', $zone)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $existingZone; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @Given /^there is "EU" zone containing all members of European Union$/ |
77
|
|
|
*/ |
78
|
|
|
public function thereIsEUZoneContainingAllMembersOfEuropeanUnion() |
79
|
|
|
{ |
80
|
|
|
$zone = $this->zoneFactory->createWithMembers($this->euMembers); |
81
|
|
|
$zone->setType(ZoneInterface::TYPE_COUNTRY); |
82
|
|
|
$zone->setCode('EU'); |
83
|
|
|
$zone->setName('European Union'); |
84
|
|
|
|
85
|
|
|
$this->zoneRepository->add($zone); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @Given default tax zone is :taxZone |
90
|
|
|
*/ |
91
|
|
|
public function defaultTaxZoneIs($taxZone) |
92
|
|
|
{ |
93
|
|
|
$zone = $this->getZoneByCode($taxZone); |
94
|
|
|
|
95
|
|
|
$settings = $this->settingsManager->loadSettings('sylius_taxation'); |
96
|
|
|
$settings->set('default_tax_zone', $zone); |
97
|
|
|
$this->settingsManager->saveSettings('sylius_taxation', $settings); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|