|
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\Service\Resolver; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface; |
|
15
|
|
|
use Sylius\Behat\Page\Admin\Product\UpdateConfigurableProductPageInterface; |
|
16
|
|
|
use Sylius\Behat\Page\Admin\Product\UpdateSimpleProductPageInterface; |
|
17
|
|
|
use Sylius\Component\Product\Model\ProductInterface; |
|
18
|
|
|
use Webmozart\Assert\Assert; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Łukasz Chruściel <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class CurrentProductPageResolver implements CurrentProductPageResolverInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var CurrentPageResolverInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $currentPageResolver; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param CurrentPageResolverInterface $currentPageResolver |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(CurrentPageResolverInterface $currentPageResolver) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->currentPageResolver = $currentPageResolver; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
* |
|
41
|
|
|
* @throws \LogicException |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getCurrentPageWithForm(array $pages, ProductInterface $product = null) |
|
44
|
|
|
{ |
|
45
|
|
|
$resolvedPage = $this->currentPageResolver->getCurrentPageWithForm($pages); |
|
46
|
|
|
|
|
47
|
|
|
if (!$resolvedPage instanceof UpdatePageInterface) { |
|
48
|
|
|
return $resolvedPage; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
Assert::notNull($product, 'It is not possible to determine a product edit page without product provided.'); |
|
52
|
|
|
|
|
53
|
|
|
if ($product->isSimple()) { |
|
54
|
|
|
$resolvedPage = $this->getSimplePage($pages); |
|
55
|
|
|
} else { |
|
56
|
|
|
$resolvedPage = $this->getConfigurablePage($pages); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
Assert::notNull($resolvedPage, 'Route name could not be matched to provided pages.'); |
|
60
|
|
|
|
|
61
|
|
|
return $resolvedPage; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param array $pages |
|
66
|
|
|
* |
|
67
|
|
|
* @return UpdateSimpleProductPageInterface|null |
|
68
|
|
|
*/ |
|
69
|
|
|
private function getSimplePage(array $pages) |
|
70
|
|
|
{ |
|
71
|
|
|
foreach ($pages as $page) { |
|
72
|
|
|
if ($page instanceof UpdateSimpleProductPageInterface) { |
|
73
|
|
|
return $page; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return null; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param array $pages |
|
82
|
|
|
* |
|
83
|
|
|
* @return UpdateConfigurableProductPageInterface|null |
|
84
|
|
|
*/ |
|
85
|
|
|
private function getConfigurablePage(array $pages) |
|
86
|
|
|
{ |
|
87
|
|
|
foreach ($pages as $page) { |
|
88
|
|
|
if ($page instanceof UpdateConfigurableProductPageInterface) { |
|
89
|
|
|
return $page; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return null; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|