From 8f652bcd8eadd006b089c71b34e08408c92faca5 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 15:38:52 +0000 Subject: [PATCH 01/11] Moved some helper functions into own helper classes --- .../Acceptance/ConvertKitBroadcasts.php | 174 ++++++++ .../ConvertKitRestrictedContent.php | 420 ++++++++++++++++++ 2 files changed, 594 insertions(+) create mode 100644 tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php create mode 100644 tests/_support/Helper/Acceptance/ConvertKitRestrictedContent.php diff --git a/tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php b/tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php new file mode 100644 index 000000000..2f78f3111 --- /dev/null +++ b/tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php @@ -0,0 +1,174 @@ +{yourFunctionName}. + * + * @since 2.0.0 + */ +class ConvertKitBroadcasts extends \Codeception\Module +{ + /** + * Check that expected HTML exists in the DOM of the page we're viewing for + * a Broadcasts block or shortcode, based on its configuration. + * + * @since 1.9.7.5 + * + * @param AcceptanceTester $I Tester. + * @param bool|int $numberOfPosts Number of Broadcasts listed. + * @param bool|string $seePrevPaginationLabel Test if the "previous" pagination link is output and matches expected label. + * @param bool|string $seeNextPaginationLabel Test if the "next" pagination link is output and matches expected label. + * @param bool $seeGrid Test if the broadcasts are displayed in grid view (false = list view). + * @param bool $seeImage Test if the broadcasts display images. + * @param bool $seeDescription Test if the broadcasts display descriptions. + * @param bool|string $seeReadMore Test if the broadcasts display a read more link matching the given text. + */ + public function seeBroadcastsOutput($I, $options = false) + { + // Define defaults. + $defaults = [ + 'number_of_posts' => false, + 'see_prev_pagination_label' => false, + 'see_next_pagination_label' => false, + 'see_grid' => false, + 'see_image' => false, + 'see_description' => false, + 'see_read_more' => false, + ]; + + // If options is an array, merge with defaults. + if (is_array($options)) { + $options = array_merge($defaults, $options); + } else { + $options = $defaults; + } + + // Confirm that the block displays. + $I->seeElementInDOM('div.convertkit-broadcasts'); + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list'); + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast'); + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast a.convertkit-broadcast-title'); + + // Confirm that UTM parameters exist on a broadcast link. + $I->assertStringContainsString( + 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', + $I->grabAttributeFrom('a.convertkit-broadcast-title', 'href') + ); + + // If Display as grid is enabled, confirm the applicable HTML exists so that CSS can style this layout. + if ($options['see_grid']) { + $I->seeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); + } else { + $I->dontSeeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); + } + + // If Display image is enabled, confirm the image is displayed. + if ($options['see_image']) { + $I->seeElementInDOM('a.convertkit-broadcast-image img'); + $I->assertStringContainsString( + 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', + $I->grabAttributeFrom('a.convertkit-broadcast-image', 'href') + ); + } else { + $I->dontSeeElementInDOM('a.convertkit-broadcast-image img'); + } + + // If Display description is enabled, confirm the description is displayed. + if ($options['see_description']) { + $I->seeElementInDOM('.convertkit-broadcast-description'); + } else { + $I->dontSeeElementInDOM('.convertkit-broadcast-description'); + } + + // If Display read more link is enabled, confirm the read more link is displayed and matches the given text. + if ($options['see_read_more']) { + $I->seeElementInDOM('a.convertkit-broadcast-read-more'); + $I->assertStringContainsString( + 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', + $I->grabAttributeFrom('a.convertkit-broadcast-read-more', 'href') + ); + } else { + $I->dontSeeElementInDOM('a.convertkit-broadcast-read-more'); + } + + // Confirm that the number of expected broadcasts displays. + if ($options['number_of_posts'] !== false) { + $I->seeNumberOfElements('li.convertkit-broadcast', $options['number_of_posts']); + } + + // Confirm that previous pagination displays, if expected. + if ($options['see_prev_pagination_label'] !== false) { + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-prev a'); + $I->seeInSource($options['see_prev_pagination_label']); + } + + // Confirm that next pagination displays, if expected. + if ($options['see_next_pagination_label'] !== false) { + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-next a'); + $I->seeInSource($options['see_next_pagination_label']); + } + } + + /** + * Tests that the Broadcasts pagination works, and that the expected Broadcast + * is displayed after using previous and next links. + * + * @since 2.0.0 + * + * @param AcceptanceTester $I Tester. + * @param string $previousLabel Previous / Newer Broadcasts Label. + * @param string $nextLabel Next / Older Broadcasts Label. + */ + public function testBroadcastsPagination($I, $previousLabel, $nextLabel) + { + // Confirm that the block displays one broadcast with a pagination link to older broadcasts. + $I->seeBroadcastsOutput($I, 1, false, $nextLabel); + + // Click the Older Posts link. + $I->click('li.convertkit-broadcasts-pagination-next a'); + + // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been + // removed from the block. + $I->waitForBroadcastsToLoad($I); + + // Confirm that the block displays one broadcast with a pagination link to newer broadcasts. + $I->seeBroadcastsOutput($I, 1, $previousLabel, false); + + // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. + $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_SECOND_TITLE']); + + // Click the Newer Posts link. + $I->click('li.convertkit-broadcasts-pagination-prev a'); + + // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been + // removed from the block. + $I->waitForBroadcastsToLoad($I); + + // Confirm that the block displays one broadcast with a pagination link to older broadcasts. + $I->seeBroadcastsOutput($I, 1, false, $nextLabel); + + // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. + $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_FIRST_TITLE']); + } + + /** + * Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been + * removed from the block. + * + * @since 1.9.7.6 + * + * @param AcceptanceTester $I Tester. + */ + public function waitForBroadcastsToLoad($I) + { + $I->waitForElementChange( + 'div.convertkit-broadcasts', + function(\Facebook\WebDriver\WebDriverElement $el) { + return ( strpos($el->getAttribute('class'), 'convertkit-broadcasts-loading') === false ? true : false ); + }, + 5 + ); + } \ No newline at end of file diff --git a/tests/_support/Helper/Acceptance/ConvertKitRestrictedContent.php b/tests/_support/Helper/Acceptance/ConvertKitRestrictedContent.php new file mode 100644 index 000000000..968af8748 --- /dev/null +++ b/tests/_support/Helper/Acceptance/ConvertKitRestrictedContent.php @@ -0,0 +1,420 @@ +{yourFunctionName}. + * + * @since 2.1.0 + */ +class ConvertKitRestrictedContent extends \Codeception\Module +{ + /** + * Returns the expected default settings for Restricted Content. + * + * @since 2.1.0 + * + * @return array + */ + public function getRestrictedContentDefaultSettings() + { + return array( + // Restrict by Product. + 'subscribe_heading' => 'Read this post with a premium subscription', + 'subscribe_text' => 'This post is only available to premium subscribers. Join today to get access to all posts.', + + // Restrict by Tag. + 'subscribe_heading_tag' => 'Subscribe to keep reading', + 'subscribe_text_tag' => 'This post is free to read but only available to subscribers. Join today to get access to all posts.', + + // All. + 'subscribe_button_label' => 'Subscribe', + 'email_text' => 'Already subscribed?', + 'email_button_label' => 'Log in', + 'email_description_text' => 'We\'ll email you a magic code to log you in without a password.', + 'email_check_heading' => 'We just emailed you a log in code', + 'email_check_text' => 'Enter the code below to finish logging in', + 'no_access_text' => 'Your account does not have access to this content. Please use the button above to purchase, or enter the email address you used to purchase the product.', + ); + } + + /** + * Creates a Page in the database with the given title for restricted content. + * + * The Page's content comprises of a mix of visible and member's only content. + * The default form setting is set to 'None'. + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $postType Post Type. + * @param string $title Title. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param string $restrictContentSetting Restrict Content setting. + * @return int Page ID. + */ + public function createRestrictedContentPage($I, $postType, $title, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $restrictContentSetting = '') + { + return $I->havePostInDatabase( + [ + 'post_type' => $postType, + 'post_title' => $title, + + // Emulate Gutenberg content with visible and members only content sections. + 'post_content' => '

' . $visibleContent . '

+ +' . $memberContent . '', + + // Don't display a Form on this Page, so we test against Restrict Content's Form. + 'meta_input' => [ + '_wp_convertkit_post_meta' => [ + 'form' => '-1', + 'landing_page' => '', + 'tag' => '', + 'restrict_content' => $restrictContentSetting, + ], + ], + ] + ); + } + + /** + * Run frontend tests for restricted content by ConvertKit Product, to confirm that visible and member's content + * is / is not displayed when logging in with valid and invalid subscriber email addresses. + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string|int $urlOrPageID URL or ID of Restricted Content Page. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictedContentByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Navigate to the page. + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID); + } else { + $I->amOnUrl($urlOrPageID); + } + + // Confirm Restrict Content CSS is output. + $I->seeInSource('invalid: Email address is invalid'); + $I->seeInSource('
'); + + // Check content is not displayed, and CTA displays with expected text. + $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); + + // Set cookie with signed subscriber ID and reload the restricted content page, as if we entered the + // code sent in the email as a ConvertKit subscriber who has not subscribed to the product. + $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID_NO_ACCESS']); + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID . '&ck-cache-bust=' . microtime() ); + } else { + $I->amOnUrl($urlOrPageID . '?ck-cache-bust=' . microtime() ); + } + + // Confirm an inline error message is displayed. + $I->seeInSource('
' . $textItems['no_access_text'] . '
'); + $I->seeInSource('
'); + + // Check content is not displayed, and CTA displays with expected text. + $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); + + // Login as a ConvertKit subscriber who has subscribed to the product. + $I->waitForElementVisible('input#convertkit_email'); + $I->fillField('convertkit_email', $_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL']); + $I->click('input.wp-block-button__link'); + + // Confirm that confirmation an email has been sent is displayed. + $this->testRestrictContentShowsEmailCodeForm($I, $visibleContent, $memberContent, $textItems); + + // Test that the restricted content displays when a valid signed subscriber ID is used, + // as if we entered the code sent in the email. + $this->testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent); + } + + /** + * Run frontend tests for restricted content by ConvertKit Product, using the modal authentication flow, to confirm + * that visible and member's content is / is not displayed when logging in with valid and invalid subscriber email addresses. + * + * @since 2.3.8 + * + * @param AcceptanceTester $I Tester. + * @param string|int $urlOrPageID URL or ID of Restricted Content Page. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictedContentModalByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Navigate to the page. + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID); + } else { + $I->amOnUrl($urlOrPageID); + } + + // Confirm Restrict Content CSS is output. + $I->seeInSource(''); + + // Enter the email address and submit the form. + $I->fillField('convertkit_email', $emailAddress); + $I->click('input.wp-block-button__link'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the restricted content is now displayed. + $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); + } + + /** + * Run frontend tests for restricted content, to confirm that both visible and member content is displayed + * when a valid signed subscriber ID is set as a cookie, as if the user entered a code sent in the email. + * + * @since 2.2.2 + * + * @param AcceptanceTester $I Tester. + * @param string|int $urlOrPageID URL or ID of Restricted Content Page. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + */ + public function testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent) + { + // Set cookie with signed subscriber ID, as if we entered the code sent in the email. + $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); + + // Reload the restricted content page. + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID ); + } else { + $I->amOnUrl($urlOrPageID ); + } + + // Confirm cookie was set with the expected value. + $I->assertEquals($I->grabCookie('ck_subscriber_id'), $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); + + // Confirm that the restricted content is now displayed, as we've authenticated as a subscriber + // who has access to this Product. + $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); + } + + /** + * Run frontend tests for restricted content, to confirm that: + * - visible content is displayed, + * - member's content is not displayed, + * - the CTA is displayed with the expected text + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictContentByProductHidesContentWithCTA($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the visible text displays, hidden text does not display and the CTA displays. + if ( ! empty($visibleContent)) { + $I->see($visibleContent); + } + $I->dontSee($memberContent); + + // Confirm that the CTA displays with the expected headings, text, buttons and other elements. + $I->seeElementInDOM('#convertkit-restrict-content'); + + $I->seeInSource('

' . $textItems['subscribe_heading'] . '

'); + $I->see($textItems['subscribe_text']); + + $I->see($textItems['subscribe_button_label']); + $I->seeInSource('
'); + $I->seeInSource('' . $textItems['email_description_text'] . ''); + } + + /** + * Run frontend tests for restricted content, to confirm that: + * - visible content is displayed, + * - member's content is not displayed, + * - the email code form is displayed with the expected text. + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictContentShowsEmailCodeForm($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the visible text displays, hidden text does not display and the CTA displays. + if ( ! empty($visibleContent)) { + $I->see($visibleContent); + } + $I->dontSee($memberContent); + + // Confirm that the CTA displays with the expected text. + $I->seeElementInDOM('#convertkit-restrict-content'); + $I->seeInSource('

' . $textItems['email_check_heading'] . '

'); + $I->see($textItems['email_check_text']); + $I->seeElementInDOM('input#convertkit_subscriber_code'); + $I->seeElementInDOM('input.wp-block-button__link'); + + // Enter an invalid code. + $I->fillField('subscriber_code', '999999'); + $I->click('Verify'); + + // Confirm an inline error message is displayed. + $I->seeInSource('
The entered code is invalid. Please try again, or click the link sent in the email.
'); + $I->seeInSource('
'); + } + + /** + * Run frontend tests for restricted content, to confirm that: + * - visible content is displayed, + * - member's content is displayed, + * - the CTA is not displayed + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + */ + public function testRestrictContentDisplaysContent($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.') + { + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the visible and hidden text displays. + if ( ! empty($visibleContent)) { + $I->see($visibleContent); + } + $I->see($memberContent); + + // Confirm that the CTA is not displayed. + $I->dontSeeElementInDOM('#convertkit-restrict-content'); + } +} \ No newline at end of file From a7efa00542370f2bee9e17337bb9442f672fbf1a Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 15:39:01 +0000 Subject: [PATCH 02/11] Removed helper functions from Plugin helper class --- tests/_support/Helper/Acceptance/Plugin.php | 591 +------------------- tests/acceptance.suite.yml | 2 + 2 files changed, 23 insertions(+), 570 deletions(-) diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php index 238dda2cb..daf256269 100644 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ b/tests/_support/Helper/Acceptance/Plugin.php @@ -51,23 +51,28 @@ public function deactivateConvertKitPlugin($I) * @param bool $disableCSS Disable CSS. * @param bool|string $globalNonInlineFormID Default Global non-inline Form ID (if specified, none if false). */ - public function setupConvertKitPlugin($I, $apiKey = false, $apiSecret = false, $pageFormID = false, $postFormID = false, $productFormID = false, $disableJS = false, $disableCSS = false, $globalNonInlineFormID = false) + public function setupConvertKitPlugin($I, $options = false) { - // Define the API Key and Secret, with Debug Log enabled. - $I->haveOptionInDatabase( - '_wp_convertkit_settings', - [ - 'api_key' => ( $apiKey !== false ? $apiKey : $_ENV['CONVERTKIT_API_KEY'] ), - 'api_secret' => ( $apiSecret !== false ? $apiSecret : $_ENV['CONVERTKIT_API_SECRET'] ), - 'debug' => 'on', - 'no_scripts' => ( $disableJS ? 'on' : '' ), - 'no_css' => ( $disableCSS ? 'on' : '' ), - 'post_form' => ( $postFormID !== false ? $postFormID : $_ENV['CONVERTKIT_API_FORM_ID'] ), - 'page_form' => ( $pageFormID !== false ? $pageFormID : $_ENV['CONVERTKIT_API_FORM_ID'] ), - 'product_form' => ( $productFormID !== false ? $productFormID : $_ENV['CONVERTKIT_API_FORM_ID'] ), - 'non_inline_form' => ( $globalNonInlineFormID !== false ? $globalNonInlineFormID : '' ), - ] - ); + // Define default options. + $defaults = [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'debug' => 'on', + 'no_scripts' => '', + 'no_css' => '', + 'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'product_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'non_inline_form' => '', + ]; + + // If supplied options are an array, merge them with the defaults. + if (is_array($options)) { + $options = array_merge($defaults, $options); + } + + // Define settings in options table. + $I->haveOptionInDatabase('_wp_convertkit_settings', $options); } /** @@ -692,151 +697,6 @@ public function checkSelectOptionOrder($I, $selectElement, $values) } } - /** - * Check that expected HTML exists in the DOM of the page we're viewing for - * a Broadcasts block or shortcode, based on its configuration. - * - * @since 1.9.7.5 - * - * @param AcceptanceTester $I Tester. - * @param bool|int $numberOfPosts Number of Broadcasts listed. - * @param bool|string $seePrevPaginationLabel Test if the "previous" pagination link is output and matches expected label. - * @param bool|string $seeNextPaginationLabel Test if the "next" pagination link is output and matches expected label. - * @param bool $seeGrid Test if the broadcasts are displayed in grid view (false = list view). - * @param bool $seeImage Test if the broadcasts display images. - * @param bool $seeDescription Test if the broadcasts display descriptions. - * @param bool|string $seeReadMore Test if the broadcasts display a read more link matching the given text. - */ - public function seeBroadcastsOutput($I, $numberOfPosts = false, $seePrevPaginationLabel = false, $seeNextPaginationLabel = false, $seeGrid = false, $seeImage = false, $seeDescription = false, $seeReadMore = false) - { - // Confirm that the block displays. - $I->seeElementInDOM('div.convertkit-broadcasts'); - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list'); - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast'); - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast a.convertkit-broadcast-title'); - - // Confirm that UTM parameters exist on a broadcast link. - $I->assertStringContainsString( - 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', - $I->grabAttributeFrom('a.convertkit-broadcast-title', 'href') - ); - - // If Display as grid is enabled, confirm the applicable HTML exists so that CSS can style this layout. - if ($seeGrid) { - $I->seeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); - } else { - $I->dontSeeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); - } - - // If Display image is enabled, confirm the image is displayed. - if ($seeImage) { - $I->seeElementInDOM('a.convertkit-broadcast-image img'); - $I->assertStringContainsString( - 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', - $I->grabAttributeFrom('a.convertkit-broadcast-image', 'href') - ); - } else { - $I->dontSeeElementInDOM('a.convertkit-broadcast-image img'); - } - - // If Display description is enabled, confirm the description is displayed. - if ($seeDescription) { - $I->seeElementInDOM('.convertkit-broadcast-description'); - } else { - $I->dontSeeElementInDOM('.convertkit-broadcast-description'); - } - - // If Display read more link is enabled, confirm the read more link is displayed and matches the given text. - if ($seeReadMore) { - $I->seeElementInDOM('a.convertkit-broadcast-read-more'); - $I->assertStringContainsString( - 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', - $I->grabAttributeFrom('a.convertkit-broadcast-read-more', 'href') - ); - } else { - $I->dontSeeElementInDOM('a.convertkit-broadcast-read-more'); - } - - // Confirm that the number of expected broadcasts displays. - if ($numberOfPosts !== false) { - $I->seeNumberOfElements('li.convertkit-broadcast', $numberOfPosts); - } - - // Confirm that previous pagination displays, if expected. - if ($seePrevPaginationLabel !== false) { - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-prev a'); - $I->seeInSource($seePrevPaginationLabel); - } - - // Confirm that next pagination displays, if expected. - if ($seeNextPaginationLabel !== false) { - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-next a'); - } - } - - /** - * Tests that the Broadcasts pagination works, and that the expected Broadcast - * is displayed after using previous and next links. - * - * @since 2.0.0 - * - * @param AcceptanceTester $I Tester. - * @param string $previousLabel Previous / Newer Broadcasts Label. - * @param string $nextLabel Next / Older Broadcasts Label. - */ - public function testBroadcastsPagination($I, $previousLabel, $nextLabel) - { - // Confirm that the block displays one broadcast with a pagination link to older broadcasts. - $I->seeBroadcastsOutput($I, 1, false, $nextLabel); - - // Click the Older Posts link. - $I->click('li.convertkit-broadcasts-pagination-next a'); - - // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been - // removed from the block. - $I->waitForBroadcastsToLoad($I); - - // Confirm that the block displays one broadcast with a pagination link to newer broadcasts. - $I->seeBroadcastsOutput($I, 1, $previousLabel, false); - - // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. - $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_SECOND_TITLE']); - - // Click the Newer Posts link. - $I->click('li.convertkit-broadcasts-pagination-prev a'); - - // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been - // removed from the block. - $I->waitForBroadcastsToLoad($I); - - // Confirm that the block displays one broadcast with a pagination link to older broadcasts. - $I->seeBroadcastsOutput($I, 1, false, $nextLabel); - - // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. - $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_FIRST_TITLE']); - } - - /** - * Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been - * removed from the block. - * - * @since 1.9.7.6 - * - * @param AcceptanceTester $I Tester. - */ - public function waitForBroadcastsToLoad($I) - { - $I->waitForElementChange( - 'div.convertkit-broadcasts', - function(\Facebook\WebDriver\WebDriverElement $el) { - return ( strpos($el->getAttribute('class'), 'convertkit-broadcasts-loading') === false ? true : false ); - }, - 5 - ); - } - /** * Check that expected HTML exists in the DOM of the page we're viewing * when a ConvertKit Product link was inserted into a paragraph or button, @@ -870,415 +730,6 @@ public function seeProductLink($I, $productURL, $text = false) $I->seeElementInDOM('iframe[data-active]'); } - /** - * Returns the expected default settings for Restricted Content. - * - * @since 2.1.0 - * - * @return array - */ - public function getRestrictedContentDefaultSettings() - { - return array( - // Restrict by Product. - 'subscribe_heading' => 'Read this post with a premium subscription', - 'subscribe_text' => 'This post is only available to premium subscribers. Join today to get access to all posts.', - - // Restrict by Tag. - 'subscribe_heading_tag' => 'Subscribe to keep reading', - 'subscribe_text_tag' => 'This post is free to read but only available to subscribers. Join today to get access to all posts.', - - // All. - 'subscribe_button_label' => 'Subscribe', - 'email_text' => 'Already subscribed?', - 'email_button_label' => 'Log in', - 'email_description_text' => 'We\'ll email you a magic code to log you in without a password.', - 'email_check_heading' => 'We just emailed you a log in code', - 'email_check_text' => 'Enter the code below to finish logging in', - 'no_access_text' => 'Your account does not have access to this content. Please use the button above to purchase, or enter the email address you used to purchase the product.', - ); - } - - /** - * Creates a Page in the database with the given title for restricted content. - * - * The Page's content comprises of a mix of visible and member's only content. - * The default form setting is set to 'None'. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $postType Post Type. - * @param string $title Title. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param string $restrictContentSetting Restrict Content setting. - * @return int Page ID. - */ - public function createRestrictedContentPage($I, $postType, $title, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $restrictContentSetting = '') - { - return $I->havePostInDatabase( - [ - 'post_type' => $postType, - 'post_title' => $title, - - // Emulate Gutenberg content with visible and members only content sections. - 'post_content' => '

' . $visibleContent . '

- -' . $memberContent . '', - - // Don't display a Form on this Page, so we test against Restrict Content's Form. - 'meta_input' => [ - '_wp_convertkit_post_meta' => [ - 'form' => '-1', - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => $restrictContentSetting, - ], - ], - ] - ); - } - - /** - * Run frontend tests for restricted content by ConvertKit Product, to confirm that visible and member's content - * is / is not displayed when logging in with valid and invalid subscriber email addresses. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string|int $urlOrPageID URL or ID of Restricted Content Page. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictedContentByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Navigate to the page. - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID); - } else { - $I->amOnUrl($urlOrPageID); - } - - // Confirm Restrict Content CSS is output. - $I->seeInSource('invalid: Email address is invalid
'); - $I->seeInSource('
'); - - // Check content is not displayed, and CTA displays with expected text. - $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); - - // Set cookie with signed subscriber ID and reload the restricted content page, as if we entered the - // code sent in the email as a ConvertKit subscriber who has not subscribed to the product. - $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID_NO_ACCESS']); - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID . '&ck-cache-bust=' . microtime() ); - } else { - $I->amOnUrl($urlOrPageID . '?ck-cache-bust=' . microtime() ); - } - - // Confirm an inline error message is displayed. - $I->seeInSource('
' . $textItems['no_access_text'] . '
'); - $I->seeInSource('
'); - - // Check content is not displayed, and CTA displays with expected text. - $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); - - // Login as a ConvertKit subscriber who has subscribed to the product. - $I->waitForElementVisible('input#convertkit_email'); - $I->fillField('convertkit_email', $_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL']); - $I->click('input.wp-block-button__link'); - - // Confirm that confirmation an email has been sent is displayed. - $this->testRestrictContentShowsEmailCodeForm($I, $visibleContent, $memberContent, $textItems); - - // Test that the restricted content displays when a valid signed subscriber ID is used, - // as if we entered the code sent in the email. - $this->testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent); - } - - /** - * Run frontend tests for restricted content by ConvertKit Product, using the modal authentication flow, to confirm - * that visible and member's content is / is not displayed when logging in with valid and invalid subscriber email addresses. - * - * @since 2.3.8 - * - * @param AcceptanceTester $I Tester. - * @param string|int $urlOrPageID URL or ID of Restricted Content Page. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictedContentModalByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Navigate to the page. - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID); - } else { - $I->amOnUrl($urlOrPageID); - } - - // Confirm Restrict Content CSS is output. - $I->seeInSource(''); - - // Enter the email address and submit the form. - $I->fillField('convertkit_email', $emailAddress); - $I->click('input.wp-block-button__link'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the restricted content is now displayed. - $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); - } - - /** - * Run frontend tests for restricted content, to confirm that both visible and member content is displayed - * when a valid signed subscriber ID is set as a cookie, as if the user entered a code sent in the email. - * - * @since 2.2.2 - * - * @param AcceptanceTester $I Tester. - * @param string|int $urlOrPageID URL or ID of Restricted Content Page. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - */ - public function testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent) - { - // Set cookie with signed subscriber ID, as if we entered the code sent in the email. - $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); - - // Reload the restricted content page. - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID ); - } else { - $I->amOnUrl($urlOrPageID ); - } - - // Confirm cookie was set with the expected value. - $I->assertEquals($I->grabCookie('ck_subscriber_id'), $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); - - // Confirm that the restricted content is now displayed, as we've authenticated as a subscriber - // who has access to this Product. - $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); - } - - /** - * Run frontend tests for restricted content, to confirm that: - * - visible content is displayed, - * - member's content is not displayed, - * - the CTA is displayed with the expected text - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictContentByProductHidesContentWithCTA($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the visible text displays, hidden text does not display and the CTA displays. - if ( ! empty($visibleContent)) { - $I->see($visibleContent); - } - $I->dontSee($memberContent); - - // Confirm that the CTA displays with the expected headings, text, buttons and other elements. - $I->seeElementInDOM('#convertkit-restrict-content'); - - $I->seeInSource('

