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); |
|
|
|
|
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|