Completed
Push — master ( 2c8981...1ecbe4 )
by Kamil
23:19
created

ProductContext::iShouldBeAbleToAccessProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
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\Ui\Shop;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\Page\Shop\Product\ShowPageInterface;
16
use Sylius\Component\Core\Model\ProductInterface;
17
use Webmozart\Assert\Assert;
18
19
/**
20
 * @author Kamil Kokot <[email protected]>
21
 * @author Magdalena Banasiak <[email protected]>
22
 * @author Anna Walasek <[email protected]>
23
 */
24
final class ProductContext implements Context
25
{
26
    /**
27
     * @var ShowPageInterface
28
     */
29
    private $showPage;
30
31
    /**
32
     * @param ShowPageInterface $showPage
33
     */
34
    public function __construct(ShowPageInterface $showPage)
35
    {
36
        $this->showPage = $showPage;
37
    }
38
39
    /**
40
     * @Then I should be able to access product :product
41
     */
42
    public function iShouldBeAbleToAccessProduct(ProductInterface $product)
43
    {
44
        $this->showPage->tryToOpen(['slug' => $product->getSlug()]);
45
46
        Assert::true(
47
            $this->showPage->isOpen(['slug' => $product->getSlug()]),
48
            'Product show page should be open, but it does not.'
49
        );
50
    }
51
52
    /**
53
     * @Then I should not be able to access product :product
54
     */
55
    public function iShouldNotBeAbleToAccessProduct(ProductInterface $product)
56
    {
57
        $this->showPage->tryToOpen(['slug' => $product->getSlug()]);
58
59
        Assert::false(
60
            $this->showPage->isOpen(['slug' => $product->getSlug()]),
61
            'Product show page should not be open, but it does.'
62
        );
63
    }
64
65
    /**
66
     * @When /^I check (this product)'s details/
67
     */
68
    public function iOpenProductPage(ProductInterface $product)
69
    {
70
        $this->showPage->open(['slug' => $product->getSlug()]);
71
    }
72
73
    /**
74
     * @Given I should see the product name :name
75
     */
76
    public function iShouldSeeProductName($name)
77
    {
78
        Assert::same(
79
            $name,
80
            $this->showPage->getName(),
81
            'Product should have name %2$s, but it has %s'
82
        );
83
    }
84
85
    /**
86
     * @When I open page :url
87
     */
88
    public function iOpenPage($url)
89
    {
90
        $this->showPage->visit($url);
91
    }
92
93
    /**
94
     * @Then I should be on :product product detailed page
95
     */
96
    public function iShouldBeOnProductDetailedPage(ProductInterface $product)
97
    {
98
        Assert::true(
99
            $this->showPage->isOpen(['slug' => $product->getSlug()]),
100
            sprintf('Product %s show page should be open, but it does not.', $product->getName())
101
        );
102
    }
103
104
    /**
105
     * @Then I should see the product attribute :attributeName with value :AttributeValue
106
     */
107
    public function iShouldSeeTheProductAttributeWithValue($attributeName, $AttributeValue)
108
    {
109
        Assert::true(
110
            $this->showPage->isAttributeWithValueOnPage($attributeName, $AttributeValue),
111
            sprintf('Product should have attribute %s with value %s, but it does not.', $attributeName, $AttributeValue)
112
        );
113
    }
114
}
115