|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Behat\Page\Admin\Promotion; |
|
15
|
|
|
|
|
16
|
|
|
use Behat\Mink\Element\NodeElement; |
|
17
|
|
|
use Sylius\Behat\Behaviour\ChecksCodeImmutability; |
|
18
|
|
|
use Sylius\Behat\Behaviour\NamesIt; |
|
19
|
|
|
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; |
|
20
|
|
|
|
|
21
|
|
|
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use NamesIt; |
|
24
|
|
|
use ChecksCodeImmutability; |
|
25
|
|
|
|
|
26
|
|
|
public function setPriority(?int $priority): void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->getDocument()->fillField('Priority', $priority); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getPriority(): int |
|
32
|
|
|
{ |
|
33
|
|
|
return (int) $this->getElement('priority')->getValue(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function checkChannelsState(string $channelName): bool |
|
37
|
|
|
{ |
|
38
|
|
|
$field = $this->getDocument()->findField($channelName); |
|
39
|
|
|
|
|
40
|
|
|
return (bool) $field->getValue(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function fillUsageLimit(string $limit): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->getDocument()->fillField('Usage limit', $limit); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function makeExclusive(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->getDocument()->checkField('Exclusive'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function checkCouponBased(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->getDocument()->checkField('Coupon based'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function checkChannel(string $name): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->getDocument()->checkField($name); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function setStartsAt(\DateTimeInterface $dateTime): void |
|
64
|
|
|
{ |
|
65
|
|
|
$timestamp = $dateTime->getTimestamp(); |
|
66
|
|
|
|
|
67
|
|
|
$this->getDocument()->fillField('sylius_promotion_startsAt_date', date('Y-m-d', $timestamp)); |
|
68
|
|
|
$this->getDocument()->fillField('sylius_promotion_startsAt_time', date('H:i', $timestamp)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function setEndsAt(\DateTimeInterface $dateTime): void |
|
72
|
|
|
{ |
|
73
|
|
|
$timestamp = $dateTime->getTimestamp(); |
|
74
|
|
|
|
|
75
|
|
|
$this->getDocument()->fillField('sylius_promotion_endsAt_date', date('Y-m-d', $timestamp)); |
|
76
|
|
|
$this->getDocument()->fillField('sylius_promotion_endsAt_time', date('H:i', $timestamp)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function hasStartsAt(\DateTimeInterface $dateTime): bool |
|
80
|
|
|
{ |
|
81
|
|
|
$timestamp = $dateTime->getTimestamp(); |
|
82
|
|
|
|
|
83
|
|
|
return $this->getElement('starts_at_date')->getValue() === date('Y-m-d', $timestamp) |
|
84
|
|
|
&& $this->getElement('starts_at_time')->getValue() === date('H:i', $timestamp); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function hasEndsAt(\DateTimeInterface $dateTime): bool |
|
88
|
|
|
{ |
|
89
|
|
|
$timestamp = $dateTime->getTimestamp(); |
|
90
|
|
|
|
|
91
|
|
|
return $this->getElement('ends_at_date')->getValue() === date('Y-m-d', $timestamp) |
|
92
|
|
|
&& $this->getElement('ends_at_time')->getValue() === date('H:i', $timestamp); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
public function isCouponManagementAvailable(): bool |
|
97
|
|
|
{ |
|
98
|
|
|
$element = $this->getDocument()->find('css', 'a:contains("Manage coupons")'); |
|
99
|
|
|
|
|
100
|
|
|
return null !== $element; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function manageCoupons(): void |
|
104
|
|
|
{ |
|
105
|
|
|
$this->getDocument()->clickLink('Manage coupons'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function hasAnyRule(): bool |
|
109
|
|
|
{ |
|
110
|
|
|
$items = $this->getElement('rules')->findAll('css', 'div[data-form-collection="item"]'); |
|
111
|
|
|
|
|
112
|
|
|
return 0 < count($items); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function hasRule(string $name): bool |
|
116
|
|
|
{ |
|
117
|
|
|
$items = $this->getElement('rules')->findAll('css', 'div[data-form-collection="item"]'); |
|
118
|
|
|
|
|
119
|
|
|
foreach ($items as $item) { |
|
120
|
|
|
$selectedOption = $item->find('css', 'option[selected="selected"]'); |
|
121
|
|
|
|
|
122
|
|
|
/** @var NodeElement $selectedOption */ |
|
123
|
|
|
if ($selectedOption->getText() === $name) { |
|
124
|
|
|
return true; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
protected function getCodeElement(): NodeElement |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->getElement('code'); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
protected function getDefinedElements(): array |
|
137
|
|
|
{ |
|
138
|
|
|
return [ |
|
139
|
|
|
'code' => '#sylius_promotion_code', |
|
140
|
|
|
'priority' => '#sylius_promotion_priority', |
|
141
|
|
|
'coupon_based' => '#sylius_promotion_couponBased', |
|
142
|
|
|
'ends_at' => '#sylius_promotion_endsAt', |
|
143
|
|
|
'ends_at_date' => '#sylius_promotion_endsAt_date', |
|
144
|
|
|
'ends_at_time' => '#sylius_promotion_endsAt_time', |
|
145
|
|
|
'exclusive' => '#sylius_promotion_exclusive', |
|
146
|
|
|
'name' => '#sylius_promotion_name', |
|
147
|
|
|
'rules' => '#rules', |
|
148
|
|
|
'starts_at' => '#sylius_promotion_startsAt', |
|
149
|
|
|
'starts_at_date' => '#sylius_promotion_startsAt_date', |
|
150
|
|
|
'starts_at_time' => '#sylius_promotion_startsAt_time', |
|
151
|
|
|
'usage_limit' => '#sylius_promotion_usageLimit', |
|
152
|
|
|
]; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|