' . $textItems['subscribe_heading'] . '

'); - $I->see($textItems['subscribe_text']); - - $I->see($textItems['subscribe_button_label']); - $I->seeInSource('
'); - $I->seeInSource('' . $textItems['email_description_text'] . ''); - } - - /** - * Run frontend tests for restricted content, to confirm that: - * - visible content is displayed, - * - member's content is not displayed, - * - the email code form is displayed with the expected text. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictContentShowsEmailCodeForm($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the visible text displays, hidden text does not display and the CTA displays. - if ( ! empty($visibleContent)) { - $I->see($visibleContent); - } - $I->dontSee($memberContent); - - // Confirm that the CTA displays with the expected text. - $I->seeElementInDOM('#convertkit-restrict-content'); - $I->seeInSource('

' . $textItems['email_check_heading'] . '

'); - $I->see($textItems['email_check_text']); - $I->seeElementInDOM('input#convertkit_subscriber_code'); - $I->seeElementInDOM('input.wp-block-button__link'); - - // Enter an invalid code. - $I->fillField('subscriber_code', '999999'); - $I->click('Verify'); - - // Confirm an inline error message is displayed. - $I->seeInSource('
The entered code is invalid. Please try again, or click the link sent in the email.
'); - $I->seeInSource('
'); - } - - /** - * Run frontend tests for restricted content, to confirm that: - * - visible content is displayed, - * - member's content is displayed, - * - the CTA is not displayed - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - */ - public function testRestrictContentDisplaysContent($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.') - { - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the visible and hidden text displays. - if ( ! empty($visibleContent)) { - $I->see($visibleContent); - } - $I->see($memberContent); - - // Confirm that the CTA is not displayed. - $I->dontSeeElementInDOM('#convertkit-restrict-content'); - } - /** * Check that expected HTML exists in the DOM of the page we're viewing for * a Form Trigger block or shortcode, and that the button loads the expected diff --git a/tests/acceptance.suite.yml b/tests/acceptance.suite.yml index 457804b1a..82e55db79 100644 --- a/tests/acceptance.suite.yml +++ b/tests/acceptance.suite.yml @@ -22,6 +22,8 @@ modules: # Our helper classes, which contain functions used across multiple tests. # If you created a new file in tests/_support/Helper/Acceptance, add its namespace and class below, - \Helper\Acceptance\ConvertKitAPI + - \Helper\Acceptance\ConvertKitBroadcasts + - \Helper\Acceptance\ConvertKitRestrictedContent - \Helper\Acceptance\CustomPostType - \Helper\Acceptance\Email - \Helper\Acceptance\Plugin From 628ff4ea1a941fdfe4de15021061476a59aaf6c0 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 17:09:47 +0000 Subject: [PATCH 03/11] Use new `setupConvertKitPluginAPIKeyNoData` method --- tests/_support/Helper/Acceptance/Plugin.php | 13 +++++++++++++ .../broadcasts/blocks/PageBlockBroadcastsCest.php | 4 ++-- tests/acceptance/forms/blocks/PageBlockFormCest.php | 4 ++-- .../forms/blocks/PageBlockFormTriggerCest.php | 4 ++-- .../acceptance/forms/general/NonInlineFormCest.php | 2 +- tests/acceptance/forms/general/PageNoFormCest.php | 2 +- .../forms/shortcodes/PageShortcodeFormCest.php | 2 +- .../shortcodes/PageShortcodeFormTriggerCest.php | 2 +- .../integrations/other/ContactForm7FormCest.php | 4 ++-- .../integrations/other/ForminatorCest.php | 4 ++-- tests/acceptance/products/PageBlockProductCest.php | 4 ++-- .../products/PageShortcodeProductCest.php | 2 +- .../RestrictContentFilterPageCest.php | 2 +- .../RestrictContentFilterPostCest.php | 2 +- .../restrict-content/RestrictContentSetupCest.php | 2 +- 15 files changed, 33 insertions(+), 20 deletions(-) diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php index daf256269..180019c30 100644 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ b/tests/_support/Helper/Acceptance/Plugin.php @@ -69,12 +69,25 @@ public function setupConvertKitPlugin($I, $options = false) // If supplied options are an array, merge them with the defaults. if (is_array($options)) { $options = array_merge($defaults, $options); + } else { + $options = $defaults; } // Define settings in options table. $I->haveOptionInDatabase('_wp_convertkit_settings', $options); } + public function setupConvertKitPluginAPIKeyNoData($I) + { + $I->setupConvertKitPlugin($I, [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY_NO_DATA'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ]); + } + /** * Helper method to define cached Resources (Forms, Landing Pages, Posts, Products and Tags), * directly into the database, instead of querying the API for them via the Resource classes. diff --git a/tests/acceptance/broadcasts/blocks/PageBlockBroadcastsCest.php b/tests/acceptance/broadcasts/blocks/PageBlockBroadcastsCest.php index 145b2afcf..cbe922b03 100644 --- a/tests/acceptance/broadcasts/blocks/PageBlockBroadcastsCest.php +++ b/tests/acceptance/broadcasts/blocks/PageBlockBroadcastsCest.php @@ -58,7 +58,7 @@ public function testBroadcastsBlockWhenNoAPIKey(AcceptanceTester $I) public function testBroadcastsBlockWithNoBroadcasts(AcceptanceTester $I) { // Setup Plugin with API keys for ConvertKit Account that has no Broadcasts. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA']); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Gutenberg editor. @@ -109,7 +109,7 @@ public function testBroadcastsBlockWithNoBroadcasts(AcceptanceTester $I) public function testBroadcastsBlockRefreshButton(AcceptanceTester $I) { // Setup Plugin with API keys for ConvertKit Account that has no Broadcasts. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA']); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/blocks/PageBlockFormCest.php b/tests/acceptance/forms/blocks/PageBlockFormCest.php index fc5841dd7..c91401ebb 100644 --- a/tests/acceptance/forms/blocks/PageBlockFormCest.php +++ b/tests/acceptance/forms/blocks/PageBlockFormCest.php @@ -539,7 +539,7 @@ public function testFormBlockWhenNoAPIKey(AcceptanceTester $I) public function testFormBlockWhenNoForms(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Gutenberg editor. @@ -587,7 +587,7 @@ public function testFormBlockWhenNoForms(AcceptanceTester $I) public function testFormBlockRefreshButton(AcceptanceTester $I) { // Setup Plugin with API keys for ConvertKit Account that has no Broadcasts. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA']); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php b/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php index a63cb6ecc..5c7b0bda6 100644 --- a/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php +++ b/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php @@ -389,7 +389,7 @@ public function testFormTriggerBlockWhenNoAPIKey(AcceptanceTester $I) public function testFormTriggerBlockWhenNoForms(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Gutenberg editor. @@ -437,7 +437,7 @@ public function testFormTriggerBlockWhenNoForms(AcceptanceTester $I) public function testFormTriggerBlockRefreshButton(AcceptanceTester $I) { // Setup Plugin with API keys for ConvertKit Account that has no Broadcasts. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA']); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/general/NonInlineFormCest.php b/tests/acceptance/forms/general/NonInlineFormCest.php index bde2748fa..08fdf6a48 100644 --- a/tests/acceptance/forms/general/NonInlineFormCest.php +++ b/tests/acceptance/forms/general/NonInlineFormCest.php @@ -30,7 +30,7 @@ public function _before(AcceptanceTester $I) public function testSettingsWhenNoNonInlineForms(AcceptanceTester $I) { // Setup Plugin with API Keys for an account that has no non-inline forms. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA']); + $I->setupConvertKitPluginAPIKeyNoData($I); } /** diff --git a/tests/acceptance/forms/general/PageNoFormCest.php b/tests/acceptance/forms/general/PageNoFormCest.php index c042a2bc1..6249506f8 100644 --- a/tests/acceptance/forms/general/PageNoFormCest.php +++ b/tests/acceptance/forms/general/PageNoFormCest.php @@ -17,7 +17,7 @@ public function _before(AcceptanceTester $I) { // Activate and Setup ConvertKit plugin. $I->activateConvertKitPlugin($I); - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Navigate to Pages > Add New. diff --git a/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php b/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php index 5e0de512d..77da29e18 100644 --- a/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php +++ b/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php @@ -412,7 +412,7 @@ public function testFormShortcodeWhenNoAPIKey(AcceptanceTester $I) public function testFormShortcodeWhenNoForms(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Classic Editor. diff --git a/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php b/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php index 78a7e49a7..ab2a5e7ab 100644 --- a/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php +++ b/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php @@ -330,7 +330,7 @@ public function testFormTriggerShortcodeWhenNoAPIKey(AcceptanceTester $I) public function testFormTriggerShortcodeWhenNoForms(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Classic Editor. diff --git a/tests/acceptance/integrations/other/ContactForm7FormCest.php b/tests/acceptance/integrations/other/ContactForm7FormCest.php index 51e6f3f05..3abc166c4 100644 --- a/tests/acceptance/integrations/other/ContactForm7FormCest.php +++ b/tests/acceptance/integrations/other/ContactForm7FormCest.php @@ -50,7 +50,7 @@ public function testSettingsContactForm7WhenNoAPIKeyAndSecret(AcceptanceTester $ public function testSettingsContactForm7WhenNoForms(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Load Contact Form 7 Plugin Settings. @@ -149,7 +149,7 @@ function($I) { public function testSettingsContactForm7CreatorNetworkRecommendationsOptionWhenDisabledOnConvertKitAccount(AcceptanceTester $I) { // Setup ConvertKit Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResources($I); // Create Contact Form 7 Form. diff --git a/tests/acceptance/integrations/other/ForminatorCest.php b/tests/acceptance/integrations/other/ForminatorCest.php index 3588f6804..cd651966f 100644 --- a/tests/acceptance/integrations/other/ForminatorCest.php +++ b/tests/acceptance/integrations/other/ForminatorCest.php @@ -50,7 +50,7 @@ public function testSettingsForminatorWhenNoAPIKeyAndSecret(AcceptanceTester $I) public function testSettingsForminatorWhenNoForms(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Load Forminator Plugin Settings. @@ -151,7 +151,7 @@ function($I) { public function testSettingsForminatorCreatorNetworkRecommendationsWhenDisabledOnConvertKitAccount(AcceptanceTester $I) { // Setup ConvertKit Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResources($I); // Create Forminator Form. diff --git a/tests/acceptance/products/PageBlockProductCest.php b/tests/acceptance/products/PageBlockProductCest.php index c6a897e7d..95a7ed69a 100644 --- a/tests/acceptance/products/PageBlockProductCest.php +++ b/tests/acceptance/products/PageBlockProductCest.php @@ -294,7 +294,7 @@ public function testProductBlockWhenNoAPIKey(AcceptanceTester $I) public function testProductBlockWhenNoProducts(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Gutenberg editor. @@ -342,7 +342,7 @@ public function testProductBlockWhenNoProducts(AcceptanceTester $I) public function testProductBlockRefreshButton(AcceptanceTester $I) { // Setup Plugin with API keys for ConvertKit Account that has no Products. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA']); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/products/PageShortcodeProductCest.php b/tests/acceptance/products/PageShortcodeProductCest.php index ab7d2009b..6ffbd5d65 100644 --- a/tests/acceptance/products/PageShortcodeProductCest.php +++ b/tests/acceptance/products/PageShortcodeProductCest.php @@ -330,7 +330,7 @@ public function testProductShortcodeWhenNoAPIKey(AcceptanceTester $I) public function testProductShortcodeWhenNoProducts(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], '', '', ''); + $I->setupConvertKitPluginAPIKeyNoData($I); $I->setupConvertKitPluginResourcesNoData($I); // Add a Page using the Classic Editor. diff --git a/tests/acceptance/restrict-content/RestrictContentFilterPageCest.php b/tests/acceptance/restrict-content/RestrictContentFilterPageCest.php index 1bd3e89d4..649bf8da6 100644 --- a/tests/acceptance/restrict-content/RestrictContentFilterPageCest.php +++ b/tests/acceptance/restrict-content/RestrictContentFilterPageCest.php @@ -49,7 +49,7 @@ public function testNoFilterDisplayedWhenNoAPIKeys(AcceptanceTester $I) public function testNoFilterDisplayedWhenNoResources(AcceptanceTester $I) { // Setup Plugin using API keys that have no resources. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA']); + $I->setupConvertKitPluginAPIKeyNoData($I); // Navigate to Pages. $I->amOnAdminPage('edit.php?post_type=page'); diff --git a/tests/acceptance/restrict-content/RestrictContentFilterPostCest.php b/tests/acceptance/restrict-content/RestrictContentFilterPostCest.php index c865d19ff..2554bf7ba 100644 --- a/tests/acceptance/restrict-content/RestrictContentFilterPostCest.php +++ b/tests/acceptance/restrict-content/RestrictContentFilterPostCest.php @@ -49,7 +49,7 @@ public function testNoFilterDisplayedWhenNoAPIKeys(AcceptanceTester $I) public function testNoFilterDisplayedWhenNoResources(AcceptanceTester $I) { // Setup Plugin using API keys that have no resources. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA']); + $I->setupConvertKitPluginAPIKeyNoData($I); // Navigate to Posts. $I->amOnAdminPage('edit.php?post_type=post'); diff --git a/tests/acceptance/restrict-content/RestrictContentSetupCest.php b/tests/acceptance/restrict-content/RestrictContentSetupCest.php index 36e2caa42..156c6b907 100644 --- a/tests/acceptance/restrict-content/RestrictContentSetupCest.php +++ b/tests/acceptance/restrict-content/RestrictContentSetupCest.php @@ -95,7 +95,7 @@ public function testNoMemberContentWizardDashboardSubmenuItem(AcceptanceTester $ public function testAddNewMemberContentDisplaysCTAWhenNoResources(AcceptanceTester $I) { // Setup Plugin using API keys that have no resources. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY_NO_DATA'], $_ENV['CONVERTKIT_API_SECRET_NO_DATA']); + $I->setupConvertKitPluginAPIKeyNoData($I); // Navigate to Pages. $I->amOnAdminPage('edit.php?post_type=page'); From b90b6cf2dbd80b296adb5e2d34bcdb499fd16284 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 17:11:06 +0000 Subject: [PATCH 04/11] Use new `setupConvertKitPluginNoForms` method --- tests/_support/Helper/Acceptance/Plugin.php | 9 +++++++++ .../forms/blocks/PageBlockFormTriggerCest.php | 16 ++++++++-------- .../PageBlockFormatterFormTriggerCest.php | 6 +++--- .../acceptance/forms/general/PageFormCest.php | 2 +- .../forms/general/PageLandingPageCest.php | 2 +- .../acceptance/forms/general/PostFormCest.php | 2 +- .../forms/general/PostLandingPageCest.php | 2 +- .../forms/general/WidgetFormCest.php | 2 +- .../forms/shortcodes/PageShortcodeFormCest.php | 18 +++++++++--------- .../PageShortcodeFormTriggerCest.php | 14 +++++++------- tests/acceptance/general/ReviewRequestCest.php | 2 +- .../elementor/ElementorFormCest.php | 2 +- .../woocommerce/WooCommerceProductFormCest.php | 6 +++--- .../PageBlockFormatterProductLinkCest.php | 6 +++--- .../products/PageBlockProductCest.php | 14 +++++++------- .../products/PageShortcodeProductCest.php | 14 +++++++------- .../tags/PageShortcodeCustomContentCest.php | 2 +- tests/acceptance/tags/PageTagCest.php | 2 +- 18 files changed, 65 insertions(+), 56 deletions(-) diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php index 180019c30..2ae86f810 100644 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ b/tests/_support/Helper/Acceptance/Plugin.php @@ -88,6 +88,15 @@ public function setupConvertKitPluginAPIKeyNoData($I) ]); } + public function setupConvertKitPluginNoForms($I) + { + $I->setupConvertKitPlugin($I, [ + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ]); + } + /** * Helper method to define cached Resources (Forms, Landing Pages, Posts, Products and Tags), * directly into the database, instead of querying the API for them via the Resource classes. diff --git a/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php b/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php index 5c7b0bda6..cd1a4329a 100644 --- a/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php +++ b/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php @@ -28,7 +28,7 @@ public function _before(AcceptanceTester $I) public function testFormTriggerBlockWithValidFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -70,7 +70,7 @@ public function testFormTriggerBlockWithValidFormParameter(AcceptanceTester $I) public function testFormTriggerBlocksWithValidFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -126,7 +126,7 @@ public function testFormTriggerBlocksWithValidFormParameter(AcceptanceTester $I) public function testFormTriggerBlockWithNoFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -169,7 +169,7 @@ public function testFormTriggerBlockWithNoFormParameter(AcceptanceTester $I) public function testFormTriggerBlockWithTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -203,7 +203,7 @@ public function testFormTriggerBlockWithTextParameter(AcceptanceTester $I) public function testFormTriggerBlockWithBlankTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -237,7 +237,7 @@ public function testFormTriggerBlockWithBlankTextParameter(AcceptanceTester $I) public function testFormTriggerBlockWithThemeColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -281,7 +281,7 @@ public function testFormTriggerBlockWithThemeColorParameters(AcceptanceTester $I public function testFormTriggerBlockWithHexColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -323,7 +323,7 @@ public function testFormTriggerBlockWithHexColorParameters(AcceptanceTester $I) public function testFormTriggerBlockParameterEscaping(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define a 'bad' block. This is difficult to do in Gutenberg, but let's assume it's possible. diff --git a/tests/acceptance/forms/blocks/PageBlockFormatterFormTriggerCest.php b/tests/acceptance/forms/blocks/PageBlockFormatterFormTriggerCest.php index 855d7ac19..8b54de77c 100644 --- a/tests/acceptance/forms/blocks/PageBlockFormatterFormTriggerCest.php +++ b/tests/acceptance/forms/blocks/PageBlockFormatterFormTriggerCest.php @@ -28,7 +28,7 @@ public function _before(AcceptanceTester $I) public function testFormTriggerFormatterWithModalForm(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -82,7 +82,7 @@ public function testFormTriggerFormatterWithModalForm(AcceptanceTester $I) public function testFormTriggerFormatterToggleFormSelection(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -142,7 +142,7 @@ public function testFormTriggerFormatterToggleFormSelection(AcceptanceTester $I) public function testFormTriggerFormatterWithNoForm(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/general/PageFormCest.php b/tests/acceptance/forms/general/PageFormCest.php index 3e251b9c5..f12d3c60a 100644 --- a/tests/acceptance/forms/general/PageFormCest.php +++ b/tests/acceptance/forms/general/PageFormCest.php @@ -53,7 +53,7 @@ public function testAccessibility(AcceptanceTester $I) public function testAddNewPageUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin(AcceptanceTester $I) { // Setup ConvertKit plugin with no default Forms configured. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/general/PageLandingPageCest.php b/tests/acceptance/forms/general/PageLandingPageCest.php index 6564112ab..a70587b24 100644 --- a/tests/acceptance/forms/general/PageLandingPageCest.php +++ b/tests/acceptance/forms/general/PageLandingPageCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); } diff --git a/tests/acceptance/forms/general/PostFormCest.php b/tests/acceptance/forms/general/PostFormCest.php index 91c639511..672cd695d 100644 --- a/tests/acceptance/forms/general/PostFormCest.php +++ b/tests/acceptance/forms/general/PostFormCest.php @@ -52,7 +52,7 @@ public function testAccessibility(AcceptanceTester $I) public function testAddNewPostUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin(AcceptanceTester $I) { // Setup Plugin, without defining default Forms. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Post using the Gutenberg editor. diff --git a/tests/acceptance/forms/general/PostLandingPageCest.php b/tests/acceptance/forms/general/PostLandingPageCest.php index 4f8a173af..bfdff4cf6 100644 --- a/tests/acceptance/forms/general/PostLandingPageCest.php +++ b/tests/acceptance/forms/general/PostLandingPageCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); } diff --git a/tests/acceptance/forms/general/WidgetFormCest.php b/tests/acceptance/forms/general/WidgetFormCest.php index 2cb773882..ea146c9c3 100644 --- a/tests/acceptance/forms/general/WidgetFormCest.php +++ b/tests/acceptance/forms/general/WidgetFormCest.php @@ -22,7 +22,7 @@ class WidgetFormCest public function _before(AcceptanceTester $I) { $I->activateConvertKitPlugin($I); - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Activate an older WordPress Theme that supports Widgets. diff --git a/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php b/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php index 77da29e18..7c1be4b95 100644 --- a/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php +++ b/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testFormShortcodeInVisualEditorWithValidFormParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); // Don't specify default forms. + $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -73,7 +73,7 @@ public function testFormShortcodeInVisualEditorWithValidFormParameter(Acceptance public function testFormShortcodeInTextEditorWithValidFormParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); // Don't specify default forms. + $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -116,7 +116,7 @@ public function testFormShortcodeInTextEditorWithValidFormParameter(AcceptanceTe public function testFormShortcodeWithInvalidFormParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); // Don't specify default forms. + $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -147,7 +147,7 @@ public function testFormShortcodeWithInvalidFormParameter(AcceptanceTester $I) public function testFormShortcodeWithValidIDParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); // Don't specify default forms. + $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -179,7 +179,7 @@ public function testFormShortcodeWithValidIDParameter(AcceptanceTester $I) public function testFormShortcodeWithInvalidIDParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); // Don't specify default forms. + $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -217,7 +217,7 @@ public function testFormShortcodeWithInvalidIDParameter(AcceptanceTester $I) public function testFormShortcodeWhenFormDoesNotExistInPluginFormResources(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); // Don't specify default forms. + $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Update the Form Resource option table value to only contain a dummy Form with an ID @@ -262,7 +262,7 @@ public function testFormShortcodeWhenFormDoesNotExistInPluginFormResources(Accep public function testFormShortcodeWithValidLegacyFormParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); // Don't specify default forms. + $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -293,7 +293,7 @@ public function testFormShortcodeWithValidLegacyFormParameter(AcceptanceTester $ public function testFormShortcodeWithValidLegacyIDParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); // Don't specify default forms. + $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -326,7 +326,7 @@ public function testFormShortcodeWithValidLegacyIDParameter(AcceptanceTester $I) public function testFormShortcodeWithValidLegacyFormShortcodeFromConvertKitApp(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); // Don't specify default forms. + $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. diff --git a/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php b/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php index ab2a5e7ab..13d1cc3a5 100644 --- a/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php +++ b/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testFormTriggerShortcodeInVisualEditorWithValidFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -63,7 +63,7 @@ public function testFormTriggerShortcodeInVisualEditorWithValidFormParameter(Acc public function testFormTriggerShortcodeInTextEditorWithValidFormTriggerParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -96,7 +96,7 @@ public function testFormTriggerShortcodeInTextEditorWithValidFormTriggerParamete public function testFormTriggerShortcodeWithInvalidFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -127,7 +127,7 @@ public function testFormTriggerShortcodeWithInvalidFormParameter(AcceptanceTeste public function testFormTriggerShortcodeInVisualEditorWithTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -161,7 +161,7 @@ public function testFormTriggerShortcodeInVisualEditorWithTextParameter(Acceptan public function testFormTriggerShortcodeInVisualEditorWithBlankTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -195,7 +195,7 @@ public function testFormTriggerShortcodeInVisualEditorWithBlankTextParameter(Acc public function testFormTriggerShortcodeWithHexColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -237,7 +237,7 @@ public function testFormTriggerShortcodeWithHexColorParameters(AcceptanceTester public function testFormTriggerShortcodeParameterEscaping(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define a 'bad' shortcode. diff --git a/tests/acceptance/general/ReviewRequestCest.php b/tests/acceptance/general/ReviewRequestCest.php index 1bd20158d..383ce4fd3 100644 --- a/tests/acceptance/general/ReviewRequestCest.php +++ b/tests/acceptance/general/ReviewRequestCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testReviewRequestOnSaveSettings(AcceptanceTester $I) { // Setup Plugin, without defining default Forms. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); // Go to the Plugin's Settings Screen. $I->loadConvertKitSettingsGeneralScreen($I); diff --git a/tests/acceptance/integrations/elementor/ElementorFormCest.php b/tests/acceptance/integrations/elementor/ElementorFormCest.php index 83328d8a2..d62a5b0e5 100644 --- a/tests/acceptance/integrations/elementor/ElementorFormCest.php +++ b/tests/acceptance/integrations/elementor/ElementorFormCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateThirdPartyPlugin($I, 'elementor'); // Setup Plugin, without defining default Forms. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); } diff --git a/tests/acceptance/integrations/woocommerce/WooCommerceProductFormCest.php b/tests/acceptance/integrations/woocommerce/WooCommerceProductFormCest.php index 2d325e906..4f7ead8cb 100644 --- a/tests/acceptance/integrations/woocommerce/WooCommerceProductFormCest.php +++ b/tests/acceptance/integrations/woocommerce/WooCommerceProductFormCest.php @@ -31,7 +31,7 @@ public function _before(AcceptanceTester $I) public function testAddNewProductUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Navigate to Products > Add New. @@ -153,7 +153,7 @@ public function testAddNewProductUsingDefinedForm(AcceptanceTester $I) public function testAddNewProductUsingFormShortcodeInVisualEditor(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Product using the Classic Editor. @@ -196,7 +196,7 @@ public function testAddNewProductUsingFormShortcodeInVisualEditor(AcceptanceTest public function testAddNewProductUsingFormShortcodeInTextEditor(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Product using the Classic Editor. diff --git a/tests/acceptance/products/PageBlockFormatterProductLinkCest.php b/tests/acceptance/products/PageBlockFormatterProductLinkCest.php index a384f522f..3b4472ba4 100644 --- a/tests/acceptance/products/PageBlockFormatterProductLinkCest.php +++ b/tests/acceptance/products/PageBlockFormatterProductLinkCest.php @@ -28,7 +28,7 @@ public function _before(AcceptanceTester $I) public function testProductLinkFormatter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -78,7 +78,7 @@ public function testProductLinkFormatter(AcceptanceTester $I) public function testProductLinkFormatterToggleProductSelection(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -138,7 +138,7 @@ public function testProductLinkFormatterToggleProductSelection(AcceptanceTester public function testProductLinkFormatterWithNoProduct(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/products/PageBlockProductCest.php b/tests/acceptance/products/PageBlockProductCest.php index 95a7ed69a..26812b13c 100644 --- a/tests/acceptance/products/PageBlockProductCest.php +++ b/tests/acceptance/products/PageBlockProductCest.php @@ -28,7 +28,7 @@ public function _before(AcceptanceTester $I) public function testProductBlockWithValidProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -70,7 +70,7 @@ public function testProductBlockWithValidProductParameter(AcceptanceTester $I) public function testProductBlockWithNoProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -113,7 +113,7 @@ public function testProductBlockWithNoProductParameter(AcceptanceTester $I) public function testProductBlockWithTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -147,7 +147,7 @@ public function testProductBlockWithTextParameter(AcceptanceTester $I) public function testProductBlockWithBlankTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -181,7 +181,7 @@ public function testProductBlockWithBlankTextParameter(AcceptanceTester $I) public function testProductBlockWithThemeColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -225,7 +225,7 @@ public function testProductBlockWithThemeColorParameters(AcceptanceTester $I) public function testProductBlockWithHexColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -385,7 +385,7 @@ public function testProductBlockRefreshButton(AcceptanceTester $I) public function testProductBlockParameterEscaping(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define a 'bad' block. This is difficult to do in Gutenberg, but let's assume it's possible. diff --git a/tests/acceptance/products/PageShortcodeProductCest.php b/tests/acceptance/products/PageShortcodeProductCest.php index 6ffbd5d65..5c554fe84 100644 --- a/tests/acceptance/products/PageShortcodeProductCest.php +++ b/tests/acceptance/products/PageShortcodeProductCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testProductShortcodeInVisualEditorWithValidProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -63,7 +63,7 @@ public function testProductShortcodeInVisualEditorWithValidProductParameter(Acce public function testProductShortcodeInTextEditorWithValidProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -96,7 +96,7 @@ public function testProductShortcodeInTextEditorWithValidProductParameter(Accept public function testProductShortcodeWithInvalidProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -127,7 +127,7 @@ public function testProductShortcodeWithInvalidProductParameter(AcceptanceTester public function testProductShortcodeInVisualEditorWithTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -161,7 +161,7 @@ public function testProductShortcodeInVisualEditorWithTextParameter(AcceptanceTe public function testProductShortcodeInVisualEditorWithBlankTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -195,7 +195,7 @@ public function testProductShortcodeInVisualEditorWithBlankTextParameter(Accepta public function testProductShortcodeWithHexColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -237,7 +237,7 @@ public function testProductShortcodeWithHexColorParameters(AcceptanceTester $I) public function testProductShortcodeParameterEscaping(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); // Define a 'bad' shortcode. diff --git a/tests/acceptance/tags/PageShortcodeCustomContentCest.php b/tests/acceptance/tags/PageShortcodeCustomContentCest.php index e4dc8cdf0..21bc9c28a 100644 --- a/tests/acceptance/tags/PageShortcodeCustomContentCest.php +++ b/tests/acceptance/tags/PageShortcodeCustomContentCest.php @@ -18,7 +18,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); } diff --git a/tests/acceptance/tags/PageTagCest.php b/tests/acceptance/tags/PageTagCest.php index 067a5ae94..1c3bb7c53 100644 --- a/tests/acceptance/tags/PageTagCest.php +++ b/tests/acceptance/tags/PageTagCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', '', ''); + $I->setupConvertKitPluginNoForms($I); $I->setupConvertKitPluginResources($I); } From 5f93a321cc50b7f5290f4f7afb838b88108731cc Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 17:12:22 +0000 Subject: [PATCH 05/11] Rename method to `setupConvertKitPluginNoDefaultForms` --- tests/_support/Helper/Acceptance/Plugin.php | 2 +- .../forms/blocks/PageBlockFormTriggerCest.php | 16 ++++++++-------- .../PageBlockFormatterFormTriggerCest.php | 6 +++--- .../acceptance/forms/general/PageFormCest.php | 2 +- .../forms/general/PageLandingPageCest.php | 2 +- .../acceptance/forms/general/PostFormCest.php | 2 +- .../forms/general/PostLandingPageCest.php | 2 +- .../forms/general/WidgetFormCest.php | 2 +- .../forms/shortcodes/PageShortcodeFormCest.php | 18 +++++++++--------- .../PageShortcodeFormTriggerCest.php | 14 +++++++------- .../general/PluginSettingsGeneralCest.php | 2 +- tests/acceptance/general/ReviewRequestCest.php | 2 +- .../elementor/ElementorFormCest.php | 2 +- .../woocommerce/WooCommerceProductFormCest.php | 6 +++--- .../PageBlockFormatterProductLinkCest.php | 6 +++--- .../products/PageBlockProductCest.php | 14 +++++++------- .../products/PageShortcodeProductCest.php | 14 +++++++------- .../tags/PageShortcodeCustomContentCest.php | 2 +- tests/acceptance/tags/PageTagCest.php | 2 +- 19 files changed, 58 insertions(+), 58 deletions(-) diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php index 2ae86f810..740d884d8 100644 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ b/tests/_support/Helper/Acceptance/Plugin.php @@ -88,7 +88,7 @@ public function setupConvertKitPluginAPIKeyNoData($I) ]); } - public function setupConvertKitPluginNoForms($I) + public function setupConvertKitPluginNoDefaultForms($I) { $I->setupConvertKitPlugin($I, [ 'post_form' => '', diff --git a/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php b/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php index cd1a4329a..ef27f0d9d 100644 --- a/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php +++ b/tests/acceptance/forms/blocks/PageBlockFormTriggerCest.php @@ -28,7 +28,7 @@ public function _before(AcceptanceTester $I) public function testFormTriggerBlockWithValidFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -70,7 +70,7 @@ public function testFormTriggerBlockWithValidFormParameter(AcceptanceTester $I) public function testFormTriggerBlocksWithValidFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -126,7 +126,7 @@ public function testFormTriggerBlocksWithValidFormParameter(AcceptanceTester $I) public function testFormTriggerBlockWithNoFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -169,7 +169,7 @@ public function testFormTriggerBlockWithNoFormParameter(AcceptanceTester $I) public function testFormTriggerBlockWithTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -203,7 +203,7 @@ public function testFormTriggerBlockWithTextParameter(AcceptanceTester $I) public function testFormTriggerBlockWithBlankTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -237,7 +237,7 @@ public function testFormTriggerBlockWithBlankTextParameter(AcceptanceTester $I) public function testFormTriggerBlockWithThemeColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -281,7 +281,7 @@ public function testFormTriggerBlockWithThemeColorParameters(AcceptanceTester $I public function testFormTriggerBlockWithHexColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -323,7 +323,7 @@ public function testFormTriggerBlockWithHexColorParameters(AcceptanceTester $I) public function testFormTriggerBlockParameterEscaping(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define a 'bad' block. This is difficult to do in Gutenberg, but let's assume it's possible. diff --git a/tests/acceptance/forms/blocks/PageBlockFormatterFormTriggerCest.php b/tests/acceptance/forms/blocks/PageBlockFormatterFormTriggerCest.php index 8b54de77c..95044c41f 100644 --- a/tests/acceptance/forms/blocks/PageBlockFormatterFormTriggerCest.php +++ b/tests/acceptance/forms/blocks/PageBlockFormatterFormTriggerCest.php @@ -28,7 +28,7 @@ public function _before(AcceptanceTester $I) public function testFormTriggerFormatterWithModalForm(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -82,7 +82,7 @@ public function testFormTriggerFormatterWithModalForm(AcceptanceTester $I) public function testFormTriggerFormatterToggleFormSelection(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -142,7 +142,7 @@ public function testFormTriggerFormatterToggleFormSelection(AcceptanceTester $I) public function testFormTriggerFormatterWithNoForm(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/general/PageFormCest.php b/tests/acceptance/forms/general/PageFormCest.php index f12d3c60a..19cec62d8 100644 --- a/tests/acceptance/forms/general/PageFormCest.php +++ b/tests/acceptance/forms/general/PageFormCest.php @@ -53,7 +53,7 @@ public function testAccessibility(AcceptanceTester $I) public function testAddNewPageUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin(AcceptanceTester $I) { // Setup ConvertKit plugin with no default Forms configured. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/general/PageLandingPageCest.php b/tests/acceptance/forms/general/PageLandingPageCest.php index a70587b24..3c5687e7a 100644 --- a/tests/acceptance/forms/general/PageLandingPageCest.php +++ b/tests/acceptance/forms/general/PageLandingPageCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); } diff --git a/tests/acceptance/forms/general/PostFormCest.php b/tests/acceptance/forms/general/PostFormCest.php index 672cd695d..64baef1cb 100644 --- a/tests/acceptance/forms/general/PostFormCest.php +++ b/tests/acceptance/forms/general/PostFormCest.php @@ -52,7 +52,7 @@ public function testAccessibility(AcceptanceTester $I) public function testAddNewPostUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin(AcceptanceTester $I) { // Setup Plugin, without defining default Forms. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Post using the Gutenberg editor. diff --git a/tests/acceptance/forms/general/PostLandingPageCest.php b/tests/acceptance/forms/general/PostLandingPageCest.php index bfdff4cf6..40b47c7b0 100644 --- a/tests/acceptance/forms/general/PostLandingPageCest.php +++ b/tests/acceptance/forms/general/PostLandingPageCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); } diff --git a/tests/acceptance/forms/general/WidgetFormCest.php b/tests/acceptance/forms/general/WidgetFormCest.php index ea146c9c3..be373aac0 100644 --- a/tests/acceptance/forms/general/WidgetFormCest.php +++ b/tests/acceptance/forms/general/WidgetFormCest.php @@ -22,7 +22,7 @@ class WidgetFormCest public function _before(AcceptanceTester $I) { $I->activateConvertKitPlugin($I); - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Activate an older WordPress Theme that supports Widgets. diff --git a/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php b/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php index 7c1be4b95..518a69f97 100644 --- a/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php +++ b/tests/acceptance/forms/shortcodes/PageShortcodeFormCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testFormShortcodeInVisualEditorWithValidFormParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. + $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -73,7 +73,7 @@ public function testFormShortcodeInVisualEditorWithValidFormParameter(Acceptance public function testFormShortcodeInTextEditorWithValidFormParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. + $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -116,7 +116,7 @@ public function testFormShortcodeInTextEditorWithValidFormParameter(AcceptanceTe public function testFormShortcodeWithInvalidFormParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. + $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -147,7 +147,7 @@ public function testFormShortcodeWithInvalidFormParameter(AcceptanceTester $I) public function testFormShortcodeWithValidIDParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. + $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -179,7 +179,7 @@ public function testFormShortcodeWithValidIDParameter(AcceptanceTester $I) public function testFormShortcodeWithInvalidIDParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. + $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -217,7 +217,7 @@ public function testFormShortcodeWithInvalidIDParameter(AcceptanceTester $I) public function testFormShortcodeWhenFormDoesNotExistInPluginFormResources(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. + $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Update the Form Resource option table value to only contain a dummy Form with an ID @@ -262,7 +262,7 @@ public function testFormShortcodeWhenFormDoesNotExistInPluginFormResources(Accep public function testFormShortcodeWithValidLegacyFormParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. + $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -293,7 +293,7 @@ public function testFormShortcodeWithValidLegacyFormParameter(AcceptanceTester $ public function testFormShortcodeWithValidLegacyIDParameter(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. + $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -326,7 +326,7 @@ public function testFormShortcodeWithValidLegacyIDParameter(AcceptanceTester $I) public function testFormShortcodeWithValidLegacyFormShortcodeFromConvertKitApp(AcceptanceTester $I) { // Setup Plugin. - $I->setupConvertKitPluginNoForms($I); // Don't specify default forms. + $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. diff --git a/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php b/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php index 13d1cc3a5..eadbb36cc 100644 --- a/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php +++ b/tests/acceptance/forms/shortcodes/PageShortcodeFormTriggerCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testFormTriggerShortcodeInVisualEditorWithValidFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -63,7 +63,7 @@ public function testFormTriggerShortcodeInVisualEditorWithValidFormParameter(Acc public function testFormTriggerShortcodeInTextEditorWithValidFormTriggerParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -96,7 +96,7 @@ public function testFormTriggerShortcodeInTextEditorWithValidFormTriggerParamete public function testFormTriggerShortcodeWithInvalidFormParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -127,7 +127,7 @@ public function testFormTriggerShortcodeWithInvalidFormParameter(AcceptanceTeste public function testFormTriggerShortcodeInVisualEditorWithTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -161,7 +161,7 @@ public function testFormTriggerShortcodeInVisualEditorWithTextParameter(Acceptan public function testFormTriggerShortcodeInVisualEditorWithBlankTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -195,7 +195,7 @@ public function testFormTriggerShortcodeInVisualEditorWithBlankTextParameter(Acc public function testFormTriggerShortcodeWithHexColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -237,7 +237,7 @@ public function testFormTriggerShortcodeWithHexColorParameters(AcceptanceTester public function testFormTriggerShortcodeParameterEscaping(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define a 'bad' shortcode. diff --git a/tests/acceptance/general/PluginSettingsGeneralCest.php b/tests/acceptance/general/PluginSettingsGeneralCest.php index dd602bb00..69b1e2d02 100644 --- a/tests/acceptance/general/PluginSettingsGeneralCest.php +++ b/tests/acceptance/general/PluginSettingsGeneralCest.php @@ -221,7 +221,7 @@ public function testChangeDefaultFormSettingAndPreviewFormLinks(AcceptanceTester ); // Setup Plugin, without defining default Forms. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', ''); + $I->setupConvertKitPluginNoDefaultForms($I); // Go to the Plugin's Settings Screen. $I->loadConvertKitSettingsGeneralScreen($I); diff --git a/tests/acceptance/general/ReviewRequestCest.php b/tests/acceptance/general/ReviewRequestCest.php index 383ce4fd3..682a99258 100644 --- a/tests/acceptance/general/ReviewRequestCest.php +++ b/tests/acceptance/general/ReviewRequestCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testReviewRequestOnSaveSettings(AcceptanceTester $I) { // Setup Plugin, without defining default Forms. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); // Go to the Plugin's Settings Screen. $I->loadConvertKitSettingsGeneralScreen($I); diff --git a/tests/acceptance/integrations/elementor/ElementorFormCest.php b/tests/acceptance/integrations/elementor/ElementorFormCest.php index d62a5b0e5..e35031c30 100644 --- a/tests/acceptance/integrations/elementor/ElementorFormCest.php +++ b/tests/acceptance/integrations/elementor/ElementorFormCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateThirdPartyPlugin($I, 'elementor'); // Setup Plugin, without defining default Forms. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); } diff --git a/tests/acceptance/integrations/woocommerce/WooCommerceProductFormCest.php b/tests/acceptance/integrations/woocommerce/WooCommerceProductFormCest.php index 4f7ead8cb..d4c57f5b6 100644 --- a/tests/acceptance/integrations/woocommerce/WooCommerceProductFormCest.php +++ b/tests/acceptance/integrations/woocommerce/WooCommerceProductFormCest.php @@ -31,7 +31,7 @@ public function _before(AcceptanceTester $I) public function testAddNewProductUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Navigate to Products > Add New. @@ -153,7 +153,7 @@ public function testAddNewProductUsingDefinedForm(AcceptanceTester $I) public function testAddNewProductUsingFormShortcodeInVisualEditor(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Product using the Classic Editor. @@ -196,7 +196,7 @@ public function testAddNewProductUsingFormShortcodeInVisualEditor(AcceptanceTest public function testAddNewProductUsingFormShortcodeInTextEditor(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Product using the Classic Editor. diff --git a/tests/acceptance/products/PageBlockFormatterProductLinkCest.php b/tests/acceptance/products/PageBlockFormatterProductLinkCest.php index 3b4472ba4..91c0f8904 100644 --- a/tests/acceptance/products/PageBlockFormatterProductLinkCest.php +++ b/tests/acceptance/products/PageBlockFormatterProductLinkCest.php @@ -28,7 +28,7 @@ public function _before(AcceptanceTester $I) public function testProductLinkFormatter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -78,7 +78,7 @@ public function testProductLinkFormatter(AcceptanceTester $I) public function testProductLinkFormatterToggleProductSelection(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -138,7 +138,7 @@ public function testProductLinkFormatterToggleProductSelection(AcceptanceTester public function testProductLinkFormatterWithNoProduct(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/products/PageBlockProductCest.php b/tests/acceptance/products/PageBlockProductCest.php index 26812b13c..0f0388d9e 100644 --- a/tests/acceptance/products/PageBlockProductCest.php +++ b/tests/acceptance/products/PageBlockProductCest.php @@ -28,7 +28,7 @@ public function _before(AcceptanceTester $I) public function testProductBlockWithValidProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -70,7 +70,7 @@ public function testProductBlockWithValidProductParameter(AcceptanceTester $I) public function testProductBlockWithNoProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -113,7 +113,7 @@ public function testProductBlockWithNoProductParameter(AcceptanceTester $I) public function testProductBlockWithTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -147,7 +147,7 @@ public function testProductBlockWithTextParameter(AcceptanceTester $I) public function testProductBlockWithBlankTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. @@ -181,7 +181,7 @@ public function testProductBlockWithBlankTextParameter(AcceptanceTester $I) public function testProductBlockWithThemeColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -225,7 +225,7 @@ public function testProductBlockWithThemeColorParameters(AcceptanceTester $I) public function testProductBlockWithHexColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -385,7 +385,7 @@ public function testProductBlockRefreshButton(AcceptanceTester $I) public function testProductBlockParameterEscaping(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define a 'bad' block. This is difficult to do in Gutenberg, but let's assume it's possible. diff --git a/tests/acceptance/products/PageShortcodeProductCest.php b/tests/acceptance/products/PageShortcodeProductCest.php index 5c554fe84..d2025e4f8 100644 --- a/tests/acceptance/products/PageShortcodeProductCest.php +++ b/tests/acceptance/products/PageShortcodeProductCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testProductShortcodeInVisualEditorWithValidProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -63,7 +63,7 @@ public function testProductShortcodeInVisualEditorWithValidProductParameter(Acce public function testProductShortcodeInTextEditorWithValidProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -96,7 +96,7 @@ public function testProductShortcodeInTextEditorWithValidProductParameter(Accept public function testProductShortcodeWithInvalidProductParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -127,7 +127,7 @@ public function testProductShortcodeWithInvalidProductParameter(AcceptanceTester public function testProductShortcodeInVisualEditorWithTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -161,7 +161,7 @@ public function testProductShortcodeInVisualEditorWithTextParameter(AcceptanceTe public function testProductShortcodeInVisualEditorWithBlankTextParameter(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Add a Page using the Classic Editor. @@ -195,7 +195,7 @@ public function testProductShortcodeInVisualEditorWithBlankTextParameter(Accepta public function testProductShortcodeWithHexColorParameters(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define colors. @@ -237,7 +237,7 @@ public function testProductShortcodeWithHexColorParameters(AcceptanceTester $I) public function testProductShortcodeParameterEscaping(AcceptanceTester $I) { // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); // Define a 'bad' shortcode. diff --git a/tests/acceptance/tags/PageShortcodeCustomContentCest.php b/tests/acceptance/tags/PageShortcodeCustomContentCest.php index 21bc9c28a..df3f63f0c 100644 --- a/tests/acceptance/tags/PageShortcodeCustomContentCest.php +++ b/tests/acceptance/tags/PageShortcodeCustomContentCest.php @@ -18,7 +18,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); } diff --git a/tests/acceptance/tags/PageTagCest.php b/tests/acceptance/tags/PageTagCest.php index 1c3bb7c53..1a39dae06 100644 --- a/tests/acceptance/tags/PageTagCest.php +++ b/tests/acceptance/tags/PageTagCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit Plugin with no default form specified. - $I->setupConvertKitPluginNoForms($I); + $I->setupConvertKitPluginNoDefaultForms($I); $I->setupConvertKitPluginResources($I); } From 33e33bb96a2a78b79df5029e6b5fd85b5c34afce Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 17:19:49 +0000 Subject: [PATCH 06/11] Use new `setupConvertKitPluginDisableJS` helper method --- tests/_support/Helper/Acceptance/Plugin.php | 18 +++++++++++++++ .../acceptance/forms/general/CPTFormCest.php | 2 +- .../acceptance/forms/general/PageFormCest.php | 6 ++++- .../acceptance/forms/general/PostFormCest.php | 6 ++++- .../general/RefreshResourcesButtonCest.php | 22 +++++++++---------- .../RestrictContentProductPageCest.php | 12 +++++----- .../RestrictContentProductPostCest.php | 14 ++++++------ .../RestrictContentSettingsCest.php | 2 +- .../RestrictContentSetupCest.php | 2 +- 9 files changed, 55 insertions(+), 29 deletions(-) diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php index 740d884d8..0c57c658b 100644 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ b/tests/_support/Helper/Acceptance/Plugin.php @@ -88,6 +88,17 @@ public function setupConvertKitPluginAPIKeyNoData($I) ]); } + public function setupConvertKitPluginFakeAPIKey($I) + { + $I->setupConvertKitPlugin($I, [ + 'api_key' => 'fakeApiKey' + 'api_secret' => 'fakeApiSecret', + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ]); + } + public function setupConvertKitPluginNoDefaultForms($I) { $I->setupConvertKitPlugin($I, [ @@ -97,6 +108,13 @@ public function setupConvertKitPluginNoDefaultForms($I) ]); } + public function setupConvertKitPluginDisableJS($I) + { + $I->setupConvertKitPlugin($I, [ + 'no_scripts' => 'on', + ]); + } + /** * Helper method to define cached Resources (Forms, Landing Pages, Posts, Products and Tags), * directly into the database, instead of querying the API for them via the Resource classes. diff --git a/tests/acceptance/forms/general/CPTFormCest.php b/tests/acceptance/forms/general/CPTFormCest.php index 5044f497c..285251c92 100644 --- a/tests/acceptance/forms/general/CPTFormCest.php +++ b/tests/acceptance/forms/general/CPTFormCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit plugin . - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET']); + $I->setupConvertKitPlugin($I); $I->setupConvertKitPluginResources($I); // Create a Custom Post Type called Articles, using the Custom Post Type UI Plugin. diff --git a/tests/acceptance/forms/general/PageFormCest.php b/tests/acceptance/forms/general/PageFormCest.php index 19cec62d8..d822d0390 100644 --- a/tests/acceptance/forms/general/PageFormCest.php +++ b/tests/acceptance/forms/general/PageFormCest.php @@ -130,7 +130,11 @@ public function testAddNewPageUsingDefaultForm(AcceptanceTester $I) public function testAddNewPageUsingDefaultLegacyForm(AcceptanceTester $I) { // Setup ConvertKit plugin to use legacy Form as default for Pages. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], '', ''); + $I->setupConvertKitPlugin($I, [ + 'page_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + 'post_form' => '', + 'product_form' => '' + ]); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/general/PostFormCest.php b/tests/acceptance/forms/general/PostFormCest.php index 64baef1cb..e1fd3ee84 100644 --- a/tests/acceptance/forms/general/PostFormCest.php +++ b/tests/acceptance/forms/general/PostFormCest.php @@ -129,7 +129,11 @@ public function testAddNewPostUsingDefaultForm(AcceptanceTester $I) public function testAddNewPostUsingDefaultLegacyForm(AcceptanceTester $I) { // Setup Plugin, without defining default Forms. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET'], '', $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], ''); + $I->setupConvertKitPlugin($I, [ + 'page_form' => '', + 'post_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + 'product_form' => '' + ]); $I->setupConvertKitPluginResources($I); // Add a Post using the Gutenberg editor. diff --git a/tests/acceptance/general/RefreshResourcesButtonCest.php b/tests/acceptance/general/RefreshResourcesButtonCest.php index 5da818165..0fd7e195e 100644 --- a/tests/acceptance/general/RefreshResourcesButtonCest.php +++ b/tests/acceptance/general/RefreshResourcesButtonCest.php @@ -31,7 +31,7 @@ public function _before(AcceptanceTester $I) public function testRefreshResourcesOnPage(AcceptanceTester $I) { // Setup ConvertKit Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET']); + $I->setupConvertKitPlugin($I); // Navigate to Pages > Add New. $I->amOnAdminPage('post-new.php?post_type=page'); @@ -118,7 +118,7 @@ public function testRefreshResourcesOnPage(AcceptanceTester $I) public function testRefreshResourcesOnQuickEdit(AcceptanceTester $I) { // Setup ConvertKit Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET']); + $I->setupConvertKitPlugin($I); // Programmatically create a Page. $pageID = $I->havePostInDatabase( @@ -191,7 +191,7 @@ public function testRefreshResourcesOnQuickEdit(AcceptanceTester $I) public function testRefreshResourcesOnBulkEdit(AcceptanceTester $I) { // Setup ConvertKit Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET']); + $I->setupConvertKitPlugin($I); // Programmatically create two Pages. $pageIDs = array( @@ -274,7 +274,7 @@ public function testRefreshResourcesOnBulkEdit(AcceptanceTester $I) public function testRefreshResourcesOnAddCategory(AcceptanceTester $I) { // Setup ConvertKit Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET']); + $I->setupConvertKitPlugin($I); // Navigate to Posts > Categories. $I->amOnAdminPage('edit-tags.php?taxonomy=category'); @@ -309,7 +309,7 @@ public function testRefreshResourcesOnAddCategory(AcceptanceTester $I) public function testRefreshResourcesOnEditCategory(AcceptanceTester $I) { // Setup ConvertKit Plugin. - $I->setupConvertKitPlugin($I, $_ENV['CONVERTKIT_API_KEY'], $_ENV['CONVERTKIT_API_SECRET']); + $I->setupConvertKitPlugin($I); // Create Category. $termID = $I->haveTermInDatabase( 'ConvertKit Refresh Resources', 'category' ); @@ -349,7 +349,7 @@ public function testRefreshResourcesOnEditCategory(AcceptanceTester $I) public function testRefreshResourcesErrorNoticeOnPage(AcceptanceTester $I) { // Setup ConvertKit Plugin with invalid API credentials, so that the AJAX request returns an error. - $I->setupConvertKitPlugin($I, 'fakeApiKey', 'fakeApiSecret', '', '', ''); + $I->setupConvertKitPluginFakeAPIKey($I); // Navigate to Pages > Add New. $I->amOnAdminPage('post-new.php?post_type=page'); @@ -384,7 +384,7 @@ public function testRefreshResourcesErrorNoticeOnPage(AcceptanceTester $I) public function testRefreshResourcesErrorNoticeOnPageClassicEditor(AcceptanceTester $I) { // Setup ConvertKit Plugin with invalid API credentials, so that the AJAX request returns an error. - $I->setupConvertKitPlugin($I, 'fakeApiKey', 'fakeApiSecret', '', '', ''); + $I->setupConvertKitPluginFakeAPIKey($I); // Add a Page using the Classic Editor. $I->addClassicEditorPage($I, 'page', 'ConvertKit: Page: Refresh Resources: Classic Editor' ); @@ -416,7 +416,7 @@ public function testRefreshResourcesErrorNoticeOnPageClassicEditor(AcceptanceTes public function testRefreshResourcesErrorNoticeOnQuickEdit(AcceptanceTester $I) { // Setup ConvertKit Plugin with invalid API credentials, so that the AJAX request returns an error. - $I->setupConvertKitPlugin($I, 'fakeApiKey', 'fakeApiSecret', '', '', ''); + $I->setupConvertKitPluginFakeAPIKey($I); // Programmatically create a Page. $pageID = $I->havePostInDatabase( @@ -456,7 +456,7 @@ public function testRefreshResourcesErrorNoticeOnQuickEdit(AcceptanceTester $I) public function testRefreshResourcesErrorNoticeOnBulkEdit(AcceptanceTester $I) { // Setup ConvertKit Plugin with invalid API credentials, so that the AJAX request returns an error. - $I->setupConvertKitPlugin($I, 'fakeApiKey', 'fakeApiSecret', '', '', ''); + $I->setupConvertKitPluginFakeAPIKey($I); // Programmatically create two Pages. $pageIDs = array( @@ -504,7 +504,7 @@ public function testRefreshResourcesErrorNoticeOnBulkEdit(AcceptanceTester $I) public function testRefreshResourcesErrorNoticeOnAddCategory(AcceptanceTester $I) { // Setup ConvertKit Plugin with invalid API credentials, so that the AJAX request returns an error. - $I->setupConvertKitPlugin($I, 'fakeApiKey', 'fakeApiSecret', '', '', ''); + $I->setupConvertKitPluginFakeAPIKey($I); // Navigate to Posts > Categories. $I->amOnAdminPage('edit-tags.php?taxonomy=category'); @@ -536,7 +536,7 @@ public function testRefreshResourcesErrorNoticeOnAddCategory(AcceptanceTester $I public function testRefreshResourcesErrorNoticeOnEditCategory(AcceptanceTester $I) { // Setup ConvertKit Plugin with invalid API credentials, so that the AJAX request returns an error. - $I->setupConvertKitPlugin($I, 'fakeApiKey', 'fakeApiSecret', '', '', ''); + $I->setupConvertKitPluginFakeAPIKey($I); // Create Category. $termID = $I->haveTermInDatabase( 'ConvertKit Refresh Resources', 'category' ); diff --git a/tests/acceptance/restrict-content/RestrictContentProductPageCest.php b/tests/acceptance/restrict-content/RestrictContentProductPageCest.php index bbd102b49..620a71570 100644 --- a/tests/acceptance/restrict-content/RestrictContentProductPageCest.php +++ b/tests/acceptance/restrict-content/RestrictContentProductPageCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testRestrictContentWhenDisabled(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Add a Page using the Gutenberg editor. $I->addGutenbergPage($I, 'page', 'ConvertKit: Page: Restrict Content: Product'); @@ -59,7 +59,7 @@ public function testRestrictContentWhenDisabled(AcceptanceTester $I) public function testRestrictContentByProduct(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Add a Page using the Gutenberg editor. $I->addGutenbergPage($I, 'page', 'ConvertKit: Page: Restrict Content: Product'); @@ -103,7 +103,7 @@ public function testRestrictContentByProduct(AcceptanceTester $I) public function testRestrictContentByProductWithGeneratedExcerpt(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Define visible content and member only content. $visibleContent = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec at velit purus. Nam gravida tempor tellus, sit amet euismod arcu. Mauris sed mattis leo. Mauris viverra eget tellus sit amet vehicula. Nulla eget sapien quis felis euismod pellentesque. Quisque elementum et diam nec eleifend. Sed ornare quam eget augue consequat, in maximus quam fringilla. Morbi'; @@ -196,7 +196,7 @@ public function testRestrictContentModalByProduct(AcceptanceTester $I) public function testRestrictContentByInvalidProduct(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Programmatically create a Page. $pageID = $I->createRestrictedContentPage( @@ -226,7 +226,7 @@ public function testRestrictContentByInvalidProduct(AcceptanceTester $I) public function testRestrictContentByProductUsingQuickEdit(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Programmatically create a Page. $pageID = $I->createRestrictedContentPage($I, 'page', 'ConvertKit: Page: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Quick Edit'); @@ -256,7 +256,7 @@ public function testRestrictContentByProductUsingQuickEdit(AcceptanceTester $I) public function testRestrictContentByProductUsingBulkEdit(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Programmatically create two Pages. $pageIDs = array( diff --git a/tests/acceptance/restrict-content/RestrictContentProductPostCest.php b/tests/acceptance/restrict-content/RestrictContentProductPostCest.php index 808be85f7..c20f4dee6 100644 --- a/tests/acceptance/restrict-content/RestrictContentProductPostCest.php +++ b/tests/acceptance/restrict-content/RestrictContentProductPostCest.php @@ -29,7 +29,7 @@ public function _before(AcceptanceTester $I) public function testRestrictContentWhenDisabled(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Add a Post using the Gutenberg editor. $I->addGutenbergPage($I, 'post', 'ConvertKit: Post: Restrict Content: Product'); @@ -59,7 +59,7 @@ public function testRestrictContentWhenDisabled(AcceptanceTester $I) public function testRestrictContentByProduct(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Add a Post using the Gutenberg editor. $I->addGutenbergPage($I, 'post', 'ConvertKit: Post: Restrict Content: Product'); @@ -103,7 +103,7 @@ public function testRestrictContentByProduct(AcceptanceTester $I) public function testRestrictContentByProductWithGeneratedExcerpt(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Define visible content and member only content. $visibleContent = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec at velit purus. Nam gravida tempor tellus, sit amet euismod arcu. Mauris sed mattis leo. Mauris viverra eget tellus sit amet vehicula. Nulla eget sapien quis felis euismod pellentesque. Quisque elementum et diam nec eleifend. Sed ornare quam eget augue consequat, in maximus quam fringilla. Morbi'; @@ -150,7 +150,7 @@ public function testRestrictContentByProductWithGeneratedExcerpt(AcceptanceTeste public function testRestrictContentByProductWithDefinedExcerpt(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Define visible content and member only content. $excerpt = 'This is a defined excerpt'; @@ -253,7 +253,7 @@ public function testRestrictContentModalByProduct(AcceptanceTester $I) public function testRestrictContentByInvalidProduct(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Programmatically create a Page. $postID = $I->createRestrictedContentPage( @@ -283,7 +283,7 @@ public function testRestrictContentByInvalidProduct(AcceptanceTester $I) public function testRestrictContentByProductUsingQuickEdit(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Programmatically create a Post. $postID = $I->createRestrictedContentPage( @@ -317,7 +317,7 @@ public function testRestrictContentByProductUsingQuickEdit(AcceptanceTester $I) public function testRestrictContentByProductUsingBulkEdit(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Programmatically create two Posts. $postIDs = array( diff --git a/tests/acceptance/restrict-content/RestrictContentSettingsCest.php b/tests/acceptance/restrict-content/RestrictContentSettingsCest.php index 571403ed9..3214bfad1 100644 --- a/tests/acceptance/restrict-content/RestrictContentSettingsCest.php +++ b/tests/acceptance/restrict-content/RestrictContentSettingsCest.php @@ -19,7 +19,7 @@ public function _before(AcceptanceTester $I) $I->activateConvertKitPlugin($I); // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); } /** diff --git a/tests/acceptance/restrict-content/RestrictContentSetupCest.php b/tests/acceptance/restrict-content/RestrictContentSetupCest.php index 156c6b907..2c6e19104 100644 --- a/tests/acceptance/restrict-content/RestrictContentSetupCest.php +++ b/tests/acceptance/restrict-content/RestrictContentSetupCest.php @@ -460,7 +460,7 @@ public function testAddNewMemberContentCourseByTag(AcceptanceTester $I) private function _setupAndLoadAddNewMemberContentScreen(AcceptanceTester $I) { // Setup ConvertKit Plugin, disabling JS. - $I->setupConvertKitPlugin($I, false, false, false, false, false, true); + $I->setupConvertKitPluginDisableJS($I); // Navigate to Pages. $I->amOnAdminPage('edit.php?post_type=page'); From d4c887f85d819ad2fb62cb859db2b421372af58e Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 17:28:50 +0000 Subject: [PATCH 07/11] Coding standards --- .../Acceptance/ConvertKitBroadcasts.php | 174 ------ .../ConvertKitRestrictedContent.php | 420 -------------- tests/_support/Helper/Acceptance/Plugin.php | 532 ++++++++++++++++-- .../acceptance/forms/general/PageFormCest.php | 13 +- .../acceptance/forms/general/PostFormCest.php | 13 +- 5 files changed, 515 insertions(+), 637 deletions(-) delete mode 100644 tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php delete mode 100644 tests/_support/Helper/Acceptance/ConvertKitRestrictedContent.php diff --git a/tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php b/tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php deleted file mode 100644 index 2f78f3111..000000000 --- a/tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php +++ /dev/null @@ -1,174 +0,0 @@ -{yourFunctionName}. - * - * @since 2.0.0 - */ -class ConvertKitBroadcasts extends \Codeception\Module -{ - /** - * Check that expected HTML exists in the DOM of the page we're viewing for - * a Broadcasts block or shortcode, based on its configuration. - * - * @since 1.9.7.5 - * - * @param AcceptanceTester $I Tester. - * @param bool|int $numberOfPosts Number of Broadcasts listed. - * @param bool|string $seePrevPaginationLabel Test if the "previous" pagination link is output and matches expected label. - * @param bool|string $seeNextPaginationLabel Test if the "next" pagination link is output and matches expected label. - * @param bool $seeGrid Test if the broadcasts are displayed in grid view (false = list view). - * @param bool $seeImage Test if the broadcasts display images. - * @param bool $seeDescription Test if the broadcasts display descriptions. - * @param bool|string $seeReadMore Test if the broadcasts display a read more link matching the given text. - */ - public function seeBroadcastsOutput($I, $options = false) - { - // Define defaults. - $defaults = [ - 'number_of_posts' => false, - 'see_prev_pagination_label' => false, - 'see_next_pagination_label' => false, - 'see_grid' => false, - 'see_image' => false, - 'see_description' => false, - 'see_read_more' => false, - ]; - - // If options is an array, merge with defaults. - if (is_array($options)) { - $options = array_merge($defaults, $options); - } else { - $options = $defaults; - } - - // Confirm that the block displays. - $I->seeElementInDOM('div.convertkit-broadcasts'); - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list'); - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast'); - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast a.convertkit-broadcast-title'); - - // Confirm that UTM parameters exist on a broadcast link. - $I->assertStringContainsString( - 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', - $I->grabAttributeFrom('a.convertkit-broadcast-title', 'href') - ); - - // If Display as grid is enabled, confirm the applicable HTML exists so that CSS can style this layout. - if ($options['see_grid']) { - $I->seeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); - } else { - $I->dontSeeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); - } - - // If Display image is enabled, confirm the image is displayed. - if ($options['see_image']) { - $I->seeElementInDOM('a.convertkit-broadcast-image img'); - $I->assertStringContainsString( - 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', - $I->grabAttributeFrom('a.convertkit-broadcast-image', 'href') - ); - } else { - $I->dontSeeElementInDOM('a.convertkit-broadcast-image img'); - } - - // If Display description is enabled, confirm the description is displayed. - if ($options['see_description']) { - $I->seeElementInDOM('.convertkit-broadcast-description'); - } else { - $I->dontSeeElementInDOM('.convertkit-broadcast-description'); - } - - // If Display read more link is enabled, confirm the read more link is displayed and matches the given text. - if ($options['see_read_more']) { - $I->seeElementInDOM('a.convertkit-broadcast-read-more'); - $I->assertStringContainsString( - 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', - $I->grabAttributeFrom('a.convertkit-broadcast-read-more', 'href') - ); - } else { - $I->dontSeeElementInDOM('a.convertkit-broadcast-read-more'); - } - - // Confirm that the number of expected broadcasts displays. - if ($options['number_of_posts'] !== false) { - $I->seeNumberOfElements('li.convertkit-broadcast', $options['number_of_posts']); - } - - // Confirm that previous pagination displays, if expected. - if ($options['see_prev_pagination_label'] !== false) { - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-prev a'); - $I->seeInSource($options['see_prev_pagination_label']); - } - - // Confirm that next pagination displays, if expected. - if ($options['see_next_pagination_label'] !== false) { - $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-next a'); - $I->seeInSource($options['see_next_pagination_label']); - } - } - - /** - * Tests that the Broadcasts pagination works, and that the expected Broadcast - * is displayed after using previous and next links. - * - * @since 2.0.0 - * - * @param AcceptanceTester $I Tester. - * @param string $previousLabel Previous / Newer Broadcasts Label. - * @param string $nextLabel Next / Older Broadcasts Label. - */ - public function testBroadcastsPagination($I, $previousLabel, $nextLabel) - { - // Confirm that the block displays one broadcast with a pagination link to older broadcasts. - $I->seeBroadcastsOutput($I, 1, false, $nextLabel); - - // Click the Older Posts link. - $I->click('li.convertkit-broadcasts-pagination-next a'); - - // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been - // removed from the block. - $I->waitForBroadcastsToLoad($I); - - // Confirm that the block displays one broadcast with a pagination link to newer broadcasts. - $I->seeBroadcastsOutput($I, 1, $previousLabel, false); - - // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. - $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_SECOND_TITLE']); - - // Click the Newer Posts link. - $I->click('li.convertkit-broadcasts-pagination-prev a'); - - // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been - // removed from the block. - $I->waitForBroadcastsToLoad($I); - - // Confirm that the block displays one broadcast with a pagination link to older broadcasts. - $I->seeBroadcastsOutput($I, 1, false, $nextLabel); - - // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. - $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_FIRST_TITLE']); - } - - /** - * Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been - * removed from the block. - * - * @since 1.9.7.6 - * - * @param AcceptanceTester $I Tester. - */ - public function waitForBroadcastsToLoad($I) - { - $I->waitForElementChange( - 'div.convertkit-broadcasts', - function(\Facebook\WebDriver\WebDriverElement $el) { - return ( strpos($el->getAttribute('class'), 'convertkit-broadcasts-loading') === false ? true : false ); - }, - 5 - ); - } \ No newline at end of file diff --git a/tests/_support/Helper/Acceptance/ConvertKitRestrictedContent.php b/tests/_support/Helper/Acceptance/ConvertKitRestrictedContent.php deleted file mode 100644 index 968af8748..000000000 --- a/tests/_support/Helper/Acceptance/ConvertKitRestrictedContent.php +++ /dev/null @@ -1,420 +0,0 @@ -{yourFunctionName}. - * - * @since 2.1.0 - */ -class ConvertKitRestrictedContent extends \Codeception\Module -{ - /** - * Returns the expected default settings for Restricted Content. - * - * @since 2.1.0 - * - * @return array - */ - public function getRestrictedContentDefaultSettings() - { - return array( - // Restrict by Product. - 'subscribe_heading' => 'Read this post with a premium subscription', - 'subscribe_text' => 'This post is only available to premium subscribers. Join today to get access to all posts.', - - // Restrict by Tag. - 'subscribe_heading_tag' => 'Subscribe to keep reading', - 'subscribe_text_tag' => 'This post is free to read but only available to subscribers. Join today to get access to all posts.', - - // All. - 'subscribe_button_label' => 'Subscribe', - 'email_text' => 'Already subscribed?', - 'email_button_label' => 'Log in', - 'email_description_text' => 'We\'ll email you a magic code to log you in without a password.', - 'email_check_heading' => 'We just emailed you a log in code', - 'email_check_text' => 'Enter the code below to finish logging in', - 'no_access_text' => 'Your account does not have access to this content. Please use the button above to purchase, or enter the email address you used to purchase the product.', - ); - } - - /** - * Creates a Page in the database with the given title for restricted content. - * - * The Page's content comprises of a mix of visible and member's only content. - * The default form setting is set to 'None'. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $postType Post Type. - * @param string $title Title. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param string $restrictContentSetting Restrict Content setting. - * @return int Page ID. - */ - public function createRestrictedContentPage($I, $postType, $title, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $restrictContentSetting = '') - { - return $I->havePostInDatabase( - [ - 'post_type' => $postType, - 'post_title' => $title, - - // Emulate Gutenberg content with visible and members only content sections. - 'post_content' => '

' . $visibleContent . '

- -' . $memberContent . '', - - // Don't display a Form on this Page, so we test against Restrict Content's Form. - 'meta_input' => [ - '_wp_convertkit_post_meta' => [ - 'form' => '-1', - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => $restrictContentSetting, - ], - ], - ] - ); - } - - /** - * Run frontend tests for restricted content by ConvertKit Product, to confirm that visible and member's content - * is / is not displayed when logging in with valid and invalid subscriber email addresses. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string|int $urlOrPageID URL or ID of Restricted Content Page. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictedContentByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Navigate to the page. - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID); - } else { - $I->amOnUrl($urlOrPageID); - } - - // Confirm Restrict Content CSS is output. - $I->seeInSource('invalid: Email address is invalid
'); - $I->seeInSource('
'); - - // Check content is not displayed, and CTA displays with expected text. - $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); - - // Set cookie with signed subscriber ID and reload the restricted content page, as if we entered the - // code sent in the email as a ConvertKit subscriber who has not subscribed to the product. - $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID_NO_ACCESS']); - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID . '&ck-cache-bust=' . microtime() ); - } else { - $I->amOnUrl($urlOrPageID . '?ck-cache-bust=' . microtime() ); - } - - // Confirm an inline error message is displayed. - $I->seeInSource('
' . $textItems['no_access_text'] . '
'); - $I->seeInSource('
'); - - // Check content is not displayed, and CTA displays with expected text. - $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); - - // Login as a ConvertKit subscriber who has subscribed to the product. - $I->waitForElementVisible('input#convertkit_email'); - $I->fillField('convertkit_email', $_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL']); - $I->click('input.wp-block-button__link'); - - // Confirm that confirmation an email has been sent is displayed. - $this->testRestrictContentShowsEmailCodeForm($I, $visibleContent, $memberContent, $textItems); - - // Test that the restricted content displays when a valid signed subscriber ID is used, - // as if we entered the code sent in the email. - $this->testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent); - } - - /** - * Run frontend tests for restricted content by ConvertKit Product, using the modal authentication flow, to confirm - * that visible and member's content is / is not displayed when logging in with valid and invalid subscriber email addresses. - * - * @since 2.3.8 - * - * @param AcceptanceTester $I Tester. - * @param string|int $urlOrPageID URL or ID of Restricted Content Page. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictedContentModalByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Navigate to the page. - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID); - } else { - $I->amOnUrl($urlOrPageID); - } - - // Confirm Restrict Content CSS is output. - $I->seeInSource(''); - - // Enter the email address and submit the form. - $I->fillField('convertkit_email', $emailAddress); - $I->click('input.wp-block-button__link'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the restricted content is now displayed. - $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); - } - - /** - * Run frontend tests for restricted content, to confirm that both visible and member content is displayed - * when a valid signed subscriber ID is set as a cookie, as if the user entered a code sent in the email. - * - * @since 2.2.2 - * - * @param AcceptanceTester $I Tester. - * @param string|int $urlOrPageID URL or ID of Restricted Content Page. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - */ - public function testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent) - { - // Set cookie with signed subscriber ID, as if we entered the code sent in the email. - $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); - - // Reload the restricted content page. - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID ); - } else { - $I->amOnUrl($urlOrPageID ); - } - - // Confirm cookie was set with the expected value. - $I->assertEquals($I->grabCookie('ck_subscriber_id'), $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); - - // Confirm that the restricted content is now displayed, as we've authenticated as a subscriber - // who has access to this Product. - $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); - } - - /** - * Run frontend tests for restricted content, to confirm that: - * - visible content is displayed, - * - member's content is not displayed, - * - the CTA is displayed with the expected text - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictContentByProductHidesContentWithCTA($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the visible text displays, hidden text does not display and the CTA displays. - if ( ! empty($visibleContent)) { - $I->see($visibleContent); - } - $I->dontSee($memberContent); - - // Confirm that the CTA displays with the expected headings, text, buttons and other elements. - $I->seeElementInDOM('#convertkit-restrict-content'); - - $I->seeInSource('

