|
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\Api\Admin; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
|
15
|
|
|
use Sylius\Component\Core\Model\TaxonInterface; |
|
16
|
|
|
use Symfony\Component\BrowserKit\Client; |
|
17
|
|
|
use Symfony\Component\BrowserKit\Cookie; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
|
19
|
|
|
use Webmozart\Assert\Assert; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
final class ManagingTaxonsContext implements Context |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var Client |
|
28
|
|
|
*/ |
|
29
|
|
|
private $client; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var SessionInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
private $session; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Client $client |
|
38
|
|
|
* @param SessionInterface $session |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(Client $client, SessionInterface $session) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->client = $client; |
|
43
|
|
|
$this->session = $session; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @When I look for a taxon with :phrase in name |
|
48
|
|
|
*/ |
|
49
|
|
|
public function iTypeIn($phrase) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->client->getCookieJar()->set(new Cookie($this->session->getName(), $this->session->getId())); |
|
52
|
|
|
$this->client->request('GET', '/admin/ajax/taxons/search', ['phrase' => $phrase], [], ['ACCEPT' => 'application/json']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @When I want to get taxon with :code code |
|
57
|
|
|
*/ |
|
58
|
|
|
public function iWantToGetTaxonWithCode($code) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->client->getCookieJar()->set(new Cookie($this->session->getName(), $this->session->getId())); |
|
61
|
|
|
$this->client->request('GET', '/admin/ajax/taxons/leaf', ['code' => $code], [], ['ACCEPT' => 'application/json']); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @When /^I want to get children from (taxon "[^"]+")/ |
|
66
|
|
|
*/ |
|
67
|
|
|
public function iWantToGetChildrenFromTaxon(TaxonInterface $taxon) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->client->getCookieJar()->set(new Cookie($this->session->getName(), $this->session->getId())); |
|
70
|
|
|
$this->client->request('GET', '/admin/ajax/taxons/leafs', ['parentCode' => $taxon->getCode()], [], ['ACCEPT' => 'application/json']); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @When I want to get taxon root |
|
75
|
|
|
*/ |
|
76
|
|
|
public function iWantToGetTaxonRoot() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->client->getCookieJar()->set(new Cookie($this->session->getName(), $this->session->getId())); |
|
79
|
|
|
$this->client->request('GET', '/admin/ajax/taxons/root-nodes', [], [], ['ACCEPT' => 'application/json']); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @Then /^I should see (\d+) taxons on the list$/ |
|
84
|
|
|
*/ |
|
85
|
|
|
public function iShouldSeeTaxonsInTheList($number) |
|
86
|
|
|
{ |
|
87
|
|
|
$response = json_decode($this->client->getResponse()->getContent(), true); |
|
88
|
|
|
|
|
89
|
|
|
Assert::eq($number, count($response)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @Then I should see the taxon named :firstName in the list |
|
94
|
|
|
* @Then I should see the taxon named :firstName and :secondName in the list |
|
95
|
|
|
* @Then I should see the taxon named :firstName, :secondName and :thirdName in the list |
|
96
|
|
|
* @Then I should see the taxon named :firstName, :secondName, :thirdName and :fourthName in the list |
|
97
|
|
|
*/ |
|
98
|
|
|
public function iShouldSeeTheTaxonNamedAnd(...$expectedTaxonNames) |
|
99
|
|
|
{ |
|
100
|
|
|
$response = json_decode($this->client->getResponse()->getContent(), true); |
|
101
|
|
|
$taxonNames = array_map(function ($item) { |
|
102
|
|
|
return $item['name']; |
|
103
|
|
|
}, $response); |
|
104
|
|
|
|
|
105
|
|
|
Assert::allOneOf($taxonNames, $expectedTaxonNames); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|