Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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']
);

Expand Down Expand Up @@ -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,
Expand Down
175 changes: 163 additions & 12 deletions tests/EndToEnd/restrict-content/general/RestrictContentSetupCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
]
);
}
Expand Down Expand Up @@ -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.',
]
);

Expand All @@ -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.');
}

/**
Expand Down Expand Up @@ -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.',
]
);
}
Expand Down Expand Up @@ -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.',
]
);

Expand All @@ -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('<span class="post-state">Kit Member Content</span>');

// 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.');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<?php esc_html_e( 'Download', 'convertkit' ); ?>
</a>
<span class="description">
<?php esc_html_e( 'Require visitors to purchase a Kit product, or subscribe to a Kit tag, granting access to a single Page\'s content, which includes downloadable assets.', 'convertkit' ); ?>
<?php esc_html_e( 'Require visitors to purchase a Kit product, or subscribe to a Kit tag or form, granting access to a single Page\'s content, which includes downloadable assets.', 'convertkit' ); ?>
</span>
</div>

Expand All @@ -80,7 +80,7 @@
<?php esc_html_e( 'Course', 'convertkit' ); ?>
</a>
<span class="description">
<?php esc_html_e( 'Require visitors to purchase a Kit product, or subscribe to a Kit tag, granting access to a sequential series of Pages, such as a course, lessons or tutorials.', 'convertkit' ); ?>
<?php esc_html_e( 'Require visitors to purchase a Kit product, or subscribe to a Kit tag or form, granting access to a sequential series of Pages, such as a course, lessons or tutorials.', 'convertkit' ); ?>
</span>
</div>
</div>
Expand Down
Loading