' . $textItems['subscribe_heading'] . '

'); - $I->see($textItems['subscribe_text']); - - $I->see($textItems['subscribe_button_label']); - $I->seeInSource('
'); - $I->seeInSource('' . $textItems['email_description_text'] . ''); - } - - /** - * Run frontend tests for restricted content, to confirm that: - * - visible content is displayed, - * - member's content is not displayed, - * - the email code form is displayed with the expected text. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictContentShowsEmailCodeForm($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the visible text displays, hidden text does not display and the CTA displays. - if ( ! empty($visibleContent)) { - $I->see($visibleContent); - } - $I->dontSee($memberContent); - - // Confirm that the CTA displays with the expected text. - $I->seeElementInDOM('#convertkit-restrict-content'); - $I->seeInSource('

' . $textItems['email_check_heading'] . '

'); - $I->see($textItems['email_check_text']); - $I->seeElementInDOM('input#convertkit_subscriber_code'); - $I->seeElementInDOM('input.wp-block-button__link'); - - // Enter an invalid code. - $I->fillField('subscriber_code', '999999'); - $I->click('Verify'); - - // Confirm an inline error message is displayed. - $I->seeInSource('
The entered code is invalid. Please try again, or click the link sent in the email.
'); - $I->seeInSource('
'); - } - - /** - * Run frontend tests for restricted content, to confirm that: - * - visible content is displayed, - * - member's content is displayed, - * - the CTA is not displayed - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - */ - public function testRestrictContentDisplaysContent($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.') - { - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the visible and hidden text displays. - if ( ! empty($visibleContent)) { - $I->see($visibleContent); - } - $I->see($memberContent); - - // Confirm that the CTA is not displayed. - $I->dontSeeElementInDOM('#convertkit-restrict-content'); - } -} \ No newline at end of file diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php index 0c57c658b..5ebc68bf9 100644 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ b/tests/_support/Helper/Acceptance/Plugin.php @@ -36,20 +36,25 @@ public function deactivateConvertKitPlugin($I) } /** - * Helper method to programmatically setup the Plugin's API Key and Secret, - * enabling debug logging. + * Helper method to programmatically setup the Plugin's settings, as if the + * user configured the Plugin at `Settings > ConvertKit`. * * @since 1.9.6 * - * @param AcceptanceTester $I AcceptanceTester. - * @param bool|string $apiKey API Key (if specified, used instead of CONVERTKIT_API_KEY). - * @param bool|string $apiSecret API Secret (if specified, used instead of CONVERTKIT_API_SECRET). - * @param bool|string $pageFormID Default Form ID for Pages (if specified, used instead of CONVERTKIT_API_FORM_ID). - * @param bool|string $postFormID Default Form ID for Posts (if specified, used instead of CONVERTKIT_API_FORM_ID). - * @param bool|string $productFormID Default Form ID for Products (if specified, used instead of CONVERTKIT_API_FORM_ID). - * @param bool $disableJS Disable JS. - * @param bool $disableCSS Disable CSS. - * @param bool|string $globalNonInlineFormID Default Global non-inline Form ID (if specified, none if false). + * @param AcceptanceTester $I AcceptanceTester. + * @param bool|array $options { + * Optional. An array of settings. + * + * @type string $api_key API Key (if specified, used instead of CONVERTKIT_API_KEY). + * @type string $api_secret API Secret (if specified, used instead of CONVERTKIT_API_SECRET). + * @type string $debug Enable debugging (default: on). + * @type string $no_scripts Disable JS (default: off). + * @type string $no_css Disable CSS (default: off). + * @type string $post_form Default Form ID for Posts (if specified, used instead of CONVERTKIT_API_FORM_ID). + * @type string $page_form Default Form ID for Pages (if specified, used instead of CONVERTKIT_API_FORM_ID). + * @type string $product_form Default Form ID for WooCommerce Products (if specified, used instead of CONVERTKIT_API_FORM_ID). + * @type string $non_inline_form Default Global non-inline Form ID (if specified, none if false). + * } */ public function setupConvertKitPlugin($I, $options = false) { @@ -77,42 +82,92 @@ public function setupConvertKitPlugin($I, $options = false) $I->haveOptionInDatabase('_wp_convertkit_settings', $options); } + /** + * Helper method to programmatically setup the Plugin's settings, as if the + * user configured the Plugin at `Settings > ConvertKit` with a ConvertKit + * API Key and Secret for a ConvertKit account that has no data (no forms, + * products, tags etc). + * + * @since 2.4.0 + * + * @param AcceptanceTester $I AcceptanceTester. + */ public function setupConvertKitPluginAPIKeyNoData($I) { - $I->setupConvertKitPlugin($I, [ - 'api_key' => $_ENV['CONVERTKIT_API_KEY_NO_DATA'], - 'api_secret' => $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], - 'post_form' => '', - 'page_form' => '', - 'product_form' => '', - ]); + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY_NO_DATA'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ] + ); } + /** + * Helper method to programmatically setup the Plugin's settings, as if the + * user configured the Plugin at `Settings > ConvertKit` with an invalid + * ConvertKit API Key and Secret. + * + * @since 2.4.0 + * + * @param AcceptanceTester $I AcceptanceTester. + */ public function setupConvertKitPluginFakeAPIKey($I) { - $I->setupConvertKitPlugin($I, [ - 'api_key' => 'fakeApiKey' - 'api_secret' => 'fakeApiSecret', - 'post_form' => '', - 'page_form' => '', - 'product_form' => '', - ]); + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => 'fakeApiKey' + 'api_secret' => 'fakeApiSecret', + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ] + ); } + /** + * Helper method to programmatically setup the Plugin's settings, as if the + * user configured the Plugin at `Settings > ConvertKit` with a ConvertKit + * API Key and Secret, and defined no default Forms for Posts, Pages and + * WooCommerce Products. + * + * @since 2.4.0 + * + * @param AcceptanceTester $I AcceptanceTester. + */ public function setupConvertKitPluginNoDefaultForms($I) { - $I->setupConvertKitPlugin($I, [ - 'post_form' => '', - 'page_form' => '', - 'product_form' => '', - ]); + $I->setupConvertKitPlugin( + $I, + [ + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ] + ); } + /** + * Helper method to programmatically setup the Plugin's settings, as if the + * user configured the Plugin at `Settings > ConvertKit` with a ConvertKit + * API Key and Secret, and disabled JS. + * + * @since 2.4.0 + * + * @param AcceptanceTester $I AcceptanceTester. + */ public function setupConvertKitPluginDisableJS($I) { - $I->setupConvertKitPlugin($I, [ - 'no_scripts' => 'on', - ]); + $I->setupConvertKitPlugin( + $I, + [ + 'no_scripts' => 'on', + ] + ); } /** @@ -737,6 +792,8 @@ public function checkSelectOptionOrder($I, $selectElement, $values) } } +broadcasts here + /** * Check that expected HTML exists in the DOM of the page we're viewing * when a ConvertKit Product link was inserted into a paragraph or button, @@ -770,6 +827,415 @@ public function seeProductLink($I, $productURL, $text = false) $I->seeElementInDOM('iframe[data-active]'); } + /** + * Returns the expected default settings for Restricted Content. + * + * @since 2.1.0 + * + * @return array + */ + public function getRestrictedContentDefaultSettings() + { + return array( + // Restrict by Product. + 'subscribe_heading' => 'Read this post with a premium subscription', + 'subscribe_text' => 'This post is only available to premium subscribers. Join today to get access to all posts.', + + // Restrict by Tag. + 'subscribe_heading_tag' => 'Subscribe to keep reading', + 'subscribe_text_tag' => 'This post is free to read but only available to subscribers. Join today to get access to all posts.', + + // All. + 'subscribe_button_label' => 'Subscribe', + 'email_text' => 'Already subscribed?', + 'email_button_label' => 'Log in', + 'email_description_text' => 'We\'ll email you a magic code to log you in without a password.', + 'email_check_heading' => 'We just emailed you a log in code', + 'email_check_text' => 'Enter the code below to finish logging in', + 'no_access_text' => 'Your account does not have access to this content. Please use the button above to purchase, or enter the email address you used to purchase the product.', + ); + } + + /** + * Creates a Page in the database with the given title for restricted content. + * + * The Page's content comprises of a mix of visible and member's only content. + * The default form setting is set to 'None'. + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $postType Post Type. + * @param string $title Title. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param string $restrictContentSetting Restrict Content setting. + * @return int Page ID. + */ + public function createRestrictedContentPage($I, $postType, $title, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $restrictContentSetting = '') + { + return $I->havePostInDatabase( + [ + 'post_type' => $postType, + 'post_title' => $title, + + // Emulate Gutenberg content with visible and members only content sections. + 'post_content' => '

' . $visibleContent . '

+ +' . $memberContent . '', + + // Don't display a Form on this Page, so we test against Restrict Content's Form. + 'meta_input' => [ + '_wp_convertkit_post_meta' => [ + 'form' => '-1', + 'landing_page' => '', + 'tag' => '', + 'restrict_content' => $restrictContentSetting, + ], + ], + ] + ); + } + + /** + * Run frontend tests for restricted content by ConvertKit Product, to confirm that visible and member's content + * is / is not displayed when logging in with valid and invalid subscriber email addresses. + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string|int $urlOrPageID URL or ID of Restricted Content Page. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictedContentByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Navigate to the page. + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID); + } else { + $I->amOnUrl($urlOrPageID); + } + + // Confirm Restrict Content CSS is output. + $I->seeInSource('invalid: Email address is invalid
'); + $I->seeInSource('
'); + + // Check content is not displayed, and CTA displays with expected text. + $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); + + // Set cookie with signed subscriber ID and reload the restricted content page, as if we entered the + // code sent in the email as a ConvertKit subscriber who has not subscribed to the product. + $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID_NO_ACCESS']); + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID . '&ck-cache-bust=' . microtime() ); + } else { + $I->amOnUrl($urlOrPageID . '?ck-cache-bust=' . microtime() ); + } + + // Confirm an inline error message is displayed. + $I->seeInSource('
' . $textItems['no_access_text'] . '
'); + $I->seeInSource('
'); + + // Check content is not displayed, and CTA displays with expected text. + $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); + + // Login as a ConvertKit subscriber who has subscribed to the product. + $I->waitForElementVisible('input#convertkit_email'); + $I->fillField('convertkit_email', $_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL']); + $I->click('input.wp-block-button__link'); + + // Confirm that confirmation an email has been sent is displayed. + $this->testRestrictContentShowsEmailCodeForm($I, $visibleContent, $memberContent, $textItems); + + // Test that the restricted content displays when a valid signed subscriber ID is used, + // as if we entered the code sent in the email. + $this->testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent); + } + + /** + * Run frontend tests for restricted content by ConvertKit Product, using the modal authentication flow, to confirm + * that visible and member's content is / is not displayed when logging in with valid and invalid subscriber email addresses. + * + * @since 2.3.8 + * + * @param AcceptanceTester $I Tester. + * @param string|int $urlOrPageID URL or ID of Restricted Content Page. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictedContentModalByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Navigate to the page. + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID); + } else { + $I->amOnUrl($urlOrPageID); + } + + // Confirm Restrict Content CSS is output. + $I->seeInSource(''); + + // Enter the email address and submit the form. + $I->fillField('convertkit_email', $emailAddress); + $I->click('input.wp-block-button__link'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the restricted content is now displayed. + $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); + } + + /** + * Run frontend tests for restricted content, to confirm that both visible and member content is displayed + * when a valid signed subscriber ID is set as a cookie, as if the user entered a code sent in the email. + * + * @since 2.2.2 + * + * @param AcceptanceTester $I Tester. + * @param string|int $urlOrPageID URL or ID of Restricted Content Page. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + */ + public function testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent) + { + // Set cookie with signed subscriber ID, as if we entered the code sent in the email. + $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); + + // Reload the restricted content page. + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID ); + } else { + $I->amOnUrl($urlOrPageID ); + } + + // Confirm cookie was set with the expected value. + $I->assertEquals($I->grabCookie('ck_subscriber_id'), $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); + + // Confirm that the restricted content is now displayed, as we've authenticated as a subscriber + // who has access to this Product. + $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); + } + + /** + * Run frontend tests for restricted content, to confirm that: + * - visible content is displayed, + * - member's content is not displayed, + * - the CTA is displayed with the expected text + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictContentByProductHidesContentWithCTA($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the visible text displays, hidden text does not display and the CTA displays. + if ( ! empty($visibleContent)) { + $I->see($visibleContent); + } + $I->dontSee($memberContent); + + // Confirm that the CTA displays with the expected headings, text, buttons and other elements. + $I->seeElementInDOM('#convertkit-restrict-content'); + + $I->seeInSource('

