Completed
Push — master ( 1671b1...4e9462 )
by Kamil
23:39
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 3
Bugs 2 Features 0
Metric Value
c 3
b 2
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\ProductContext;
18
use Sylius\Behat\Page\Admin\Product\IndexPageInterface;
19
use Sylius\Behat\Page\Admin\Product\ShowPageInterface;
20
use Sylius\Behat\Page\Product\ProductShowPage;
21
use Sylius\Behat\Page\Admin\Product\ShowPage as AdminProductShowPage;
22
use Sylius\Behat\Page\Product\ProductShowPageInterface;
23
use Sylius\Component\Core\Model\ProductInterface;
24
use Sylius\Component\Core\Test\Services\SharedStorage;
25
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
26
27
/**
28
 * @mixin ProductContext
29
 *
30
 * @author Magdalena Banasiak <[email protected]>
31
 */
32
class ProductContextSpec extends ObjectBehavior
33
{
34
    public function let(
35
        SharedStorageInterface $sharedStorage,
36
        ProductShowPageInterface $productShowPage,
37
        ShowPageInterface $adminProductShowPage,
38
        IndexPageInterface $adminProductIndexPage
39
    ) {
40
        $this->beConstructedWith($sharedStorage, $productShowPage, $adminProductShowPage, $adminProductIndexPage);
41
    }
42
43
    function it_is_initializable()
44
    {
45
        $this->shouldHaveType('Sylius\Behat\Context\Ui\ProductContext');
46
    }
47
48
    function it_implements_context_interface()
49
    {
50
        $this->shouldImplement(Context::class);
51
    }
52
53
    function it_checks_if_i_am_able_to_access_product_page(ProductShowPageInterface $productShowPage, ProductInterface $product)
54
    {
55
        $productShowPage->tryToOpen(['product' => $product])->shouldBeCalled();
56
        $productShowPage->isOpen(['product' => $product])->willReturn(true);
57
        
58
        $this->iShouldBeAbleToAccessProduct($product);
59
    }
60
61
    function it_throws_an_exception_if_i_am_not_able_to_access_product_page_when_i_should(
62
        ProductShowPageInterface $productShowPage,
63
        ProductInterface $product
64
    ) {
65
        $productShowPage->tryToOpen(['product' => $product])->shouldBeCalled();
66
        $productShowPage->isOpen(['product' => $product])->willReturn(false);
67
68
        $this->shouldThrow(NotEqualException::class)->during('iShouldBeAbleToAccessProduct',[$product]);
69
    }
70
71
    function it_checks_if_i_am_not_able_to_access_product_page(ProductShowPageInterface $productShowPage, ProductInterface $product)
72
    {
73
        $productShowPage->tryToOpen(['product' => $product])->shouldBeCalled();
74
        $productShowPage->isOpen(['product' => $product])->willReturn(false);
75
76
        $this->iShouldNotBeAbleToAccessProduct($product);
77
    }
78
79
    function it_throws_an_exception_if_i_am_able_to_access_product_page_when_i_should_not(
80
        ProductShowPageInterface $productShowPage,
81
        ProductInterface $product
82
    ) {
83
        $productShowPage->tryToOpen(['product' => $product])->shouldBeCalled();
84
        $productShowPage->isOpen(['product' => $product])->willReturn(true);
85
86
        $this->shouldThrow(NotEqualException::class)->during('iShouldNotBeAbleToAccessProduct',[$product]);
87
    }
88
89
    function it_deletes_a_product(
90
        ShowPageInterface $adminProductShowPage,
91
        SharedStorageInterface $sharedStorage,
92
        ProductInterface $product
93
    ) {
94
        $sharedStorage->set('product', $product)->shouldBeCalled();
95
        
96
        $product->getName()->willReturn('Model');
97
        $product->getId()->willReturn(1);
98
99
        $adminProductShowPage->open(['id' => 1])->shouldBeCalled();
100
        $adminProductShowPage->deleteProduct()->shouldBeCalled();
101
102
        $this->iDeleteProduct($product);
103
    }
104
105
    function it_checks_if_a_product_does_not_exist(
106
        SharedStorageInterface $sharedStorage,
107
        IndexPageInterface $adminProductIndexPage,
108
        ProductInterface $product
109
    ) {
110
        $sharedStorage->get('product')->willReturn($product);
111
112
        $adminProductIndexPage->open()->shouldBeCalled();
113
        $adminProductIndexPage->isThereProduct($product)->willReturn(false);
114
115
        $this->productShouldNotExist($product);
116
    }
117
118
    function it_throws_an_exception_if_a_product_exists_when_it_should_not(
119
        SharedStorageInterface $sharedStorage,
120
        IndexPageInterface $adminProductIndexPage,
121
        ProductInterface $product
122
    ) {
123
        $sharedStorage->get('product')->willReturn($product);
124
125
        $adminProductIndexPage->open()->shouldBeCalled();
126
        $adminProductIndexPage->isThereProduct($product)->willReturn(true);
127
128
        $this->shouldThrow(NotEqualException::class)->during('productShouldNotExist', [$product]);
129
    }
130
}
131