-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThirdPartyPlugin.php
More file actions
135 lines (116 loc) · 3.92 KB
/
ThirdPartyPlugin.php
File metadata and controls
135 lines (116 loc) · 3.92 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
<?php
namespace Tests\Support\Helper;
/**
* Helper methods and actions related to third party Plugins,
* which are then available using $I->{yourFunctionName}.
*
* @since 1.9.6
*/
class ThirdPartyPlugin extends \Codeception\Module
{
/**
* Helper method to activate a third party Plugin, checking
* it activated and no errors were output.
*
* @since 1.4.0
*
* @param EndToEndTester $I EndToEndTester.
* @param string $name Plugin Slug.
*/
public function activateThirdPartyPlugin($I, $name)
{
// Login as the Administrator, if we're not already logged in.
if ( ! $this->amLoggedInAsAdmin($I) ) {
$this->doLoginAsAdmin($I);
}
// Go to the Plugins screen in the WordPress Administration interface.
$I->amOnPluginsPage();
// Wait for the Plugins page to load.
$I->waitForElementVisible('body.plugins-php');
// Activate the Plugin.
$I->checkOption('//*[@data-slug="' . $name . '"]/th/input');
$I->selectOption('action', 'activate-selected');
$I->click('#doaction');
// Wait for the Plugins page to load with the Plugin activated, to confirm it activated.
$I->waitForElementVisible('table.plugins tr[data-slug=' . $name . '].active');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
}
/**
* Helper method to activate a third party Plugin, checking
* it activated and no errors were output.
*
* @since 1.4.0
*
* @param EndToEndTester $I EndToEnd Tester.
* @param string $name Plugin Slug.
*/
public function deactivateThirdPartyPlugin($I, $name)
{
// Login as the Administrator, if we're not already logged in.
if ( ! $this->amLoggedInAsAdmin($I) ) {
$this->doLoginAsAdmin($I);
}
// Go to the Plugins screen in the WordPress Administration interface.
$I->amOnPluginsPage();
// Wait for the Plugins page to load.
$I->waitForElementVisible('body.plugins-php');
// Depending on the Plugin name, perform deactivation.
switch ($name) {
case 'wpforms-lite':
// Using the check option results in a 502 Bad Gateway error.
$I->click('a#deactivate-' . $name);
break;
default:
// Deactivate the Plugin.
$I->checkOption('//*[@data-slug="' . $name . '"]/th/input');
$I->selectOption('action', 'deactivate-selected');
$I->click('#doaction');
// Wait for the Plugins page to load with the Plugin deactivated, to confirm it deactivated.
$I->waitForElementVisible('table.plugins tr[data-slug=' . $name . '].inactive');
break;
}
}
/**
* Helper method to check if the Administrator is logged in.
*
* @since 1.8.1
* @param EndToEndTester $I EndToEnd Tester.
*
* @return bool
*/
public function amLoggedInAsAdmin($I)
{
$cookies = $I->grabCookiesWithPattern('/^wordpress_logged_in_[a-z0-9]{32}$/');
return ! is_null( $cookies );
}
/**
* Helper method to reliably login as the Administrator.
*
* @since 1.8.1
*
* @param EndToEndTester $I EndToEnd Tester.
*/
public function doLoginAsAdmin($I)
{
// Add admin_email_lifespan option to prevent Administration email verification screen from
// displaying on login, which causes tests to fail.
// This is included in the dump.sql file, but seems to be deleted after a test.
$I->haveOptionInDatabase('admin_email_lifespan', '1805512805');
// Load login screen.
$I->amOnPage('wp-login.php');
// Wait for the login form to load.
$I->waitForElementVisible('#user_login');
$I->waitForElementVisible('#user_pass');
$I->waitForElementVisible('#wp-submit');
// Fill in the login form.
$I->click('#user_login');
$I->fillField('#user_login', $_ENV['WORDPRESS_ADMIN_USER']);
$I->click('#user_pass');
$I->fillField('#user_pass', $_ENV['WORDPRESS_ADMIN_PASSWORD']);
// Submit.
$I->click('#wp-submit');
// Wait for the Dashboard page to load, to confirm login succeeded.
$I->waitForElementVisible('body.index-php');
}
}