' . $textItems['subscribe_heading'] . '

'); + $I->see($textItems['subscribe_text']); + + $I->see($textItems['subscribe_button_label']); + $I->seeInSource('
'); + $I->seeInSource('' . $textItems['email_description_text'] . ''); + } + + /** + * Run frontend tests for restricted content, to confirm that: + * - visible content is displayed, + * - member's content is not displayed, + * - the email code form is displayed with the expected text. + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictContentShowsEmailCodeForm($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the visible text displays, hidden text does not display and the CTA displays. + if ( ! empty($visibleContent)) { + $I->see($visibleContent); + } + $I->dontSee($memberContent); + + // Confirm that the CTA displays with the expected text. + $I->seeElementInDOM('#convertkit-restrict-content'); + $I->seeInSource('

' . $textItems['email_check_heading'] . '

'); + $I->see($textItems['email_check_text']); + $I->seeElementInDOM('input#convertkit_subscriber_code'); + $I->seeElementInDOM('input.wp-block-button__link'); + + // Enter an invalid code. + $I->fillField('subscriber_code', '999999'); + $I->click('Verify'); + + // Confirm an inline error message is displayed. + $I->seeInSource('
The entered code is invalid. Please try again, or click the link sent in the email.
'); + $I->seeInSource('
'); + } + + /** + * Run frontend tests for restricted content, to confirm that: + * - visible content is displayed, + * - member's content is displayed, + * - the CTA is not displayed + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + */ + public function testRestrictContentDisplaysContent($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.') + { + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the visible and hidden text displays. + if ( ! empty($visibleContent)) { + $I->see($visibleContent); + } + $I->see($memberContent); + + // Confirm that the CTA is not displayed. + $I->dontSeeElementInDOM('#convertkit-restrict-content'); + } + /** * Check that expected HTML exists in the DOM of the page we're viewing for * a Form Trigger block or shortcode, and that the button loads the expected diff --git a/tests/acceptance/forms/general/PageFormCest.php b/tests/acceptance/forms/general/PageFormCest.php index d822d0390..905b47566 100644 --- a/tests/acceptance/forms/general/PageFormCest.php +++ b/tests/acceptance/forms/general/PageFormCest.php @@ -130,11 +130,14 @@ public function testAddNewPageUsingDefaultForm(AcceptanceTester $I) public function testAddNewPageUsingDefaultLegacyForm(AcceptanceTester $I) { // Setup ConvertKit plugin to use legacy Form as default for Pages. - $I->setupConvertKitPlugin($I, [ - 'page_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], - 'post_form' => '', - 'product_form' => '' - ]); + $I->setupConvertKitPlugin( + $I, + [ + 'page_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + 'post_form' => '', + 'product_form' => '', + ] + ); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/general/PostFormCest.php b/tests/acceptance/forms/general/PostFormCest.php index e1fd3ee84..ae2af6c2b 100644 --- a/tests/acceptance/forms/general/PostFormCest.php +++ b/tests/acceptance/forms/general/PostFormCest.php @@ -129,11 +129,14 @@ public function testAddNewPostUsingDefaultForm(AcceptanceTester $I) public function testAddNewPostUsingDefaultLegacyForm(AcceptanceTester $I) { // Setup Plugin, without defining default Forms. - $I->setupConvertKitPlugin($I, [ - 'page_form' => '', - 'post_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], - 'product_form' => '' - ]); + $I->setupConvertKitPlugin( + $I, + [ + 'page_form' => '', + 'post_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + 'product_form' => '', + ] + ); $I->setupConvertKitPluginResources($I); // Add a Post using the Gutenberg editor. From d90ba9cc5a234844b4a6e956ddc7cb99d85423d7 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 17:30:35 +0000 Subject: [PATCH 08/11] Reinstate Broadcast and Member Content helpers Refactor these in a separate PR. --- tests/_support/Helper/Acceptance/Plugin.php | 145 +++++++++++++++++++- tests/acceptance.suite.yml | 2 - 2 files changed, 144 insertions(+), 3 deletions(-) diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php index 5ebc68bf9..7d6aa05e1 100644 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ b/tests/_support/Helper/Acceptance/Plugin.php @@ -792,7 +792,150 @@ public function checkSelectOptionOrder($I, $selectElement, $values) } } -broadcasts here + /** + * Check that expected HTML exists in the DOM of the page we're viewing for + * a Broadcasts block or shortcode, based on its configuration. + * + * @since 1.9.7.5 + * + * @param AcceptanceTester $I Tester. + * @param bool|int $numberOfPosts Number of Broadcasts listed. + * @param bool|string $seePrevPaginationLabel Test if the "previous" pagination link is output and matches expected label. + * @param bool|string $seeNextPaginationLabel Test if the "next" pagination link is output and matches expected label. + * @param bool $seeGrid Test if the broadcasts are displayed in grid view (false = list view). + * @param bool $seeImage Test if the broadcasts display images. + * @param bool $seeDescription Test if the broadcasts display descriptions. + * @param bool|string $seeReadMore Test if the broadcasts display a read more link matching the given text. + */ + public function seeBroadcastsOutput($I, $numberOfPosts = false, $seePrevPaginationLabel = false, $seeNextPaginationLabel = false, $seeGrid = false, $seeImage = false, $seeDescription = false, $seeReadMore = false) + { + // Confirm that the block displays. + $I->seeElementInDOM('div.convertkit-broadcasts'); + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list'); + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast'); + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast a.convertkit-broadcast-title'); + + // Confirm that UTM parameters exist on a broadcast link. + $I->assertStringContainsString( + 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', + $I->grabAttributeFrom('a.convertkit-broadcast-title', 'href') + ); + + // If Display as grid is enabled, confirm the applicable HTML exists so that CSS can style this layout. + if ($seeGrid) { + $I->seeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); + } else { + $I->dontSeeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); + } + + // If Display image is enabled, confirm the image is displayed. + if ($seeImage) { + $I->seeElementInDOM('a.convertkit-broadcast-image img'); + $I->assertStringContainsString( + 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', + $I->grabAttributeFrom('a.convertkit-broadcast-image', 'href') + ); + } else { + $I->dontSeeElementInDOM('a.convertkit-broadcast-image img'); + } + + // If Display description is enabled, confirm the description is displayed. + if ($seeDescription) { + $I->seeElementInDOM('.convertkit-broadcast-description'); + } else { + $I->dontSeeElementInDOM('.convertkit-broadcast-description'); + } + + // If Display read more link is enabled, confirm the read more link is displayed and matches the given text. + if ($seeReadMore) { + $I->seeElementInDOM('a.convertkit-broadcast-read-more'); + $I->assertStringContainsString( + 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', + $I->grabAttributeFrom('a.convertkit-broadcast-read-more', 'href') + ); + } else { + $I->dontSeeElementInDOM('a.convertkit-broadcast-read-more'); + } + + // Confirm that the number of expected broadcasts displays. + if ($numberOfPosts !== false) { + $I->seeNumberOfElements('li.convertkit-broadcast', $numberOfPosts); + } + + // Confirm that previous pagination displays, if expected. + if ($seePrevPaginationLabel !== false) { + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-prev a'); + $I->seeInSource($seePrevPaginationLabel); + } + + // Confirm that next pagination displays, if expected. + if ($seeNextPaginationLabel !== false) { + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-next a'); + } + } + + /** + * Tests that the Broadcasts pagination works, and that the expected Broadcast + * is displayed after using previous and next links. + * + * @since 2.0.0 + * + * @param AcceptanceTester $I Tester. + * @param string $previousLabel Previous / Newer Broadcasts Label. + * @param string $nextLabel Next / Older Broadcasts Label. + */ + public function testBroadcastsPagination($I, $previousLabel, $nextLabel) + { + // Confirm that the block displays one broadcast with a pagination link to older broadcasts. + $I->seeBroadcastsOutput($I, 1, false, $nextLabel); + + // Click the Older Posts link. + $I->click('li.convertkit-broadcasts-pagination-next a'); + + // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been + // removed from the block. + $I->waitForBroadcastsToLoad($I); + + // Confirm that the block displays one broadcast with a pagination link to newer broadcasts. + $I->seeBroadcastsOutput($I, 1, $previousLabel, false); + + // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. + $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_SECOND_TITLE']); + + // Click the Newer Posts link. + $I->click('li.convertkit-broadcasts-pagination-prev a'); + + // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been + // removed from the block. + $I->waitForBroadcastsToLoad($I); + + // Confirm that the block displays one broadcast with a pagination link to older broadcasts. + $I->seeBroadcastsOutput($I, 1, false, $nextLabel); + + // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. + $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_FIRST_TITLE']); + } + + /** + * Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been + * removed from the block. + * + * @since 1.9.7.6 + * + * @param AcceptanceTester $I Tester. + */ + public function waitForBroadcastsToLoad($I) + { + $I->waitForElementChange( + 'div.convertkit-broadcasts', + function(\Facebook\WebDriver\WebDriverElement $el) { + return ( strpos($el->getAttribute('class'), 'convertkit-broadcasts-loading') === false ? true : false ); + }, + 5 + ); + } /** * Check that expected HTML exists in the DOM of the page we're viewing diff --git a/tests/acceptance.suite.yml b/tests/acceptance.suite.yml index 82e55db79..457804b1a 100644 --- a/tests/acceptance.suite.yml +++ b/tests/acceptance.suite.yml @@ -22,8 +22,6 @@ modules: # Our helper classes, which contain functions used across multiple tests. # If you created a new file in tests/_support/Helper/Acceptance, add its namespace and class below, - \Helper\Acceptance\ConvertKitAPI - - \Helper\Acceptance\ConvertKitBroadcasts - - \Helper\Acceptance\ConvertKitRestrictedContent - \Helper\Acceptance\CustomPostType - \Helper\Acceptance\Email - \Helper\Acceptance\Plugin From 5a5db83e9f34b8a20aebcb490bb77c8bcc16fd47 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 17:32:39 +0000 Subject: [PATCH 09/11] Fix typo --- tests/_support/Helper/Acceptance/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php index 7d6aa05e1..d084c99bd 100644 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ b/tests/_support/Helper/Acceptance/Plugin.php @@ -120,7 +120,7 @@ public function setupConvertKitPluginFakeAPIKey($I) $I->setupConvertKitPlugin( $I, [ - 'api_key' => 'fakeApiKey' + 'api_key' => 'fakeApiKey', 'api_secret' => 'fakeApiSecret', 'post_form' => '', 'page_form' => '', From 2434e05be096cee7a7c772ed581c693448ef4ca0 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 5 Dec 2023 18:15:26 +0000 Subject: [PATCH 10/11] Fix failing tests --- .../forms/general/NonInlineFormCest.php | 94 ++++++------------- 1 file changed, 28 insertions(+), 66 deletions(-) diff --git a/tests/acceptance/forms/general/NonInlineFormCest.php b/tests/acceptance/forms/general/NonInlineFormCest.php index 08fdf6a48..bf10d5465 100644 --- a/tests/acceptance/forms/general/NonInlineFormCest.php +++ b/tests/acceptance/forms/general/NonInlineFormCest.php @@ -45,14 +45,9 @@ public function testDefaultNonInlineForm(AcceptanceTester $I) // Setup Plugin with a non-inline Default Form (Site Wide). $I->setupConvertKitPlugin( $I, - false, - false, - false, - false, - false, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] + [ + 'non_inline_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'], + ] ); $I->setupConvertKitPluginResources($I); @@ -114,14 +109,10 @@ public function testDefaultNonInlineFormIgnoredWhenDefaultPageNonInlineFormDefin // Setup Plugin with a non-inline Default Form for both Pages and Site Wide. $I->setupConvertKitPlugin( $I, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'], // Page Default. - false, - false, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] // Site Wide. + [ + 'page_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'], + 'non_inline_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'], + ] ); // Add a Page using the Gutenberg editor. @@ -157,14 +148,9 @@ public function testDefaultNonInlineFormIgnoredWhenPageNonInlineFormDefined(Acce // Setup Plugin with a non-inline Default Form for Site Wide. $I->setupConvertKitPlugin( $I, - false, - false, - false, - false, - false, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] // Site Wide. + [ + 'non_inline_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'], + ] ); // Add a Page using the Gutenberg editor. @@ -200,14 +186,9 @@ public function testDefaultNonInlineFormIgnoredWhenPageNonInlineFormDefinedInBlo // Setup Plugin with a non-inline Default Form for Site Wide. $I->setupConvertKitPlugin( $I, - false, - false, - false, - false, - false, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] // Site Wide. + [ + 'non_inline_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'], + ] ); // Add a Page using the Gutenberg editor. @@ -253,14 +234,9 @@ public function testDefaultNonInlineFormIgnoredWhenPageNonInlineFormDefinedInSho // Setup Plugin with a non-inline Default Form for Site Wide. $I->setupConvertKitPlugin( $I, - false, - false, - false, - false, - false, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] // Site Wide. + [ + 'non_inline_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'], + ] ); // Add a Page using the Classic Editor. @@ -307,14 +283,10 @@ public function testDefaultNonInlineFormIgnoredWhenDefaultPostNonInlineFormDefin // Setup Plugin with a non-inline Default Form for both Posts and Site Wide. $I->setupConvertKitPlugin( $I, - false, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'], // Post Default. - false, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] // Site Wide. + [ + 'post_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'], + 'non_inline_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'], + ] ); // Add a Post using the Gutenberg editor. @@ -347,17 +319,12 @@ public function testDefaultNonInlineFormIgnoredWhenDefaultPostNonInlineFormDefin */ public function testDefaultNonInlineFormIgnoredWhenPostNonInlineFormDefined(AcceptanceTester $I) { - // Setup Plugin with a non-inline Default Form for both Posts and Site Wide. + // Setup Plugin with a non-inline Default Form for Site Wide. $I->setupConvertKitPlugin( $I, - false, - false, - false, - false, - false, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] // Site Wide. + [ + 'non_inline_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'], + ] ); // Add a Post using the Gutenberg editor. @@ -390,17 +357,12 @@ public function testDefaultNonInlineFormIgnoredWhenPostNonInlineFormDefined(Acce */ public function testDefaultNonInlineFormIgnoredWhenPostCategoryNonInlineFormDefined(AcceptanceTester $I) { - // Setup Plugin with a non-inline Default Form for both Posts and Site Wide. + // Setup Plugin with a non-inline Default Form for Site Wide. $I->setupConvertKitPlugin( $I, - false, - false, - false, - false, - false, - false, - false, - $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] // Site Wide. + [ + 'non_inline_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'], + ] ); // Create Category. From 4a04b6a3a942f4b1d04d68dd3c8d009767190114 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 11 Dec 2023 14:23:03 +0000 Subject: [PATCH 11/11] Split Plugin helper functions into own classes --- .../Acceptance/ConvertKitBroadcasts.php | 218 +++ .../Helper/Acceptance/ConvertKitForms.php | 120 ++ .../Helper/Acceptance/ConvertKitPlugin.php | 858 ++++++++ .../Helper/Acceptance/ConvertKitProducts.php | 111 ++ .../Acceptance/ConvertKitRestrictContent.php | 454 +++++ tests/_support/Helper/Acceptance/Plugin.php | 1717 ----------------- tests/acceptance.suite.yml | 6 +- 7 files changed, 1766 insertions(+), 1718 deletions(-) create mode 100644 tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php create mode 100644 tests/_support/Helper/Acceptance/ConvertKitForms.php create mode 100644 tests/_support/Helper/Acceptance/ConvertKitPlugin.php create mode 100644 tests/_support/Helper/Acceptance/ConvertKitProducts.php create mode 100644 tests/_support/Helper/Acceptance/ConvertKitRestrictContent.php delete mode 100644 tests/_support/Helper/Acceptance/Plugin.php diff --git a/tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php b/tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php new file mode 100644 index 000000000..f99e94cf0 --- /dev/null +++ b/tests/_support/Helper/Acceptance/ConvertKitBroadcasts.php @@ -0,0 +1,218 @@ +{yourFunctionName}. + * + * @since 1.9.7.5 + */ +class ConvertKitBroadcasts extends \Codeception\Module +{ + /** + * Helper method to setup the Plugin's Broadcasts to Posts settings. + * + * @since 2.2.8 + * + * @param AcceptanceTester $I AcceptanceTester. + * @param bool|array $settings Array of key/value settings. If not defined, uses expected defaults. + */ + public function setupConvertKitPluginBroadcasts($I, $settings = false) + { + // Go to the Plugin's Broadcasts screen. + $I->loadConvertKitSettingsBroadcastsScreen($I); + + // Complete fields. + if ( $settings ) { + foreach ( $settings as $key => $value ) { + switch ( $key ) { + case 'enabled': + case 'enabled_export': + case 'no_styles': + if ( $value ) { + $I->checkOption('_wp_convertkit_settings_broadcasts[' . $key . ']'); + } else { + $I->uncheckOption('_wp_convertkit_settings_broadcasts[' . $key . ']'); + } + break; + + case 'post_status': + case 'category_id': + case 'author_id': + $I->fillSelect2Field($I, '#select2-_wp_convertkit_settings_broadcasts_' . $key . '-container', $value); + + break; + default: + $I->fillField('_wp_convertkit_settings_broadcasts[' . $key . ']', $value); + break; + } + } + } + + // Click the Save Changes button. + $I->click('Save Changes'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + } + + /** + * Helper method to load the Plugin's Settings > Broadcasts screen. + * + * @since 2.2.8 + * + * @param AcceptanceTester $I AcceptanceTester. + */ + public function loadConvertKitSettingsBroadcastsScreen($I) + { + $I->amOnAdminPage('options-general.php?page=_wp_convertkit_settings&tab=broadcasts'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + } + + /** + * Check that expected HTML exists in the DOM of the page we're viewing for + * a Broadcasts block or shortcode, based on its configuration. + * + * @since 1.9.7.5 + * + * @param AcceptanceTester $I Tester. + * @param bool|int $numberOfPosts Number of Broadcasts listed. + * @param bool|string $seePrevPaginationLabel Test if the "previous" pagination link is output and matches expected label. + * @param bool|string $seeNextPaginationLabel Test if the "next" pagination link is output and matches expected label. + * @param bool $seeGrid Test if the broadcasts are displayed in grid view (false = list view). + * @param bool $seeImage Test if the broadcasts display images. + * @param bool $seeDescription Test if the broadcasts display descriptions. + * @param bool|string $seeReadMore Test if the broadcasts display a read more link matching the given text. + */ + public function seeBroadcastsOutput($I, $numberOfPosts = false, $seePrevPaginationLabel = false, $seeNextPaginationLabel = false, $seeGrid = false, $seeImage = false, $seeDescription = false, $seeReadMore = false) + { + // Confirm that the block displays. + $I->seeElementInDOM('div.convertkit-broadcasts'); + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list'); + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast'); + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-list li.convertkit-broadcast a.convertkit-broadcast-title'); + + // Confirm that UTM parameters exist on a broadcast link. + $I->assertStringContainsString( + 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', + $I->grabAttributeFrom('a.convertkit-broadcast-title', 'href') + ); + + // If Display as grid is enabled, confirm the applicable HTML exists so that CSS can style this layout. + if ($seeGrid) { + $I->seeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); + } else { + $I->dontSeeElementInDOM('div.convertkit-broadcasts[data-display-grid="1"]'); + } + + // If Display image is enabled, confirm the image is displayed. + if ($seeImage) { + $I->seeElementInDOM('a.convertkit-broadcast-image img'); + $I->assertStringContainsString( + 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', + $I->grabAttributeFrom('a.convertkit-broadcast-image', 'href') + ); + } else { + $I->dontSeeElementInDOM('a.convertkit-broadcast-image img'); + } + + // If Display description is enabled, confirm the description is displayed. + if ($seeDescription) { + $I->seeElementInDOM('.convertkit-broadcast-description'); + } else { + $I->dontSeeElementInDOM('.convertkit-broadcast-description'); + } + + // If Display read more link is enabled, confirm the read more link is displayed and matches the given text. + if ($seeReadMore) { + $I->seeElementInDOM('a.convertkit-broadcast-read-more'); + $I->assertStringContainsString( + 'utm_source=wordpress&utm_term=en_US&utm_content=convertkit', + $I->grabAttributeFrom('a.convertkit-broadcast-read-more', 'href') + ); + } else { + $I->dontSeeElementInDOM('a.convertkit-broadcast-read-more'); + } + + // Confirm that the number of expected broadcasts displays. + if ($numberOfPosts !== false) { + $I->seeNumberOfElements('li.convertkit-broadcast', $numberOfPosts); + } + + // Confirm that previous pagination displays, if expected. + if ($seePrevPaginationLabel !== false) { + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-prev a'); + $I->seeInSource($seePrevPaginationLabel); + } + + // Confirm that next pagination displays, if expected. + if ($seeNextPaginationLabel !== false) { + $I->seeElementInDOM('div.convertkit-broadcasts ul.convertkit-broadcasts-pagination li.convertkit-broadcasts-pagination-next a'); + } + } + + /** + * Tests that the Broadcasts pagination works, and that the expected Broadcast + * is displayed after using previous and next links. + * + * @since 2.0.0 + * + * @param AcceptanceTester $I Tester. + * @param string $previousLabel Previous / Newer Broadcasts Label. + * @param string $nextLabel Next / Older Broadcasts Label. + */ + public function testBroadcastsPagination($I, $previousLabel, $nextLabel) + { + // Confirm that the block displays one broadcast with a pagination link to older broadcasts. + $I->seeBroadcastsOutput($I, 1, false, $nextLabel); + + // Click the Older Posts link. + $I->click('li.convertkit-broadcasts-pagination-next a'); + + // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been + // removed from the block. + $I->waitForBroadcastsToLoad($I); + + // Confirm that the block displays one broadcast with a pagination link to newer broadcasts. + $I->seeBroadcastsOutput($I, 1, $previousLabel, false); + + // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. + $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_SECOND_TITLE']); + + // Click the Newer Posts link. + $I->click('li.convertkit-broadcasts-pagination-prev a'); + + // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been + // removed from the block. + $I->waitForBroadcastsToLoad($I); + + // Confirm that the block displays one broadcast with a pagination link to older broadcasts. + $I->seeBroadcastsOutput($I, 1, false, $nextLabel); + + // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. + $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_FIRST_TITLE']); + } + + /** + * Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been + * removed from the block. + * + * @since 1.9.7.6 + * + * @param AcceptanceTester $I Tester. + */ + public function waitForBroadcastsToLoad($I) + { + $I->waitForElementChange( + 'div.convertkit-broadcasts', + function(\Facebook\WebDriver\WebDriverElement $el) { + return ( strpos($el->getAttribute('class'), 'convertkit-broadcasts-loading') === false ? true : false ); + }, + 5 + ); + } +} diff --git a/tests/_support/Helper/Acceptance/ConvertKitForms.php b/tests/_support/Helper/Acceptance/ConvertKitForms.php new file mode 100644 index 000000000..5f1f48abb --- /dev/null +++ b/tests/_support/Helper/Acceptance/ConvertKitForms.php @@ -0,0 +1,120 @@ +{yourFunctionName}. + * + * @since 2.2.0 + */ +class ConvertKitForms extends \Codeception\Module +{ + /** + * Check that expected HTML exists in the DOM of the page we're viewing for + * a Form Trigger block or shortcode, and that the button loads the expected + * ConvertKit Form. + * + * @since 2.2.0 + * + * @param AcceptanceTester $I Tester. + * @param string $formURL Form URL. + * @param bool|string $text Test if the button text matches the given value. + * @param bool|string $textColor Test if the given text color is applied. + * @param bool|string $backgroundColor Test is the given background color is applied. + */ + public function seeFormTriggerOutput($I, $formURL, $text = false, $textColor = false, $backgroundColor = false) + { + // Confirm that the button stylesheet loaded. + $I->seeInSource(' 'https://embed.filekitcdn.com/e/pX62TATVeCKK5QzkXWNLw3/qM63x7vF3qN1whboGdEpuL', + 'thumbnail_alt' => 'MacBook Pro beside plant in vase', + 'is_paid' => true, + ], + 572575 => [ + 'id' => 572575, + 'title' => 'Paid Subscriber Broadcast', + 'url' => 'https://cheerful-architect-3237.ck.page/posts/paid-subscriber-broadcast', + 'published_at' => '2022-05-03T00:00:00.000Z', + 'description' => 'Description text for Paid Subscriber Broadcast', + 'thumbnail_url' => 'https://placehold.co/600x400', + 'thumbnail_alt' => 'Alt text for Paid Subscriber Broadcast', + 'is_paid' => true, + ], + ] + ); + + // Define Products. + $I->haveOptionInDatabase( + 'convertkit_products', + [ + 36377 => [ + 'id' => 36377, + 'name' => 'Newsletter Subscription', + 'url' => 'https://cheerful-architect-3237.ck.page/products/newsletter-subscription', + 'published' => true, + ], + ] + ); + + // Define Tags. + $I->haveOptionInDatabase( + 'convertkit_tags', + [ + 2744672 => [ + 'id' => 2744672, + 'name' => 'wordpress', + 'created_at' => '2021-11-11T19:30:06.000Z', + ], + 2907192 => [ + 'id' => 2907192, + 'name' => 'gravityforms-tag-1', + 'created_at' => '2022-02-02T14:06:32.000Z', + ], + 3748541 => [ + 'id' => 3748541, + 'name' => 'wpforms', + 'created_at' => '2023-03-29T12:32:38.000Z', + ], + 2907193 => [ + 'id' => 2907193, + 'name' => 'gravityforms-tag-2', + 'created_at' => '2022-02-02T14:06:38.000Z', + ], + ] + ); + + // Define last queried to now for all resources, so they're not automatically immediately refreshed by the Plugin's logic. + $I->haveOptionInDatabase( 'convertkit_forms_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_landing_pages_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_posts_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_products_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_tags_last_queried', strtotime( 'now' ) ); + } + + /** + * Helper method to define cached Resources (Forms, Landing Pages, Posts, Products and Tags), + * directly into the database, instead of querying the API for them via the Resource classes + * as if the ConvertKit account is new and has no resources defined in ConvertKit. + * + * @since 2.0.7 + * + * @param AcceptanceTester $I AcceptanceTester. + */ + public function setupConvertKitPluginResourcesNoData($I) + { + // Define Forms as if the Forms resource class populated them from the API. + $I->haveOptionInDatabase( + 'convertkit_forms', + [] + ); + + // Define Landing Pages. + $I->haveOptionInDatabase( + 'convertkit_landing_pages', + [] + ); + + // Define Posts. + $I->haveOptionInDatabase( + 'convertkit_posts', + [] + ); + + // Define Products. + $I->haveOptionInDatabase( + 'convertkit_products', + [] + ); + + // Define Tags. + $I->haveOptionInDatabase( + 'convertkit_tags', + [] + ); + + // Define last queried to now for all resources, so they're not automatically immediately refreshed by the Plugin's logic. + $I->haveOptionInDatabase( 'convertkit_forms_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_landing_pages_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_posts_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_products_last_queried', strtotime( 'now' ) ); + $I->haveOptionInDatabase( 'convertkit_tags_last_queried', strtotime( 'now' ) ); + } + + /** + * Helper method to reset the ConvertKit Plugin settings, as if it's a clean installation. + * + * @since 1.9.6.7 + * + * @param AcceptanceTester $I AcceptanceTester. + */ + public function resetConvertKitPlugin($I) + { + // Plugin Settings. + $I->dontHaveOptionInDatabase('_wp_convertkit_settings'); + $I->dontHaveOptionInDatabase('_wp_convertkit_settings_restrict_content'); + $I->dontHaveOptionInDatabase('_wp_convertkit_settings_broadcasts'); + $I->dontHaveOptionInDatabase('convertkit_version'); + + // Resources. + $I->dontHaveOptionInDatabase('convertkit_broadcasts'); + $I->dontHaveOptionInDatabase('convertkit_broadcasts_last_queried'); + $I->dontHaveOptionInDatabase('convertkit_forms'); + $I->dontHaveOptionInDatabase('convertkit_forms_last_queried'); + $I->dontHaveOptionInDatabase('convertkit_landing_pages'); + $I->dontHaveOptionInDatabase('convertkit_landing_pages_last_queried'); + $I->dontHaveOptionInDatabase('convertkit_posts'); + $I->dontHaveOptionInDatabase('convertkit_posts_last_queried'); + $I->dontHaveOptionInDatabase('convertkit_products'); + $I->dontHaveOptionInDatabase('convertkit_products_last_queried'); + $I->dontHaveOptionInDatabase('convertkit_tags'); + $I->dontHaveOptionInDatabase('convertkit_tags_last_queried'); + + // Review Request. + $I->dontHaveOptionInDatabase('convertkit-review-request'); + $I->dontHaveOptionInDatabase('convertkit-review-dismissed'); + + // Upgrades. + $I->dontHaveOptionInDatabase('_wp_convertkit_upgrade_posts'); + } + + /** + * Helper method to load the Plugin's Settings > General screen. + * + * @since 1.9.6 + * + * @param AcceptanceTester $I AcceptanceTester. + */ + public function loadConvertKitSettingsGeneralScreen($I) + { + $I->amOnAdminPage('options-general.php?page=_wp_convertkit_settings'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + } + + /** + * Helper method to load the Plugin's Settings > Tools screen. + * + * @since 1.9.6 + * + * @param AcceptanceTester $I AcceptanceTester. + */ + public function loadConvertKitSettingsToolsScreen($I) + { + $I->amOnAdminPage('options-general.php?page=_wp_convertkit_settings&tab=tools'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + } + + /** + * Helper method to clear the Plugin's debug log. + * + * @since 1.9.6 + * + * @param AcceptanceTester $I AcceptanceTester. + */ + public function clearDebugLog($I) + { + // Go to the Plugin's Tools Screen. + $I->loadConvertKitSettingsToolsScreen($I); + + // Click the Clear log button. + $I->click('Clear log'); + } + + /** + * Helper method to determine if the given entry exists in the Plugin Debug Log screen's textarea. + * + * @since 1.9.6 + * + * @param AcceptanceTester $I AcceptanceTester. + * @param string $entry Log entry. + */ + public function seeInPluginDebugLog($I, $entry) + { + $I->loadConvertKitSettingsToolsScreen($I); + $I->seeInSource($entry); + } + + /** + * Helper method to determine if the given entry does not exist in the Plugin Debug Log screen's textarea. + * + * @since 1.9.6 + * + * @param AcceptanceTester $I AcceptanceTester. + * @param string $entry Log entry. + */ + public function dontSeeInPluginDebugLog($I, $entry) + { + $I->loadConvertKitSettingsToolsScreen($I); + $I->dontSeeInSource($entry); + } + + /** + * Helper method to determine that the order of the Form resources in the given + * select element are in the expected alphabetical order. + * + * @since 2.0.8 + * + * @param AcceptanceTester $I AcceptanceTester. + * @param string $selectElement element. + * @param bool|array $prependOptions Option elements that should appear before the resources. + */ + public function checkSelectLandingPageOptionOrder($I, $selectElement, $prependOptions = false) + { + // Define options. + $options = [ + 'Character Encoding', // First item. + 'Legacy Landing Page', // Last item. + ]; + + // Prepend options, such as 'Default' and 'None' to the options, if required. + if ( $prependOptions ) { + $options = array_merge( $prependOptions, $options ); + } + + // Check order. + $I->checkSelectOptionOrder($I, $selectElement, $options); + } + + /** + * Helper method to determine that the order of the Form resources in the given + * select element are in the expected alphabetical order. + * + * @since 2.0.8 + * + * @param AcceptanceTester $I AcceptanceTester. + * @param string $selectElement element. + * @param array $values '); + } + + // Click the button to confirm that the ConvertKit modal displays; this confirms + // necessary ConvertKit scripts have been loaded. + $I->click('a[href="' . $productURL . '"]'); + $I->seeElementInDOM('iframe[data-active]'); + } + + /** + * Check that expected HTML exists in the DOM of the page we're viewing for + * a Product block or shortcode, and that the button loads the expected + * ConvertKit Product modal. + * + * @since 1.9.8.5 + * + * @param AcceptanceTester $I Tester. + * @param string $productURL Product URL. + * @param bool|string $text Test if the button text matches the given value. + * @param bool|string $textColor Test if the given text color is applied. + * @param bool|string $backgroundColor Test is the given background color is applied. + */ + public function seeProductOutput($I, $productURL, $text = false, $textColor = false, $backgroundColor = false) + { + // Confirm that the product stylesheet loaded. + $I->seeInSource('invalid: Email address is invalid
'); + $I->seeInSource('
'); + + // Check content is not displayed, and CTA displays with expected text. + $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); + + // Set cookie with signed subscriber ID and reload the restricted content page, as if we entered the + // code sent in the email as a ConvertKit subscriber who has not subscribed to the product. + $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID_NO_ACCESS']); + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID . '&ck-cache-bust=' . microtime() ); + } else { + $I->amOnUrl($urlOrPageID . '?ck-cache-bust=' . microtime() ); + } + + // Confirm an inline error message is displayed. + $I->seeInSource('
' . $textItems['no_access_text'] . '
'); + $I->seeInSource('
'); + + // Check content is not displayed, and CTA displays with expected text. + $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); + + // Login as a ConvertKit subscriber who has subscribed to the product. + $I->waitForElementVisible('input#convertkit_email'); + $I->fillField('convertkit_email', $_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL']); + $I->click('input.wp-block-button__link'); + + // Confirm that confirmation an email has been sent is displayed. + $this->testRestrictContentShowsEmailCodeForm($I, $visibleContent, $memberContent, $textItems); + + // Test that the restricted content displays when a valid signed subscriber ID is used, + // as if we entered the code sent in the email. + $this->testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent); + } + + /** + * Run frontend tests for restricted content by ConvertKit Product, using the modal authentication flow, to confirm + * that visible and member's content is / is not displayed when logging in with valid and invalid subscriber email addresses. + * + * @since 2.3.8 + * + * @param AcceptanceTester $I Tester. + * @param string|int $urlOrPageID URL or ID of Restricted Content Page. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictedContentModalByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Navigate to the page. + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID); + } else { + $I->amOnUrl($urlOrPageID); + } + + // Confirm Restrict Content CSS is output. + $I->seeInSource(''); + + // Enter the email address and submit the form. + $I->fillField('convertkit_email', $emailAddress); + $I->click('input.wp-block-button__link'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the restricted content is now displayed. + $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); + } + + /** + * Run frontend tests for restricted content, to confirm that both visible and member content is displayed + * when a valid signed subscriber ID is set as a cookie, as if the user entered a code sent in the email. + * + * @since 2.2.2 + * + * @param AcceptanceTester $I Tester. + * @param string|int $urlOrPageID URL or ID of Restricted Content Page. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + */ + public function testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent) + { + // Set cookie with signed subscriber ID, as if we entered the code sent in the email. + $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); + + // Reload the restricted content page. + if ( is_numeric( $urlOrPageID ) ) { + $I->amOnPage('?p=' . $urlOrPageID ); + } else { + $I->amOnUrl($urlOrPageID ); + } + + // Confirm cookie was set with the expected value. + $I->assertEquals($I->grabCookie('ck_subscriber_id'), $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); + + // Confirm that the restricted content is now displayed, as we've authenticated as a subscriber + // who has access to this Product. + $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); + } + + /** + * Run frontend tests for restricted content, to confirm that: + * - visible content is displayed, + * - member's content is not displayed, + * - the CTA is displayed with the expected text + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictContentByProductHidesContentWithCTA($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the visible text displays, hidden text does not display and the CTA displays. + if ( ! empty($visibleContent)) { + $I->see($visibleContent); + } + $I->dontSee($memberContent); + + // Confirm that the CTA displays with the expected headings, text, buttons and other elements. + $I->seeElementInDOM('#convertkit-restrict-content'); + + $I->seeInSource('

