seeInSource('
seeInSource('
setupKitPlugin($I);
$I->setupKitPluginResources($I);
- // Define a 'bad' block. This is difficult to do in Gutenberg, but let's assume it's possible.
+ // It's tricky to interact with Gutenberg's margin and padding pickers, so we programmatically create the Page
+ // instead to then confirm the settings apply on the output.
+ // We don't need to test the margin and padding pickers themselves, as they are Gutenberg supplied components, and our
+ // other End To End tests confirm that the block can be added in Gutenberg etc.
$I->havePageInDatabase(
[
- 'post_name' => 'kit-page-broadcasts-block-parameter-escaping',
- 'post_content' => '',
+ 'post_name' => 'kit-page-broadcasts-block-margin-padding-params',
+ 'post_content' => '',
]
);
// Load the Page on the frontend site.
- $I->amOnPage('/kit-page-broadcasts-block-parameter-escaping');
+ $I->amOnPage('/kit-page-broadcasts-block-margin-padding-params');
// Wait for frontend web site to load.
$I->waitForElementVisible('body.page-template-default');
@@ -771,16 +773,67 @@ public function testBroadcastsBlockParameterEscaping(EndToEndTester $I)
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
- // Confirm that the output is escaped.
- $I->seeInSource('style="color:red" onmouseover="alert(1)""');
- $I->dontSeeInSource('style="color:red" onmouseover="alert(1)""');
+ // Confirm that the block displays correctly with the expected number of Broadcasts.
+ $I->seeBroadcastsOutput(
+ $I,
+ [
+ 'number_posts' => $_ENV['CONVERTKIT_API_BROADCAST_COUNT'],
+ ]
+ );
- // Test pagination.
- $I->testBroadcastsPagination($I, 'Previous', 'Next');
+ // Confirm that our stylesheet loaded.
+ $I->seeInSource('
setupKitPlugin($I);
+ $I->setupKitPluginResources($I);
+
+ // It's tricky to interact with Gutenberg's typography pickers, so we programmatically create the Page
+ // instead to then confirm the settings apply on the output.
+ // We don't need to test the typography picker itself, as it's a Gutenberg supplied component, and our
+ // other End To End tests confirm that the block can be added in Gutenberg etc.
+ $I->havePageInDatabase(
+ [
+ 'post_name' => 'kit-page-broadcasts-block-typography-params',
+ 'post_content' => '',
+ ]
+ );
+
+ // Load the Page on the frontend site.
+ $I->amOnPage('/kit-page-broadcasts-block-typography-params');
+
+ // Wait for frontend web site to load.
+ $I->waitForElementVisible('body.page-template-default');
+
+ // Check that no PHP warnings or notices were output.
+ $I->checkNoWarningsAndNoticesOnScreen($I);
+
+ // Confirm that the block displays correctly with the expected number of Broadcasts.
+ $I->seeBroadcastsOutput(
+ $I,
+ [
+ 'number_posts' => $_ENV['CONVERTKIT_API_BROADCAST_COUNT'],
+ ]
+ );
+
+ // Confirm that our stylesheet loaded.
+ $I->seeInSource('
dontSeeInSource('style="color:red" onmouseover="alert(1)""');
+ // Confirm that the chosen typography settings are applied as CSS styles.
+ $I->seeInSource('
seeInSource('
seeInSource('
seeInSource('
seeFormTriggerOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_URL']);
// Confirm that the chosen colors are applied as CSS styles.
- $I->seeInSource('class="wp-block-button__link convertkit-formtrigger has-text-color has-' . $textColor . '-color has-background has-' . $backgroundColor . '-background-color');
+ $I->seeInSource('class="convertkit-formtrigger wp-block-button__link wp-element-button wp-block-convertkit-formtrigger has-text-color has-' . $textColor . '-color has-background has-' . $backgroundColor . '-background-color');
}
/**
@@ -327,34 +327,46 @@ public function testFormTriggerBlockWithHexColorParameters(EndToEndTester $I)
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
+ // Confirm that the chosen colors are applied as CSS styles.
+ $I->seeInSource('class="convertkit-formtrigger wp-block-button__link wp-element-button wp-block-convertkit-formtrigger has-text-color has-background"');
+
// Confirm that the block displays.
- $I->seeFormTriggerOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_URL'], 'Subscribe', $textColor, $backgroundColor);
+ $I->seeFormTriggerOutput(
+ $I,
+ formURL: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_URL'],
+ text: 'Subscribe',
+ textColor: $textColor,
+ backgroundColor: $backgroundColor,
+ isBlock: true
+ );
}
/**
- * Test the Form Trigger block's parameters are correctly escaped on output,
- * to prevent XSS.
+ * Test the Form Trigger block's margin and padding parameters works.
*
- * @since 2.0.5
+ * @since 2.8.4
*
* @param EndToEndTester $I Tester.
*/
- public function testFormTriggerBlockParameterEscaping(EndToEndTester $I)
+ public function testFormTriggerBlockWithMarginAndPaddingParameters(EndToEndTester $I)
{
- // Setup Kit Plugin with no default form specified.
- $I->setupKitPluginNoDefaultForms($I);
+ // Setup Plugin and enable debug log.
+ $I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
- // Define a 'bad' block. This is difficult to do in Gutenberg, but let's assume it's possible.
+ // It's tricky to interact with Gutenberg's margin and padding pickers, so we programmatically create the Page
+ // instead to then confirm the settings apply on the output.
+ // We don't need to test the margin and padding pickers themselves, as they are Gutenberg supplied components, and our
+ // other End To End tests confirm that the block can be added in Gutenberg etc.
$I->havePageInDatabase(
[
- 'post_name' => 'kit-page-form-trigger-block-parameter-escaping',
- 'post_content' => '',
+ 'post_name' => 'kit-page-form-trigger-block-margin-padding-params',
+ 'post_content' => '',
]
);
// Load the Page on the frontend site.
- $I->amOnPage('/kit-page-form-trigger-block-parameter-escaping');
+ $I->amOnPage('/kit-page-form-trigger-block-margin-padding-params');
// Wait for frontend web site to load.
$I->waitForElementVisible('body.page-template-default');
@@ -362,12 +374,58 @@ public function testFormTriggerBlockParameterEscaping(EndToEndTester $I)
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
- // Confirm that the output is escaped.
- $I->seeInSource('style="color:red" onmouseover="alert(1)""');
- $I->dontSeeInSource('style="color:red" onmouseover="alert(1)""');
+ // Confirm that the block displays and has the inline styles applied.
+ $I->seeFormTriggerOutput(
+ $I,
+ formURL: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_URL'],
+ text: 'Subscribe',
+ styles: 'padding-top:var(--wp--preset--spacing--30);margin-top:var(--wp--preset--spacing--30)',
+ isBlock: true
+ );
+ }
- // Confirm that the Kit Form Trigger is displayed.
- $I->seeFormTriggerOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_URL'], 'Subscribe');
+ /**
+ * Test the Form Trigger block's typography parameters works.
+ *
+ * @since 2.8.4
+ *
+ * @param EndToEndTester $I Tester.
+ */
+ public function testFormTriggerBlockWithTypographyParameters(EndToEndTester $I)
+ {
+ // Setup Plugin and enable debug log.
+ $I->setupKitPlugin($I);
+ $I->setupKitPluginResources($I);
+
+ // It's tricky to interact with Gutenberg's typography pickers, so we programmatically create the Page
+ // instead to then confirm the settings apply on the output.
+ // We don't need to test the typography picker itself, as it's a Gutenberg supplied component, and our
+ // other End To End tests confirm that the block can be added in Gutenberg etc.
+ $I->havePageInDatabase(
+ [
+ 'post_name' => 'kit-page-form-trigger-block-typography-params',
+ 'post_content' => '',
+ ]
+ );
+
+ // Load the Page on the frontend site.
+ $I->amOnPage('/kit-page-form-trigger-block-typography-params');
+
+ // Wait for frontend web site to load.
+ $I->waitForElementVisible('body.page-template-default');
+
+ // Check that no PHP warnings or notices were output.
+ $I->checkNoWarningsAndNoticesOnScreen($I);
+
+ // Confirm that the block displays and has the inline styles applied.
+ $I->seeFormTriggerOutput(
+ $I,
+ formURL: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_URL'],
+ text: 'Subscribe',
+ cssClasses: 'has-large-font-size',
+ styles: 'line-height:2',
+ isBlock: true
+ );
}
/**
diff --git a/tests/EndToEnd/integrations/other/ElementorBroadcastsCest.php b/tests/EndToEnd/integrations/other/ElementorBroadcastsCest.php
index 38b0363c1..b36771d5a 100644
--- a/tests/EndToEnd/integrations/other/ElementorBroadcastsCest.php
+++ b/tests/EndToEnd/integrations/other/ElementorBroadcastsCest.php
@@ -284,7 +284,7 @@ public function testBroadcastsWidgetWithHexColorParameters(EndToEndTester $I)
$I->seeInSource(' seeInSource('seeInSource('
seeInSource('class="wp-block-button__link convertkit-product has-text-color has-' . $textColor . '-color has-background has-' . $backgroundColor . '-background-color');
+ $I->seeInSource('class="convertkit-product wp-block-button__link wp-element-button wp-block-convertkit-product has-text-color has-' . $textColor . '-color has-background has-' . $backgroundColor . '-background-color');
}
/**
@@ -516,7 +516,95 @@ public function testProductBlockWithHexColorParameters(EndToEndTester $I)
productURL: $_ENV['CONVERTKIT_API_PRODUCT_URL'],
text: 'Buy my product',
textColor: $textColor,
- backgroundColor: $backgroundColor
+ backgroundColor: $backgroundColor,
+ isBlock: true
+ );
+ }
+
+ /**
+ * Test the Form Trigger block's margin and padding parameters works.
+ *
+ * @since 2.8.4
+ *
+ * @param EndToEndTester $I Tester.
+ */
+ public function testProductBlockWithMarginAndPaddingParameters(EndToEndTester $I)
+ {
+ // Setup Plugin and enable debug log.
+ $I->setupKitPlugin($I);
+ $I->setupKitPluginResources($I);
+
+ // It's tricky to interact with Gutenberg's margin and padding pickers, so we programmatically create the Page
+ // instead to then confirm the settings apply on the output.
+ // We don't need to test the margin and padding pickers themselves, as they are Gutenberg supplied components, and our
+ // other End To End tests confirm that the block can be added in Gutenberg etc.
+ $I->havePageInDatabase(
+ [
+ 'post_name' => 'kit-page-product-block-margin-padding-params',
+ 'post_content' => '',
+ ]
+ );
+
+ // Load the Page on the frontend site.
+ $I->amOnPage('/kit-page-product-block-margin-padding-params');
+
+ // Wait for frontend web site to load.
+ $I->waitForElementVisible('body.page-template-default');
+
+ // Check that no PHP warnings or notices were output.
+ $I->checkNoWarningsAndNoticesOnScreen($I);
+
+ // Confirm that the block displays and has the inline styles applied.
+ $I->seeProductOutput(
+ $I,
+ productURL: $_ENV['CONVERTKIT_API_PRODUCT_URL'],
+ text: 'Buy my product',
+ styles: 'padding-top:var(--wp--preset--spacing--30);margin-top:var(--wp--preset--spacing--30)',
+ isBlock: true
+ );
+ }
+
+ /**
+ * Test the Product block's typography parameters works.
+ *
+ * @since 2.8.4
+ *
+ * @param EndToEndTester $I Tester.
+ */
+ public function testProductBlockWithTypographyParameters(EndToEndTester $I)
+ {
+ // Setup Plugin and enable debug log.
+ $I->setupKitPlugin($I);
+ $I->setupKitPluginResources($I);
+
+ // It's tricky to interact with Gutenberg's typography pickers, so we programmatically create the Page
+ // instead to then confirm the settings apply on the output.
+ // We don't need to test the typography picker itself, as it's a Gutenberg supplied component, and our
+ // other End To End tests confirm that the block can be added in Gutenberg etc.
+ $I->havePageInDatabase(
+ [
+ 'post_name' => 'kit-page-product-block-typography-params',
+ 'post_content' => '',
+ ]
+ );
+
+ // Load the Page on the frontend site.
+ $I->amOnPage('/kit-page-product-block-typography-params');
+
+ // Wait for frontend web site to load.
+ $I->waitForElementVisible('body.page-template-default');
+
+ // Check that no PHP warnings or notices were output.
+ $I->checkNoWarningsAndNoticesOnScreen($I);
+
+ // Confirm that the block displays and has the inline styles applied.
+ $I->seeProductOutput(
+ $I,
+ productURL: $_ENV['CONVERTKIT_API_PRODUCT_URL'],
+ text: 'Buy my product',
+ cssClasses: 'has-large-font-size',
+ styles: 'line-height:2',
+ isBlock: true
);
}
@@ -632,49 +720,6 @@ public function testProductBlockRefreshButton(EndToEndTester $I)
$I->publishAndViewGutenbergPage($I);
}
- /**
- * Test the Product block's parameters are correctly escaped on output,
- * to prevent XSS.
- *
- * @since 2.0.5
- *
- * @param EndToEndTester $I Tester.
- */
- public function testProductBlockParameterEscaping(EndToEndTester $I)
- {
- // Setup Kit Plugin with no default form specified.
- $I->setupKitPluginNoDefaultForms($I);
- $I->setupKitPluginResources($I);
-
- // Define a 'bad' block. This is difficult to do in Gutenberg, but let's assume it's possible.
- $I->havePageInDatabase(
- [
- 'post_name' => 'kit-page-product-block-parameter-escaping',
- 'post_content' => '',
- ]
- );
-
- // Load the Page on the frontend site.
- $I->amOnPage('/kit-page-product-block-parameter-escaping');
-
- // Wait for frontend web site to load.
- $I->waitForElementVisible('body.page-template-default');
-
- // Check that no PHP warnings or notices were output.
- $I->checkNoWarningsAndNoticesOnScreen($I);
-
- // Confirm that the output is escaped.
- $I->seeInSource('style="color:red" onmouseover="alert(1)""');
- $I->dontSeeInSource('style="color:red" onmouseover="alert(1)""');
-
- // Confirm that the Kit Product is displayed.
- $I->seeProductOutput(
- $I,
- productURL: $_ENV['CONVERTKIT_API_PRODUCT_URL'],
- text: 'Buy my product'
- );
- }
-
/**
* 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
diff --git a/tests/Integration/ResourceProductsTest.php b/tests/Integration/ResourceProductsTest.php
index 7037f9b18..84bf2fb33 100644
--- a/tests/Integration/ResourceProductsTest.php
+++ b/tests/Integration/ResourceProductsTest.php
@@ -235,8 +235,28 @@ public function testExist()
*/
public function testGetHTML()
{
- $result = $this->resource->get_html($_ENV['CONVERTKIT_API_PRODUCT_ID'], 'Buy now');
- $this->assertSame($result, '');
+ $result = $this->resource->get_html(
+ id: $_ENV['CONVERTKIT_API_PRODUCT_ID'],
+ button_text: 'Buy now',
+ );
+ $this->assertSame($result, '');
+
+ // Test with CSS classes and styles.
+ $result = $this->resource->get_html(
+ id: $_ENV['CONVERTKIT_API_PRODUCT_ID'],
+ button_text: 'Buy now',
+ options: [
+ 'css_classes' => array( 'wp-block-button__link', 'wp-element-button' ),
+ 'css_styles' => array(
+ 'color' => 'color:#000',
+ 'background' => 'background-color:#fff',
+ ),
+ ]
+ );
+ $this->assertSame(
+ $result,
+ ''
+ );
}
/**
diff --git a/tests/Support/Helper/KitForms.php b/tests/Support/Helper/KitForms.php
index 09619157f..a2f6b05c8 100644
--- a/tests/Support/Helper/KitForms.php
+++ b/tests/Support/Helper/KitForms.php
@@ -76,13 +76,16 @@ public function seeFormOutput($I, $formID, $position = false, $element = false,
*
* @since 2.2.0
*
- * @param EndToEndTester $I Tester.
- * @param string $formURL Form URL.
- * @param bool|string $text Test if the button text matches the given value.
- * @param bool|string $textColor Test if the given text color is applied.
+ * @param EndToEndTester $I Tester.
+ * @param string $formURL Form URL.
+ * @param bool|string $text Test if the button text matches the given value.
+ * @param bool|string $textColor Test if the given text color is applied.
* @param bool|string $backgroundColor Test is the given background color is applied.
+ * @param bool|string $cssClasses Test if the given CSS classes are applied.
+ * @param bool|string $styles Test if the given styles are applied.
+ * @param bool $isBlock Test if this is a form trigger block or shortcode.
*/
- public function seeFormTriggerOutput($I, $formURL, $text = false, $textColor = false, $backgroundColor = false)
+ public function seeFormTriggerOutput($I, $formURL, $text = false, $textColor = false, $backgroundColor = false, $cssClasses = false, $styles = false, $isBlock = false)
{
// Confirm that the button stylesheet loaded.
$I->seeInSource('