Completed
Push — master ( 308c33...4cc160 )
by Michał
303:29 queued 289:05
created

CreatePage   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 14
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 128
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A addRule() 0 6 1
A selectRuleOption() 0 4 1
A fillUsageLimit() 0 4 1
A makeExclusive() 0 4 1
A checkCouponBased() 0 4 1
A checkChannel() 0 4 1
A setEndsAt() 0 7 1
A fillRuleOption() 0 4 1
A addAction() 0 6 1
A selectActionOption() 0 4 1
A fillActionOption() 0 4 1
A getDefinedElements() 0 10 1
A getLastAddedCollectionItem() 0 6 1
A setStartsAt() 0 7 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\Page\Admin\Promotion;
13
14
use Behat\Mink\Element\NodeElement;
15
use Sylius\Behat\Behaviour\NamesIt;
16
use Sylius\Behat\Behaviour\SpecifiesItsCode;
17
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
18
19
/**
20
 * @author Mateusz Zalewski <[email protected]>
21
 * @author Łuksaz Zalewski <[email protected]>
22
 */
23
class CreatePage extends BaseCreatePage implements CreatePageInterface
24
{
25
    use NamesIt;
26
    use SpecifiesItsCode;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function addRule($ruleName)
32
    {
33
        $this->getDocument()->clickLink('Add rule');
34
35
        $this->selectRuleOption('Type', $ruleName);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function selectRuleOption($option, $value, $multiple = false)
42
    {
43
        $this->getLastAddedCollectionItem('rules')->find('named', array('select', $option))->selectOption($value, $multiple);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function fillRuleOption($option, $value)
50
    {
51
        $this->getLastAddedCollectionItem('rules')->fillField($option, $value);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function addAction($actionName)
58
    {
59
        $this->getDocument()->clickLink('Add action');
60
61
        $this->selectActionOption('Type', $actionName);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function selectActionOption($option, $value, $multiple = false)
68
    {
69
        $this->getLastAddedCollectionItem('actions')->find('named', array('select', $option))->selectOption($value, $multiple);
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function fillActionOption($option, $value)
76
    {
77
        $this->getLastAddedCollectionItem('actions')->fillField($option, $value);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function fillUsageLimit($limit)
84
    {
85
        $this->getDocument()->fillField('Usage limit', $limit);
86
    }
87
88
    public function makeExclusive()
89
    {
90
        $this->getDocument()->checkField('Exclusive');
91
    }
92
93
    public function checkCouponBased()
94
    {
95
        $this->getDocument()->checkField('Coupon based');
96
    }
97
98
    public function checkChannel($name)
99
    {
100
        $this->getDocument()->checkField($name);
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function setStartsAt(\DateTime $dateTime)
107
    {
108
        $timestamp = $dateTime->getTimestamp();
109
110
        $this->getDocument()->fillField('sylius_promotion_startsAt_date', date('Y-m-d', $timestamp));
111
        $this->getDocument()->fillField('sylius_promotion_startsAt_time', date('H:i', $timestamp));
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function setEndsAt(\DateTime $dateTime)
118
    {
119
        $timestamp = $dateTime->getTimestamp();
120
121
        $this->getDocument()->fillField('sylius_promotion_endsAt_date', date('Y-m-d', $timestamp));
122
        $this->getDocument()->fillField('sylius_promotion_endsAt_time', date('H:i', $timestamp));
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    protected function getDefinedElements()
129
    {
130
        return [
131
            'starts_at' => '#sylius_promotion_startsAt',
132
            'actions' => '#sylius_promotion_actions',
133
            'code' => '#sylius_promotion_code',
134
            'name' => '#sylius_promotion_name',
135
            'rules' => '#sylius_promotion_rules',
136
        ];
137
    }
138
139
    /**
140
     * @param string $collection
141
     *
142
     * @return NodeElement
143
     */
144
    private function getLastAddedCollectionItem($collection)
145
    {
146
        $rules = $this->getElement($collection)->findAll('css', 'div[data-form-collection="item"]');
147
148
        return end($rules);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression end($rules); of type Behat\Mink\Element\NodeElement|false adds false to the return on line 148 which is incompatible with the return type documented by Sylius\Behat\Page\Admin\...LastAddedCollectionItem of type Behat\Mink\Element\NodeElement. It seems like you forgot to handle an error condition.
Loading history...
149
    }
150
}
151