diff --git a/admin/setup-wizard/class-convertkit-admin-setup-wizard-restrict-content.php b/admin/setup-wizard/class-convertkit-admin-setup-wizard-restrict-content.php index 1c9286fe2..624da37d5 100644 --- a/admin/setup-wizard/class-convertkit-admin-setup-wizard-restrict-content.php +++ b/admin/setup-wizard/class-convertkit-admin-setup-wizard-restrict-content.php @@ -41,6 +41,15 @@ class ConvertKit_Admin_Setup_Wizard_Restrict_Content extends ConvertKit_Admin_Se */ public $type_label = ''; + /** + * Holds the ConvertKit Forms resource class. + * + * @since 2.8.3 + * + * @var bool|ConvertKit_Resource_Forms + */ + public $forms = false; + /** * Holds the ConvertKit Products resource class. * @@ -260,18 +269,20 @@ public function load_screen_data( $step ) { // Load data depending on the current step. switch ( $step ) { case 1: - // Fetch Products and Tags. + // Fetch Forms, Products and Tags. + $this->forms = new ConvertKit_Resource_Forms( 'restrict_content_wizard' ); $this->products = new ConvertKit_Resource_Products( 'restrict_content_wizard' ); $this->tags = new ConvertKit_Resource_Tags( 'restrict_content_wizard' ); - // Refresh Products and Tags resources, in case the user just created their first Product or Tag + // Refresh Forms, Products and Tags resources, in case the user just created their first Form, Product or Tag // in ConvertKit. + $this->forms->refresh(); $this->products->refresh(); $this->tags->refresh(); - // If no Products and Tags exist in ConvertKit, change the next button label and make it a link to reload + // If no Forms, Products and Tags exist in ConvertKit, change the next button label and make it a link to reload // the screen. - if ( ! $this->products->exist() && ! $this->tags->exist() ) { + if ( ! $this->forms->exist() && ! $this->products->exist() && ! $this->tags->exist() ) { unset( $this->steps[1]['next_button'] ); $this->current_url = add_query_arg( array( @@ -315,7 +326,8 @@ public function load_screen_data( $step ) { break; } - // Fetch Products and Tags. + // Fetch Forms, Products and Tags. + $this->forms = new ConvertKit_Resource_Forms( 'restrict_content_wizard' ); $this->products = new ConvertKit_Resource_Products( 'restrict_content_wizard' ); $this->tags = new ConvertKit_Resource_Tags( 'restrict_content_wizard' ); break; @@ -339,7 +351,7 @@ private function create_download( $configuration ) { $configuration['title'], $configuration['description'], $configuration['post_type'], - __( 'The downloadable content (that is available when the visitor has paid for the Kit product) goes here.', 'convertkit' ), + __( 'The downloadable member-only content goes here.', 'convertkit' ), $configuration['restrict_content'] ); @@ -406,7 +418,7 @@ private function create_course( $configuration ) { '%s %s %s', esc_html__( 'Lesson', 'convertkit' ), $i, - esc_html__( 'content (that is available when the visitor has paid for the Kit product) goes here.', 'convertkit' ) + esc_html__( 'member-only content goes here.', 'convertkit' ) ), $configuration['restrict_content'], $i, diff --git a/tests/EndToEnd/restrict-content/general/RestrictContentSetupCest.php b/tests/EndToEnd/restrict-content/general/RestrictContentSetupCest.php index 196b24167..a426035ef 100644 --- a/tests/EndToEnd/restrict-content/general/RestrictContentSetupCest.php +++ b/tests/EndToEnd/restrict-content/general/RestrictContentSetupCest.php @@ -223,7 +223,7 @@ public function testAddNewMemberContentDownloadsByProduct(EndToEndTester $I) $I, $url, [ - 'member_content' => 'The downloadable content (that is available when the visitor has paid for the Kit product) goes here.', + 'member_content' => 'The downloadable member-only content goes here.', ] ); } @@ -292,7 +292,7 @@ public function testAddNewMemberContentCourseByProduct(EndToEndTester $I) $url, [ 'visible_content' => 'Some introductory text about lesson 1', - 'member_content' => 'Lesson 1 content (that is available when the visitor has paid for the Kit product) goes here.', + 'member_content' => 'Lesson 1 member-only content goes here.', ] ); @@ -301,25 +301,25 @@ public function testAddNewMemberContentCourseByProduct(EndToEndTester $I) $I->waitForElementVisible('body.page-template-default'); $I->see('Kit: Member Content: Course: 2/3'); $I->see('Some introductory text about lesson 2'); - $I->see('Lesson 2 content (that is available when the visitor has paid for the Kit product) goes here'); + $I->see('Lesson 2 member-only content goes here.'); $I->click('Next Lesson'); $I->waitForElementVisible('body.page-template-default'); $I->see('Kit: Member Content: Course: 3/3'); $I->see('Some introductory text about lesson 3'); - $I->see('Lesson 3 content (that is available when the visitor has paid for the Kit product) goes here'); + $I->see('Lesson 3 member-only content goes here.'); $I->click('Previous Lesson'); $I->waitForElementVisible('body.page-template-default'); $I->see('Kit: Member Content: Course: 2/3'); $I->see('Some introductory text about lesson 2'); - $I->see('Lesson 2 content (that is available when the visitor has paid for the Kit product) goes here'); + $I->see('Lesson 2 member-only content goes here.'); $I->click('Previous Lesson'); $I->waitForElementVisible('body.page-template-default'); $I->see('Kit: Member Content: Course: 1/3'); $I->see('Some introductory text about lesson 1'); - $I->see('Lesson 1 content (that is available when the visitor has paid for the Kit product) goes here'); + $I->see('Lesson 1 member-only content goes here.'); } /** @@ -373,7 +373,7 @@ public function testAddNewMemberContentDownloadsByTag(EndToEndTester $I) urlOrPageID: $url, emailAddress: $I->generateEmailAddress(), options: [ - 'member_content' => 'The downloadable content (that is available when the visitor has paid for the Kit product) goes here.', + 'member_content' => 'The downloadable member-only content goes here.', ] ); } @@ -443,7 +443,7 @@ public function testAddNewMemberContentCourseByTag(EndToEndTester $I) emailAddress: $I->generateEmailAddress(), options: [ 'visible_content' => 'Some introductory text about lesson 1', - 'member_content' => 'Lesson 1 content (that is available when the visitor has paid for the Kit product) goes here.', + 'member_content' => 'Lesson 1 member-only content goes here.', ] ); @@ -452,25 +452,176 @@ public function testAddNewMemberContentCourseByTag(EndToEndTester $I) $I->waitForElementVisible('body.page-template-default'); $I->see('Kit: Member Content: Course: Tag: 2/3'); $I->see('Some introductory text about lesson 2'); - $I->see('Lesson 2 content (that is available when the visitor has paid for the Kit product) goes here'); + $I->see('Lesson 2 member-only content goes here.'); $I->click('Next Lesson'); $I->waitForElementVisible('body.page-template-default'); $I->see('Kit: Member Content: Course: Tag: 3/3'); $I->see('Some introductory text about lesson 3'); - $I->see('Lesson 3 content (that is available when the visitor has paid for the Kit product) goes here'); + $I->see('Lesson 3 member-only content goes here.'); $I->click('Previous Lesson'); $I->waitForElementVisible('body.page-template-default'); $I->see('Kit: Member Content: Course: Tag: 2/3'); $I->see('Some introductory text about lesson 2'); - $I->see('Lesson 2 content (that is available when the visitor has paid for the Kit product) goes here'); + $I->see('Lesson 2 member-only content goes here.'); $I->click('Previous Lesson'); $I->waitForElementVisible('body.page-template-default'); $I->see('Kit: Member Content: Course: Tag: 1/3'); $I->see('Some introductory text about lesson 1'); - $I->see('Lesson 1 content (that is available when the visitor has paid for the Kit product) goes here'); + $I->see('Lesson 1 member-only content goes here.'); + } + + /** + * Test that the Add New Member Content > Downloads generates the expected Page + * and restricts content by the selected Form. + * + * @since 2.8.3 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewMemberContentDownloadsByForm(EndToEndTester $I) + { + // Setup Plugin and navigate to Add New Member Content screen. + $this->_setupAndLoadAddNewMemberContentScreen($I); + + // Click Downloads button. + $I->click('Download'); + + // Confirm the Configure Download screen is displayed. + $I->see('Configure Download'); + + // Enter a title and description. + $I->fillField('title', 'Kit: Member Content: Download: Form'); + $I->fillField('description', 'Visible content.'); + + // Confirm that the limit option is not visible, as this is only for courses. + $I->dontSee('How many lessons does this course consist of?'); + + // Restrict by Form. + $I->fillSelect2Field($I, '#select2-wp-convertkit-restrict_content-container', $_ENV['CONVERTKIT_API_FORM_NAME']); + + // Click submit button. + $I->click('Submit'); + + // Wait for the WP_List_Table of Pages to load. + $I->waitForElementVisible('tbody#the-list'); + + // Confirm that one Page is listed in the WP_List_Table. + $I->see('Kit: Member Content: Download: Form'); + $I->seeInSource('Kit Member Content'); + + // Hover mouse over Post's table row. + $I->moveMouseOver('tr.iedit'); + + // Get link to Page. + $url = $I->grabAttributeFrom('tr.iedit span.view a', 'href'); + + // Test Restrict Content functionality. + $I->testRestrictedContentByFormOnFrontend( + $I, + urlOrPageID: $url, + formID: $_ENV['CONVERTKIT_API_FORM_ID'], + options: [ + 'member_content' => 'The downloadable member-only content goes here.', + ] + ); + } + + /** + * Test that the Add New Member Content > Course generates the expected Pages + * and restricts content by the selected Form. + * + * @since 2.8.3 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewMemberContentCourseByForm(EndToEndTester $I) + { + // Setup Plugin and navigate to Add New Member Content screen. + $this->_setupAndLoadAddNewMemberContentScreen($I); + + // Click Course button. + $I->click('Course'); + + // Confirm the Configure Course screen is displayed. + $I->see('Configure Course'); + + // Enter a title, description and lesson count. + $I->fillField('title', 'Kit: Member Content: Course: Form'); + $I->fillField('description', 'Visible content.'); + $I->fillField('number_of_pages', '3'); + + // Restrict by Product. + $I->fillSelect2Field($I, '#select2-wp-convertkit-restrict_content-container', $_ENV['CONVERTKIT_API_FORM_NAME']); + + // Click submit button. + $I->click('Submit'); + + // Wait for the WP_List_Table of Pages to load. + $I->waitForElementVisible('tbody#the-list'); + + // Confirm that four Pages are listed in the WP_List_Table. + $I->see('Kit: Member Content: Course: Form'); + $I->see('— Kit: Member Content: Course: Form: 1/3'); + $I->see('— Kit: Member Content: Course: Form: 2/3'); + $I->see('— Kit: Member Content: Course: Form: 3/3'); + $I->see('Kit Member Content | Parent Page: Kit: Member Content: Course: Form'); + + // Hover mouse over Post's table row. + $I->moveMouseOver('tr.iedit:first-child'); + + // Wait for View link to be visible. + $I->waitForElementVisible('tr.iedit:first-child span.view a'); + + // Click View link. + $I->click('tr.iedit:first-child span.view a'); + + // Wait for frontend web site to load. + $I->waitForElementVisible('body.page-template-default'); + + // Confirm the Start Course button exists. + $I->see('Start Course'); + + // Get URL to first restricted content page. + $url = $I->grabAttributeFrom('.wp-block-button a', 'href'); + + // Test Restrict Content functionality. + $I->testRestrictedContentByFormOnFrontend( + $I, + urlOrPageID: $url, + formID: $_ENV['CONVERTKIT_API_FORM_ID'], + options: [ + 'visible_content' => 'Some introductory text about lesson 1', + 'member_content' => 'Lesson 1 member-only content goes here.', + ] + ); + + // Test Next / Previous links. + $I->click('Next Lesson'); + $I->waitForElementVisible('body.page-template-default'); + $I->see('Kit: Member Content: Course: Form: 2/3'); + $I->see('Some introductory text about lesson 2'); + $I->see('Lesson 2 member-only content goes here.'); + + $I->click('Next Lesson'); + $I->waitForElementVisible('body.page-template-default'); + $I->see('Kit: Member Content: Course: Form: 3/3'); + $I->see('Some introductory text about lesson 3'); + $I->see('Lesson 3 member-only content goes here.'); + + $I->click('Previous Lesson'); + $I->waitForElementVisible('body.page-template-default'); + $I->see('Kit: Member Content: Course: Form: 2/3'); + $I->see('Some introductory text about lesson 2'); + $I->see('Lesson 2 member-only content goes here.'); + + $I->click('Previous Lesson'); + $I->waitForElementVisible('body.page-template-default'); + $I->see('Kit: Member Content: Course: Form: 1/3'); + $I->see('Some introductory text about lesson 1'); + $I->see('Lesson 1 member-only content goes here.'); } /** diff --git a/views/backend/setup-wizard/convertkit-restrict-content-setup/content-1.php b/views/backend/setup-wizard/convertkit-restrict-content-setup/content-1.php index 55c509bfd..544ffd428 100644 --- a/views/backend/setup-wizard/convertkit-restrict-content-setup/content-1.php +++ b/views/backend/setup-wizard/convertkit-restrict-content-setup/content-1.php @@ -71,7 +71,7 @@ - + @@ -80,7 +80,7 @@ - + diff --git a/views/backend/setup-wizard/convertkit-restrict-content-setup/content-2.php b/views/backend/setup-wizard/convertkit-restrict-content-setup/content-2.php index 79683a84f..e9e1574e6 100644 --- a/views/backend/setup-wizard/convertkit-restrict-content-setup/content-2.php +++ b/views/backend/setup-wizard/convertkit-restrict-content-setup/content-2.php @@ -53,42 +53,64 @@
+
+
+
+
+
+
+
+
+
+
+