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 @@ -250,6 +250,60 @@ public function testRestrictContentModalByProduct(EndToEndTester $I)
$I->testRestrictedContentModal($I, $url);
}

/**
* Test that restricting content by a Product specified in the Page Settings displays
* an inline error message when the subscriber logged in to view content gated
* by a Kit Form, and then views content gated by a Kit Product where the subscriber does
* not have access to the Product.
*
* @since 3.0.8
*
* @param EndToEndTester $I Tester.
*/
public function testRestrictContentDisplaysNoticeWhenNoAccess(EndToEndTester $I)
{
// Setup Kit Plugin.
$I->setupKitPlugin($I);

// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Restrict Content: Product: No Access'
);

// Configure metabox's Restrict Content setting = Product name.
$I->configureMetaboxSettings(
$I,
metabox: 'wp-convertkit-meta-box',
configuration: [
'form' => [ 'select2', 'None' ],
'restrict_content' => [ 'select2', $_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);

// 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);

// Confirm an inline error message is displayed.
$options = $I->getRestrictedContentOptionsWithDefaultsMerged();
$I->seeRestrictContentError($I, $options['settings']['no_access_text']);
}

/**
* Test that restricting content by a Product that does not exist does not output
* a fatal error and instead displays all of the Page's content.
Expand Down
12 changes: 6 additions & 6 deletions tests/Support/Helper/KitRestrictContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public function testRestrictedContentModal($I, $urlOrPageID, $options = false)
public function testRestrictContentByProductHidesContentWithCTA($I, $options = false)
{
// Merge options with defaults.
$options = $this->_getRestrictedContentOptionsWithDefaultsMerged($options);
$options = $this->getRestrictedContentOptionsWithDefaultsMerged($options);

// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
Expand Down Expand Up @@ -671,7 +671,7 @@ public function testRestrictContentByProductHidesContentWithCTA($I, $options = f
public function testRestrictContentByTagHidesContentWithCTA($I, $options = false, $testRecaptcha = false)
{
// Merge options with defaults.
$options = $this->_getRestrictedContentOptionsWithDefaultsMerged($options);
$options = $this->getRestrictedContentOptionsWithDefaultsMerged($options);

// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
Expand Down Expand Up @@ -710,7 +710,7 @@ public function testRestrictContentByTagHidesContentWithCTA($I, $options = false
public function testRestrictContentByFormHidesContentWithCTA($I, $formID, $options = false)
{
// Merge options with defaults.
$options = $this->_getRestrictedContentOptionsWithDefaultsMerged($options);
$options = $this->getRestrictedContentOptionsWithDefaultsMerged($options);

// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
Expand Down Expand Up @@ -754,7 +754,7 @@ public function testRestrictContentByFormHidesContentWithCTA($I, $formID, $optio
public function testRestrictContentDisplaysContent($I, $options = false)
{
// Merge options with defaults.
$options = $this->_getRestrictedContentOptionsWithDefaultsMerged($options);
$options = $this->getRestrictedContentOptionsWithDefaultsMerged($options);

// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
Expand Down Expand Up @@ -789,7 +789,7 @@ public function testRestrictContentDisplaysContent($I, $options = false)
public function setupRestrictContentTest($I, $options, $urlOrPageID)
{
// Merge options with defaults.
$options = $this->_getRestrictedContentOptionsWithDefaultsMerged($options);
$options = $this->getRestrictedContentOptionsWithDefaultsMerged($options);

// Clear any existing cookie from a previous test and reload.
$I->clearRestrictContentCookie($I);
Expand Down Expand Up @@ -952,7 +952,7 @@ public function clearRestrictContentCookie($I)
* @type array $settings Restrict content settings. If not defined, uses expected defaults.
* }
*/
private function _getRestrictedContentOptionsWithDefaultsMerged($options = false)
public function getRestrictedContentOptionsWithDefaultsMerged($options = false)
{
// Define default options for Restrict Content tests.
$defaults = [
Expand Down
3 changes: 3 additions & 0 deletions views/frontend/restrict-content/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@

// Output a login link or form, if require login enabled.
require 'login.php';

// Output notices.
require 'notices.php';
?>
</div>