Completed
Push — master ( 4e9462...2570d1 )
by Kamil
18:48
created

it_implements_context_interface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Context\Ui;
13
14
use Behat\Behat\Context\Context;
15
use PhpSpec\Exception\Example\NotEqualException;
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Behat\Context\Ui\Admin\ManagingShippingMethodsContext;
18
use Sylius\Behat\Page\Admin\ShippingMethod\IndexPageInterface;
19
use Sylius\Behat\Page\Admin\ShippingMethod\ShowPageInterface;
20
use Sylius\Behat\Page\UnexpectedPageException;
21
use Sylius\Component\Core\Model\ShippingMethodInterface;
22
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
23
24
/**
25
 * @mixin ManagingShippingMethodsContext
26
 *
27
 * @author Jan Góralski <[email protected]>
28
 */
29
class ManagingShippingMethodsContextSpec extends ObjectBehavior
30
{
31
    function let(
32
        SharedStorageInterface $sharedStorage,
33
        ShowPageInterface $shippingMethodShowPage,
34
        IndexPageInterface $shippingMethodIndexPage
35
    ) {
36
        $this->beConstructedWith($sharedStorage, $shippingMethodShowPage, $shippingMethodIndexPage);
37
    }
38
39
    function it_is_initializable()
40
    {
41
        $this->shouldHaveType('Sylius\Behat\Context\Ui\Admin\ManagingShippingMethodsContext');
42
    }
43
44
    function it_implements_context_interface()
45
    {
46
        $this->shouldImplement(Context::class);
47
    }
48
49
    function it_deletes_given_shipping_method(
50
        ShowPageInterface $shippingMethodShowPage,
51
        ShippingMethodInterface $shippingMethod
52
    ) {
53
        $shippingMethod->getId()->willReturn(5);
54
        $shippingMethodShowPage->open(['id' => 5])->shouldBeCalled();
55
        $shippingMethodShowPage->pressDelete()->shouldBeCalled();
56
57
        $this->iTryToDeleteShippingMethod($shippingMethod);
58
    }
59
60
    function it_sets_error_flash_if_method_is_in_use(ShowPageInterface $shippingMethodShowPage)
61
    {
62
        $shippingMethodShowPage->flashContainsMessage(
63
            'Cannot delete, the shipping method is in use.'
64
        )->willReturn(true);
65
66
        $this->iShouldBeNotifiedItIsUsed();
67
    }
68
69
    function it_throws_exception_when_flash_was_not_set(ShowPageInterface $shippingMethodShowPage)
70
    {
71
        $shippingMethodShowPage->flashContainsMessage(
72
            'Cannot delete, the shipping method is in use.'
73
        )->willReturn(false);
74
75
        $this->shouldThrow(NotEqualException::class)->during('iShouldBeNotifiedItIsUsed');
76
    }
77
78
    function it_checks_whether_a_shipping_method_was_removed(
79
        IndexPageInterface $shippingMethodIndexPage,
80
        ShippingMethodInterface $shippingMethod
81
    ) {
82
        $shippingMethodIndexPage->isOpen()->willReturn(true);
83
        $shippingMethod->getName()->willReturn('UPS Express');
84
85
        $shippingMethodIndexPage->isThereShippingMethodNamed('UPS Express')->willReturn(false);
86
87
        $this->shippingMethodShouldBeRemoved($shippingMethod);
88
    }
89
90
    function it_throws_exception_when_a_shipping_method_was_not_removed_when_it_should_have_been(
91
        IndexPageInterface $shippingMethodIndexPage,
92
        ShippingMethodInterface $shippingMethod
93
    ) {
94
        $shippingMethod->getName()->willReturn('UPS Express');
95
96
        $shippingMethodIndexPage->isOpen()->willReturn(true);
97
        $shippingMethodIndexPage->isThereShippingMethodNamed('UPS Express')->willReturn(true);
98
99
        $this->shouldThrow(NotEqualException::class)->during('shippingMethodShouldBeRemoved', [$shippingMethod]);
100
    }
101
102
    function it_throws_exception_if_there_was_no_redirect_to_index_after_successful_deletion_of_a_shipping_method(
103
        IndexPageInterface $shippingMethodIndexPage,
104
        ShippingMethodInterface $shippingMethod
105
    ) {
106
        $shippingMethod->getName()->willReturn('UPS Express');
107
108
        $shippingMethodIndexPage->isOpen()->willReturn(false);
109
        $shippingMethodIndexPage->isThereShippingMethodNamed('UPS Express')->willReturn(false);
110
111
        $this->shouldThrow(NotEqualException::class)->during('shippingMethodShouldBeRemoved', [$shippingMethod]);
112
    }
113
114
    function it_checks_whether_a_shipping_method_was_not_removed(
115
        ShowPageInterface $shippingMethodShowPage,
116
        ShippingMethodInterface $shippingMethod
117
    ) {
118
        $shippingMethod->getName()->willReturn('UPS Express');
119
        $shippingMethod->getId()->willReturn(5);
120
121
        $shippingMethodShowPage->isOpen(['id' => 5])->willReturn(true);
122
        $shippingMethodShowPage->verify(['id' => 5])->willNotThrow(UnexpectedPageException::class);
123
124
        $this->shippingMethodShouldNotBeRemoved($shippingMethod);
125
    }
126
127
    function it_throws_exception_when_a_shipping_method_was_removed_when_it_should_not(
128
        ShowPageInterface $shippingMethodShowPage,
129
        IndexPageInterface $shippingMethodIndexPage,
130
        ShippingMethodInterface $shippingMethod
131
    ) {
132
        $shippingMethod->getName()->willReturn('UPS Express');
133
        $shippingMethod->getId()->willReturn(5);
134
135
        $shippingMethodShowPage->isOpen(['id' => 5])->willReturn(true);
136
        $shippingMethodIndexPage->isThereShippingMethodNamed('UPS Express')->willReturn(false);
137
138
        $this->shouldThrow(NotEqualException::class)->during('shippingMethodShouldNotBeRemoved', [$shippingMethod]);
139
    }
140
141
    function it_checks_if_there_was_no_redirect_to_index_after_unsuccessful_deletion_of_a_shipping_method(
142
        ShowPageInterface $shippingMethodShowPage,
143
        IndexPageInterface $shippingMethodIndexPage,
144
        ShippingMethodInterface $shippingMethod
145
    ) {
146
        $shippingMethod->getName()->willReturn('UPS Express');
147
        $shippingMethod->getId()->willReturn(5);
148
149
        $shippingMethodShowPage->isOpen(['id' => 5])->willReturn(false);
150
        $shippingMethodIndexPage->isThereShippingMethodNamed('UPS Express')->willReturn(true);
151
152
        $this->shouldThrow(NotEqualException::class)->during('shippingMethodShouldNotBeRemoved', [$shippingMethod]);
153
    }
154
}
155