' . $textItems['subscribe_heading'] . '

'); + $I->see($textItems['subscribe_text']); + + $I->see($textItems['subscribe_button_label']); + $I->seeInSource(''); + $I->seeInSource('' . $textItems['email_description_text'] . ''); + } + + /** + * Run frontend tests for restricted content, to confirm that: + * - visible content is displayed, + * - member's content is not displayed, + * - the email code form is displayed with the expected text. + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. + */ + public function testRestrictContentShowsEmailCodeForm($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems) + { + // Define expected text and labels if not supplied. + if ( ! $textItems ) { + $textItems = $this->getRestrictedContentDefaultSettings(); + } + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the visible text displays, hidden text does not display and the CTA displays. + if ( ! empty($visibleContent)) { + $I->see($visibleContent); + } + $I->dontSee($memberContent); + + // Confirm that the CTA displays with the expected text. + $I->seeElementInDOM('#convertkit-restrict-content'); + $I->seeInSource('

' . $textItems['email_check_heading'] . '

'); + $I->see($textItems['email_check_text']); + $I->seeElementInDOM('input#convertkit_subscriber_code'); + $I->seeElementInDOM('input.wp-block-button__link'); + + // Enter an invalid code. + $I->fillField('subscriber_code', '999999'); + $I->click('Verify'); + + // Confirm an inline error message is displayed. + $I->seeInSource('
The entered code is invalid. Please try again, or click the link sent in the email.
'); + $I->seeInSource('
'); + } + + /** + * Run frontend tests for restricted content, to confirm that: + * - visible content is displayed, + * - member's content is displayed, + * - the CTA is not displayed + * + * @since 2.1.0 + * + * @param AcceptanceTester $I Tester. + * @param string $visibleContent Content that should always be visible. + * @param string $memberContent Content that should only be available to authenticated subscribers. + */ + public function testRestrictContentDisplaysContent($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.') + { + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the visible and hidden text displays. + if ( ! empty($visibleContent)) { + $I->see($visibleContent); + } + $I->see($memberContent); + + // Confirm that the CTA is not displayed. + $I->dontSeeElementInDOM('#convertkit-restrict-content'); + } +} diff --git a/tests/_support/Helper/Acceptance/Plugin.php b/tests/_support/Helper/Acceptance/Plugin.php deleted file mode 100644 index d084c99bd..000000000 --- a/tests/_support/Helper/Acceptance/Plugin.php +++ /dev/null @@ -1,1717 +0,0 @@ -{yourFunctionName}. - * - * @since 1.9.6 - */ -class Plugin extends \Codeception\Module -{ - /** - * Helper method to activate the ConvertKit Plugin, checking - * it activated and no errors were output. - * - * @since 1.9.6 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function activateConvertKitPlugin($I) - { - $I->activateThirdPartyPlugin($I, 'convertkit'); - } - - /** - * Helper method to deactivate the ConvertKit Plugin, checking - * it activated and no errors were output. - * - * @since 1.9.6 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function deactivateConvertKitPlugin($I) - { - $I->deactivateThirdPartyPlugin($I, 'convertkit'); - } - - /** - * Helper method to programmatically setup the Plugin's settings, as if the - * user configured the Plugin at `Settings > ConvertKit`. - * - * @since 1.9.6 - * - * @param AcceptanceTester $I AcceptanceTester. - * @param bool|array $options { - * Optional. An array of settings. - * - * @type string $api_key API Key (if specified, used instead of CONVERTKIT_API_KEY). - * @type string $api_secret API Secret (if specified, used instead of CONVERTKIT_API_SECRET). - * @type string $debug Enable debugging (default: on). - * @type string $no_scripts Disable JS (default: off). - * @type string $no_css Disable CSS (default: off). - * @type string $post_form Default Form ID for Posts (if specified, used instead of CONVERTKIT_API_FORM_ID). - * @type string $page_form Default Form ID for Pages (if specified, used instead of CONVERTKIT_API_FORM_ID). - * @type string $product_form Default Form ID for WooCommerce Products (if specified, used instead of CONVERTKIT_API_FORM_ID). - * @type string $non_inline_form Default Global non-inline Form ID (if specified, none if false). - * } - */ - public function setupConvertKitPlugin($I, $options = false) - { - // Define default options. - $defaults = [ - 'api_key' => $_ENV['CONVERTKIT_API_KEY'], - 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], - 'debug' => 'on', - 'no_scripts' => '', - 'no_css' => '', - 'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'], - 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], - 'product_form' => $_ENV['CONVERTKIT_API_FORM_ID'], - 'non_inline_form' => '', - ]; - - // If supplied options are an array, merge them with the defaults. - if (is_array($options)) { - $options = array_merge($defaults, $options); - } else { - $options = $defaults; - } - - // Define settings in options table. - $I->haveOptionInDatabase('_wp_convertkit_settings', $options); - } - - /** - * Helper method to programmatically setup the Plugin's settings, as if the - * user configured the Plugin at `Settings > ConvertKit` with a ConvertKit - * API Key and Secret for a ConvertKit account that has no data (no forms, - * products, tags etc). - * - * @since 2.4.0 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function setupConvertKitPluginAPIKeyNoData($I) - { - $I->setupConvertKitPlugin( - $I, - [ - 'api_key' => $_ENV['CONVERTKIT_API_KEY_NO_DATA'], - 'api_secret' => $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], - 'post_form' => '', - 'page_form' => '', - 'product_form' => '', - ] - ); - } - - /** - * Helper method to programmatically setup the Plugin's settings, as if the - * user configured the Plugin at `Settings > ConvertKit` with an invalid - * ConvertKit API Key and Secret. - * - * @since 2.4.0 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function setupConvertKitPluginFakeAPIKey($I) - { - $I->setupConvertKitPlugin( - $I, - [ - 'api_key' => 'fakeApiKey', - 'api_secret' => 'fakeApiSecret', - 'post_form' => '', - 'page_form' => '', - 'product_form' => '', - ] - ); - } - - /** - * Helper method to programmatically setup the Plugin's settings, as if the - * user configured the Plugin at `Settings > ConvertKit` with a ConvertKit - * API Key and Secret, and defined no default Forms for Posts, Pages and - * WooCommerce Products. - * - * @since 2.4.0 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function setupConvertKitPluginNoDefaultForms($I) - { - $I->setupConvertKitPlugin( - $I, - [ - 'post_form' => '', - 'page_form' => '', - 'product_form' => '', - ] - ); - } - - /** - * Helper method to programmatically setup the Plugin's settings, as if the - * user configured the Plugin at `Settings > ConvertKit` with a ConvertKit - * API Key and Secret, and disabled JS. - * - * @since 2.4.0 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function setupConvertKitPluginDisableJS($I) - { - $I->setupConvertKitPlugin( - $I, - [ - 'no_scripts' => 'on', - ] - ); - } - - /** - * Helper method to define cached Resources (Forms, Landing Pages, Posts, Products and Tags), - * directly into the database, instead of querying the API for them via the Resource classes. - * - * This can safely be done for Acceptance tests, as WPUnit tests ensure that - * caching Resources from calls made to the API work and store data in the expected - * structure. - * - * Defining cached Resources here reduces the number of API calls made for each test, - * reducing the likelihood of hitting a rate limit due to running tests in parallel. - * - * Resources are deliberately not in order, to emulate how the data might not always - * be in alphabetical / published order from the API. - * - * @since 2.0.7 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function setupConvertKitPluginResources($I) - { - // Define Forms as if the Forms resource class populated them from the API. - $I->haveOptionInDatabase( - 'convertkit_forms', - [ - 3003590 => [ - 'id' => 3003590, - 'name' => 'Third Party Integrations Form', - 'created_at' => '2022-02-17T15:05:31.000Z', - 'type' => 'embed', - 'format' => 'inline', - 'embed_js' => 'https://cheerful-architect-3237.ck.page/71cbcc4042/index.js', - 'embed_url' => 'https://cheerful-architect-3237.ck.page/71cbcc4042', - 'archived' => false, - 'uid' => '71cbcc4042', - ], - 2780977 => [ - 'id' => 2780977, - 'name' => 'Modal Form', - 'created_at' => '2021-11-17T04:22:06.000Z', - 'type' => 'embed', - 'format' => 'modal', - 'embed_js' => 'https://cheerful-architect-3237.ck.page/397e876257/index.js', - 'embed_url' => 'https://cheerful-architect-3237.ck.page/397e876257', - 'archived' => false, - 'uid' => '397e876257', - ], - 2780979 => [ - 'id' => 2780979, - 'name' => 'Slide In Form', - 'created_at' => '2021-11-17T04:22:24.000Z', - 'type' => 'embed', - 'format' => 'slide in', - 'embed_js' => 'https://cheerful-architect-3237.ck.page/e0d65bed9d/index.js', - 'embed_url' => 'https://cheerful-architect-3237.ck.page/e0d65bed9d', - 'archived' => false, - 'uid' => 'e0d65bed9d', - ], - 2765139 => [ - 'id' => 2765139, - 'name' => 'Page Form', - 'created_at' => '2021-11-11T15:30:40.000Z', - 'type' => 'embed', - 'format' => 'inline', - 'embed_js' => 'https://cheerful-architect-3237.ck.page/85629c512d/index.js', - 'embed_url' => 'https://cheerful-architect-3237.ck.page/85629c512d', - 'archived' => false, - 'uid' => '85629c512d', - ], - 470099 => [ - 'id' => 470099, - 'name' => 'Legacy Form', - 'created_at' => null, - 'type' => 'embed', - 'url' => 'https://app.convertkit.com/landing_pages/470099', - 'embed_js' => 'https://api.convertkit.com/api/v3/forms/470099.js?api_key=' . $_ENV['CONVERTKIT_API_KEY'], - 'embed_url' => 'https://api.convertkit.com/api/v3/forms/470099.html?api_key=' . $_ENV['CONVERTKIT_API_KEY'], - 'title' => 'Join the newsletter', - 'description' => '

Subscribe to get our latest content by email.

', - 'sign_up_button_text' => 'Subscribe', - 'success_message' => 'Success! Now check your email to confirm your subscription.', - 'archived' => false, - ], - 2780980 => [ - 'id' => 2780980, - 'name' => 'Sticky Bar Form', - 'created_at' => '2021-11-17T04:22:42.000Z', - 'type' => 'embed', - 'format' => 'sticky bar', - 'embed_js' => 'https://cheerful-architect-3237.ck.page/9f5c601482/index.js', - 'embed_url' => 'https://cheerful-architect-3237.ck.page/9f5c601482', - 'archived' => false, - 'uid' => '9f5c601482', - ], - 3437554 => [ - 'id' => 3437554, - 'name' => 'AAA Test', - 'created_at' => '2022-07-15T15:06:32.000Z', - 'type' => 'embed', - 'format' => 'inline', - 'embed_js' => 'https://cheerful-architect-3237.ck.page/3bb15822a2/index.js', - 'embed_url' => 'https://cheerful-architect-3237.ck.page/3bb15822a2', - 'archived' => false, - 'uid' => '3bb15822a2', - ], - 2765149 => [ - 'id' => 2765149, - 'name' => 'WooCommerce Product Form', - 'created_at' => '2021-11-11T15:32:54.000Z', - 'type' => 'embed', - 'format' => 'inline', - 'embed_js' => 'https://cheerful-architect-3237.ck.page/7e238f3920/index.js', - 'embed_url' => 'https://cheerful-architect-3237.ck.page/7e238f3920', - 'archived' => false, - 'uid' => '7e238f3920', - ], - ] - ); - - // Define Landing Pages. - $I->haveOptionInDatabase( - 'convertkit_landing_pages', - [ - 2765196 => [ - 'id' => 2765196, - 'name' => 'Landing Page', - 'created_at' => '2021-11-11T15:45:33.000Z', - 'type' => 'hosted', - 'format' => null, - 'embed_js' => 'https://cheerful-architect-3237.ck.page/99f1db6843/index.js', - 'embed_url' => 'https://cheerful-architect-3237.ck.page/99f1db6843', - 'archived' => false, - 'uid' => '99f1db6843', - ], - 2849151 => [ - 'id' => 2849151, - 'name' => 'Character Encoding', - 'created_at' => '2021-12-16T14:55:58.000Z', - 'type' => 'hosted', - 'format' => null, - 'embed_js' => 'https://cheerful-architect-3237.ck.page/cc5eb21744/index.js', - 'embed_url' => 'https://cheerful-architect-3237.ck.page/cc5eb21744', - 'archived' => false, - 'uid' => 'cc5eb21744', - ], - 470103 => [ - 'id' => 470103, - 'name' => 'Legacy Landing Page', - 'created_at' => null, - 'type' => 'hosted', - 'url' => 'https://app.convertkit.com/landing_pages/470103', - 'embed_js' => 'https://api.convertkit.com/api/v3/forms/470103.js?api_key=' . $_ENV['CONVERTKIT_API_KEY'], - 'embed_url' => 'https://api.convertkit.com/api/v3/forms/470103.html?api_key=' . $_ENV['CONVERTKIT_API_KEY'], - 'title' => '', - 'description' => '', - 'sign_up_button_text' => 'Register', - 'success_message' => null, - 'archived' => false, - ], - ] - ); - - // Define Posts. - $I->haveOptionInDatabase( - 'convertkit_posts', - [ - 224758 => [ - 'id' => 224758, - 'title' => 'Test Subject', - 'url' => 'https://cheerful-architect-3237.ck.page/posts/test-subject', - 'published_at' => '2022-01-24T00:00:00.000Z', - 'description' => 'Description text for Test Subject', - 'thumbnail_url' => 'https://placehold.co/600x400', - 'thumbnail_alt' => 'Alt text for Test Subject', - 'is_paid' => null, - ], - 489480 => [ - 'id' => 489480, - 'title' => 'Broadcast 2', - 'url' => 'https://cheerful-architect-3237.ck.page/posts/broadcast-2', - 'published_at' => '2022-04-08T00:00:00.000Z', - 'description' => 'Description text for Broadcast 2', - 'thumbnail_url' => 'https://placehold.co/600x400', - 'thumbnail_alt' => 'Alt text for Broadcast 2', - 'is_paid' => null, - ], - 3175837 => [ - 'id' => 3175837, - 'title' => 'HTML Template Test', - 'url' => 'https://cheerful-architect-3237.ck.page/posts/html-template-test', - 'published_at' => '2023-08-02T16:34:51.000Z', - 'description' => "Heading 1\nParagraph\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ultrices vehicula erat, eu faucibus ligula viverra sit amet. Nullam porta scelerisque lacus eu dignissim. Curabitur mattis dui est, sed gravida ex tincidunt sed.\nLorem ipsum dolor sit amet, consectetur adipiscing...", - 'thumbnail_url' => 'https://embed.filekitcdn.com/e/pX62TATVeCKK5QzkXWNLw3/qM63x7vF3qN1whboGdEpuL', - 'thumbnail_alt' => 'MacBook Pro beside plant in vase', - 'is_paid' => true, - ], - 572575 => [ - 'id' => 572575, - 'title' => 'Paid Subscriber Broadcast', - 'url' => 'https://cheerful-architect-3237.ck.page/posts/paid-subscriber-broadcast', - 'published_at' => '2022-05-03T00:00:00.000Z', - 'description' => 'Description text for Paid Subscriber Broadcast', - 'thumbnail_url' => 'https://placehold.co/600x400', - 'thumbnail_alt' => 'Alt text for Paid Subscriber Broadcast', - 'is_paid' => true, - ], - ] - ); - - // Define Products. - $I->haveOptionInDatabase( - 'convertkit_products', - [ - 36377 => [ - 'id' => 36377, - 'name' => 'Newsletter Subscription', - 'url' => 'https://cheerful-architect-3237.ck.page/products/newsletter-subscription', - 'published' => true, - ], - ] - ); - - // Define Tags. - $I->haveOptionInDatabase( - 'convertkit_tags', - [ - 2744672 => [ - 'id' => 2744672, - 'name' => 'wordpress', - 'created_at' => '2021-11-11T19:30:06.000Z', - ], - 2907192 => [ - 'id' => 2907192, - 'name' => 'gravityforms-tag-1', - 'created_at' => '2022-02-02T14:06:32.000Z', - ], - 3748541 => [ - 'id' => 3748541, - 'name' => 'wpforms', - 'created_at' => '2023-03-29T12:32:38.000Z', - ], - 2907193 => [ - 'id' => 2907193, - 'name' => 'gravityforms-tag-2', - 'created_at' => '2022-02-02T14:06:38.000Z', - ], - ] - ); - - // Define last queried to now for all resources, so they're not automatically immediately refreshed by the Plugin's logic. - $I->haveOptionInDatabase( 'convertkit_forms_last_queried', strtotime( 'now' ) ); - $I->haveOptionInDatabase( 'convertkit_landing_pages_last_queried', strtotime( 'now' ) ); - $I->haveOptionInDatabase( 'convertkit_posts_last_queried', strtotime( 'now' ) ); - $I->haveOptionInDatabase( 'convertkit_products_last_queried', strtotime( 'now' ) ); - $I->haveOptionInDatabase( 'convertkit_tags_last_queried', strtotime( 'now' ) ); - } - - /** - * Helper method to define cached Resources (Forms, Landing Pages, Posts, Products and Tags), - * directly into the database, instead of querying the API for them via the Resource classes - * as if the ConvertKit account is new and has no resources defined in ConvertKit. - * - * @since 2.0.7 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function setupConvertKitPluginResourcesNoData($I) - { - // Define Forms as if the Forms resource class populated them from the API. - $I->haveOptionInDatabase( - 'convertkit_forms', - [] - ); - - // Define Landing Pages. - $I->haveOptionInDatabase( - 'convertkit_landing_pages', - [] - ); - - // Define Posts. - $I->haveOptionInDatabase( - 'convertkit_posts', - [] - ); - - // Define Products. - $I->haveOptionInDatabase( - 'convertkit_products', - [] - ); - - // Define Tags. - $I->haveOptionInDatabase( - 'convertkit_tags', - [] - ); - - // Define last queried to now for all resources, so they're not automatically immediately refreshed by the Plugin's logic. - $I->haveOptionInDatabase( 'convertkit_forms_last_queried', strtotime( 'now' ) ); - $I->haveOptionInDatabase( 'convertkit_landing_pages_last_queried', strtotime( 'now' ) ); - $I->haveOptionInDatabase( 'convertkit_posts_last_queried', strtotime( 'now' ) ); - $I->haveOptionInDatabase( 'convertkit_products_last_queried', strtotime( 'now' ) ); - $I->haveOptionInDatabase( 'convertkit_tags_last_queried', strtotime( 'now' ) ); - } - - /** - * Helper method to programmatically setup the Plugin's Member Content settings. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I AcceptanceTester. - * @param bool|array $settings Array of key/value settings. - */ - public function setupConvertKitPluginRestrictContent($I, $settings) - { - $I->haveOptionInDatabase( - '_wp_convertkit_settings_restrict_content', - array_merge( - $settings, - $I->getRestrictedContentDefaultSettings() - ) - ); - } - - /** - * Helper method to setup the Plugin's Broadcasts to Posts settings. - * - * @since 2.2.8 - * - * @param AcceptanceTester $I AcceptanceTester. - * @param bool|array $settings Array of key/value settings. If not defined, uses expected defaults. - */ - public function setupConvertKitPluginBroadcasts($I, $settings = false) - { - // Go to the Plugin's Broadcasts screen. - $I->loadConvertKitSettingsBroadcastsScreen($I); - - // Complete fields. - if ( $settings ) { - foreach ( $settings as $key => $value ) { - switch ( $key ) { - case 'enabled': - case 'enabled_export': - case 'no_styles': - if ( $value ) { - $I->checkOption('_wp_convertkit_settings_broadcasts[' . $key . ']'); - } else { - $I->uncheckOption('_wp_convertkit_settings_broadcasts[' . $key . ']'); - } - break; - - case 'post_status': - case 'category_id': - case 'author_id': - $I->fillSelect2Field($I, '#select2-_wp_convertkit_settings_broadcasts_' . $key . '-container', $value); - - break; - default: - $I->fillField('_wp_convertkit_settings_broadcasts[' . $key . ']', $value); - break; - } - } - } - - // Click the Save Changes button. - $I->click('Save Changes'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - } - - /** - * Helper method to reset the ConvertKit Plugin settings, as if it's a clean installation. - * - * @since 1.9.6.7 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function resetConvertKitPlugin($I) - { - // Plugin Settings. - $I->dontHaveOptionInDatabase('_wp_convertkit_settings'); - $I->dontHaveOptionInDatabase('_wp_convertkit_settings_restrict_content'); - $I->dontHaveOptionInDatabase('_wp_convertkit_settings_broadcasts'); - $I->dontHaveOptionInDatabase('convertkit_version'); - - // Resources. - $I->dontHaveOptionInDatabase('convertkit_broadcasts'); - $I->dontHaveOptionInDatabase('convertkit_broadcasts_last_queried'); - $I->dontHaveOptionInDatabase('convertkit_forms'); - $I->dontHaveOptionInDatabase('convertkit_forms_last_queried'); - $I->dontHaveOptionInDatabase('convertkit_landing_pages'); - $I->dontHaveOptionInDatabase('convertkit_landing_pages_last_queried'); - $I->dontHaveOptionInDatabase('convertkit_posts'); - $I->dontHaveOptionInDatabase('convertkit_posts_last_queried'); - $I->dontHaveOptionInDatabase('convertkit_products'); - $I->dontHaveOptionInDatabase('convertkit_products_last_queried'); - $I->dontHaveOptionInDatabase('convertkit_tags'); - $I->dontHaveOptionInDatabase('convertkit_tags_last_queried'); - - // Review Request. - $I->dontHaveOptionInDatabase('convertkit-review-request'); - $I->dontHaveOptionInDatabase('convertkit-review-dismissed'); - - // Upgrades. - $I->dontHaveOptionInDatabase('_wp_convertkit_upgrade_posts'); - } - - /** - * Helper method to load the Plugin's Settings > General screen. - * - * @since 1.9.6 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function loadConvertKitSettingsGeneralScreen($I) - { - $I->amOnAdminPage('options-general.php?page=_wp_convertkit_settings'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - } - - /** - * Helper method to load the Plugin's Settings > Tools screen. - * - * @since 1.9.6 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function loadConvertKitSettingsToolsScreen($I) - { - $I->amOnAdminPage('options-general.php?page=_wp_convertkit_settings&tab=tools'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - } - - /** - * Helper method to load the Plugin's Settings > Member Content screen. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function loadConvertKitSettingsRestrictContentScreen($I) - { - $I->amOnAdminPage('options-general.php?page=_wp_convertkit_settings&tab=restrict-content'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - } - - /** - * Helper method to load the Plugin's Settings > Broadcasts screen. - * - * @since 2.2.8 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function loadConvertKitSettingsBroadcastsScreen($I) - { - $I->amOnAdminPage('options-general.php?page=_wp_convertkit_settings&tab=broadcasts'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - } - - /** - * Helper method to clear the Plugin's debug log. - * - * @since 1.9.6 - * - * @param AcceptanceTester $I AcceptanceTester. - */ - public function clearDebugLog($I) - { - // Go to the Plugin's Tools Screen. - $I->loadConvertKitSettingsToolsScreen($I); - - // Click the Clear log button. - $I->click('Clear log'); - } - - /** - * Helper method to determine if the given entry exists in the Plugin Debug Log screen's textarea. - * - * @since 1.9.6 - * - * @param AcceptanceTester $I AcceptanceTester. - * @param string $entry Log entry. - */ - public function seeInPluginDebugLog($I, $entry) - { - $I->loadConvertKitSettingsToolsScreen($I); - $I->seeInSource($entry); - } - - /** - * Helper method to determine if the given entry does not exist in the Plugin Debug Log screen's textarea. - * - * @since 1.9.6 - * - * @param AcceptanceTester $I AcceptanceTester. - * @param string $entry Log entry. - */ - public function dontSeeInPluginDebugLog($I, $entry) - { - $I->loadConvertKitSettingsToolsScreen($I); - $I->dontSeeInSource($entry); - } - - /** - * Helper method to determine that the order of the Form resources in the given - * select element are in the expected alphabetical order. - * - * @since 2.0.8 - * - * @param AcceptanceTester $I AcceptanceTester. - * @param string $selectElement element. - * @param bool|array $prependOptions Option elements that should appear before the resources. - */ - public function checkSelectLandingPageOptionOrder($I, $selectElement, $prependOptions = false) - { - // Define options. - $options = [ - 'Character Encoding', // First item. - 'Legacy Landing Page', // Last item. - ]; - - // Prepend options, such as 'Default' and 'None' to the options, if required. - if ( $prependOptions ) { - $options = array_merge( $prependOptions, $options ); - } - - // Check order. - $I->checkSelectOptionOrder($I, $selectElement, $options); - } - - /** - * Helper method to determine that the order of the Form resources in the given - * select element are in the expected alphabetical order. - * - * @since 2.0.8 - * - * @param AcceptanceTester $I AcceptanceTester. - * @param string $selectElement element. - * @param array $values
seeInSource($_ENV['CONVERTKIT_API_BROADCAST_SECOND_TITLE']); - - // Click the Newer Posts link. - $I->click('li.convertkit-broadcasts-pagination-prev a'); - - // Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been - // removed from the block. - $I->waitForBroadcastsToLoad($I); - - // Confirm that the block displays one broadcast with a pagination link to older broadcasts. - $I->seeBroadcastsOutput($I, 1, false, $nextLabel); - - // Confirm that the expected Broadcast name is displayed and links to the expected URL, with UTM parameters. - $I->seeInSource('seeInSource($_ENV['CONVERTKIT_API_BROADCAST_FIRST_TITLE']); - } - - /** - * Wait for the AJAX request to complete, by checking if the convertkit-broadcasts-loading class has been - * removed from the block. - * - * @since 1.9.7.6 - * - * @param AcceptanceTester $I Tester. - */ - public function waitForBroadcastsToLoad($I) - { - $I->waitForElementChange( - 'div.convertkit-broadcasts', - function(\Facebook\WebDriver\WebDriverElement $el) { - return ( strpos($el->getAttribute('class'), 'convertkit-broadcasts-loading') === false ? true : false ); - }, - 5 - ); - } - - /** - * Check that expected HTML exists in the DOM of the page we're viewing - * when a ConvertKit Product link was inserted into a paragraph or button, - * and that the button loads the expected ConvertKit Product modal. - * - * @since 2.0.0 - * - * @param AcceptanceTester $I Tester. - * @param string $productURL Product URL. - * @param bool|string $text Test if the link text matches the given value. - */ - public function seeProductLink($I, $productURL, $text = false) - { - // Confirm that the commerce.js script exists. - $I->seeInSource('commerce.js'); - - // Confirm that the link exists. - $I->seeElementInDOM('a[data-commerce]'); - - // Confirm that the link points to the correct product. - $I->assertEquals($productURL, $I->grabAttributeFrom('a[data-commerce]', 'href')); - - // Confirm that the button text is as expected. - if ($text !== false) { - $I->seeInSource('>' . $text . ''); - } - - // Click the button to confirm that the ConvertKit modal displays; this confirms - // necessary ConvertKit scripts have been loaded. - $I->click('a[href="' . $productURL . '"]'); - $I->seeElementInDOM('iframe[data-active]'); - } - - /** - * Returns the expected default settings for Restricted Content. - * - * @since 2.1.0 - * - * @return array - */ - public function getRestrictedContentDefaultSettings() - { - return array( - // Restrict by Product. - 'subscribe_heading' => 'Read this post with a premium subscription', - 'subscribe_text' => 'This post is only available to premium subscribers. Join today to get access to all posts.', - - // Restrict by Tag. - 'subscribe_heading_tag' => 'Subscribe to keep reading', - 'subscribe_text_tag' => 'This post is free to read but only available to subscribers. Join today to get access to all posts.', - - // All. - 'subscribe_button_label' => 'Subscribe', - 'email_text' => 'Already subscribed?', - 'email_button_label' => 'Log in', - 'email_description_text' => 'We\'ll email you a magic code to log you in without a password.', - 'email_check_heading' => 'We just emailed you a log in code', - 'email_check_text' => 'Enter the code below to finish logging in', - 'no_access_text' => 'Your account does not have access to this content. Please use the button above to purchase, or enter the email address you used to purchase the product.', - ); - } - - /** - * Creates a Page in the database with the given title for restricted content. - * - * The Page's content comprises of a mix of visible and member's only content. - * The default form setting is set to 'None'. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $postType Post Type. - * @param string $title Title. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param string $restrictContentSetting Restrict Content setting. - * @return int Page ID. - */ - public function createRestrictedContentPage($I, $postType, $title, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $restrictContentSetting = '') - { - return $I->havePostInDatabase( - [ - 'post_type' => $postType, - 'post_title' => $title, - - // Emulate Gutenberg content with visible and members only content sections. - 'post_content' => '

' . $visibleContent . '

- -' . $memberContent . '', - - // Don't display a Form on this Page, so we test against Restrict Content's Form. - 'meta_input' => [ - '_wp_convertkit_post_meta' => [ - 'form' => '-1', - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => $restrictContentSetting, - ], - ], - ] - ); - } - - /** - * Run frontend tests for restricted content by ConvertKit Product, to confirm that visible and member's content - * is / is not displayed when logging in with valid and invalid subscriber email addresses. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string|int $urlOrPageID URL or ID of Restricted Content Page. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictedContentByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Navigate to the page. - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID); - } else { - $I->amOnUrl($urlOrPageID); - } - - // Confirm Restrict Content CSS is output. - $I->seeInSource('invalid: Email address is invalid
'); - $I->seeInSource('
'); - - // Check content is not displayed, and CTA displays with expected text. - $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); - - // Set cookie with signed subscriber ID and reload the restricted content page, as if we entered the - // code sent in the email as a ConvertKit subscriber who has not subscribed to the product. - $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID_NO_ACCESS']); - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID . '&ck-cache-bust=' . microtime() ); - } else { - $I->amOnUrl($urlOrPageID . '?ck-cache-bust=' . microtime() ); - } - - // Confirm an inline error message is displayed. - $I->seeInSource('
' . $textItems['no_access_text'] . '
'); - $I->seeInSource('
'); - - // Check content is not displayed, and CTA displays with expected text. - $this->testRestrictContentByProductHidesContentWithCTA($I, $visibleContent, $memberContent, $textItems); - - // Login as a ConvertKit subscriber who has subscribed to the product. - $I->waitForElementVisible('input#convertkit_email'); - $I->fillField('convertkit_email', $_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL']); - $I->click('input.wp-block-button__link'); - - // Confirm that confirmation an email has been sent is displayed. - $this->testRestrictContentShowsEmailCodeForm($I, $visibleContent, $memberContent, $textItems); - - // Test that the restricted content displays when a valid signed subscriber ID is used, - // as if we entered the code sent in the email. - $this->testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent); - } - - /** - * Run frontend tests for restricted content by ConvertKit Product, using the modal authentication flow, to confirm - * that visible and member's content is / is not displayed when logging in with valid and invalid subscriber email addresses. - * - * @since 2.3.8 - * - * @param AcceptanceTester $I Tester. - * @param string|int $urlOrPageID URL or ID of Restricted Content Page. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictedContentModalByProductOnFrontend($I, $urlOrPageID, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Navigate to the page. - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID); - } else { - $I->amOnUrl($urlOrPageID); - } - - // Confirm Restrict Content CSS is output. - $I->seeInSource(''); - - // Enter the email address and submit the form. - $I->fillField('convertkit_email', $emailAddress); - $I->click('input.wp-block-button__link'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the restricted content is now displayed. - $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); - } - - /** - * Run frontend tests for restricted content, to confirm that both visible and member content is displayed - * when a valid signed subscriber ID is set as a cookie, as if the user entered a code sent in the email. - * - * @since 2.2.2 - * - * @param AcceptanceTester $I Tester. - * @param string|int $urlOrPageID URL or ID of Restricted Content Page. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - */ - public function testRestrictedContentShowsContentWithValidSubscriberID($I, $urlOrPageID, $visibleContent, $memberContent) - { - // Set cookie with signed subscriber ID, as if we entered the code sent in the email. - $I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); - - // Reload the restricted content page. - if ( is_numeric( $urlOrPageID ) ) { - $I->amOnPage('?p=' . $urlOrPageID ); - } else { - $I->amOnUrl($urlOrPageID ); - } - - // Confirm cookie was set with the expected value. - $I->assertEquals($I->grabCookie('ck_subscriber_id'), $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID']); - - // Confirm that the restricted content is now displayed, as we've authenticated as a subscriber - // who has access to this Product. - $I->testRestrictContentDisplaysContent($I, $visibleContent, $memberContent); - } - - /** - * Run frontend tests for restricted content, to confirm that: - * - visible content is displayed, - * - member's content is not displayed, - * - the CTA is displayed with the expected text - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictContentByProductHidesContentWithCTA($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems = false) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the visible text displays, hidden text does not display and the CTA displays. - if ( ! empty($visibleContent)) { - $I->see($visibleContent); - } - $I->dontSee($memberContent); - - // Confirm that the CTA displays with the expected headings, text, buttons and other elements. - $I->seeElementInDOM('#convertkit-restrict-content'); - - $I->seeInSource('

