From 004291e15c583b88d6491877197cd2f90bdaf3fd Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 15 Apr 2026 17:04:50 +0800 Subject: [PATCH 1/5] Tests: Member Content: Refactor Tests --- .../RestrictContentProductPageCest.php | 577 ++++++++++-------- 1 file changed, 319 insertions(+), 258 deletions(-) diff --git a/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php b/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php index f6179b2be..f35d5dd06 100644 --- a/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php +++ b/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php @@ -11,6 +11,19 @@ */ class RestrictContentProductPageCest { + /** + * Post Types to test. + * + * @since 3.3.0 + * + * @var array + */ + private $postTypes = [ + 'page', + 'post', + 'article', + ]; + /** * Run common actions before running the test functions in this class. * @@ -22,6 +35,9 @@ public function _before(EndToEndTester $I) { // Activate Kit plugin. $I->activateKitPlugin($I); + + // Create Custom Post Types using the Custom Post Type UI Plugin. + $I->registerCustomPostTypes($I); } /** @@ -36,28 +52,32 @@ public function testRestrictContentWhenDisabled(EndToEndTester $I) // Setup Kit Plugin, disabling JS. $I->setupKitPluginDisableJS($I); - // Add a Page using the Gutenberg editor. - $I->addGutenbergPage( - $I, - title: 'Kit: Page: Restrict Content: Product' - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Page. - $url = $I->publishGutenbergPage($I); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Restrict Content: Product' + ); - // Confirm that all content is displayed. - $I->amOnUrl($url); - $I->see('Visible content.'); - $I->see('Member-only content.'); + // Add blocks. + $I->addGutenbergParagraphBlock($I, 'Visible content.'); + $I->addGutenbergBlock( + $I, + blockName: 'More', + blockProgrammaticName: 'more' + ); + $I->addGutenbergParagraphBlock($I, 'Member-only content.'); + + // Publish Page. + $url = $I->publishGutenbergPage($I); + + // Confirm that all content is displayed. + $I->amOnUrl($url); + $I->see('Visible content.'); + $I->see('Member-only content.'); + } } /** @@ -74,33 +94,37 @@ public function testRestrictContentByProduct(EndToEndTester $I) $I->setupKitPluginDisableJS($I); $I->setupKitPluginResources($I); - // Add a Page using the Gutenberg editor. - $I->addGutenbergPage( - $I, - title: 'Kit: Page: Restrict Content: Product' - ); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Restrict Content: Product' + ); - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); + // Configure metabox's Restrict Content setting = Product name. + $I->configurePluginSidebarSettings( + $I, + form: 'None', + restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] + ); - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); + // Add blocks. + $I->addGutenbergParagraphBlock($I, 'Visible content.'); + $I->addGutenbergBlock( + $I, + blockName: 'More', + blockProgrammaticName: 'more' + ); + $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - // Publish Page. - $url = $I->publishGutenbergPage($I); + // Publish Page. + $url = $I->publishGutenbergPage($I); - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $url); + // Test Restrict Content functionality. + $I->testRestrictedContentByProductOnFrontend($I, $url); + } } /** @@ -118,34 +142,38 @@ public function testRestrictContentByProductWithAddTag(EndToEndTester $I) $I->setupKitPluginDisableJS($I); $I->setupKitPluginResources($I); - // Add a Page using the Gutenberg editor. - $I->addGutenbergPage( - $I, - title: 'Kit: Page: Restrict Content: Product' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - tag: $_ENV['CONVERTKIT_API_TAG_NAME'], - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Restrict Content: Product' + ); - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); + // Configure metabox's Restrict Content setting = Product name. + $I->configurePluginSidebarSettings( + $I, + form: 'None', + tag: $_ENV['CONVERTKIT_API_TAG_NAME'], + restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] + ); + + // Add blocks. + $I->addGutenbergParagraphBlock($I, 'Visible content.'); + $I->addGutenbergBlock( + $I, + blockName: 'More', + blockProgrammaticName: 'more' + ); + $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - // Publish Page. - $url = $I->publishGutenbergPage($I); + // Publish Page. + $url = $I->publishGutenbergPage($I); - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $url); + // Test Restrict Content functionality. + $I->testRestrictedContentByProductOnFrontend($I, $url); + } } /** @@ -167,35 +195,39 @@ public function testRestrictContentByProductWithGeneratedExcerpt(EndToEndTester $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'; $memberOnlyContent = 'Member-only content'; - // Add a Page using the Gutenberg editor. - $I->addGutenbergPage( - $I, - title: 'Kit: Page: Restrict Content: Product: Generated Excerpt' - ); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Restrict Content: Product: Generated Excerpt' + ); - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); + // Configure metabox's Restrict Content setting = Product name. + $I->configurePluginSidebarSettings( + $I, + form: 'None', + restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] + ); - // Add blocks. - $I->addGutenbergParagraphBlock($I, $visibleContent); - $I->addGutenbergParagraphBlock($I, $memberOnlyContent); + // Add blocks. + $I->addGutenbergParagraphBlock($I, $visibleContent); + $I->addGutenbergParagraphBlock($I, $memberOnlyContent); - // Publish Page. - $url = $I->publishGutenbergPage($I); + // Publish Page. + $url = $I->publishGutenbergPage($I); - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend( - $I, - urlOrPageID: $url, - options: [ - 'visible_content' => $visibleContent, - 'member_content' => $memberOnlyContent, - ] - ); + // Test Restrict Content functionality. + $I->testRestrictedContentByProductOnFrontend( + $I, + urlOrPageID: $url, + options: [ + 'visible_content' => $visibleContent, + 'member_content' => $memberOnlyContent, + ] + ); + } } /** @@ -213,33 +245,37 @@ public function testRestrictContentModalByProduct(EndToEndTester $I) $I->setupKitPlugin($I); $I->setupKitPluginResources($I); - // Add a Page using the Gutenberg editor. - $I->addGutenbergPage( - $I, - title: 'Kit: Page: Restrict Content: Product: Modal' - ); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Restrict Content: Product: Modal' + ); - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); + // Configure metabox's Restrict Content setting = Product name. + $I->configurePluginSidebarSettings( + $I, + form: 'None', + restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] + ); - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); + // Add blocks. + $I->addGutenbergParagraphBlock($I, 'Visible content.'); + $I->addGutenbergBlock( + $I, + blockName: 'More', + blockProgrammaticName: 'more' + ); + $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - // Publish Page. - $url = $I->publishGutenbergPage($I); + // Publish Page. + $url = $I->publishGutenbergPage($I); - // Test Restrict Content functionality. - $I->testRestrictedContentModal($I, $url); + // Test Restrict Content functionality. + $I->testRestrictedContentModal($I, $url); + } } /** @@ -265,39 +301,43 @@ public function testRestrictContentContainerCSSClasses(EndToEndTester $I) // Setup Restrict Content functionality with container CSS classes. $I->setupKitPluginRestrictContent($I, $settings); - // Add the Page using the Gutenberg editor. - $I->addGutenbergPage( - $I, - title: 'Kit: Page: Restrict Content: Container CSS Classes' - ); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add the Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Restrict Content: Container CSS Classes' + ); - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); + // Configure metabox's Restrict Content setting = Product name. + $I->configurePluginSidebarSettings( + $I, + form: 'None', + restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] + ); - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); + // Add blocks. + $I->addGutenbergParagraphBlock($I, 'Visible content.'); + $I->addGutenbergBlock( + $I, + blockName: 'More', + blockProgrammaticName: 'more' + ); + $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - // Publish Page. - $url = $I->publishGutenbergPage($I); + // Publish Page. + $url = $I->publishGutenbergPage($I); - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend( - $I, - urlOrPageID: $url, - options: [ - 'settings' => $settings, - ] - ); + // Test Restrict Content functionality. + $I->testRestrictedContentByProductOnFrontend( + $I, + urlOrPageID: $url, + options: [ + 'settings' => $settings, + ] + ); + } } /** @@ -316,40 +356,44 @@ public function testRestrictContentDisplaysNoticeWhenNoAccess(EndToEndTester $I) $I->setupKitPlugin($I); $I->setupKitPluginResources($I); - // Add a Page using the Gutenberg editor. - $I->addGutenbergPage( - $I, - title: 'Kit: Page: Restrict Content: Product: No Access' - ); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Restrict Content: Product: No Access' + ); - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); + // Configure metabox's Restrict Content setting = Product name. + $I->configurePluginSidebarSettings( + $I, + form: 'None', + restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] + ); - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); + // Add blocks. + $I->addGutenbergParagraphBlock($I, 'Visible content.'); + $I->addGutenbergBlock( + $I, + blockName: 'More', + blockProgrammaticName: 'more' + ); + $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - // Publish Page. - $url = $I->publishGutenbergPage($I); + // Publish Page. + $url = $I->publishGutenbergPage($I); - // Set cookie with signed subscriber ID, as if we logged in before to e.g. content gated by a Kit Form. - $I->setRestrictContentCookieAndReload($I, $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID_NO_ACCESS'], $url); + // Set cookie with signed subscriber ID, as if we logged in before to e.g. content gated by a Kit Form. + $I->setRestrictContentCookieAndReload($I, $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID_NO_ACCESS'], $url); - // View page. - $I->amOnUrl($url); + // View page. + $I->amOnUrl($url); - // Confirm an inline error message is displayed. - $options = $I->getRestrictedContentOptionsWithDefaultsMerged(); - $I->seeRestrictContentError($I, $options['settings']['no_access_text']); + // Confirm an inline error message is displayed. + $options = $I->getRestrictedContentOptionsWithDefaultsMerged(); + $I->seeRestrictContentError($I, $options['settings']['no_access_text']); + } } /** @@ -369,20 +413,24 @@ public function testRestrictContentByInvalidProduct(EndToEndTester $I) $I->setupKitPluginDisableJS($I); $I->setupKitPluginResources($I); - // Programmatically create a Page. - $pageID = $I->createRestrictedContentPage( - $I, - [ - 'post_title' => 'Kit: Page: Restrict Content: Invalid Product', - 'restrict_content_setting' => 'product_12345', // A fake Product that does not exist in Kit. - ] - ); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Programmatically create a Page. + $pageID = $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restrict Content: Invalid Product', + 'restrict_content_setting' => 'product_12345', // A fake Product that does not exist in Kit. + ] + ); - // Navigate to the page. - $I->amOnPage('?p=' . $pageID); + // Navigate to the page. + $I->amOnPage('?p=' . $pageID); - // Confirm all content displays, with no errors, as the Product is invalid. - $I->testRestrictContentDisplaysContent($I); + // Confirm all content displays, with no errors, as the Product is invalid. + $I->testRestrictContentDisplaysContent($I); + } } /** @@ -472,36 +520,40 @@ public function testRestrictContentUsingCrawler(EndToEndTester $I) ] ); - // Add a Page using the Gutenberg editor. - $I->addGutenbergPage( - $I, - title: 'Kit: Page: Restrict Content: Product: Search Engines' - ); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Restrict Content: Product: Search Engines' + ); - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); + // Configure metabox's Restrict Content setting = Product name. + $I->configurePluginSidebarSettings( + $I, + form: 'None', + restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] + ); - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); + // Add blocks. + $I->addGutenbergParagraphBlock($I, 'Visible content.'); + $I->addGutenbergBlock( + $I, + blockName: 'More', + blockProgrammaticName: 'more' + ); + $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - // Publish Page. - $url = $I->publishGutenbergPage($I); + // Publish Page. + $url = $I->publishGutenbergPage($I); - // Load page. - $I->amOnUrl($url); + // Load page. + $I->amOnUrl($url); - // Confirm page displays all content, as we're a crawler. - $I->testRestrictContentDisplaysContent($I); + // Confirm page displays all content, as we're a crawler. + $I->testRestrictContentDisplaysContent($I); + } } /** @@ -518,26 +570,30 @@ public function testRestrictContentByProductUsingQuickEdit(EndToEndTester $I) $I->setupKitPluginDisableJS($I); $I->setupKitPluginResources($I); - // Programmatically create a Page. - $pageID = $I->createRestrictedContentPage( - $I, - [ - 'post_title' => 'Kit: Page: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Quick Edit', - ] - ); + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Programmatically create a Page. + $pageID = $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Quick Edit', + ] + ); - // Quick Edit the Page in the Pages WP_List_Table. - $I->quickEdit( - $I, - postType: 'page', - postID: $pageID, - configuration: [ - 'restrict_content' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ], - ] - ); + // Quick Edit the Page in the Pages WP_List_Table. + $I->quickEdit( + $I, + postType: $postType, + postID: $pageID, + configuration: [ + 'restrict_content' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ], + ] + ); - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $pageID); + // Test Restrict Content functionality. + $I->testRestrictedContentByProductOnFrontend($I, $pageID); + } } /** @@ -554,37 +610,42 @@ public function testRestrictContentByProductUsingBulkEdit(EndToEndTester $I) $I->setupKitPluginDisableJS($I); $I->setupKitPluginResources($I); - // Programmatically create two Pages. - $pageIDs = array( - $I->createRestrictedContentPage( + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Programmatically create two Pages. + $pageIDs = array( + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Bulk Edit #1', + ] + ), + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Bulk Edit #2', + ] + ), + ); + + // Bulk Edit the Pages in the Pages WP_List_Table. + $I->bulkEdit( $I, - [ - 'post_title' => 'Kit: Page: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Bulk Edit #1', - ] - ), - $I->createRestrictedContentPage( - $I, - [ - 'post_title' => 'Kit: Page: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Bulk Edit #2', + postType: $postType, + postIDs: $pageIDs, + configuration: [ + 'restrict_content' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ], ] - ), - ); - - // Bulk Edit the Pages in the Pages WP_List_Table. - $I->bulkEdit( - $I, - postType: 'page', - postIDs: $pageIDs, - configuration: [ - 'restrict_content' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ], - ] - ); - - // Iterate through Pages to run frontend tests. - foreach ($pageIDs as $pageID) { - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $pageID); - $I->clearRestrictContentCookie($I); + ); + + // Iterate through Pages to run frontend tests. + foreach ($pageIDs as $pageID) { + // Test Restrict Content functionality. + $I->testRestrictedContentByProductOnFrontend($I, $pageID); + $I->clearRestrictContentCookie($I); + } } } From e0fae47e95ae069e8bb0153576546318e21aacd6 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 15 Apr 2026 18:00:50 +0800 Subject: [PATCH 2/5] Refactor tests --- .../general/RestrictContentFilterCPTCest.php | 437 --------------- .../general/RestrictContentFilterCest.php | 443 +++++++++++++++ .../general/RestrictContentFilterPageCest.php | 404 -------------- .../general/RestrictContentFilterPostCest.php | 409 -------------- .../RestrictContentProductCPTCest.php | 482 ----------------- .../RestrictContentProductPageCest.php | 5 +- .../RestrictContentProductPostCest.php | 510 ------------------ 7 files changed, 446 insertions(+), 2244 deletions(-) delete mode 100644 tests/EndToEnd/restrict-content/general/RestrictContentFilterCPTCest.php create mode 100644 tests/EndToEnd/restrict-content/general/RestrictContentFilterCest.php delete mode 100644 tests/EndToEnd/restrict-content/general/RestrictContentFilterPageCest.php delete mode 100644 tests/EndToEnd/restrict-content/general/RestrictContentFilterPostCest.php delete mode 100644 tests/EndToEnd/restrict-content/post-types/RestrictContentProductCPTCest.php delete mode 100644 tests/EndToEnd/restrict-content/post-types/RestrictContentProductPostCest.php diff --git a/tests/EndToEnd/restrict-content/general/RestrictContentFilterCPTCest.php b/tests/EndToEnd/restrict-content/general/RestrictContentFilterCPTCest.php deleted file mode 100644 index 6bafb8829..000000000 --- a/tests/EndToEnd/restrict-content/general/RestrictContentFilterCPTCest.php +++ /dev/null @@ -1,437 +0,0 @@ -activateKitPlugin($I); - - // Create Custom Post Types using the Custom Post Type UI Plugin. - $I->registerCustomPostTypes($I); - } - - /** - * Test that no dropdown filter on the CPT screen is displayed when no credentials are configured. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilterDisplayedWhenNoCredentials(EndToEndTester $I) - { - // Navigate to Articles. - $I->amOnAdminPage('edit.php?post_type=article'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check no filter is displayed, as the Plugin isn't configured. - $I->dontSeeElementInDOM('#wp-convertkit-restrict-content-filter'); - } - - /** - * Test that no dropdown filter on the CPT screen is displayed when the Kit - * account has no Forms, Tag and Products. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilterDisplayedWhenNoResources(EndToEndTester $I) - { - // Setup Plugin using credentials that have no resources. - $I->setupKitPluginCredentialsNoData($I); - - // Navigate to Articles. - $I->amOnAdminPage('edit.php?post_type=article'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check no filter is displayed, as the Kit account has no resources. - $I->dontSeeElementInDOM('#wp-convertkit-restrict-content-filter'); - } - - /** - * Test that no dropdown filter on the CPT screen is displayed when the Post Type - * is not public. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilterOnPrivateCPT(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Navigate to Private CPT. - $I->amOnAdminPage('edit.php?post_type=private'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check no filter is displayed. - $I->dontSeeElementInDOM('#wp-convertkit-restrict-content-filter'); - } - - /** - * Test that filtering by Product works on the Articles screen. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByProduct(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create Article, set to restrict content to a Product. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restricted Content: Product: Filter Test', - 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], - ] - ); - - // Navigate to Articles. - $I->amOnAdminPage('edit.php?post_type=article'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Article is listed, and has the 'Kit Member Content' label. - $I->see('Kit: Article: Restricted Content: Product: Filter Test'); - $I->see('Kit Member Content'); - - // Filter by Product. - $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_PRODUCT_NAME']); - $I->click('Filter'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Article is still listed, and has the 'Kit Member Content' label. - $I->see('Kit: Article: Restricted Content: Product: Filter Test'); - $I->see('Kit Member Content'); - } - - /** - * Test that filtering by Tag works on the Articles screen. - * - * @since 2.7.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByTag(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create Article, set to restrict content to a Product. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restricted Content: Tag: Filter Test', - 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], - ] - ); - - // Navigate to Articles. - $I->amOnAdminPage('edit.php?post_type=article'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Article is listed, and has the 'Kit Member Content' label. - $I->see('Kit: Article: Restricted Content: Tag: Filter Test'); - $I->see('Kit Member Content'); - - // Filter by Tag. - $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_TAG_NAME']); - $I->click('Filter'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Article is still listed, and has the 'Kit Member Content' label. - $I->see('Kit: Article: Restricted Content: Tag: Filter Test'); - $I->see('Kit Member Content'); - } - - /** - * Test that filtering by Form works on the Articles screen. - * - * @since 2.7.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByForm(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create Article, set to restrict content to a Product. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restricted Content: Form: Filter Test', - 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], - ] - ); - - // Navigate to Articles. - $I->amOnAdminPage('edit.php?post_type=article'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Article is listed, and has the 'Kit Member Content' label. - $I->see('Kit: Article: Restricted Content: Form: Filter Test'); - $I->see('Kit Member Content'); - - // Filter by Form. - $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_FORM_NAME']); - $I->click('Filter'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Article is still listed, and has the 'Kit Member Content' label. - $I->see('Kit: Article: Restricted Content: Form: Filter Test'); - $I->see('Kit Member Content'); - } - - /** - * Test that filtering by 'All member-only content' works on the CPT screen. - * - * @since 2.8.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByAllMemberOnlyContent(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create a mix of Posts restricted and not restricted to Forms, Tags and Products. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restricted Content: Form: Filter Test', - 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restricted Content: Tag: Filter Test', - 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restricted Content: Product: Filter Test', - 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Standard', - 'meta_input' => [ - '_wp_convertkit_post_meta' => [ - 'form' => '0', - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => '0', - ], - ], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Standard: No Meta', - ] - ); - - // Navigate to Articles. - $I->amOnAdminPage('edit.php?post_type=article'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Filter by All member-only content. - $I->selectOption('#wp-convertkit-restrict-content-filter', 'All member-only content'); - $I->click('Filter'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Restrict Content Articles are listed. - $I->see('Kit: Article: Restricted Content: Form: Filter Test'); - $I->see('Kit: Article: Restricted Content: Tag: Filter Test'); - $I->see('Kit: Article: Restricted Content: Product: Filter Test'); - - // Confirm that no non-Restrict Content Posts are not listed. - $I->dontSee('Kit: Article: Standard'); - $I->dontSee('Kit: Article: Standard: No Meta'); - } - - /** - * Test that no filtering takes place when the filter is set to All Content on the CPT screen. - * - * @since 2.8.6 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilteringWhenAllContentSelected(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create a mix of Posts restricted and not restricted to Forms, Tags and Products. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restricted Content: Form: No Filter Test', - 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restricted Content: Tag: No Filter Test', - 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restricted Content: Product: No Filter Test', - 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Standard', - 'meta_input' => [ - '_wp_convertkit_post_meta' => [ - 'form' => '0', - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => '0', - ], - ], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Standard: No Meta', - ] - ); - - // Navigate to Articles. - $I->amOnAdminPage('edit.php?post_type=article'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Click the Filter button with no changes made. - $I->click('Filter'); - - // Wait for the WP_List_Table of Articles to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that all 5 Articles still display. - $I->see('Kit: Article: Restricted Content: Form: No Filter Test'); - $I->see('Kit: Article: Restricted Content: Tag: No Filter Test'); - $I->see('Kit: Article: Restricted Content: Product: No Filter Test'); - $I->see('Kit: Article: Standard'); - $I->see('Kit: Article: Standard: No Meta'); - } - - /** - * Deactivate and reset Plugin(s) after each test, if the test passes. - * We don't use _after, as this would provide a screenshot of the Plugin - * deactivation and not the true test error. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function _passed(EndToEndTester $I) - { - $I->unregisterCustomPostTypes($I); - $I->deactivateKitPlugin($I); - $I->resetKitPlugin($I); - } -} diff --git a/tests/EndToEnd/restrict-content/general/RestrictContentFilterCest.php b/tests/EndToEnd/restrict-content/general/RestrictContentFilterCest.php new file mode 100644 index 000000000..715f7cc29 --- /dev/null +++ b/tests/EndToEnd/restrict-content/general/RestrictContentFilterCest.php @@ -0,0 +1,443 @@ +activateKitPlugin($I); + + // Create Custom Post Types using the Custom Post Type UI Plugin. + $I->registerCustomPostTypes($I); + } + + /** + * Test that no dropdown filter on the Pages screen is displayed when no credentials are configured. + * + * @since 2.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function testNoFilterDisplayedWhenNoCredentials(EndToEndTester $I) + { + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Navigate to the Post Type. + $I->amOnAdminPage('edit.php?post_type=' . $postType); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Check no filter is displayed, as the Plugin isn't configured. + $I->dontSeeElementInDOM('#wp-convertkit-restrict-content-filter'); + } + } + + /** + * Test that no dropdown filter on the Pages screen is displayed when the Kit + * account has no Forms, Tag and Products. + * + * @since 2.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function testNoFilterDisplayedWhenNoResources(EndToEndTester $I) + { + // Setup Plugin using credentials that have no resources. + $I->setupKitPluginCredentialsNoData($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Navigate to the Post Type. + $I->amOnAdminPage('edit.php?post_type=' . $postType); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Check no filter is displayed, as the Kit account has no resources. + $I->dontSeeElementInDOM('#wp-convertkit-restrict-content-filter'); + } + } + + /** + * Test that filtering by Product works on the Pages screen. + * + * @since 2.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function testFilterByProduct(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Create Page, set to restrict content to a Product. + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restricted Content: Product: Filter Test', + 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], + ] + ); + + // Navigate to the Post Type. + $I->amOnAdminPage('edit.php?post_type=' . $postType); + + // Wait for the WP_List_Table of the Post Type to load. + $I->waitForElementVisible('tbody#the-list'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the Post is listed, and has the 'Kit Member Content' label. + $I->see('Kit: ' . $postType . ': Restricted Content: Product: Filter Test'); + $I->see('Kit Member Content'); + + // Filter by Product. + $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_PRODUCT_NAME']); + $I->click('Filter'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Check the filter dropdown is set to the selected value. + $I->seeOptionIsSelected('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_PRODUCT_NAME']); + + // Confirm that the Page is still listed, and has the 'Kit Member Content' label. + $I->see('Kit: ' . $postType . ': Restricted Content: Product: Filter Test'); + $I->see('Kit Member Content'); + } + } + + /** + * Test that filtering by Tag works on the Pages screen. + * + * @since 2.7.3 + * + * @param EndToEndTester $I Tester. + */ + public function testFilterByTag(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Create Page, set to restrict content to a Tag. + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restricted Content: Tag: Filter Test', + 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], + ] + ); + + // Navigate to the Post Type. + $I->amOnAdminPage('edit.php?post_type=' . $postType); + + // Wait for the WP_List_Table of the Post Type to load. + $I->waitForElementVisible('tbody#the-list'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the Post is listed, and has the 'Kit Member Content' label. + $I->see('Kit: ' . $postType . ': Restricted Content: Tag: Filter Test'); + $I->see('Kit Member Content'); + + // Filter by Tag. + $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_TAG_NAME']); + $I->click('Filter'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Check the filter dropdown is set to the selected value. + $I->seeOptionIsSelected('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_TAG_NAME']); + + // Confirm that the Page is still listed, and has the 'Kit Member Content' label. + $I->see('Kit: ' . $postType . ': Restricted Content: Tag: Filter Test'); + $I->see('Kit Member Content'); + } + } + + /** + * Test that filtering by Form works on the Pages screen. + * + * @since 2.7.3 + * + * @param EndToEndTester $I Tester. + */ + public function testFilterByForm(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Create Page, set to restrict content to a Form. + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restricted Content: Form: Filter Test', + 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], + ] + ); + + // Navigate to the Post Type. + $I->amOnAdminPage('edit.php?post_type=' . $postType); + + // Wait for the WP_List_Table of the Post Type to load. + $I->waitForElementVisible('tbody#the-list'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that the Post is listed, and has the 'Kit Member Content' label. + $I->see('Kit: ' . $postType . ': Restricted Content: Form: Filter Test'); + $I->see('Kit Member Content'); + + // Filter by Form. + $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_FORM_NAME']); + $I->click('Filter'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Check the filter dropdown is set to the selected value. + $I->seeOptionIsSelected('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_FORM_NAME']); + + // Confirm that the Page is still listed, and has the 'Kit Member Content' label. + $I->see('Kit: ' . $postType . ': Restricted Content: Form: Filter Test'); + $I->see('Kit Member Content'); + } + } + + /** + * Test that filtering by 'All member-only content' works on the Pages screen. + * + * @since 2.8.3 + * + * @param EndToEndTester $I Tester. + */ + public function testFilterByAllMemberOnlyContent(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Create a mix of Pages restricted and not restricted to Forms, Tags and Products. + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restricted Content: Form: Filter Test', + 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], + ] + ); + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restricted Content: Tag: Filter Test', + 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], + ] + ); + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restricted Content: Product: Filter Test', + 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], + ] + ); + $I->havePostInDatabase( + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Standard', + 'meta_input' => [ + '_wp_convertkit_post_meta' => [ + 'form' => '0', + 'landing_page' => '', + 'tag' => '', + 'restrict_content' => '0', + ], + ], + ] + ); + $I->havePostInDatabase( + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Standard: No Meta', + ] + ); + + // Navigate to the Post Type. + $I->amOnAdminPage('edit.php?post_type=' . $postType); + + // Wait for the WP_List_Table of the Post Type to load. + $I->waitForElementVisible('tbody#the-list'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Filter by All member-only content. + $I->selectOption('#wp-convertkit-restrict-content-filter', 'All member-only content'); + $I->click('Filter'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Check the filter dropdown is set to the selected value. + $I->seeOptionIsSelected('#wp-convertkit-restrict-content-filter', 'All member-only content'); + + // Confirm that the Restrict Content Pages are listed. + $I->see('Kit: ' . $postType . ': Restricted Content: Form: Filter Test'); + $I->see('Kit: ' . $postType . ': Restricted Content: Tag: Filter Test'); + $I->see('Kit: ' . $postType . ': Restricted Content: Product: Filter Test'); + + // Confirm that no non-Restrict Content Pages are not listed. + $I->dontSee('Kit: ' . $postType . ': Standard'); + $I->dontSee('Kit: ' . $postType . ': Standard: No Meta'); + } + } + + /** + * Test that no filtering takes place when the filter is set to All Content on the Pages screen. + * + * @since 2.8.6 + * + * @param EndToEndTester $I Tester. + */ + public function testNoFilteringWhenAllContentSelected(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Create a mix of Posts restricted and not restricted to Forms, Tags and Products. + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restricted Content: Form: No Filter Test', + 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], + ] + ); + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restricted Content: Tag: No Filter Test', + 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], + ] + ); + $I->createRestrictedContentPage( + $I, + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Restricted Content: Product: No Filter Test', + 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], + ] + ); + $I->havePostInDatabase( + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Standard', + 'meta_input' => [ + '_wp_convertkit_post_meta' => [ + 'form' => '0', + 'landing_page' => '', + 'tag' => '', + 'restrict_content' => '0', + ], + ], + ] + ); + $I->havePostInDatabase( + [ + 'post_type' => $postType, + 'post_title' => 'Kit: ' . $postType . ': Standard: No Meta', + ] + ); + + // Navigate to the Post Type. + $I->amOnAdminPage('edit.php?post_type=' . $postType); + + // Wait for the WP_List_Table of the Post Type to load. + $I->waitForElementVisible('tbody#the-list'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Click the Filter button with no changes made. + $I->click('Filter'); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that all 5 Pages still display. + $I->see('Kit: ' . $postType . ': Restricted Content: Form: No Filter Test'); + $I->see('Kit: ' . $postType . ': Restricted Content: Tag: No Filter Test'); + $I->see('Kit: ' . $postType . ': Restricted Content: Product: No Filter Test'); + $I->see('Kit: ' . $postType . ': Standard'); + $I->see('Kit: ' . $postType . ': Standard: No Meta'); + } + } + + /** + * Deactivate and reset Plugin(s) after each test, if the test passes. + * We don't use _after, as this would provide a screenshot of the Plugin + * deactivation and not the true test error. + * + * @since 2.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function _passed(EndToEndTester $I) + { + $I->deactivateKitPlugin($I); + $I->resetKitPlugin($I); + } +} diff --git a/tests/EndToEnd/restrict-content/general/RestrictContentFilterPageCest.php b/tests/EndToEnd/restrict-content/general/RestrictContentFilterPageCest.php deleted file mode 100644 index 79f637b71..000000000 --- a/tests/EndToEnd/restrict-content/general/RestrictContentFilterPageCest.php +++ /dev/null @@ -1,404 +0,0 @@ -activateKitPlugin($I); - } - - /** - * Test that no dropdown filter on the Pages screen is displayed when no credentials are configured. - * - * @since 2.1.0 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilterDisplayedWhenNoCredentials(EndToEndTester $I) - { - // Navigate to Pages. - $I->amOnAdminPage('edit.php?post_type=page'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check no filter is displayed, as the Plugin isn't configured. - $I->dontSeeElementInDOM('#wp-convertkit-restrict-content-filter'); - } - - /** - * Test that no dropdown filter on the Pages screen is displayed when the Kit - * account has no Forms, Tag and Products. - * - * @since 2.1.0 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilterDisplayedWhenNoResources(EndToEndTester $I) - { - // Setup Plugin using credentials that have no resources. - $I->setupKitPluginCredentialsNoData($I); - - // Navigate to Pages. - $I->amOnAdminPage('edit.php?post_type=page'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check no filter is displayed, as the Kit account has no resources. - $I->dontSeeElementInDOM('#wp-convertkit-restrict-content-filter'); - } - - /** - * Test that filtering by Product works on the Pages screen. - * - * @since 2.1.0 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByProduct(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create Page, set to restrict content to a Product. - $I->createRestrictedContentPage( - $I, - [ - 'post_title' => 'Kit: Page: Restricted Content: Product: Filter Test', - 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], - ] - ); - - // Navigate to Pages. - $I->amOnAdminPage('edit.php?post_type=page'); - - // Wait for the WP_List_Table of Pages to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Page is listed, and has the 'Kit Member Content' label. - $I->see('Kit: Page: Restricted Content: Product: Filter Test'); - $I->see('Kit Member Content'); - - // Filter by Product. - $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_PRODUCT_NAME']); - $I->click('Filter'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check the filter dropdown is set to the selected value. - $I->seeOptionIsSelected('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_PRODUCT_NAME']); - - // Confirm that the Page is still listed, and has the 'Kit Member Content' label. - $I->see('Kit: Page: Restricted Content: Product: Filter Test'); - $I->see('Kit Member Content'); - } - - /** - * Test that filtering by Tag works on the Pages screen. - * - * @since 2.7.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByTag(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create Page, set to restrict content to a Tag. - $I->createRestrictedContentPage( - $I, - [ - 'post_title' => 'Kit: Page: Restricted Content: Tag: Filter Test', - 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], - ] - ); - - // Navigate to Pages. - $I->amOnAdminPage('edit.php?post_type=page'); - - // Wait for the WP_List_Table of Pages to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Page is listed, and has the 'Kit Member Content' label. - $I->see('Kit: Page: Restricted Content: Tag: Filter Test'); - $I->see('Kit Member Content'); - - // Filter by Tag. - $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_TAG_NAME']); - $I->click('Filter'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check the filter dropdown is set to the selected value. - $I->seeOptionIsSelected('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_TAG_NAME']); - - // Confirm that the Page is still listed, and has the 'Kit Member Content' label. - $I->see('Kit: Page: Restricted Content: Tag: Filter Test'); - $I->see('Kit Member Content'); - } - - /** - * Test that filtering by Form works on the Pages screen. - * - * @since 2.7.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByForm(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create Page, set to restrict content to a Form. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Restricted Content: Form: Filter Test', - 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], - ] - ); - - // Navigate to Pages. - $I->amOnAdminPage('edit.php?post_type=page'); - - // Wait for the WP_List_Table of Pages to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Page is listed, and has the 'Kit Member Content' label. - $I->see('Kit: Page: Restricted Content: Form: Filter Test'); - $I->see('Kit Member Content'); - - // Filter by Form. - $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_FORM_NAME']); - $I->click('Filter'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check the filter dropdown is set to the selected value. - $I->seeOptionIsSelected('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_FORM_NAME']); - - // Confirm that the Page is still listed, and has the 'Kit Member Content' label. - $I->see('Kit: Page: Restricted Content: Form: Filter Test'); - $I->see('Kit Member Content'); - } - - /** - * Test that filtering by 'All member-only content' works on the Pages screen. - * - * @since 2.8.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByAllMemberOnlyContent(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create a mix of Pages restricted and not restricted to Forms, Tags and Products. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Restricted Content: Form: Filter Test', - 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Restricted Content: Tag: Filter Test', - 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Restricted Content: Product: Filter Test', - 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Standard', - 'meta_input' => [ - '_wp_convertkit_post_meta' => [ - 'form' => '0', - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => '0', - ], - ], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Standard: No Meta', - ] - ); - - // Navigate to Pages. - $I->amOnAdminPage('edit.php?post_type=page'); - - // Wait for the WP_List_Table of Pages to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Filter by All member-only content. - $I->selectOption('#wp-convertkit-restrict-content-filter', 'All member-only content'); - $I->click('Filter'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check the filter dropdown is set to the selected value. - $I->seeOptionIsSelected('#wp-convertkit-restrict-content-filter', 'All member-only content'); - - // Confirm that the Restrict Content Pages are listed. - $I->see('Kit: Page: Restricted Content: Form: Filter Test'); - $I->see('Kit: Page: Restricted Content: Tag: Filter Test'); - $I->see('Kit: Page: Restricted Content: Product: Filter Test'); - - // Confirm that no non-Restrict Content Pages are not listed. - $I->dontSee('Kit: Page: Standard'); - $I->dontSee('Kit: Page: Standard: No Meta'); - } - - /** - * Test that no filtering takes place when the filter is set to All Content on the Pages screen. - * - * @since 2.8.6 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilteringWhenAllContentSelected(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create a mix of Posts restricted and not restricted to Forms, Tags and Products. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Restricted Content: Form: No Filter Test', - 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Restricted Content: Tag: No Filter Test', - 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Restricted Content: Product: No Filter Test', - 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Standard', - 'meta_input' => [ - '_wp_convertkit_post_meta' => [ - 'form' => '0', - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => '0', - ], - ], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'page', - 'post_title' => 'Kit: Page: Standard: No Meta', - ] - ); - - // Navigate to Pages. - $I->amOnAdminPage('edit.php?post_type=page'); - - // Wait for the WP_List_Table of Pages to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Click the Filter button with no changes made. - $I->click('Filter'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that all 5 Pages still display. - $I->see('Kit: Page: Restricted Content: Form: No Filter Test'); - $I->see('Kit: Page: Restricted Content: Tag: No Filter Test'); - $I->see('Kit: Page: Restricted Content: Product: No Filter Test'); - $I->see('Kit: Page: Standard'); - $I->see('Kit: Page: Standard: No Meta'); - } - - /** - * Deactivate and reset Plugin(s) after each test, if the test passes. - * We don't use _after, as this would provide a screenshot of the Plugin - * deactivation and not the true test error. - * - * @since 2.1.0 - * - * @param EndToEndTester $I Tester. - */ - public function _passed(EndToEndTester $I) - { - $I->deactivateKitPlugin($I); - $I->resetKitPlugin($I); - } -} diff --git a/tests/EndToEnd/restrict-content/general/RestrictContentFilterPostCest.php b/tests/EndToEnd/restrict-content/general/RestrictContentFilterPostCest.php deleted file mode 100644 index f7279c8e8..000000000 --- a/tests/EndToEnd/restrict-content/general/RestrictContentFilterPostCest.php +++ /dev/null @@ -1,409 +0,0 @@ -activateKitPlugin($I); - } - - /** - * Test that no dropdown filter on the Posts screen is displayed when no credentials are configured. - * - * @since 2.3.2 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilterDisplayedWhenNoCredentials(EndToEndTester $I) - { - // Navigate to Posts. - $I->amOnAdminPage('edit.php?post_type=post'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check no filter is displayed, as the Plugin isn't configured. - $I->dontSeeElementInDOM('#wp-convertkit-restrict-content-filter'); - } - - /** - * Test that no dropdown filter on the Posts screen is displayed when the Kit - * account has no Forms, Tag and Products. - * - * @since 2.3.2 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilterDisplayedWhenNoResources(EndToEndTester $I) - { - // Setup Plugin using credentials that have no resources. - $I->setupKitPluginCredentialsNoData($I); - - // Navigate to Posts. - $I->amOnAdminPage('edit.php?post_type=post'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Check no filter is displayed, as the Kit account has no resources. - $I->dontSeeElementInDOM('#wp-convertkit-restrict-content-filter'); - } - - /** - * Test that filtering by Product works on the Posts screen. - * - * @since 2.3.2 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByProduct(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create Post, set to restrict content to a Product. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restricted Content: Product: Filter Test', - 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], - ] - ); - - // Navigate to Posts. - $I->amOnAdminPage('edit.php?post_type=post'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Post is listed, and has the 'Kit Member Content' label. - $I->see('Kit: Post: Restricted Content: Product: Filter Test'); - $I->see('Kit Member Content'); - - // Filter by Product. - $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_PRODUCT_NAME']); - $I->click('Filter'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Post is still listed, and has the 'Kit Member Content' label. - $I->see('Kit: Post: Restricted Content: Product: Filter Test'); - $I->see('Kit Member Content'); - } - - /** - * Test that filtering by Tag works on the Posts screen. - * - * @since 2.7.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByTag(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create Post, set to restrict content to a Tag. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restricted Content: Tag: Filter Test', - 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], - ] - ); - - // Navigate to Posts. - $I->amOnAdminPage('edit.php?post_type=post'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Post is listed, and has the 'Kit Member Content' label. - $I->see('Kit: Post: Restricted Content: Tag: Filter Test'); - $I->see('Kit Member Content'); - - // Filter by Tag. - $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_TAG_NAME']); - $I->click('Filter'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Post is still listed, and has the 'Kit Member Content' label. - $I->see('Kit: Post: Restricted Content: Tag: Filter Test'); - $I->see('Kit Member Content'); - } - - /** - * Test that filtering by Form works on the Posts screen. - * - * @since 2.7.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByForm(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create Post, set to restrict content to a Form. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restricted Content: Form: Filter Test', - 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], - ] - ); - - // Navigate to Posts. - $I->amOnAdminPage('edit.php?post_type=post'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Post is listed, and has the 'Kit Member Content' label. - $I->see('Kit: Post: Restricted Content: Form: Filter Test'); - $I->see('Kit Member Content'); - - // Filter by Form. - $I->selectOption('#wp-convertkit-restrict-content-filter', $_ENV['CONVERTKIT_API_FORM_NAME']); - $I->click('Filter'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Post is still listed, and has the 'Kit Member Content' label. - $I->see('Kit: Post: Restricted Content: Form: Filter Test'); - $I->see('Kit Member Content'); - } - - /** - * Test that filtering by 'All member-only content' works on the Posts screen. - * - * @since 2.8.3 - * - * @param EndToEndTester $I Tester. - */ - public function testFilterByAllMemberOnlyContent(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create a mix of Posts restricted and not restricted to Forms, Tags and Products. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restricted Content: Form: Filter Test', - 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restricted Content: Tag: Filter Test', - 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restricted Content: Product: Filter Test', - 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Standard', - 'meta_input' => [ - '_wp_convertkit_post_meta' => [ - 'form' => '0', - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => '0', - ], - ], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Standard: No Meta', - ] - ); - - // Navigate to Posts. - $I->amOnAdminPage('edit.php?post_type=post'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Filter by All member-only content. - $I->selectOption('#wp-convertkit-restrict-content-filter', 'All member-only content'); - $I->click('Filter'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that the Restrict Content Posts are listed. - $I->see('Kit: Post: Restricted Content: Form: Filter Test'); - $I->see('Kit: Post: Restricted Content: Tag: Filter Test'); - $I->see('Kit: Post: Restricted Content: Product: Filter Test'); - - // Confirm that no non-Restrict Content Posts are not listed. - $I->dontSee('Kit: Post: Standard'); - $I->dontSee('Kit: Post: Standard: No Meta'); - } - - /** - * Test that no filtering takes place when the filter is set to All Content on the Posts screen. - * - * @since 2.8.6 - * - * @param EndToEndTester $I Tester. - */ - public function testNoFilteringWhenAllContentSelected(EndToEndTester $I) - { - // Setup Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Create a mix of Posts restricted and not restricted to Forms, Tags and Products. - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restricted Content: Form: No Filter Test', - 'restrict_content_setting' => 'form_' . $_ENV['CONVERTKIT_API_FORM_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restricted Content: Tag: No Filter Test', - 'restrict_content_setting' => 'tag_' . $_ENV['CONVERTKIT_API_TAG_ID'], - ] - ); - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restricted Content: Product: No Filter Test', - 'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Standard', - 'meta_input' => [ - '_wp_convertkit_post_meta' => [ - 'form' => '0', - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => '0', - ], - ], - ] - ); - $I->havePostInDatabase( - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Standard: No Meta', - ] - ); - - // Navigate to Posts. - $I->amOnAdminPage('edit.php?post_type=post'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Click the Filter button with no changes made. - $I->click('Filter'); - - // Wait for the WP_List_Table of Posts to load. - $I->waitForElementVisible('tbody#the-list'); - - // Check that no PHP warnings or notices were output. - $I->checkNoWarningsAndNoticesOnScreen($I); - - // Confirm that all 5 Posts still display. - $I->see('Kit: Post: Restricted Content: Form: No Filter Test'); - $I->see('Kit: Post: Restricted Content: Tag: No Filter Test'); - $I->see('Kit: Post: Restricted Content: Product: No Filter Test'); - $I->see('Kit: Post: Standard'); - $I->see('Kit: Post: Standard: No Meta'); - } - - /** - * Deactivate and reset Plugin(s) after each test, if the test passes. - * We don't use _after, as this would provide a screenshot of the Plugin - * deactivation and not the true test error. - * - * @since 2.3.2 - * - * @param EndToEndTester $I Tester. - */ - public function _passed(EndToEndTester $I) - { - $I->deactivateKitPlugin($I); - $I->resetKitPlugin($I); - } -} diff --git a/tests/EndToEnd/restrict-content/post-types/RestrictContentProductCPTCest.php b/tests/EndToEnd/restrict-content/post-types/RestrictContentProductCPTCest.php deleted file mode 100644 index 4ac891328..000000000 --- a/tests/EndToEnd/restrict-content/post-types/RestrictContentProductCPTCest.php +++ /dev/null @@ -1,482 +0,0 @@ -activateKitPlugin($I); - - // Create Custom Post Types using the Custom Post Type UI Plugin. - $I->registerCustomPostTypes($I); - } - - /** - * Test that content is not restricted when not configured on a WordPress CPT. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentWhenDisabled(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - - // Add the CPT using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'article', - title: 'Kit: Article: Restrict Content: Product' - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Article. - $url = $I->publishGutenbergPage($I); - - // Confirm that all content is displayed. - $I->amOnUrl($url); - $I->see('Visible content.'); - $I->see('Member-only content.'); - } - - /** - * Test that no Restrict Content options are displayed when the Post Type - * is not public. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testNoRestrictContentOnPrivateCPT(EndToEndTester $I) - { - // Activate Classic Editor Plugin. - $I->activateThirdPartyPlugin($I, 'classic-editor'); - - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - - // Add the CPT using the Gutenberg editor. - $I->addClassicEditorPage( - $I, - postType: 'private', - title: 'Kit: Private: Restrict Content' - ); - - // Check that the metabox is not displayed. - $I->dontSeeElementInDOM('#wp-convertkit-meta-box'); - - // Publish and view the Page on the frontend site. - $I->publishAndViewClassicEditorPage($I); - - // Deactivate Classic Editor Plugin. - $I->deactivateThirdPartyPlugin($I, 'classic-editor'); - } - - /** - * Test that restricting content by a Product specified in the CPT Settings works when - * creating and viewing a new WordPress CPT. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProduct(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Add the CPT using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'article', - title: 'Kit: Article: Restrict Content: Product' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Article. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $url); - } - - /** - * Test that restricting content by a Product specified in the CPT Settings works when - * creating and viewing a new WordPress Page, and the "Add a Tag" CPT setting does - * not result in a critical error due to the use of a signed subscriber ID. - * - * @since 2.7.7 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProductWithAddTag(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Add a CPT using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'article', - title: 'Kit: Article: Restrict Content: Product' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - tag: $_ENV['CONVERTKIT_API_TAG_NAME'], - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Article. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $url); - } - - /** - * Test that restricting content by a Product specified in the CPT Settings works when - * creating and viewing a new WordPress CPT, and that the WordPress generated CPT Excerpt - * is displayed when no more tag exists. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProductWithGeneratedExcerpt(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($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'; - $memberOnlyContent = 'Member-only content'; - - // Add the CPT using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'article', - title: 'Kit: Article: Restrict Content: Product: Generated Excerpt' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, $visibleContent); - $I->addGutenbergParagraphBlock($I, $memberOnlyContent); - - // Publish Page. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend( - $I, - urlOrPageID: $url, - options: [ - 'visible_content' => $visibleContent, - 'member_content' => $memberOnlyContent, - ] - ); - } - - /** - * Test that restricting content by a Product specified in the CPT Settings works when - * creating and viewing a new WordPress CPT, and JS is enabled to allow the modal - * version for the authentication flow to be used. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentModalByProduct(EndToEndTester $I) - { - // Setup Kit Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Add the CPT using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'article', - title: 'Kit: Article: Restrict Content: Product: Modal' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Article. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentModal($I, $url); - } - - /** - * Test that restricting content by a Product specified in the CPT Settings works when - * creating and viewing a new WordPress CPT, and that the container CSS classes are applied - * to the content preview and call to action. - * - * @since 3.1.4 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentContainerCSSClasses(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Define Restrict Content settings. - $settings = [ - 'container_css_classes' => 'custom-container-css-class', - ]; - - // Setup Restrict Content functionality with container CSS classes. - $I->setupKitPluginRestrictContent($I, $settings); - - // Add the CPT using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'article', - title: 'Kit: Article: Restrict Content: Container CSS Classes' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Page. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend( - $I, - urlOrPageID: $url, - options: [ - 'settings' => $settings, - ] - ); - } - - /** - * Test that restricting content by a Product that does not exist does not output - * a fatal error and instead displays all of the CPT's content. - * - * This checks for when a Product is deleted in Kit, but is still specified - * as the Restrict Content setting for the CPT. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByInvalidProduct(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Programmatically create the CPT. - $postID = $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restrict Content: Invalid Product', - 'restrict_content_setting' => 'product_12345', // A fake Product that does not exist in Kit. - ] - ); - - // Navigate to the article. - $I->amOnPage('?p=' . $postID); - - // Confirm all content displays, with no errors, as the Product is invalid. - $I->testRestrictContentDisplaysContent($I); - } - - /** - * Test that restricting content by a Product specified in the CPT Settings works when - * using the Quick Edit functionality. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProductUsingQuickEdit(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Programmatically create the CPT. - $postID = $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Quick Edit', - ] - ); - - // Quick Edit the CPT in the CPTs WP_List_Table. - $I->quickEdit( - $I, - postType: 'article', - postID: $postID, - configuration: [ - 'restrict_content' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ], - ] - ); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $postID); - } - - /** - * Test that restricting content by a Product specified in the CPT Settings works when - * using the Bulk Edit functionality. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProductUsingBulkEdit(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Programmatically create two CPTs. - $postIDs = array( - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Bulk Edit #1', - ] - ), - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'article', - 'post_title' => 'Kit: Article: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Bulk Edit #2', - ] - ), - ); - - // Bulk Edit the CPTs in the CPTs WP_List_Table. - $I->bulkEdit( - $I, - postType: 'article', - postIDs: $postIDs, - configuration: [ - 'restrict_content' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ], - ] - ); - - // Iterate through Articles to run frontend tests. - foreach ($postIDs as $postID) { - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $postID); - $I->clearRestrictContentCookie($I); - } - } - - /** - * Deactivate and reset Plugin(s) after each test, if the test passes. - * We don't use _after, as this would provide a screenshot of the Plugin - * deactivation and not the true test error. - * - * @since 2.4.3 - * - * @param EndToEndTester $I Tester. - */ - public function _passed(EndToEndTester $I) - { - $I->unregisterCustomPostTypes($I); - $I->clearRestrictContentCookie($I); - $I->deactivateKitPlugin($I); - $I->resetKitPlugin($I); - } -} diff --git a/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php b/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php index f35d5dd06..cf04e0858 100644 --- a/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php +++ b/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php @@ -5,11 +5,12 @@ use Tests\Support\EndToEndTester; /** - * Tests Restrict Content by Product functionality on WordPress Pages. + * Tests Restrict Content by Product functionality on WordPress Pages, Posts and Custom Post Types + * using the Block Editor. * * @since 2.1.0 */ -class RestrictContentProductPageCest +class RestrictContentProductCest { /** * Post Types to test. diff --git a/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPostCest.php b/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPostCest.php deleted file mode 100644 index 15783a5cd..000000000 --- a/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPostCest.php +++ /dev/null @@ -1,510 +0,0 @@ -activateKitPlugin($I); - } - - /** - * Test that content is not restricted when not configured on a WordPress Post. - * - * @since 2.3.2 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentWhenDisabled(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - - // Add a Post using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'post', - title: 'Kit: Post: Restrict Content: Product' - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Post. - $url = $I->publishGutenbergPage($I); - - // Confirm that all content is displayed. - $I->amOnUrl($url); - $I->see('Visible content.'); - $I->see('Member-only content.'); - } - - /** - * Test that restricting content by a Product specified in the Post Settings works when - * creating and viewing a new WordPress Post. - * - * @since 2.3.2 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProduct(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Add a Post using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'post', - title: 'Kit: Post: Restrict Content: Product' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Post. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $url); - } - - /** - * Test that restricting content by a Product specified in the Post Settings works when - * creating and viewing a new WordPress Page, and the "Add a Tag" Post setting does - * not result in a critical error due to the use of a signed subscriber ID. - * - * @since 2.7.7 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProductWithAddTag(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Add a Post using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'post', - title: 'Kit: Post: Restrict Content: Product' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - tag: $_ENV['CONVERTKIT_API_TAG_NAME'], - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Post. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $url); - } - - /** - * Test that restricting content by a Product specified in the Post Settings works when - * creating and viewing a new WordPress Post, and that the WordPress generated Post Excerpt - * is displayed when no more tag exists. - * - * @since 2.3.7 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProductWithGeneratedExcerpt(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($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'; - $memberOnlyContent = 'Member-only content'; - - // Add a Post using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'post', - title: 'Kit: Post: Restrict Content: Product: Generated Excerpt' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, $visibleContent); - $I->addGutenbergParagraphBlock($I, $memberOnlyContent); - - // Publish Page. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend( - $I, - urlOrPageID: $url, - options: [ - 'visible_content' => $visibleContent, - 'member_content' => $memberOnlyContent, - ] - ); - } - - /** - * Test that restricting content by a Product specified in the Post Settings works when - * creating and viewing a new WordPress Post, and that the Excerpt defined in the Post - * is displayed when no more tag exists. - * - * @since 2.3.7 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProductWithDefinedExcerpt(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Define visible content and member-only content. - $options = [ - 'visible_content' => 'This is a defined excerpt', - 'member_content' => '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', - ]; - - // Add a Post using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'post', - title: 'Kit: Post: Restrict Content: Product: Defined Excerpt' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add member content only as a block. - // Visible content will be defined in the excerpt. - $I->addGutenbergParagraphBlock($I, $options['member_content']); - - // Define excerpt. - $I->addGutenbergExcerpt($I, $options['visible_content']); - - // Publish Post. - $url = $I->publishGutenbergPage($I); - - // Navigate to the page. - $I->amOnUrl($url); - - // Test Restrict Content functionality. - // Check content is not displayed, and CTA displays with expected text. - $I->testRestrictContentByProductHidesContentWithCTA($I, $options); - - // Test that the restricted content displays when a valid signed subscriber ID is used, - // as if we entered the code sent in the email. - // Excerpt should not be displayed, as its an excerpt, and we now show the member content instead. - $I->setRestrictContentCookieAndReload($I, $_ENV['CONVERTKIT_API_SIGNED_SUBSCRIBER_ID'], $url); - - // The excerpt shouldn't display, so update the options. - $options['visible_content'] = ''; - $I->testRestrictContentDisplaysContent($I, $options); - - // Assert that the excerpt is no longer displayed. - $I->dontSee('This is a defined excerpt'); - } - - /** - * Test that restricting content by a Product specified in the Post Settings works when - * creating and viewing a new WordPress Post, and JS is enabled to allow the modal - * version for the authentication flow to be used. - * - * @since 2.3.8 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentModalByProduct(EndToEndTester $I) - { - // Setup Kit Plugin. - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Add a Post using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'post', - title: 'Kit: Post: Restrict Content: Product: Modal' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Post. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentModal($I, $url); - } - - /** - * Test that restricting content by a Product specified in the Post Settings works when - * creating and viewing a new WordPress Post, and that the container CSS classes are applied - * to the content preview and call to action. - * - * @since 3.1.4 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentContainerCSSClasses(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Define Restrict Content settings. - $settings = [ - 'container_css_classes' => 'custom-container-css-class', - ]; - - // Setup Restrict Content functionality with container CSS classes. - $I->setupKitPluginRestrictContent($I, $settings); - - // Add the Post using the Gutenberg editor. - $I->addGutenbergPage( - $I, - postType: 'post', - title: 'Kit: Post: Restrict Content: Container CSS Classes' - ); - - // Configure metabox's Restrict Content setting = Product name. - $I->configurePluginSidebarSettings( - $I, - form: 'None', - restrictContent: $_ENV['CONVERTKIT_API_PRODUCT_NAME'] - ); - - // Add blocks. - $I->addGutenbergParagraphBlock($I, 'Visible content.'); - $I->addGutenbergBlock( - $I, - blockName: 'More', - blockProgrammaticName: 'more' - ); - $I->addGutenbergParagraphBlock($I, 'Member-only content.'); - - // Publish Page. - $url = $I->publishGutenbergPage($I); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend( - $I, - urlOrPageID: $url, - options: [ - 'settings' => $settings, - ] - ); - } - - /** - * Test that restricting content by a Product that does not exist does not output - * a fatal error and instead displays all of the Post's content. - * - * This checks for when a Product is deleted in Kit, but is still specified - * as the Restrict Content setting for a Post. - * - * @since 2.3.3 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByInvalidProduct(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Programmatically create a Post. - $postID = $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restrict Content: Invalid Product', - 'restrict_content_setting' => 'product_12345', // A fake Product that does not exist in Kit. - ] - ); - - // Navigate to the post. - $I->amOnPage('?p=' . $postID); - - // Confirm all content displays, with no errors, as the Product is invalid. - $I->testRestrictContentDisplaysContent($I); - } - - /** - * Test that restricting content by a Product specified in the Post Settings works when - * using the Quick Edit functionality. - * - * @since 2.3.2 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProductUsingQuickEdit(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Programmatically create a Post. - $postID = $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Quick Edit', - ] - ); - - // Quick Edit the Post in the Posts WP_List_Table. - $I->quickEdit( - $I, - postType: 'post', - postID: $postID, - configuration: [ - 'restrict_content' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ], - ] - ); - - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $postID); - } - - /** - * Test that restricting content by a Product specified in the Post Settings works when - * using the Bulk Edit functionality. - * - * @since 2.3.2 - * - * @param EndToEndTester $I Tester. - */ - public function testRestrictContentByProductUsingBulkEdit(EndToEndTester $I) - { - // Setup Kit Plugin, disabling JS. - $I->setupKitPluginDisableJS($I); - $I->setupKitPluginResources($I); - - // Programmatically create two Posts. - $postIDs = array( - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Bulk Edit #1', - ] - ), - $I->createRestrictedContentPage( - $I, - [ - 'post_type' => 'post', - 'post_title' => 'Kit: Post: Restrict Content: Product: ' . $_ENV['CONVERTKIT_API_PRODUCT_NAME'] . ': Bulk Edit #2', - ] - ), - ); - - // Bulk Edit the Posts in the Posts WP_List_Table. - $I->bulkEdit( - $I, - postType: 'post', - postIDs: $postIDs, - configuration: [ - 'restrict_content' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ], - ] - ); - - // Iterate through Posts to run frontend tests. - foreach ($postIDs as $postID) { - // Test Restrict Content functionality. - $I->testRestrictedContentByProductOnFrontend($I, $postID); - $I->clearRestrictContentCookie($I); - } - } - - /** - * Deactivate and reset Plugin(s) after each test, if the test passes. - * We don't use _after, as this would provide a screenshot of the Plugin - * deactivation and not the true test error. - * - * @since 2.3.2 - * - * @param EndToEndTester $I Tester. - */ - public function _passed(EndToEndTester $I) - { - $I->clearRestrictContentCookie($I); - $I->deactivateKitPlugin($I); - $I->resetKitPlugin($I); - } -} From 30563c2e088eeb91e2623f58777484b329cca22b Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 15 Apr 2026 18:06:38 +0800 Subject: [PATCH 3/5] Rename test file --- ...tContentProductPageCest.php => RestrictContentProductCest.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/EndToEnd/restrict-content/post-types/{RestrictContentProductPageCest.php => RestrictContentProductCest.php} (100%) diff --git a/tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php b/tests/EndToEnd/restrict-content/post-types/RestrictContentProductCest.php similarity index 100% rename from tests/EndToEnd/restrict-content/post-types/RestrictContentProductPageCest.php rename to tests/EndToEnd/restrict-content/post-types/RestrictContentProductCest.php From b65aa79c95d2236402de09de105ae73491218825 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 15 Apr 2026 19:18:28 +0800 Subject: [PATCH 4/5] Block Editor: Settings Sidebar: Support `optgroup` for Member Content --- ...onvertkit-plugin-sidebar-post-settings.php | 18 +++- resources/backend/js/gutenberg.js | 91 +++++++++++++++++-- 2 files changed, 100 insertions(+), 9 deletions(-) diff --git a/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php b/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php index c84121cee..e504bad9a 100644 --- a/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php +++ b/includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php @@ -160,9 +160,13 @@ public function get_fields() { '0' => esc_html__( 'Don\'t restrict content to member-only', 'convertkit' ), ); if ( $convertkit_forms->exist() ) { + $restrict_content['forms'] = array( + 'label' => esc_html__( 'Forms', 'convertkit' ), + 'values' => array(), + ); foreach ( $convertkit_forms->get() as $form ) { // Legacy forms don't include a `format` key, so define them as inline. - $restrict_content[ 'form_' . absint( $form['id'] ) ] = sprintf( + $restrict_content['forms']['values'][ 'form_' . absint( $form['id'] ) ] = sprintf( '%s [%s]', sanitize_text_field( $form['name'] ), ( ! empty( $form['format'] ) ? sanitize_text_field( $form['format'] ) : 'inline' ) @@ -170,13 +174,21 @@ public function get_fields() { } } if ( $convertkit_tags->exist() ) { + $restrict_content['tags'] = array( + 'label' => esc_html__( 'Tags', 'convertkit' ), + 'values' => array(), + ); foreach ( $convertkit_tags->get() as $tag ) { - $restrict_content[ 'tag_' . absint( $tag['id'] ) ] = sanitize_text_field( $tag['name'] ); + $restrict_content['tags']['values'][ 'tag_' . absint( $tag['id'] ) ] = sanitize_text_field( $tag['name'] ); } } if ( $convertkit_products->exist() ) { + $restrict_content['products'] = array( + 'label' => esc_html__( 'Products', 'convertkit' ), + 'values' => array(), + ); foreach ( $convertkit_products->get() as $product ) { - $restrict_content[ 'product_' . $product['id'] ] = sanitize_text_field( $product['name'] ); + $restrict_content['products']['values'][ 'product_' . $product['id'] ] = sanitize_text_field( $product['name'] ); } } diff --git a/resources/backend/js/gutenberg.js b/resources/backend/js/gutenberg.js index 1e617cbbb..24965b7ad 100644 --- a/resources/backend/js/gutenberg.js +++ b/resources/backend/js/gutenberg.js @@ -1009,25 +1009,104 @@ function convertKitGutenbergRegisterPluginSidebar(sidebar) { // depending on the Field Type (select, textarea, text etc). switch (field.type) { case 'select': - // Build options for