Completed
Push — master ( 0bcb3b...91c399 )
by Kamil
17:43
created

iShouldSeeOnlyOneTrackedVariantInTheList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
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 Sylius\Behat\Context\Ui\Admin;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\Page\Admin\Inventory\IndexPageInterface;
16
use Webmozart\Assert\Assert;
17
18
/**
19
 * @author Grzegorz Sadowski <[email protected]>
20
 */
21
final class ManagingInventoryContext implements Context
22
{
23
    /**
24
     * @var IndexPageInterface
25
     */
26
    private $indexPage;
27
28
    /**
29
     * @param IndexPageInterface $indexPage
30
     */
31
    public function __construct(IndexPageInterface $indexPage)
32
    {
33
        $this->indexPage = $indexPage;
34
    }
35
36
    /**
37
     * @When I want to browse inventory
38
     */
39
    public function iWantToBrowseInventory()
40
    {
41
        $this->indexPage->open();
42
    }
43
44
    /**
45
     * @When /^I filter tracked variants with (code|name) containing "([^"]+)"/
46
     */
47
    public function iFilterTrackedVariantsWithCodeContaining($field, $value)
48
    {
49
        $this->indexPage->specifyFilterType($field, 'Contains');
50
        $this->indexPage->specifyFilterValue($field, $value);
51
52
        $this->indexPage->filter();
53
    }
54
55
    /**
56
     * @Then I should see only one tracked variant in the list
57
     */
58
    public function iShouldSeeOnlyOneTrackedVariantInTheList()
59
    {
60
        $foundRows = $this->indexPage->countItems();
61
62
        Assert::same(
63
            1,
64
            $foundRows,
65
            '%s rows with tracked product variants should appear on page, %s rows has been found.'
66
        );
67
    }
68
69
    /**
70
     * @Then I should see that the :productVariantName variant has :quantity quantity on hand
71
     */
72
    public function iShouldSeeThatTheProductVariantHasQuantityOnHand($productVariantName, $quantity)
73
    {
74
        Assert::true(
75
            $this->indexPage->isSingleResourceOnPage([
76
                'name' => $productVariantName,
77
                'inventory' => sprintf('%s Available on hand', $quantity)
78
            ]),
79
            sprintf(
80
                'This "%s" variant should have %s on hand quantity, but it does not.',
81
                $productVariantName,
82
                $quantity
83
            )
84
        );
85
    }
86
}
87