Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Create Broadcast in Kit to all Post Types #766

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions includes/class-convertkit-broadcasts-exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function __construct() {
add_action( 'init', array( $this, 'run_row_action' ) );

// Add action below Post Title in WP_List_Table classes.
add_filter( 'page_row_actions', array( $this, 'add_row_action' ), 10, 2 );
add_filter( 'post_row_actions', array( $this, 'add_row_action' ), 10, 2 );

}
Expand Down Expand Up @@ -167,6 +168,7 @@ public function add_row_action( $actions, $post ) {
// Build URL.
$url = add_query_arg(
array(
'post_type' => $post->post_type,
'convertkit-action' => 'broadcast-export',
'id' => $post->ID,
'nonce' => wp_create_nonce( 'action-convertkit-broadcast-export' ),
Expand Down
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);
}
}