Completed
Push — missing-product-variant-variab... ( a08960 )
by Kamil
22:45
created

UpdatePage   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 15
lcom 2
cbo 5
dl 0
loc 127
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setPriority() 0 4 1
A getPriority() 0 4 1
A checkChannelsState() 0 6 1
A fillUsageLimit() 0 4 1
A makeExclusive() 0 4 1
A checkCouponBased() 0 4 1
A checkChannel() 0 4 1
A setStartsAt() 0 7 1
A setEndsAt() 0 7 1
A hasStartsAt() 0 7 2
A hasEndsAt() 0 7 2
A getCodeElement() 0 4 1
A getDefinedElements() 0 17 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 Sylius\Behat\Behaviour\ChecksCodeImmutability;
15
use Sylius\Behat\Behaviour\NamesIt;
16
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
17
18
/**
19
 * @author Mateusz Zalewski <[email protected]>
20
 * @author Łukasz Chruściel <[email protected]>
21
 */
22
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
23
{
24
    use NamesIt;
25
    use ChecksCodeImmutability;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function setPriority($priority)
31
    {
32
        $this->getDocument()->fillField('Priority', $priority);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getPriority()
39
    {
40
        return $this->getElement('priority')->getValue();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function checkChannelsState($channelName)
47
    {
48
        $field = $this->getDocument()->findField($channelName);
49
50
        return (bool) $field->getValue();
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function fillUsageLimit($limit)
57
    {
58
        $this->getDocument()->fillField('Usage limit', $limit);
59
    }
60
61
    public function makeExclusive()
62
    {
63
        $this->getDocument()->checkField('Exclusive');
64
    }
65
66
    public function checkCouponBased()
67
    {
68
        $this->getDocument()->checkField('Coupon based');
69
    }
70
71
    public function checkChannel($name)
72
    {
73
        $this->getDocument()->checkField($name);
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function setStartsAt(\DateTime $dateTime)
80
    {
81
        $timestamp = $dateTime->getTimestamp();
82
83
        $this->getDocument()->fillField('sylius_promotion_startsAt_date', date('Y-m-d', $timestamp));
84
        $this->getDocument()->fillField('sylius_promotion_startsAt_time', date('H:i', $timestamp));
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function setEndsAt(\DateTime $dateTime)
91
    {
92
        $timestamp = $dateTime->getTimestamp();
93
94
        $this->getDocument()->fillField('sylius_promotion_endsAt_date', date('Y-m-d', $timestamp));
95
        $this->getDocument()->fillField('sylius_promotion_endsAt_time', date('H:i', $timestamp));
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function hasStartsAt(\DateTime $dateTime)
102
    {
103
        $timestamp = $dateTime->getTimestamp();
104
105
        return $this->getElement('starts_at_date')->getValue() === date('Y-m-d', $timestamp)
106
            && $this->getElement('starts_at_time')->getValue() === date('H:i', $timestamp);
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function hasEndsAt(\DateTime $dateTime)
113
    {
114
        $timestamp = $dateTime->getTimestamp();
115
116
        return $this->getElement('ends_at_date')->getValue() === date('Y-m-d', $timestamp)
117
            && $this->getElement('ends_at_time')->getValue() === date('H:i', $timestamp);
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    protected function getCodeElement()
124
    {
125
        return $this->getElement('code');
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131
    protected function getDefinedElements()
132
    {
133
        return [
134
            'code' => '#sylius_promotion_code',
135
            'priority' => '#sylius_promotion_priority',
136
            'coupon_based' => '#sylius_promotion_couponBased',
137
            'ends_at' => '#sylius_promotion_endsAt',
138
            'ends_at_date' => '#sylius_promotion_endsAt_date',
139
            'ends_at_time' => '#sylius_promotion_endsAt_time',
140
            'exclusive' => '#sylius_promotion_exclusive',
141
            'name' => '#sylius_promotion_name',
142
            'starts_at' => '#sylius_promotion_startsAt',
143
            'starts_at_date' => '#sylius_promotion_startsAt_date',
144
            'starts_at_time' => '#sylius_promotion_startsAt_time',
145
            'usage_limit' => '#sylius_promotion_usageLimit',
146
        ];
147
    }
148
}
149