-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
tests/acceptance/broadcasts/import-export/BroadcastsExportCPTRowActionCest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
<?php | ||
/** | ||
* Tests Post export to Broadcast functionality. | ||
* | ||
* @since 2.7.2 | ||
*/ | ||
class BroadcastsExportCPTRowActionCest | ||
{ | ||
/** | ||
* Run common actions before running the test functions in this class. | ||
* | ||
* @since 2.7.2 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function _before(AcceptanceTester $I) | ||
{ | ||
// Activate ConvertKit Plugin. | ||
$I->activateConvertKitPlugin($I); | ||
$I->setupConvertKitPlugin($I); | ||
$I->setupConvertKitPluginResources($I); | ||
|
||
// Create a public Custom Post Type called Articles, using the Custom Post Type UI Plugin. | ||
$I->registerCustomPostType($I, 'article', 'Articles', 'Article'); | ||
} | ||
|
||
/** | ||
* Tests that no action is displayed in the Articles table when the 'Enable Export Actions' is disabled | ||
* in the Plugin's settings. | ||
* | ||
* @since 2.7.2 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function testBroadcastsExportRowActionWhenDisabled(AcceptanceTester $I) | ||
{ | ||
// Programmatically create an Article. | ||
$postID = $I->havePostInDatabase( | ||
[ | ||
'post_type' => 'article', | ||
'post_title' => 'Kit: Export Article to Broadcast', | ||
'post_content' => 'Kit: Export Article to Broadcast: Content', | ||
'post_excerpt' => 'Kit: Export Article to Broadcast: Excerpt', | ||
] | ||
); | ||
|
||
// Navigate to the Articles WP_List_Table. | ||
$I->amOnAdminPage('edit.php?post_type=article'); | ||
|
||
// Confirm that no action to export the Post is displayed. | ||
$I->dontSeeInSource('span.convertkit_broadcast_export'); | ||
} | ||
|
||
/** | ||
* Tests that an action is displayed in the Articles table when the 'Enable Export Actions' is enabled | ||
* in the Plugin's settings, and a Broadcast is created in ConvertKit when clicked. | ||
* | ||
* @since 2.7.2 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function testBroadcastsExportRowActionWhenEnabled(AcceptanceTester $I) | ||
{ | ||
// Enable Export Actions for Articles. | ||
$I->setupConvertKitPluginBroadcasts( | ||
$I, | ||
[ | ||
'enabled_export' => true, | ||
] | ||
); | ||
|
||
// Programmatically create a Post. | ||
$postID = $I->havePostInDatabase( | ||
[ | ||
'post_type' => 'article', | ||
'post_title' => 'Kit: Export Article to Broadcast', | ||
'post_content' => '<p class="style-test">Kit: Export Article to Broadcast: Content</p>', | ||
'post_excerpt' => 'Kit: Export Article to Broadcast: Excerpt', | ||
] | ||
); | ||
|
||
// Navigate to the Articles WP_List_Table. | ||
$I->amOnAdminPage('edit.php?post_type=article'); | ||
|
||
// Hover mouse over Post's table row. | ||
$I->moveMouseOver('tr.iedit:first-child'); | ||
|
||
// Wait for export link to be visible. | ||
$I->waitForElementVisible('tr.iedit:first-child span.convertkit_broadcast_export a'); | ||
|
||
// Click the export action. | ||
$I->click('tr.iedit:first-child span.convertkit_broadcast_export a'); | ||
|
||
// Confirm that a success message displays. | ||
$I->waitForElementVisible('.notice-success'); | ||
$I->see('Successfully created Kit Broadcast from Post'); | ||
|
||
// Get Broadcast ID from 'Click here' link. | ||
$broadcastID = (int) filter_var($I->grabAttributeFrom('.notice-success p a', 'href'), FILTER_SANITIZE_NUMBER_INT); | ||
|
||
// Fetch Broadcast from the API. | ||
$broadcast = $I->apiGetBroadcast($broadcastID); | ||
|
||
// Delete Broadcast. | ||
$I->apiDeleteBroadcast($broadcastID); | ||
|
||
// Confirm styles were included in the Broadcast. | ||
$I->assertStringContainsString('class="style-test"', $broadcast['broadcast']['content']); | ||
} | ||
|
||
/** | ||
* Tests that the 'Disable Styles' setting is honored when enabled in the Plugin's settings, and a | ||
* Broadcast is created in ConvertKit. | ||
* | ||
* @since 2.7.2 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function testBroadcastsExportActionWithDisableStylesEnabled(AcceptanceTester $I) | ||
{ | ||
// Enable Export Actions for Articles. | ||
$I->setupConvertKitPluginBroadcasts( | ||
$I, | ||
[ | ||
'enabled_export' => true, | ||
'no_styles' => true, | ||
] | ||
); | ||
|
||
// Programmatically create a Post. | ||
$postID = $I->havePostInDatabase( | ||
[ | ||
'post_type' => 'article', | ||
'post_title' => 'Kit: Export Article to Broadcast: Disable Styles', | ||
'post_content' => '<p class="style-test">Kit: Export Post to Broadcast: Disable Styles: Content</p>', | ||
'post_excerpt' => 'Kit: Export Article to Broadcast: Disable Styles: Excerpt', | ||
] | ||
); | ||
|
||
// Navigate to the Articles WP_List_Table. | ||
$I->amOnAdminPage('edit.php?post_type=article'); | ||
|
||
// Hover mouse over Post's table row. | ||
$I->moveMouseOver('tr.iedit:first-child'); | ||
|
||
// Wait for export link to be visible. | ||
$I->waitForElementVisible('tr.iedit:first-child span.convertkit_broadcast_export a'); | ||
|
||
// Click the export action. | ||
$I->click('tr.iedit:first-child span.convertkit_broadcast_export a'); | ||
|
||
// Confirm that a success message displays. | ||
$I->waitForElementVisible('.notice-success'); | ||
$I->see('Successfully created Kit Broadcast from Post'); | ||
|
||
// Get Broadcast ID from 'Click here' link. | ||
$broadcastID = (int) filter_var($I->grabAttributeFrom('.notice-success p a', 'href'), FILTER_SANITIZE_NUMBER_INT); | ||
|
||
// Fetch Broadcast from the API. | ||
$broadcast = $I->apiGetBroadcast($broadcastID); | ||
|
||
// Delete Broadcast. | ||
$I->apiDeleteBroadcast($broadcastID); | ||
|
||
// Confirm styles were not included in the Broadcast. | ||
$I->assertStringNotContainsString('class="style-test"', $broadcast['broadcast']['content']); | ||
} | ||
|
||
/** | ||
* 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.7.2 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function _passed(AcceptanceTester $I) | ||
{ | ||
$I->unregisterCustomPostType($I, 'article'); | ||
$I->deactivateConvertKitPlugin($I); | ||
$I->resetConvertKitPlugin($I); | ||
} | ||
} |