-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathBroadcastsExportPostCest.php
More file actions
211 lines (180 loc) · 5.36 KB
/
BroadcastsExportPostCest.php
File metadata and controls
211 lines (180 loc) · 5.36 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
<?php
namespace Tests\EndToEnd;
use Tests\Support\EndToEndTester;
/**
* Tests Post export to Broadcast functionality in Gutenberg.
*
* @since 2.4.0
*/
class BroadcastsExportPostCest
{
/**
* Run common actions before running the test functions in this class.
*
* @since 2.4.0
*
* @param EndToEndTester $I Tester.
*/
public function _before(EndToEndTester $I)
{
// Activate Kit Plugin.
$I->activateKitPlugin($I);
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
}
/**
* Tests that no "Create Broadcast" option is displayed when creating a Post and the 'Enable Export Actions' is disabled
* in the Plugin's settings.
*
* @since 2.4.0
*
* @param EndToEndTester $I Tester.
*/
public function testCreateBroadcastNotDisplayedWhenDisabledInPlugin(EndToEndTester $I)
{
// Add a Post using the Gutenberg editor.
$I->addGutenbergPage(
$I,
postType: 'post',
title: 'Kit: Post: Broadcast: Export: Disabled in Plugin'
);
// Click the Publish button.
$I->click('.editor-post-publish-button__button');
// When the pre-publish panel displays, confirm no Create Broadcast option exists.
$I->waitForElementVisible('.editor-post-publish-panel__header-publish-button');
// Confirm no Create Broadcast option is displayed.
$I->dontSeeElementInDOM('.convertkit-pre-publish-actions');
// Publish the page, to prevent an alert when navigating away for the next test.
$I->clickPublishOnPrePublishChecksForGutenbergPage($I);
}
/**
* Tests that no "Create Broadcast" option is displayed when creating a Page and the 'Enable Export Actions' is enabled
* in the Plugin's settings.
*
* @since 2.4.0
*
* @param EndToEndTester $I Tester.
*/
public function testCreateBroadcastNotDisplayedOnPages(EndToEndTester $I)
{
// Enable Export Actions for Posts.
$I->setupKitPluginBroadcasts(
$I,
[
'enabled_export' => true,
]
);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
postType: 'page',
title: 'Kit: Page: Broadcast: Export: Disabled in Plugin'
);
// Click the Publish button.
$I->click('.editor-post-publish-button__button');
// When the pre-publish panel displays, confirm no Create Broadcast option exists.
$I->waitForElementVisible('.editor-post-publish-panel__header-publish-button');
// Confirm no Create Broadcast option is displayed.
$I->dontSeeElementInDOM('.convertkit-pre-publish-actions');
// Publish the page, to prevent an alert when navigating away for the next test.
$I->clickPublishOnPrePublishChecksForGutenbergPage($I);
}
/**
* Tests that:
* - the "Create Broadcast" option is displayed when creating a Post,
* - the Broadcast is not created in Kit when the "Create Broadcast" option is not enabled on the Post.
*
* @since 2.4.0
*
* @param EndToEndTester $I Tester.
*/
public function testCreateBroadcastWhenDisabledInPost(EndToEndTester $I)
{
// Enable Export Actions for Posts.
$I->setupKitPluginBroadcasts(
$I,
[
'enabled_export' => true,
]
);
// Add a Post using the Gutenberg editor.
$I->addGutenbergPage(
$I,
postType: 'post',
title: 'Kit: Post: Broadcast: Export: Disabled in Post'
);
// Publish Post.
$I->publishGutenbergPage($I);
// Get Post ID.
$postID = $I->grabValueFrom('post_ID');
// Confirm Broadcast was not created in Kit.
$I->dontSeePostMetaInDatabase(
array(
'post_id' => $postID,
'meta_key' => '_convertkit_broadcast_export_id',
)
);
}
/**
* Tests that:
* - the "Create Broadcast" option is displayed when creating a Post,
* - the Broadcast is created in Kit when the "Create Broadcast" option is enabled on the Post.
*
* @since 2.4.0
*
* @param EndToEndTester $I Tester.
*/
public function testCreateBroadcastWhenEnabledInPost(EndToEndTester $I)
{
// Enable Export Actions for Posts.
$I->setupKitPluginBroadcasts(
$I,
[
'enabled_export' => true,
]
);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
postType: 'post',
title: 'Kit: Page: Broadcast: Export: Enabled in Post'
);
// Click the Publish button.
$I->click('.editor-post-publish-button__button');
// Wait for the Create Broadcast option to be visible.
$I->waitForElementVisible('.convertkit-pre-publish-actions.is-opened');
// Enable the Create Broadcast option.
$I->click('.convertkit-pre-publish-actions.is-opened input#convertkit_action_broadcast_export');
// Publish the Post.
$I->clickPublishOnPrePublishChecksForGutenbergPage($I);
// Get Post ID.
$postID = $I->grabValueFrom('post_ID');
// Confirm Broadcast was created in Kit.
$I->seePostMetaInDatabase(
array(
'post_id' => $postID,
'meta_key' => '_convertkit_broadcast_export_id',
)
);
// Get Broadcast ID.
$broadcastID = $I->grabPostMetaFromDatabase($postID, '_convertkit_broadcast_export_id', true);
// Fetch Broadcast from the API.
$broadcast = $I->apiGetBroadcast($broadcastID);
// Delete Broadcast.
$I->apiDeleteBroadcast($broadcastID);
}
/**
* Deactivate and reset Plugin(s) after each test, if the test passes.
* We don't use _after, as this would provide a screenshot of the Plugin
* deactivation and not the true test error.
*
* @since 2.4.0
*
* @param EndToEndTester $I Tester.
*/
public function _passed(EndToEndTester $I)
{
$I->deactivateKitPlugin($I);
$I->resetKitPlugin($I);
}
}