' . $textItems['subscribe_heading'] . '

'); - $I->see($textItems['subscribe_text']); - - $I->see($textItems['subscribe_button_label']); - $I->seeInSource(''); - $I->seeInSource('' . $textItems['email_description_text'] . ''); - } - - /** - * Run frontend tests for restricted content, to confirm that: - * - visible content is displayed, - * - member's content is not displayed, - * - the email code form is displayed with the expected text. - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - * @param bool|array $textItems Expected text for subscribe text, subscribe button label, email text etc. If not defined, uses expected defaults. - */ - public function testRestrictContentShowsEmailCodeForm($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.', $textItems) - { - // Define expected text and labels if not supplied. - if ( ! $textItems ) { - $textItems = $this->getRestrictedContentDefaultSettings(); - } - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the visible text displays, hidden text does not display and the CTA displays. - if ( ! empty($visibleContent)) { - $I->see($visibleContent); - } - $I->dontSee($memberContent); - - // Confirm that the CTA displays with the expected text. - $I->seeElementInDOM('#convertkit-restrict-content'); - $I->seeInSource('

' . $textItems['email_check_heading'] . '

'); - $I->see($textItems['email_check_text']); - $I->seeElementInDOM('input#convertkit_subscriber_code'); - $I->seeElementInDOM('input.wp-block-button__link'); - - // Enter an invalid code. - $I->fillField('subscriber_code', '999999'); - $I->click('Verify'); - - // Confirm an inline error message is displayed. - $I->seeInSource('
The entered code is invalid. Please try again, or click the link sent in the email.
'); - $I->seeInSource('
'); - } - - /** - * Run frontend tests for restricted content, to confirm that: - * - visible content is displayed, - * - member's content is displayed, - * - the CTA is not displayed - * - * @since 2.1.0 - * - * @param AcceptanceTester $I Tester. - * @param string $visibleContent Content that should always be visible. - * @param string $memberContent Content that should only be available to authenticated subscribers. - */ - public function testRestrictContentDisplaysContent($I, $visibleContent = 'Visible content.', $memberContent = 'Member only content.') - { - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the visible and hidden text displays. - if ( ! empty($visibleContent)) { - $I->see($visibleContent); - } - $I->see($memberContent); - - // Confirm that the CTA is not displayed. - $I->dontSeeElementInDOM('#convertkit-restrict-content'); - } - - /** - * Check that expected HTML exists in the DOM of the page we're viewing for - * a Form Trigger block or shortcode, and that the button loads the expected - * ConvertKit Form. - * - * @since 2.2.0 - * - * @param AcceptanceTester $I Tester. - * @param string $formURL Form URL. - * @param bool|string $text Test if the button text matches the given value. - * @param bool|string $textColor Test if the given text color is applied. - * @param bool|string $backgroundColor Test is the given background color is applied. - */ - public function seeFormTriggerOutput($I, $formURL, $text = false, $textColor = false, $backgroundColor = false) - { - // Confirm that the button stylesheet loaded. - $I->seeInSource('