-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathWPBulkEdit.php
More file actions
97 lines (84 loc) · 2.73 KB
/
WPBulkEdit.php
File metadata and controls
97 lines (84 loc) · 2.73 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
<?php
namespace Tests\Support\Helper;
/**
* Helper methods and actions related to WordPress' Bulk Edit functionality,
* which are then available using $I->{yourFunctionName}.
*
* @since 1.9.6
*/
class WPBulkEdit extends \Codeception\Module
{
/**
* Bulk Edits the given Post IDs, changing form field values and saving.
*
* @since 1.9.8.0
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $postType Programmatic Post Type.
* @param array $postIDs Post IDs.
* @param array $configuration Configuration (field => value key/value array).
*/
public function bulkEdit($I, $postType, $postIDs, $configuration)
{
// Open Bulk Edit form for the Posts.
$I->openBulkEdit($I, $postType, $postIDs);
// Apply configuration.
foreach ($configuration as $field => $attributes) {
// Field ID will be prefixed with wp-convertkit-bulk-edit-.
$fieldID = 'wp-convertkit-bulk-edit-' . $field;
// Check that the field exists.
$I->seeElementInDOM('#convertkit-bulk-edit #' . $fieldID);
// Depending on the field's type, define its value.
switch ($attributes[0]) {
case 'select':
$I->selectOption('#convertkit-bulk-edit #' . $fieldID, $attributes[1]);
break;
default:
$I->fillField('#convertkit-bulk-edit #' . $fieldID, $attributes[1]);
break;
}
}
// Wait, because some bulk edit screens (WooCommerce) hijack the UI and scroll back to the top of the page.
$I->wait(2);
// Scroll so that the Update button is in the viewport.
$I->scrollTo('#bulk-edit .inline-edit-wrapper:last-child');
// Click Update.
$I->click('#bulk_edit');
// Wait for the confirmation message to display.
$I->waitForElementVisible('div.updated');
$I->wait(2);
// Confirm that Bulk Editing saved with no errors.
switch ($postType) {
case 'post':
case 'page':
case 'product':
$I->see(count($postIDs) . ' ' . $postType . 's updated.');
break;
default:
$I->see(count($postIDs) . ' posts updated.');
break;
}
}
/**
* Opens the Bulk Edit form for the given Post ID.
*
* @since 1.9.8.1
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $postType Programmatic Post Type.
* @param array $postIDs Post IDs.
*/
public function openBulkEdit($I, $postType, $postIDs)
{
// Navigate to Post Type's WP_List_Table.
$I->amOnAdminPage('edit.php?post_type=' . $postType);
// Check boxes for Post IDs.
foreach ($postIDs as $postID) {
$I->checkOption('#cb-select-' . $postID);
}
// Select Edit from the Bulk actions dropdown.
$I->selectOption('#bulk-action-selector-top', 'Bulk edit');
// Click Apply button.
$I->click('#doaction');
}
}