Skip to content

Commit e9b1a02

Browse files
authored
Merge pull request #833 from Kit/add-form-support-restrict-content-wizard
Restrict Content: Setup Wizard: Add option to specify form
2 parents b373827 + 8deca4e commit e9b1a02

4 files changed

Lines changed: 226 additions & 41 deletions

File tree

admin/setup-wizard/class-convertkit-admin-setup-wizard-restrict-content.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ class ConvertKit_Admin_Setup_Wizard_Restrict_Content extends ConvertKit_Admin_Se
4141
*/
4242
public $type_label = '';
4343

44+
/**
45+
* Holds the ConvertKit Forms resource class.
46+
*
47+
* @since 2.8.3
48+
*
49+
* @var bool|ConvertKit_Resource_Forms
50+
*/
51+
public $forms = false;
52+
4453
/**
4554
* Holds the ConvertKit Products resource class.
4655
*
@@ -260,18 +269,20 @@ public function load_screen_data( $step ) {
260269
// Load data depending on the current step.
261270
switch ( $step ) {
262271
case 1:
263-
// Fetch Products and Tags.
272+
// Fetch Forms, Products and Tags.
273+
$this->forms = new ConvertKit_Resource_Forms( 'restrict_content_wizard' );
264274
$this->products = new ConvertKit_Resource_Products( 'restrict_content_wizard' );
265275
$this->tags = new ConvertKit_Resource_Tags( 'restrict_content_wizard' );
266276

267-
// Refresh Products and Tags resources, in case the user just created their first Product or Tag
277+
// Refresh Forms, Products and Tags resources, in case the user just created their first Form, Product or Tag
268278
// in ConvertKit.
279+
$this->forms->refresh();
269280
$this->products->refresh();
270281
$this->tags->refresh();
271282

272-
// If no Products and Tags exist in ConvertKit, change the next button label and make it a link to reload
283+
// If no Forms, Products and Tags exist in ConvertKit, change the next button label and make it a link to reload
273284
// the screen.
274-
if ( ! $this->products->exist() && ! $this->tags->exist() ) {
285+
if ( ! $this->forms->exist() && ! $this->products->exist() && ! $this->tags->exist() ) {
275286
unset( $this->steps[1]['next_button'] );
276287
$this->current_url = add_query_arg(
277288
array(
@@ -315,7 +326,8 @@ public function load_screen_data( $step ) {
315326
break;
316327
}
317328

318-
// Fetch Products and Tags.
329+
// Fetch Forms, Products and Tags.
330+
$this->forms = new ConvertKit_Resource_Forms( 'restrict_content_wizard' );
319331
$this->products = new ConvertKit_Resource_Products( 'restrict_content_wizard' );
320332
$this->tags = new ConvertKit_Resource_Tags( 'restrict_content_wizard' );
321333
break;
@@ -339,7 +351,7 @@ private function create_download( $configuration ) {
339351
$configuration['title'],
340352
$configuration['description'],
341353
$configuration['post_type'],
342-
__( 'The downloadable content (that is available when the visitor has paid for the Kit product) goes here.', 'convertkit' ),
354+
__( 'The downloadable member-only content goes here.', 'convertkit' ),
343355
$configuration['restrict_content']
344356
);
345357

@@ -406,7 +418,7 @@ private function create_course( $configuration ) {
406418
'%s %s %s',
407419
esc_html__( 'Lesson', 'convertkit' ),
408420
$i,
409-
esc_html__( 'content (that is available when the visitor has paid for the Kit product) goes here.', 'convertkit' )
421+
esc_html__( 'member-only content goes here.', 'convertkit' )
410422
),
411423
$configuration['restrict_content'],
412424
$i,

tests/EndToEnd/restrict-content/general/RestrictContentSetupCest.php

Lines changed: 163 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function testAddNewMemberContentDownloadsByProduct(EndToEndTester $I)
223223
$I,
224224
$url,
225225
[
226-
'member_content' => 'The downloadable content (that is available when the visitor has paid for the Kit product) goes here.',
226+
'member_content' => 'The downloadable member-only content goes here.',
227227
]
228228
);
229229
}
@@ -292,7 +292,7 @@ public function testAddNewMemberContentCourseByProduct(EndToEndTester $I)
292292
$url,
293293
[
294294
'visible_content' => 'Some introductory text about lesson 1',
295-
'member_content' => 'Lesson 1 content (that is available when the visitor has paid for the Kit product) goes here.',
295+
'member_content' => 'Lesson 1 member-only content goes here.',
296296
]
297297
);
298298

@@ -301,25 +301,25 @@ public function testAddNewMemberContentCourseByProduct(EndToEndTester $I)
301301
$I->waitForElementVisible('body.page-template-default');
302302
$I->see('Kit: Member Content: Course: 2/3');
303303
$I->see('Some introductory text about lesson 2');
304-
$I->see('Lesson 2 content (that is available when the visitor has paid for the Kit product) goes here');
304+
$I->see('Lesson 2 member-only content goes here.');
305305

306306
$I->click('Next Lesson');
307307
$I->waitForElementVisible('body.page-template-default');
308308
$I->see('Kit: Member Content: Course: 3/3');
309309
$I->see('Some introductory text about lesson 3');
310-
$I->see('Lesson 3 content (that is available when the visitor has paid for the Kit product) goes here');
310+
$I->see('Lesson 3 member-only content goes here.');
311311

312312
$I->click('Previous Lesson');
313313
$I->waitForElementVisible('body.page-template-default');
314314
$I->see('Kit: Member Content: Course: 2/3');
315315
$I->see('Some introductory text about lesson 2');
316-
$I->see('Lesson 2 content (that is available when the visitor has paid for the Kit product) goes here');
316+
$I->see('Lesson 2 member-only content goes here.');
317317

318318
$I->click('Previous Lesson');
319319
$I->waitForElementVisible('body.page-template-default');
320320
$I->see('Kit: Member Content: Course: 1/3');
321321
$I->see('Some introductory text about lesson 1');
322-
$I->see('Lesson 1 content (that is available when the visitor has paid for the Kit product) goes here');
322+
$I->see('Lesson 1 member-only content goes here.');
323323
}
324324

325325
/**
@@ -373,7 +373,7 @@ public function testAddNewMemberContentDownloadsByTag(EndToEndTester $I)
373373
urlOrPageID: $url,
374374
emailAddress: $I->generateEmailAddress(),
375375
options: [
376-
'member_content' => 'The downloadable content (that is available when the visitor has paid for the Kit product) goes here.',
376+
'member_content' => 'The downloadable member-only content goes here.',
377377
]
378378
);
379379
}
@@ -443,7 +443,7 @@ public function testAddNewMemberContentCourseByTag(EndToEndTester $I)
443443
emailAddress: $I->generateEmailAddress(),
444444
options: [
445445
'visible_content' => 'Some introductory text about lesson 1',
446-
'member_content' => 'Lesson 1 content (that is available when the visitor has paid for the Kit product) goes here.',
446+
'member_content' => 'Lesson 1 member-only content goes here.',
447447
]
448448
);
449449

@@ -452,25 +452,176 @@ public function testAddNewMemberContentCourseByTag(EndToEndTester $I)
452452
$I->waitForElementVisible('body.page-template-default');
453453
$I->see('Kit: Member Content: Course: Tag: 2/3');
454454
$I->see('Some introductory text about lesson 2');
455-
$I->see('Lesson 2 content (that is available when the visitor has paid for the Kit product) goes here');
455+
$I->see('Lesson 2 member-only content goes here.');
456456

457457
$I->click('Next Lesson');
458458
$I->waitForElementVisible('body.page-template-default');
459459
$I->see('Kit: Member Content: Course: Tag: 3/3');
460460
$I->see('Some introductory text about lesson 3');
461-
$I->see('Lesson 3 content (that is available when the visitor has paid for the Kit product) goes here');
461+
$I->see('Lesson 3 member-only content goes here.');
462462

463463
$I->click('Previous Lesson');
464464
$I->waitForElementVisible('body.page-template-default');
465465
$I->see('Kit: Member Content: Course: Tag: 2/3');
466466
$I->see('Some introductory text about lesson 2');
467-
$I->see('Lesson 2 content (that is available when the visitor has paid for the Kit product) goes here');
467+
$I->see('Lesson 2 member-only content goes here.');
468468

469469
$I->click('Previous Lesson');
470470
$I->waitForElementVisible('body.page-template-default');
471471
$I->see('Kit: Member Content: Course: Tag: 1/3');
472472
$I->see('Some introductory text about lesson 1');
473-
$I->see('Lesson 1 content (that is available when the visitor has paid for the Kit product) goes here');
473+
$I->see('Lesson 1 member-only content goes here.');
474+
}
475+
476+
/**
477+
* Test that the Add New Member Content > Downloads generates the expected Page
478+
* and restricts content by the selected Form.
479+
*
480+
* @since 2.8.3
481+
*
482+
* @param EndToEndTester $I Tester.
483+
*/
484+
public function testAddNewMemberContentDownloadsByForm(EndToEndTester $I)
485+
{
486+
// Setup Plugin and navigate to Add New Member Content screen.
487+
$this->_setupAndLoadAddNewMemberContentScreen($I);
488+
489+
// Click Downloads button.
490+
$I->click('Download');
491+
492+
// Confirm the Configure Download screen is displayed.
493+
$I->see('Configure Download');
494+
495+
// Enter a title and description.
496+
$I->fillField('title', 'Kit: Member Content: Download: Form');
497+
$I->fillField('description', 'Visible content.');
498+
499+
// Confirm that the limit option is not visible, as this is only for courses.
500+
$I->dontSee('How many lessons does this course consist of?');
501+
502+
// Restrict by Form.
503+
$I->fillSelect2Field($I, '#select2-wp-convertkit-restrict_content-container', $_ENV['CONVERTKIT_API_FORM_NAME']);
504+
505+
// Click submit button.
506+
$I->click('Submit');
507+
508+
// Wait for the WP_List_Table of Pages to load.
509+
$I->waitForElementVisible('tbody#the-list');
510+
511+
// Confirm that one Page is listed in the WP_List_Table.
512+
$I->see('Kit: Member Content: Download: Form');
513+
$I->seeInSource('<span class="post-state">Kit Member Content</span>');
514+
515+
// Hover mouse over Post's table row.
516+
$I->moveMouseOver('tr.iedit');
517+
518+
// Get link to Page.
519+
$url = $I->grabAttributeFrom('tr.iedit span.view a', 'href');
520+
521+
// Test Restrict Content functionality.
522+
$I->testRestrictedContentByFormOnFrontend(
523+
$I,
524+
urlOrPageID: $url,
525+
formID: $_ENV['CONVERTKIT_API_FORM_ID'],
526+
options: [
527+
'member_content' => 'The downloadable member-only content goes here.',
528+
]
529+
);
530+
}
531+
532+
/**
533+
* Test that the Add New Member Content > Course generates the expected Pages
534+
* and restricts content by the selected Form.
535+
*
536+
* @since 2.8.3
537+
*
538+
* @param EndToEndTester $I Tester.
539+
*/
540+
public function testAddNewMemberContentCourseByForm(EndToEndTester $I)
541+
{
542+
// Setup Plugin and navigate to Add New Member Content screen.
543+
$this->_setupAndLoadAddNewMemberContentScreen($I);
544+
545+
// Click Course button.
546+
$I->click('Course');
547+
548+
// Confirm the Configure Course screen is displayed.
549+
$I->see('Configure Course');
550+
551+
// Enter a title, description and lesson count.
552+
$I->fillField('title', 'Kit: Member Content: Course: Form');
553+
$I->fillField('description', 'Visible content.');
554+
$I->fillField('number_of_pages', '3');
555+
556+
// Restrict by Product.
557+
$I->fillSelect2Field($I, '#select2-wp-convertkit-restrict_content-container', $_ENV['CONVERTKIT_API_FORM_NAME']);
558+
559+
// Click submit button.
560+
$I->click('Submit');
561+
562+
// Wait for the WP_List_Table of Pages to load.
563+
$I->waitForElementVisible('tbody#the-list');
564+
565+
// Confirm that four Pages are listed in the WP_List_Table.
566+
$I->see('Kit: Member Content: Course: Form');
567+
$I->see('— Kit: Member Content: Course: Form: 1/3');
568+
$I->see('— Kit: Member Content: Course: Form: 2/3');
569+
$I->see('— Kit: Member Content: Course: Form: 3/3');
570+
$I->see('Kit Member Content | Parent Page: Kit: Member Content: Course: Form');
571+
572+
// Hover mouse over Post's table row.
573+
$I->moveMouseOver('tr.iedit:first-child');
574+
575+
// Wait for View link to be visible.
576+
$I->waitForElementVisible('tr.iedit:first-child span.view a');
577+
578+
// Click View link.
579+
$I->click('tr.iedit:first-child span.view a');
580+
581+
// Wait for frontend web site to load.
582+
$I->waitForElementVisible('body.page-template-default');
583+
584+
// Confirm the Start Course button exists.
585+
$I->see('Start Course');
586+
587+
// Get URL to first restricted content page.
588+
$url = $I->grabAttributeFrom('.wp-block-button a', 'href');
589+
590+
// Test Restrict Content functionality.
591+
$I->testRestrictedContentByFormOnFrontend(
592+
$I,
593+
urlOrPageID: $url,
594+
formID: $_ENV['CONVERTKIT_API_FORM_ID'],
595+
options: [
596+
'visible_content' => 'Some introductory text about lesson 1',
597+
'member_content' => 'Lesson 1 member-only content goes here.',
598+
]
599+
);
600+
601+
// Test Next / Previous links.
602+
$I->click('Next Lesson');
603+
$I->waitForElementVisible('body.page-template-default');
604+
$I->see('Kit: Member Content: Course: Form: 2/3');
605+
$I->see('Some introductory text about lesson 2');
606+
$I->see('Lesson 2 member-only content goes here.');
607+
608+
$I->click('Next Lesson');
609+
$I->waitForElementVisible('body.page-template-default');
610+
$I->see('Kit: Member Content: Course: Form: 3/3');
611+
$I->see('Some introductory text about lesson 3');
612+
$I->see('Lesson 3 member-only content goes here.');
613+
614+
$I->click('Previous Lesson');
615+
$I->waitForElementVisible('body.page-template-default');
616+
$I->see('Kit: Member Content: Course: Form: 2/3');
617+
$I->see('Some introductory text about lesson 2');
618+
$I->see('Lesson 2 member-only content goes here.');
619+
620+
$I->click('Previous Lesson');
621+
$I->waitForElementVisible('body.page-template-default');
622+
$I->see('Kit: Member Content: Course: Form: 1/3');
623+
$I->see('Some introductory text about lesson 1');
624+
$I->see('Lesson 1 member-only content goes here.');
474625
}
475626

476627
/**

views/backend/setup-wizard/convertkit-restrict-content-setup/content-1.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<?php esc_html_e( 'Download', 'convertkit' ); ?>
7272
</a>
7373
<span class="description">
74-
<?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' ); ?>
74+
<?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' ); ?>
7575
</span>
7676
</div>
7777

@@ -80,7 +80,7 @@
8080
<?php esc_html_e( 'Course', 'convertkit' ); ?>
8181
</a>
8282
<span class="description">
83-
<?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' ); ?>
83+
<?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' ); ?>
8484
</span>
8585
</div>
8686
</div>

0 commit comments

Comments
 (0)