-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathWPGutenberg.php
More file actions
736 lines (642 loc) · 25.1 KB
/
WPGutenberg.php
File metadata and controls
736 lines (642 loc) · 25.1 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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
<?php
namespace Tests\Support\Helper;
/**
* Helper methods and actions related to WordPress' Gutenberg / Block editor,
* which are then available using $I->{yourFunctionName}.
*
* @since 1.9.6
*/
class WPGutenberg extends \Codeception\Module
{
/**
* Helper method to determine if the Gutenberg IFrame editor is enabled
* in tests by inspecting the WORDPRESS_V3_BLOCK_EDITOR_ENABLED environment variable.
*
* @since 3.1.4
*
* @return bool
*/
public function isGutenbergIFrameEditorEnabled()
{
return filter_var($_ENV['WORDPRESS_V3_BLOCK_EDITOR_ENABLED'], FILTER_VALIDATE_BOOLEAN);
}
/**
* Helper method to switch to the Gutenberg editor Iframe
* when all blocks use the Block API v3:
* https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/
*
* @since 2.7.7
*
* @param EndToEndTester $I EndToEnd Tester.
*/
public function switchToGutenbergIFrameEditor($I)
{
// Don't switch if the iframe doesn't exist e.g. Divi is active, which prevents
// the iframe block editor in WordPress 7.0+ from being used.
if ( ! $I->tryToSeeElement('iframe[name="editor-canvas"]')) {
return;
}
$I->switchToIFrame('iframe[name="editor-canvas"]');
}
/**
* Add a Page, Post or Custom Post Type using Gutenberg in WordPress.
*
* @since 1.9.7.5
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $postType Post Type.
* @param string $title Post Title.
*/
public function addGutenbergPage($I, $postType = 'page', $title = 'Gutenberg Title')
{
// Navigate to Post Type (e.g. Pages / Posts) > Add New.
$I->amOnAdminPage('post-new.php?post_type=' . $postType);
$I->waitForElementVisible('body.post-new-php');
// Switch to the Gutenberg IFrame.
if ($this->isGutenbergIFrameEditorEnabled()) {
$I->switchToGutenbergIFrameEditor($I);
}
// Define the Title.
$I->waitForElementVisible('.editor-post-title__input');
$I->fillField('.editor-post-title__input', $title);
// Switch back to main window.
if ($this->isGutenbergIFrameEditorEnabled()) {
$I->switchToIFrame();
}
}
/**
* Clicks the Add Block Button, supporting both old and new selector names depending on the WordPress version.
*
* @since 3.1.4
*
* @param EndToEndTester $I EndToEnd Tester.
*/
public function clickAddGutenbergBlockButton($I)
{
if ($I->grabMultiple('button.editor-document-tools__inserter-toggle')) {
$I->click('button.editor-document-tools__inserter-toggle');
} elseif ($I->grabMultiple('button.edit-post-header-toolbar__inserter-toggle')) {
$I->click('button.edit-post-header-toolbar__inserter-toggle');
} else {
$I->fail('Add Block button not found for either supported selector.');
}
}
/**
* Add the given block when adding or editing a Page, Post or Custom Post Type
* in Gutenberg.
*
* If a block configuration is specified, applies it to the newly added block.
*
* @since 1.9.7.4
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $blockName Block Name (e.g. 'Kit Form').
* @param string $blockProgrammaticName Programmatic Block Name (e.g. 'convertkit-form').
* @param bool|array $blockConfiguration Block Configuration (field => value key/value array).
*/
public function addGutenbergBlock($I, $blockName, $blockProgrammaticName, $blockConfiguration = false)
{
// Click Add Block Button.
$this->clickAddGutenbergBlockButton($I);
// When the Blocks sidebar appears, search for the block.
$I->waitForElementVisible('.interface-interface-skeleton__secondary-sidebar[aria-label="Block Library"]');
$I->seeElementInDOM('.interface-interface-skeleton__secondary-sidebar[aria-label="Block Library"]');
$I->fillField('.block-editor-inserter__menu input[type=search]', $blockName);
// Let WordPress load any matching block patterns, which reloads the DOM elements.
// If we don't do this, we get stale reference errors when trying to click a block to insert.
$I->wait(2);
// Build potential programmatic block names.
$potentialNames = [ $blockProgrammaticName ];
if (strpos($blockProgrammaticName, '/') !== false) {
// Also add last segment after slash, for compatibility with older WordPress versions.
$parts = explode('/', $blockProgrammaticName);
if (count($parts) === 2) {
$potentialNames[] = $parts[1];
}
}
// Confirm the block is available.
foreach ($potentialNames as $name) {
// Check for both XPath (to cover slashes) and regular selector (no slash).
if (strpos($name, '/') !== false) {
$xpath = '//button[contains(@class, "editor-block-list-item-' . $name . '") and contains(@class,"block-editor-block-types-list__item") and contains(@class,"components-button")]';
try {
$I->waitForElementVisible([ 'xpath' => $xpath ]);
$I->seeElementInDOM([ 'xpath' => $xpath ]);
$I->click([ 'xpath' => $xpath ]);
break;
} catch (\Exception $e) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
// Not found, try others.
}
} else {
$selector = '.block-editor-inserter__panel-content button.editor-block-list-item-' . $name;
try {
$I->waitForElementVisible($selector);
$I->seeElementInDOM($selector);
$I->click($selector);
break;
} catch (\Exception $e) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
// Not found, try others.
}
}
}
// Close block inserter.
$this->clickAddGutenbergBlockButton($I);
// If a Block configuration is specified, apply it to the Block now.
if ($blockConfiguration) {
$I->waitForElementVisible('.interface-interface-skeleton__sidebar[aria-label="Editor settings"]');
foreach ($blockConfiguration as $field => $attributes) {
// Field ID will be block's programmatic name with underscores instead of hyphens,
// followed by the attribute name.
$fieldID = '#' . str_replace('-', '_', $blockProgrammaticName) . '_' . $field;
// If the attribute has a third value, we may need to open the panel
// to see the fields.
if (count($attributes) > 2) {
$I->click($attributes[2], '.interface-interface-skeleton__sidebar[aria-label="Editor settings"]');
}
// Depending on the field's type, define its value.
switch ($attributes[0]) {
case 'select':
$I->selectOption($fieldID, $attributes[1]);
break;
case 'toggle':
// The block editor doesn't use the field ID, so we need to find the field by the label.
$field = "//label[normalize-space(text())='" . $field . "']/preceding-sibling::span/input";
// Determine if the toggle has checked the checkbox.
$isChecked = $I->grabAttributeFrom($field, 'checked');
// If the attribute is true, and the checkbox is not checked, click the toggle to check it.
if ( $attributes[1] && ! $isChecked ) {
$I->click($field);
}
// If the attribute is false, and the checkbox is checked, click the toggle to uncheck it.
if ( ! $attributes[1] && $isChecked ) {
$I->click($field);
}
break;
default:
$I->fillField($fieldID, $attributes[1]);
break;
}
}
}
// Ensure that the block inserter is fully closed before continuing;
// this ensures multiple calls to addGutenbergBlock work.
$I->waitForElementNotVisible('.interface-interface-skeleton__secondary-sidebar[aria-label="Block Library"]');
}
/**
* Adds a paragraph block when adding or editing a Page, Post or Custom Post Type
* in Gutenberg.
*
* @since 2.0.0
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $text Paragraph Text.
*/
public function addGutenbergParagraphBlock($I, $text)
{
// Add paragraph block.
$I->addGutenbergBlock($I, 'Paragraph', 'paragraph/paragraph');
// Switch to the Gutenberg IFrame.
if ($this->isGutenbergIFrameEditorEnabled()) {
$I->switchToGutenbergIFrameEditor($I);
}
// Click the editor area and enter the text in the paragraph.
$I->click('.wp-block-post-content');
$I->fillField('.wp-block-post-content p[data-empty="true"]', $text);
// Switch back to main window.
if ($this->isGutenbergIFrameEditorEnabled()) {
$I->switchToIFrame();
}
}
/**
* Adds a link to the given Page, Post or Custom Post Type Name in the last paragraph in the Gutenberg
* editor.
*
* @since 2.0.0
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $name Page, Post or Custom Post Type Title/Name to link to.
*/
public function addGutenbergLinkToParagraph($I, $name)
{
// Focus away from paragraph and then back to the paragraph, so that the block toolbar displays.
$I->click('div.edit-post-visual-editor__post-title-wrapper h1');
$I->click('.wp-block-post-content p');
$I->waitForElementVisible('.wp-block-post-content p.is-selected');
// Insert link via block toolbar.
$this->insertGutenbergLink($I, $name);
// Confirm that the Product text exists in the paragraph.
$I->see($name, '.wp-block-post-content p.is-selected');
}
/**
* Adds a link to the given Page, Post or Custom Post Type Name in the selected Button block
* in the Gutenberg editor.
*
* @since 2.0.0
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $name Page, Post or Custom Post Type Title/Name to link to.
*/
public function addGutenbergLinkToButton($I, $name)
{
// Enter text.
$I->fillField('.wp-block-post-content .wp-block-button .block-editor-rich-text__editable', $name);
// Focus away from button and then back to the button, so that the block toolbar displays.
$I->click('div.edit-post-visual-editor__post-title-wrapper h1');
$I->click('.wp-block-post-content .wp-block-button');
$I->waitForElementVisible('.wp-block-post-content div.is-selected');
// Insert link via block toolbar.
$this->insertGutenbergLink($I, $name);
// Confirm that the Product text exists in the button.
$I->see($name, '.wp-block-post-content .wp-block-button');
}
/**
* Adds the given text as the excerpt in the Gutenberg editor.
*
* @since 2.3.7
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $excerpt Post excerpt.
*/
public function addGutenbergExcerpt($I, $excerpt)
{
// Click the Post tab.
$I->click('button[data-tab-id="edit-post/document"]');
// Click the 'Add an excerpt' link.
$I->click('div.editor-post-excerpt__dropdown button');
// Insert the excerpt into the field.
$I->waitForElementVisible('.editor-post-excerpt');
$I->fillField('.editor-post-excerpt textarea', $excerpt);
}
/**
* Helper method to insert a link into the selected element, by:
* - clicking the link button in the selected block's toolbar,
* - searching for the Page, Post or Custom Post Type,
* - clicking the matched result to insert the link and text.
*
* The block must be selected in Gutenberg prior to calling this function.
*
* @since 2.0.0
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $name Page, Post or Custom Post Type Title/Name to link to.
*/
private function insertGutenbergLink($I, $name)
{
// Click link button in block toolbar.
$I->waitForElementVisible('.block-editor-block-toolbar button[aria-label="Link"]');
$I->click('.block-editor-block-toolbar button[aria-label="Link"]');
// Enter Product name in search field.
$I->waitForElementVisible('.block-editor-link-control__search-input-wrapper input.block-editor-url-input__input');
$I->fillField('.block-editor-link-control__search-input-wrapper input.block-editor-url-input__input', $name);
$I->waitForElementVisible('.block-editor-link-control__search-results-wrapper');
$I->see($name);
// Click the Product name to create a link to it.
$I->click($name, '.block-editor-link-control__search-results');
}
/**
* Helper method to select an existing block previously added to the Gutenberg editor.
*
* @since 3.1.4
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $blockProgrammaticName Programmatic Block Name (e.g. 'convertkit/form-builder-field-name').
*/
public function selectGutenbergBlockInEditor($I, $blockProgrammaticName)
{
if ($this->isGutenbergIFrameEditorEnabled()) {
$I->switchToGutenbergIFrameEditor($I);
}
$I->click('div[data-type="' . $blockProgrammaticName . '"]');
if ($this->isGutenbergIFrameEditorEnabled()) {
$I->switchToIFrame();
}
}
/**
* Asserts that the given block is available in the Gutenberg block library.
*
* Supports blocks whose programmatic names may be either "block/block" or just "block",
* such as for Paragraph ("paragraph/paragraph" or "paragraph") and Heading ("heading/heading" or "heading")
* for compatibility with different WordPress versions.
*
* @since 3.0.0
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $blockName Block Name (e.g. 'Kit Form').
* @param string $blockProgrammaticName Programmatic Block Name (e.g. 'convertkit-form' or 'paragraph/paragraph').
*/
public function seeGutenbergBlockAvailable($I, $blockName, $blockProgrammaticName)
{
// Click Add Block Button.
$this->clickAddGutenbergBlockButton($I);
// When the Blocks sidebar appears, search for the block.
$I->waitForElementVisible('.interface-interface-skeleton__secondary-sidebar[aria-label="Block Library"]');
$I->seeElementInDOM('.interface-interface-skeleton__secondary-sidebar[aria-label="Block Library"]');
$I->fillField('.block-editor-inserter__menu input[type=search]', $blockName);
// Let WordPress load any matching block patterns, which reloads the DOM elements.
// If we don't do this, we get stale reference errors when trying to click a block to insert.
$I->wait(2);
// Build potential programmatic block names.
$potentialNames = [ $blockProgrammaticName ];
if (strpos($blockProgrammaticName, '/') !== false) {
// Also add last segment after slash, for compatibility with older WordPress versions.
$parts = explode('/', $blockProgrammaticName);
if (count($parts) === 2) {
$potentialNames[] = $parts[1];
}
}
// Confirm the block is available.
$found = false;
foreach ($potentialNames as $name) {
// Check for both XPath (to cover slashes) and regular selector (no slash).
if (strpos($name, '/') !== false) {
$xpath = '//button[contains(@class, "editor-block-list-item-' . $name . '") and contains(@class,"block-editor-block-types-list__item") and contains(@class,"components-button")]';
try {
$I->waitForElementVisible([ 'xpath' => $xpath ], 2);
$found = true;
break;
} catch (\Exception $e) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
// Not found, try others.
}
} else {
$selector = '.block-editor-inserter__panel-content button.editor-block-list-item-' . $name;
try {
$I->waitForElementVisible($selector, 2);
$found = true;
break;
} catch (\Exception $e) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
// Not found, try others.
}
}
}
// Fail if we don't find any.
if ( ! $found) {
$I->fail("Block '{$blockName}' not found.");
}
// Clear the search field.
$I->click('button[aria-label="Reset search"]');
// Close block inserter.
$this->clickAddGutenbergBlockButton($I);
}
/**
* Asserts that the given block is not available in the Gutenberg block library.
*
* @since 3.0.0
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $blockName Block Name (e.g. 'Kit Form').
* @param string $blockProgrammaticName Programmatic Block Name (e.g. 'convertkit-form').
*/
public function dontSeeGutenbergBlockAvailable($I, $blockName, $blockProgrammaticName)
{
// Click Add Block Button.
$this->clickAddGutenbergBlockButton($I);
// When the Blocks sidebar appears, search for the block.
$I->waitForElementVisible('.interface-interface-skeleton__secondary-sidebar[aria-label="Block Library"]');
$I->seeElementInDOM('.interface-interface-skeleton__secondary-sidebar[aria-label="Block Library"]');
$I->fillField('.block-editor-inserter__menu input[type=search]', $blockName);
// Let WordPress load any matching block patterns, which reloads the DOM elements.
// If we don't do this, we get stale reference errors when trying to click a block to insert.
$I->wait(2);
// Confirm the 'No results' message is displayed.
$I->dontSeeElementInDOM('.block-editor-inserter__panel-content button.editor-block-list-item-' . $blockProgrammaticName);
// Clear the search field.
$I->click('button[aria-label="Reset search"]');
// Close block inserter.
$this->clickAddGutenbergBlockButton($I);
}
/**
* Applies the given block formatter to the currently selected block.
*
* @since 2.2.0
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $formatterName Formatter Name (e.g. 'Kit Form Trigger').
* @param string $formatterProgrammaticName Programmatic Formatter Name (e.g. 'convertkit-form-link').
* @param bool|array $formatterConfiguration Block formatter's configuration (field => value key/value array).
*/
public function applyGutenbergFormatter($I, $formatterName, $formatterProgrammaticName, $formatterConfiguration = false)
{
// Click More button in block toolbar.
$I->waitForElementVisible('.block-editor-block-toolbar button[aria-label="More"]');
$I->click('.block-editor-block-toolbar button[aria-label="More"]');
// Click Block Formatter button, and wait for the popover to be fully visible.
$I->waitForElementVisible('.components-popover.is-positioned');
$I->waitForElementVisible('.components-dropdown-menu__popover');
$I->wait(1);
$I->click($formatterName, '.components-dropdown-menu__popover');
// Apply formatter configuration.
if ( $formatterConfiguration ) {
// Confirm the popover displays.
$I->waitForElementVisible('.components-popover');
foreach ($formatterConfiguration as $field => $attributes) {
// Field ID will be formatter's programmatic name, followed by the attribute name.
$fieldID = '#' . $formatterProgrammaticName . '-' . $field;
// Wait for the field to be visible within the popover.
// This prevents tests from trying to fill out the field before it is positioned.
$I->waitForElementVisible('.components-popover ' . $fieldID);
// Depending on the field's type, define its value.
switch ($attributes[0]) {
case 'select':
$I->selectOption($fieldID, $attributes[1]);
break;
case 'toggle':
$I->click($fieldID);
break;
default:
$I->fillField($fieldID, $attributes[1]);
break;
}
}
}
}
/**
* Asserts that the given block formatter is not registered.
*
* @since 2.2.2
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $formatterName Formatter Name (e.g. 'Kit Form Trigger').
*/
public function dontSeeGutenbergFormatter($I, $formatterName)
{
// Click More button in block toolbar.
$I->waitForElementVisible('.block-editor-block-toolbar button[aria-label="More"]');
$I->click('.block-editor-block-toolbar button[aria-label="More"]');
// Click Block Formatter button.
$I->waitForElementVisible('.components-dropdown-menu__popover');
// Confirm the Block Formatter is not registered.
$I->dontSee($formatterName, '.components-dropdown-menu__popover');
}
/**
* Check that the given block did not output any errors when rendered in the
* Gutenberg editor.
*
* @since 1.9.7.4
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $blockName Block Name (e.g. 'Kit Form').
*/
public function checkGutenbergBlockHasNoErrors($I, $blockName)
{
// Check that the "This block has encountered an error and cannot be previewed." element doesn't exist.
$I->dontSeeElementInDOM('.block-editor-block-list__layout div[data-title="' . $blockName . '"] .block-editor-block-list__block-crash-warning');
}
/**
* Publish a Page, Post or Custom Post Type initiated by the addGutenbergPage() function,
* loading it on the frontend web site.
*
* @since 1.9.7.5
*
* @param EndToEndTester $I EndToEnd Tester.
* @return string $url Page / Post URL.
*/
public function publishAndViewGutenbergPage($I)
{
// Publish Gutenberg Page.
$url = $I->publishGutenbergPage($I);
// Load the Page on the frontend site.
$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);
// Return URL.
return $url;
}
/**
* Publish a Page, Post or Custom Post Type initiated by the addGutenbergPage() function,
* returning the published URL.
*
* @since 2.1.0
*
* @param EndToEndTester $I EndToEnd Tester.
*/
public function publishGutenbergPage($I)
{
// Click the Publish button.
$I->click('.editor-post-publish-button__button');
// Click the Publish button on the pre-publish Panel.
return $I->clickPublishOnPrePublishChecksForGutenbergPage($I);
}
/**
* Clicks the Publish button the pre-publish checks sidebar, confirming the Page, Post or Custom Post Type
* published and returning its URL.
*
* @since 2.4.0
*
* @param EndToEndTester $I EndToEnd Tester.
*/
public function clickPublishOnPrePublishChecksForGutenbergPage($I)
{
// Click publish on the pre-publish panel.
$I->waitForElementVisible('.editor-post-publish-panel__header-publish-button');
$I->performOn(
'.editor-post-publish-panel__header-publish-button',
function($I) {
$I->click('.editor-post-publish-panel__header-publish-button button');
},
15
);
// Wait for the snackbar notification that the post has been published.
$I->waitForElementVisible('div.components-snackbar__content a.components-snackbar__action', 30);
// Return the URL from the 'View Post' button in the snackbar.
return $I->grabAttributeFrom('div.components-snackbar__content a.components-snackbar__action', 'href');
}
/**
* Add a Page, Post or Custom Post Type directly to the WordPress database,
* with dummy content used for testing.
*
* @since 2.6.2
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $postType Post Type.
* @param string $title Post Title.
* @param string $formID Meta Box `Form` value (-1: Default).
*/
public function addGutenbergPageToDatabase($I, $postType = 'page', $title = 'Gutenberg Title', $formID = '-1')
{
return $I->havePostInDatabase(
[
'post_title' => $title,
'post_type' => $postType,
'post_status' => 'publish',
'meta_input' => [
'_wp_convertkit_post_meta' => [
'form' => $formID,
'landing_page' => '',
'tag' => '',
],
],
'post_content' => '<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:paragraph -->
<p>Item #1</p>
<!-- /wp:paragraph -->
<!-- wp:heading -->
<h2 class="wp-block-heading">Item #1</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Item #2: Adhaésionés altéram improbis mi pariendarum sit stulti triarium</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:image {"id":4237,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://placehold.co/600x400" alt="Image #1" /></figure>
<!-- /wp:image --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- wp:heading -->
<h2 class="wp-block-heading">Item #2</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Item #3</p>
<!-- /wp:paragraph -->
<!-- wp:image {"id":4240,"aspectRatio":"1","scale":"cover","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://placehold.co/600x400" alt="Image #2" /></figure>
<!-- /wp:image -->
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading">Item #1</h3>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Item #4</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading">Item #1</h4>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Item #5</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- wp:heading {"level":5} -->
<h5 class="wp-block-heading">Item #1</h5>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Item #6</p>
<!-- /wp:paragraph -->
<!-- wp:heading {"level":6} -->
<h6 class="wp-block-heading">Item #1</h6>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Item #7</p>
<!-- /wp:paragraph -->
<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading">Item #2</h3>
<!-- /wp:heading -->
<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading">Item #2</h4>
<!-- /wp:heading -->
<!-- wp:heading {"level":5} -->
<h5 class="wp-block-heading">Item #2</h5>
<!-- /wp:heading -->
<!-- wp:heading {"level":6} -->
<h6 class="wp-block-heading">Item #2</h6>
<!-- /wp:heading -->',
]
);
}
}