diff --git a/includes/class-convertkit-broadcasts-exporter.php b/includes/class-convertkit-broadcasts-exporter.php index f808204e..f0f9ab99 100644 --- a/includes/class-convertkit-broadcasts-exporter.php +++ b/includes/class-convertkit-broadcasts-exporter.php @@ -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 ); } @@ -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' ), diff --git a/tests/acceptance/broadcasts/import-export/BroadcastsExportCPTRowActionCest.php b/tests/acceptance/broadcasts/import-export/BroadcastsExportCPTRowActionCest.php new file mode 100644 index 00000000..cf1b1d45 --- /dev/null +++ b/tests/acceptance/broadcasts/import-export/BroadcastsExportCPTRowActionCest.php @@ -0,0 +1,184 @@ +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' => '

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'); + + // 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' => '

Kit: Export Post to Broadcast: Disable Styles: Content

', + '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); + } +}