|
1
|
|
|
<?php |
|
2
|
|
|
namespace EventEspresso\Codeception\helpers; |
|
3
|
|
|
|
|
4
|
|
|
use Page\MessagesAdmin as MessagesPage; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Trait MessagesAdmin |
|
8
|
|
|
* Helper actions for the Messages Admin Pages |
|
9
|
|
|
* @package EventEspresso\Codeception\helpers |
|
10
|
|
|
*/ |
|
11
|
|
|
trait MessagesAdmin |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15
|
|
|
* a string. |
|
16
|
|
|
*/ |
|
17
|
|
|
public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18
|
|
|
{ |
|
19
|
|
|
$this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24
|
|
|
* a string. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27
|
|
|
{ |
|
28
|
|
|
$this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34
|
|
|
* a string. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37
|
|
|
{ |
|
38
|
|
|
$this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Directs to message settings page |
|
44
|
|
|
*/ |
|
45
|
|
|
public function amOnMessageSettingsPage() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52
|
|
|
{ |
|
53
|
|
|
$this->actor()->dragAndDrop( |
|
|
|
|
|
|
54
|
|
|
MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55
|
|
|
MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Assumes you are already on the list table page that has the ui for editing the template. |
|
62
|
|
|
* @param string $message_type_slug |
|
63
|
|
|
* @param string $context [optional] if you want to click directly to the given context in the editor |
|
64
|
|
|
*/ |
|
65
|
|
|
public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66
|
|
|
{ |
|
67
|
|
|
$this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73
|
|
|
* filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74
|
|
|
* |
|
75
|
|
|
* @param int $expected_occurence_count |
|
76
|
|
|
* @param string $text_to_check_for |
|
77
|
|
|
* @param string $field |
|
78
|
|
|
* @param string $message_type_label |
|
79
|
|
|
* @param string $message_status |
|
80
|
|
|
* @param string $messenger |
|
81
|
|
|
* @param string $context |
|
82
|
|
|
*/ |
|
83
|
|
|
public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84
|
|
|
$expected_occurence_count, |
|
85
|
|
|
$text_to_check_for, |
|
86
|
|
|
$field, |
|
87
|
|
|
$message_type_label, |
|
88
|
|
|
$message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89
|
|
|
$messenger = 'Email', |
|
90
|
|
|
$context = 'Event Admin' |
|
91
|
|
|
) { |
|
92
|
|
|
$elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
|
|
|
|
|
93
|
|
|
$field, |
|
94
|
|
|
$message_type_label, |
|
95
|
|
|
$message_status, |
|
96
|
|
|
$messenger, |
|
97
|
|
|
$context, |
|
98
|
|
|
$text_to_check_for, |
|
99
|
|
|
0 |
|
100
|
|
|
)); |
|
101
|
|
|
$actual_count = count($elements); |
|
102
|
|
|
$this->actor()->assertEquals( |
|
|
|
|
|
|
103
|
|
|
$expected_occurence_count, |
|
104
|
|
|
$actual_count, |
|
105
|
|
|
sprintf( |
|
106
|
|
|
'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107
|
|
|
$expected_occurence_count, |
|
108
|
|
|
$text_to_check_for, |
|
109
|
|
|
$field, |
|
110
|
|
|
$actual_count |
|
111
|
|
|
) |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* This will create a custom message template for the given messenger and message type from the context of the |
|
118
|
|
|
* default (global) message template list table. |
|
119
|
|
|
* Also takes care of verifying the template was created. |
|
120
|
|
|
* @param string $message_type_label |
|
121
|
|
|
* @param string $messenger_label |
|
122
|
|
|
*/ |
|
123
|
|
|
public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124
|
|
|
{ |
|
125
|
|
|
$this->amOnDefaultMessageTemplateListTablePage(); |
|
126
|
|
|
$this->actor()->click( |
|
|
|
|
|
|
127
|
|
|
MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128
|
|
|
$message_type_label, |
|
129
|
|
|
$messenger_label |
|
130
|
|
|
) |
|
131
|
|
|
); |
|
132
|
|
|
$this->actor()->seeInField('#title', 'New Custom Template'); |
|
|
|
|
|
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* This switches the context of the current messages template to the given reference. |
|
138
|
|
|
* @param string $context_reference This should be the visible label for the option. |
|
139
|
|
|
*/ |
|
140
|
|
|
public function switchContextTo($context_reference) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
|
|
|
|
|
143
|
|
|
$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
|
|
|
|
|
144
|
|
|
$this->actor()->waitForText($context_reference, 10, 'h1'); |
|
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150
|
|
|
* toggling. |
|
151
|
|
|
* |
|
152
|
|
|
* @param string $context_string What context is being switched (used for the expected state text) |
|
153
|
|
|
* @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154
|
|
|
* (false) |
|
155
|
|
|
*/ |
|
156
|
|
|
public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157
|
|
|
{ |
|
158
|
|
|
$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
|
|
|
|
|
159
|
|
|
if ($expected_state_is_active) { |
|
160
|
|
|
$this->actor()->waitForText("The template for $context_string is currently active."); |
|
|
|
|
|
|
161
|
|
|
} else { |
|
162
|
|
|
$this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Triggers saving the message template. |
|
169
|
|
|
* @param bool $and_close Use to indicate to click the Save and Close button. |
|
170
|
|
|
*/ |
|
171
|
|
|
public function saveMessageTemplate($and_close = false) |
|
172
|
|
|
{ |
|
173
|
|
|
if ($and_close) { |
|
174
|
|
|
$this->actor()->click('Save and Close'); |
|
|
|
|
|
|
175
|
|
|
} else { |
|
176
|
|
|
$this->actor()->click('Save'); |
|
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
$this->actor()->waitForText('successfully updated'); |
|
|
|
|
|
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* This takes care of clicking the View Message icon for the given parameters. |
|
184
|
|
|
* Assumes you are already viewing the messages activity list table. |
|
185
|
|
|
* @param $message_type_label |
|
186
|
|
|
* @param $message_status |
|
187
|
|
|
* @param string $messenger |
|
188
|
|
|
* @param string $context |
|
189
|
|
|
* @param int $number_in_set |
|
190
|
|
|
*/ |
|
191
|
|
|
public function viewMessageInMessagesListTableFor( |
|
192
|
|
|
$message_type_label, |
|
193
|
|
|
$message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
194
|
|
|
$messenger = 'Email', |
|
195
|
|
|
$context = 'Event Admin', |
|
196
|
|
|
$number_in_set = 1 |
|
197
|
|
|
) { |
|
198
|
|
|
$this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
|
|
|
|
|
199
|
|
|
$message_type_label, |
|
200
|
|
|
$message_status, |
|
201
|
|
|
$messenger, |
|
202
|
|
|
$context, |
|
203
|
|
|
$number_in_set |
|
204
|
|
|
)); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* Takes care of deleting a message matching the given parameters via the message activity list table. |
|
210
|
|
|
* Assumes you are already viewing the messages activity list table. |
|
211
|
|
|
* @param $message_type_label |
|
212
|
|
|
* @param $message_status |
|
213
|
|
|
* @param string $messenger |
|
214
|
|
|
* @param string $context |
|
215
|
|
|
* @param int $number_in_set |
|
216
|
|
|
*/ |
|
217
|
|
|
public function deleteMessageInMessagesListTableFor( |
|
218
|
|
|
$message_type_label, |
|
219
|
|
|
$message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
220
|
|
|
$messenger = 'Email', |
|
221
|
|
|
$context = 'Event Admin', |
|
222
|
|
|
$number_in_set = 1 |
|
223
|
|
|
) { |
|
224
|
|
|
$delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
225
|
|
|
$message_type_label, |
|
226
|
|
|
$message_status, |
|
227
|
|
|
$messenger, |
|
228
|
|
|
$context, |
|
229
|
|
|
$number_in_set |
|
230
|
|
|
); |
|
231
|
|
|
$this->actor()->moveMouseOver( |
|
|
|
|
|
|
232
|
|
|
MessagesPage::messagesActivityListTableCellSelectorFor( |
|
233
|
|
|
'to', |
|
234
|
|
|
$message_type_label, |
|
235
|
|
|
$message_status, |
|
236
|
|
|
$messenger, |
|
237
|
|
|
$context, |
|
238
|
|
|
'', |
|
239
|
|
|
$number_in_set |
|
240
|
|
|
), |
|
241
|
|
|
5, |
|
242
|
|
|
5 |
|
243
|
|
|
); |
|
244
|
|
|
$this->actor()->waitForElementVisible( |
|
|
|
|
|
|
245
|
|
|
$delete_action_selector |
|
246
|
|
|
); |
|
247
|
|
|
$this->actor()->click( |
|
|
|
|
|
|
248
|
|
|
$delete_action_selector |
|
249
|
|
|
); |
|
250
|
|
|
$this->actor()->waitForText('successfully deleted'); |
|
|
|
|
|
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
256
|
|
|
* list table, this will take care of validating the given text is in that window. |
|
257
|
|
|
* @param string $text_to_view |
|
258
|
|
|
*/ |
|
259
|
|
|
public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
260
|
|
|
{ |
|
261
|
|
|
$this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
|
|
|
|
|
262
|
|
|
$this->actor()->switchToIframe('message-view-window'); |
|
|
|
|
|
|
263
|
|
|
$should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
|
|
|
|
|
264
|
|
|
$this->actor()->switchToIframe(); |
|
|
|
|
|
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* This returns the value for the link at the given selector in the message modal. |
|
270
|
|
|
* @param string $selector (any selector string accepted by WebDriver) |
|
271
|
|
|
*/ |
|
272
|
|
|
public function observeLinkAtSelectorInMessageModal($selector) |
|
273
|
|
|
{ |
|
274
|
|
|
$this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
|
|
|
|
|
275
|
|
|
$this->actor()->switchToIframe('message-view-window'); |
|
|
|
|
|
|
276
|
|
|
$link = $this->actor()->observeLinkUrlAt($selector); |
|
|
|
|
|
|
277
|
|
|
$this->actor()->switchToIframe(); |
|
|
|
|
|
|
278
|
|
|
return $link; |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
284
|
|
|
* list table, this will take care of validating the given text is NOT that window. |
|
285
|
|
|
* @param string $text_to_view |
|
286
|
|
|
*/ |
|
287
|
|
|
public function dontSeeTextInViewMessageModal($text_to_view) |
|
288
|
|
|
{ |
|
289
|
|
|
$this->seeTextInViewMessageModal($text_to_view, true); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
|
|
293
|
|
|
public function dismissMessageModal() |
|
294
|
|
|
{ |
|
295
|
|
|
$this->actor()->click('#espresso-admin-page-overlay-dv'); |
|
|
|
|
|
|
296
|
|
|
//this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
297
|
|
|
$this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
|
|
|
|
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.