-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDiviBuilder.php
More file actions
292 lines (253 loc) · 9.33 KB
/
DiviBuilder.php
File metadata and controls
292 lines (253 loc) · 9.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
namespace Tests\Support\Helper;
/**
* Helper methods and actions related to WordPress Caching Plugins,
* which are then available using $I->{yourFunctionName}.
*
* @since 2.5.7
*/
class DiviBuilder extends \Codeception\Module
{
/**
* Helper method to create a Divi Page in the WordPress Administration interface.
*
* @since 2.5.7
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $title Page Title.
*/
public function createDiviPageInBackendEditor($I, $title)
{
// Activate Classic Editor Plugin.
$I->activateThirdPartyPlugin($I, 'classic-editor');
// Add a Page using the Classic Editor.
$I->addClassicEditorPage($I, 'page', $title);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configureMetaboxSettings(
$I,
'wp-convertkit-meta-box',
[
'form' => [ 'select2', 'None' ],
]
);
// Scroll to Publish meta box, so its buttons are not hidden.
$I->scrollTo('#submitdiv');
// Wait for the Publish button to change its state from disabled (WordPress disables it for a moment when auto-saving).
$I->waitForElementVisible('input#publish:not(:disabled)');
// Click the Publish button twice, because Divi is flaky at best.
$I->click('input#publish');
$I->wait(2);
$I->click('input#publish');
// Wait for notice to display.
$I->waitForElementNotVisible('.et-fb-preloader');
$I->waitForElementVisible('.notice-success');
$I->wait(2);
// Remove transient set by Divi that would show the welcome modal.
$I->dontHaveTransientInDatabase('et_builder_show_bfb_welcome_modal');
// Click Divi Builder button.
$I->click('#et_pb_toggle_builder');
// Dismiss modal if displayed.
// May have been dismissed by other tests in the suite e.g. DiviFormCest.
try {
$I->waitForElementVisible('.et-core-modal-action-dont-restore');
$I->click('.et-core-modal-action-dont-restore');
} catch ( \Facebook\WebDriver\Exception\NoSuchElementException $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
// No modal exists, so nothing to dismiss.
}
// Click Build from scratch button.
$I->waitForElementVisible('.et-fb-page-creation-card-build_from_scratch');
$I->click('Start Building', '.et-fb-page-creation-card-build_from_scratch');
}
/**
* Helper method to create a Divi Page in the Frontend interface.
*
* @since 2.5.7
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $title Page Title.
* @param bool $configureMetaBox Configure Plugin's Meta Box to set Form = None (set to false if running a test with no credentials).
* @return string Page URL.
*/
public function createDiviPageInFrontendEditor($I, $title, $configureMetaBox = true)
{
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: $title
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
if ($configureMetaBox) {
$I->configureMetaboxSettings(
$I,
'wp-convertkit-meta-box',
[
'form' => [ 'select2', 'None' ],
]
);
}
// Publish Page.
$url = $I->publishGutenbergPage($I);
// Load page.
$I->amOnUrl($url);
// Enable the Divi Builder.
$I->waitForElementVisible('#wp-admin-bar-et-use-visual-builder');
$I->click('#wp-admin-bar-et-use-visual-builder a');
// Dismiss modal if displayed.
// May have been dismissed by other tests in the suite e.g. DiviFormCest.
try {
$I->waitForElementVisible('.et-core-modal-action-dont-restore');
$I->click('.et-core-modal-action-dont-restore');
} catch ( \Facebook\WebDriver\Exception\NoSuchElementException $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
// No modal exists, so nothing to dismiss.
}
// Click Build from scratch button.
$I->waitForElementVisible('.et-fb-page-creation-card-build_from_scratch');
$I->click('Start Building', '.et-fb-page-creation-card-build_from_scratch');
return $url;
}
/**
* Helper method to insert a given Divi module in to a page edited with either the
* backend or frontend editor, with the supplied configuration.
*
* @since 2.5.7
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $name Module Name.
* @param string $programmaticName Programmatic Module Name.
* @param bool|string $fieldName Field Name.
* @param bool|string $fieldValue Field Value.
*/
public function insertDiviRowWithModule($I, $name, $programmaticName, $fieldName = false, $fieldValue = false)
{
// Insert row.
$I->waitForElementVisible('li[data-layout="4_4"]');
$I->click('li[data-layout="4_4"]');
// Search for module.
$I->waitForElementVisible('input[name="filterByTitle"]');
$I->fillField('filterByTitle', $name);
// Insert module.
$I->waitForElementVisible('li.' . $programmaticName);
$I->wait(2);
$I->click('li.' . $programmaticName);
// Wait for module to load.
$I->waitForElementVisible('div.et-fb-modal');
// Select field value.
if ($fieldName && $fieldValue) {
$I->waitForElementVisible('#et-fb-' . $fieldName);
$I->click('#et-fb-' . $fieldName);
$I->click('li[data-value="' . $fieldValue . '"]', '#et-fb-' . $fieldName);
}
}
/**
* Helper method to save the Divi module added using insertDiviRowWithModule() in the backend editor, saving
* the WordPress Page and viewing it on the frontend site.
*
* @since 2.5.7
*
* @param EndToEndTester $I EndToEnd Tester.
*/
public function saveDiviModuleInBackendEditorAndViewPage($I)
{
// Save module.
$I->waitForElementVisible('button[data-tip="Save Changes"]');
$I->click('button[data-tip="Save Changes"]');
// Update page.
$I->click('Update');
// Wait for the save to complete.
$I->waitForElementVisible('#message');
$I->see('Page updated.', '#message');
$I->waitForElementNotVisible('.et-fb-preloader');
// Load the Page on the frontend site.
$I->click('.notice-success a');
$I->waitForElementVisible('body');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
}
/**
* Helper method to save the Divi module added using insertDiviRowWithModule() in the frontend editor, saving
* the WordPress Page and viewing it on the frontend site.
*
* @since 2.5.7
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $url Page URL.
*/
public function saveDiviModuleInFrontendEditorAndViewPage($I, $url)
{
// Save module.
$I->click('button[data-tip="Save Changes"]');
// Save page.
$I->click('.et-fb-page-settings-bar__toggle-button');
$I->waitForElementVisible('button.et-fb-button--publish');
$I->click('button.et-fb-button--publish');
$I->wait(3);
// Load page without Divi frontend builder.
$I->amOnUrl($url);
// Wait for frontend web site to load.
$I->waitForElementVisible('body');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
}
/**
* Helper method to see specific text is displayed in a Divi module.
*
* @since 3.0.8
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $title Title of the module.
* @param string $text Text to confirm is displayed.
*/
public function seeTextInDiviModule($I, $title, $text)
{
// Switch to Divi Builder iframe.
$I->switchToIFrame('iframe[id="et-fb-app-frame"]');
// Confirm the on screen message displays.
$I->waitForElementVisible('div.convertkit-divi-module');
$I->see($title, 'div.convertkit-divi-module');
$I->see($text, 'div.convertkit-divi-module');
// Switch back to main window.
$I->switchToIFrame();
}
/**
* Create a Page in the database comprising of Divi Page Builder data
* containing a Kit module.
*
* @since 2.5.7
*
* @param EndToEndTester $I Tester.
* @param string $title Page Title.
* @param string $programmaticName Programmatic Module Name.
* @param string $fieldName Field Name.
* @param string $fieldValue Field Value.
* @return int Page ID
*/
public function createPageWithDiviModuleProgrammatically($I, $title, $programmaticName, $fieldName, $fieldValue)
{
return $I->havePostInDatabase(
[
'post_title' => $title,
'post_type' => 'page',
'post_status' => 'publish',
'post_content' => '[et_pb_section fb_built="1" _builder_version="4.27.0" _module_preset="default" global_colors_info="{}"]
[et_pb_row _builder_version="4.27.0" _module_preset="default"]
[et_pb_column _builder_version="4.27.0" _module_preset="default" type="4_4"]
[' . $programmaticName . ' _builder_version="4.27.0" _module_preset="default" ' . $fieldName . '="' . $fieldValue . '" hover_enabled="0" sticky_enabled="0"][/' . $programmaticName . ']
[/et_pb_column]
[/et_pb_row]
[/et_pb_section]',
'meta_input' => [
// Enable Divi Builder.
'_et_pb_use_builder' => 'on',
'_et_pb_built_for_post_type' => 'page',
// Configure Kit Plugin to not display a default Form,
// as we are testing for the Form in Elementor.
'_wp_convertkit_post_meta' => [
'form' => '0',
'landing_page' => '',
'tag' => '',
],
],
]
);
}
}