|
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\Ui; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
|
15
|
|
|
use Behat\Mink\Mink; |
|
16
|
|
|
use Behat\Mink\Session; |
|
17
|
|
|
use Behat\MinkExtension\Context\MinkAwareContext; |
|
18
|
|
|
use Behat\Symfony2Extension\Driver\KernelDriver; |
|
19
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Kamil Kokot <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
final class ChannelContext implements Context |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var Session |
|
28
|
|
|
*/ |
|
29
|
|
|
private $minkSession; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
private $minkParameters; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Session $minkSession |
|
38
|
|
|
* @param array $minkParameters |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(Session $minkSession, array $minkParameters) |
|
41
|
|
|
{ |
|
42
|
|
|
if (!isset($minkParameters['base_url'])) { |
|
43
|
|
|
$minkParameters['base_url'] = null; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->minkSession = $minkSession; |
|
47
|
|
|
$this->minkParameters = $minkParameters; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @When I change my current channel to :channel |
|
52
|
|
|
*/ |
|
53
|
|
|
public function iChangeMyCurrentChannelTo(ChannelInterface $channel) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->prepareSessionIfNeeded(); |
|
56
|
|
|
|
|
57
|
|
|
$this->minkSession->setCookie('_channel_code', $channel->getCode()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function prepareSessionIfNeeded() |
|
61
|
|
|
{ |
|
62
|
|
|
if ($this->minkSession->getDriver() instanceof KernelDriver) { |
|
63
|
|
|
return; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if (false !== strpos($this->minkSession->getCurrentUrl(), $this->minkParameters['base_url'])) { |
|
67
|
|
|
return; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$this->minkSession->visit(rtrim($this->minkParameters['base_url'], '/') . '/'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|