|
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 spec\Sylius\Behat\Service\Resolver; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Sylius\Behat\Page\Admin\Product\UpdateConfigurableProductPageInterface; |
|
16
|
|
|
use Sylius\Behat\Page\Admin\Product\UpdateSimpleProductPageInterface; |
|
17
|
|
|
use Sylius\Behat\Page\SymfonyPageInterface; |
|
18
|
|
|
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
|
19
|
|
|
use Sylius\Behat\Service\Resolver\CurrentProductPageResolver; |
|
20
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @mixin CurrentProductPageResolver |
|
24
|
|
|
* |
|
25
|
|
|
* @author Łukasz Chruściel <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class CurrentProductPageResolverSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function let(CurrentPageResolverInterface $currentPageResolver) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->beConstructedWith($currentPageResolver); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function it_is_initializable() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldHaveType('Sylius\Behat\Service\Resolver\CurrentProductPageResolver'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_implements_current_page_resolver_interface() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->shouldImplement(CurrentPageResolverInterface::class); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_delegates_current_page_matching_by_default( |
|
45
|
|
|
CurrentPageResolverInterface $currentPageResolver, |
|
46
|
|
|
SymfonyPageInterface $createPage, |
|
47
|
|
|
SymfonyPageInterface $updatePage |
|
48
|
|
|
) { |
|
49
|
|
|
$currentPageResolver->getCurrentPageWithForm([$createPage, $updatePage])->willReturn($createPage); |
|
50
|
|
|
|
|
51
|
|
|
$this->getCurrentPageWithForm([$createPage, $updatePage])->shouldReturn($createPage); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function it_throws_an_exception_if_product_was_not_provided_after_update_page_matched( |
|
55
|
|
|
CurrentPageResolverInterface $currentPageResolver, |
|
56
|
|
|
UpdateSimpleProductPageInterface $simpleUpdatePage, |
|
57
|
|
|
UpdateConfigurableProductPageInterface $configurableUpdatePage |
|
58
|
|
|
) { |
|
59
|
|
|
$currentPageResolver->getCurrentPageWithForm([$configurableUpdatePage, $simpleUpdatePage])->willReturn($simpleUpdatePage); |
|
60
|
|
|
|
|
61
|
|
|
$this |
|
62
|
|
|
->shouldThrow(new \InvalidArgumentException('It is not possible to determine a product edit page without product provided.')) |
|
63
|
|
|
->during('getCurrentPageWithForm', [[$configurableUpdatePage, $simpleUpdatePage]]) |
|
64
|
|
|
; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
function it_matches_proper_update_page_based_on_product_type( |
|
68
|
|
|
ProductInterface $product, |
|
69
|
|
|
CurrentPageResolverInterface $currentPageResolver, |
|
70
|
|
|
UpdateConfigurableProductPageInterface $configurableUpdatePage, |
|
71
|
|
|
UpdateSimpleProductPageInterface $simpleUpdatePage |
|
72
|
|
|
) { |
|
73
|
|
|
$product->isSimple()->willReturn(false); |
|
74
|
|
|
$currentPageResolver->getCurrentPageWithForm([$configurableUpdatePage, $simpleUpdatePage])->willReturn($simpleUpdatePage); |
|
75
|
|
|
|
|
76
|
|
|
$this->getCurrentPageWithForm([$configurableUpdatePage, $simpleUpdatePage], $product)->shouldReturn($configurableUpdatePage); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
function it_throws_an_exception_if_product_page_could_not_be_matched( |
|
80
|
|
|
ProductInterface $product, |
|
81
|
|
|
CurrentPageResolverInterface $currentPageResolver, |
|
82
|
|
|
UpdateConfigurableProductPageInterface $configurableUpdatePage |
|
83
|
|
|
) { |
|
84
|
|
|
$product->isSimple()->willReturn(true); |
|
85
|
|
|
$currentPageResolver->getCurrentPageWithForm([$configurableUpdatePage])->willReturn($configurableUpdatePage); |
|
86
|
|
|
|
|
87
|
|
|
$this |
|
88
|
|
|
->shouldThrow(new \InvalidArgumentException('Route name could not be matched to provided pages.')) |
|
89
|
|
|
->during('getCurrentPageWithForm', [[$configurableUpdatePage], $product]) |
|
90
|
|
|
; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|