woocommerce/plugins/woocommerce-blocks/tests/php/Templates/SingleProductTemplateCompat...

407 lines
22 KiB
PHP
Raw Normal View History

<?php
namespace Automattic\WooCommerce\Blocks\Tests\Templates;
use \WP_UnitTestCase;
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplateCompatibility;
/**
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
* Tests the SingleProductTemplateCompatibility class
*
*/
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
class SingleProductTemplateCompatibilityTests extends WP_UnitTestCase {
/**
* Test that the default Single Product Template is not wrapped in a div.
*
*/
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
public function test_no_add_compatibility_layer_with_default_single_product_template() {
$default_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:woocommerce/legacy-template {"template":"single-product"} /-->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}, "__wooCommerceIsFirstBlock":true,"__wooCommerceIsLastBlock":true} -->
<div class="wp-block-group">
<!-- wp:woocommerce/legacy-template {"template":"single-product"} /-->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
$result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template );
$result_without_withespace = preg_replace( '/\s+/', '', $result );
$expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template );
$this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' );
}
/**
* Test that the Single Product Template is wrapped in a div with the correct class if it contains a block related to the Single Product Template.
*/
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
public function test_add_compatibility_layer_if_contains_single_product_blocks() {
$default_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
<!-- wp:group {"className":"woocommerce product", "__wooCommerceIsFirstBlock":true,"__wooCommerceIsLastBlock":true} -->
<div class="wp-block-group woocommerce product">
<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
$result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template );
$result_without_withespace = preg_replace( '/\s+/', '', $result );
$expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template );
$this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' );
}
/**
* Test that the Single Product Template is wrapped in a div with the correct class if it contains a block related to the Single Product Template in a nested structure.
*/
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
public function test_add_compatibility_layer_if_contains_nested_single_product_blocks() {
$default_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:group {"align":"wide","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignwide">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
<!-- wp:query {"queryId":2,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"__woocommerceAttributes":[],"__woocommerceStockStatus":["instock","outofstock","onbackorder"]},"displayLayout":{"type":"flex","columns":3},"namespace":"woocommerce/product-query"} -->
<div class="wp-block-query">
<!-- wp:post-template {"__woocommerceNamespace":"woocommerce/product-query/product-template"} -->
<!-- wp:woocommerce/product-image {"isDescendentOfQueryLoop":true} /-->
<!-- wp:post-title {"textAlign":"center","level":3,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
<!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- wp:woocommerce/product-button {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
<!-- wp:query-no-results -->
<!-- wp:paragraph {"placeholder":"Add text or blocks that will display when a query returns no results."} -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results -->
</div>
<!-- /wp:query -->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
<!-- wp:group {"className":"woocommerce product", "__wooCommerceIsFirstBlock":true,"__wooCommerceIsLastBlock":true} -->
<div class="wp-block-group woocommerce product">
<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:group {"align":"wide","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignwide">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
<!-- wp:query {"queryId":2,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"__woocommerceAttributes":[],"__woocommerceStockStatus":["instock","outofstock","onbackorder"]},"displayLayout":{"type":"flex","columns":3},"namespace":"woocommerce/product-query"} -->
<div class="wp-block-query">
<!-- wp:post-template {"__woocommerceNamespace":"woocommerce/product-query/product-template"} -->
<!-- wp:woocommerce/product-image {"isDescendentOfQueryLoop":true} /-->
<!-- wp:post-title {"textAlign":"center","level":3,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
<!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- wp:woocommerce/product-button {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
<!-- wp:query-no-results -->
<!-- wp:paragraph {"placeholder":"Add text or blocks that will display when a query returns no results."} -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results -->
</div>
<!-- /wp:query -->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
$result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template );
$result_without_withespace = preg_replace( '/\s+/', '', $result );
$expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template );
$this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' );
}
/**
* Test that the Single Product Template is wrapped in a div with the correct class if it contains a block related to the Single Product Template in a nested structure.
*/
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
public function test_add_compatibility_layer_without_a_main_wrapper() {
$default_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:woocommerce/product-image-gallery /-->
<!-- wp:query {"queryId":2,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"__woocommerceAttributes":[],"__woocommerceStockStatus":["instock","outofstock","onbackorder"]},"displayLayout":{"type":"flex","columns":3},"namespace":"woocommerce/product-query"} -->
<div class="wp-block-query">
<!-- wp:post-template {"__woocommerceNamespace":"woocommerce/product-query/product-template"} -->
<!-- wp:woocommerce/product-image {"isDescendentOfQueryLoop":true} /-->
<!-- wp:post-title {"textAlign":"center","level":3,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
<!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- wp:woocommerce/product-button {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
<!-- wp:query-no-results -->
<!-- wp:paragraph {"placeholder":"Add text or blocks that will display when a query returns no results."} -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results -->
</div>
<!-- /wp:query -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
<!-- wp:group {"className":"woocommerce product", "__wooCommerceIsFirstBlock":true,"__wooCommerceIsLastBlock":true} -->
<div class="wp-block-group woocommerce product">
<!-- wp:woocommerce/product-image-gallery /-->
<!-- wp:query {"queryId":2,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"__woocommerceAttributes":[],"__woocommerceStockStatus":["instock","outofstock","onbackorder"]},"displayLayout":{"type":"flex","columns":3},"namespace":"woocommerce/product-query"} -->
<div class="wp-block-query">
<!-- wp:post-template {"__woocommerceNamespace":"woocommerce/product-query/product-template"} -->
<!-- wp:woocommerce/product-image {"isDescendentOfQueryLoop":true} /-->
<!-- wp:post-title {"textAlign":"center","level":3,"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-query/product-title"} /-->
<!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- wp:woocommerce/product-button {"isDescendentOfQueryLoop":true,"textAlign":"center","fontSize":"small","style":{"spacing":{"margin":{"bottom":"1rem"}}}} /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination {"layout":{"type":"flex","justifyContent":"center"}} -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->
<!-- wp:query-no-results -->
<!-- wp:paragraph {"placeholder":"Add text or blocks that will display when a query returns no results."} -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results -->
</div>
<!-- /wp:query -->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
$result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template );
$result_without_withespace = preg_replace( '/\s+/', '', $result );
$expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template );
$this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' );
}
/**
* Test that the Single Product Template is wrapped in a div with the correct class if it contains a block related to the Single Product Template.
*/
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
public function test_add_compatibility_layer_with_multiple_header() {
$default_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:woocommerce/product-image-gallery /-->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
<!-- wp:group {"className":"woocommerce product", "__wooCommerceIsFirstBlock":true,"__wooCommerceIsLastBlock":true} -->
<div class="wp-block-group woocommerce product">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
$result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template );
$result_without_withespace = preg_replace( '/\s+/', '', $result );
$expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template );
$this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' );
}
/**
* Test that the Single Product Template is wrapped in a div with the correct class if it contains a block related to the Single Product Template.
*/
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
public function test_add_compatibility_layer_with_multiple_footer() {
$default_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:woocommerce/product-image-gallery /-->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
<!-- wp:group {"className":"woocommerce product", "__wooCommerceIsFirstBlock":true,"__wooCommerceIsLastBlock":true} -->
<div class="wp-block-group woocommerce product">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
$result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template );
$result_without_withespace = preg_replace( '/\s+/', '', $result );
$expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template );
$this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' );
}
/**
* Test that the Single Product Template is wrapped in a div with the correct class if it contains a block related to the Single Product Template.
*/
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
public function test_add_compatibility_layer_with_multiple_blocks_related_to_the_single_product_template() {
$default_single_product_template = '
<!-- wp:paragraph -->
<p>test</p>
<!-- /wp:paragraph -->
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:woocommerce/product-image-gallery /-->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->
<!-- wp:woocommerce/product-image-gallery /-->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = '
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
<!-- wp:paragraph {"__wooCommerceIsFirstBlock":true} -->
<p>test</p>
<!-- /wp:paragraph -->
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:group {"className":"woocommerce product"} -->
<div class="wp-block-group woocommerce product">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
<!-- wp:group {"className":"woocommerce product", "__wooCommerceIsLastBlock":true} -->
<div class="wp-block-group woocommerce product">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
Single Product Template: Add compatibility layer (https://github.com/woocommerce/woocommerce-blocks/pull/8442) * Add minimum structure for Single Product Details block * Add Product Image Gallery woocommerce/woocommerce-blocks#8233 Add Product Image Gallery * Add tests for Single Product Details block * Add the initial basis for the Add to Cart button * Trigger the single product add to cart action for each product type. * wip: create block structure and add initial styles * Add block details to the SingleProductDetails.php file * Rename the block from add-to-cart-button to add-to-cart-form * Update to use the cart icon. * Implement the skeleton for the editor preview. * Render tabs title with empty content * Use woocommerce_output_product_data_tabs function to retrieve tabs data * Update styles and add Notice for the display in the Editor. * Update CSS. * Add base tests for the new Add to Cart Form component. * Add Product Image Gallery block * remove support global styles * remove support global styles * Update the button CSS. * Remove customizations for the Single Product Details block * Update styles for the cart form. * update td style. * Update divs and CSS. * Use conventional input instead of the experimental InputControl * address CSS feedback * add support for the custom classname * remove save function * Remove unnecessary console.log from the Edit.tsx file * Remove block classname from block wrapper * Remove unnecessary WooCommerce tabs filter from the BlockTemplatesController * Remove attributes property from the block registration * Remove isExperimental flag for the Single Product Details block * Remove get_classes_and_styles_by_attributes method from SingleProductDetails block * Prevent Single Product Details block from apppearing in Pages or Posts * add second parameter to the subscribe function * Implement the new design and copy provided for the editor. * Make the notice compatible with dark themes. * Some additional CSS tweaks * adjust the padding for the input * wrap the Single Product Template in a div with the product class * Fix PHP Coding Standards warnings * improve logic and increase coverage of unit test * improve logic and increase coverage of unit test * fix test * format HTML * fix edge case * update @types/wordpress__data package * update placeholder, icon and description * update tsconfig * update block name * fix SCSS linter error * address feedback * create SingleProductTemplateCompatibility class * Add Hooks compatibility * remove not used file * remove not used files * Add compatibility layer for the Single Product template * fix check * address feedback * remove unused import * double empty line * remove logic in the constructor * remove hook * generate the docs * add missing hooks * fix docs * address feedback * fix linter * fix import * Disable compatibility layer when the WooCommerce Product Grid Block block and WooCommerce Single Product Block are used (https://github.com/woocommerce/woocommerce-blocks/pull/8538) * disable compatibility layer via hook * update docs * generate the docs * fix version * fix import * fix code after merge --------- Co-authored-by: Alexandre Lara <allexandrelara@gmail.com> Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-02-28 15:13:30 +00:00
$result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template );
$result_without_withespace = preg_replace( '/\s+/', '', $result );
$expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template );
$this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' );
}
/**
* Test that the Single Product Template is wrapped in a div with the correct class if it contains a block related to the Single Product Template and custom HTML isn't removed.
*/
public function test_add_compatibility_layer_if_contains_single_product_blocks_and_custom_HTML_not_removed() {
$default_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<span>Custom HTML</span>
<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<span>Custom HTML</span>
<!-- wp:group {"className":"woocommerce product", "__wooCommerceIsFirstBlock":true,"__wooCommerceIsLastBlock":true} -->
<div class="wp-block-group woocommerce product">
<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template );
$result_without_withespace = preg_replace( '/\s+/', '', $result );
$expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template );
$this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' );
}
/**
* @group failing
* Test that the Single Product Template doesn't remove any blocks if those aren't grouped in a a core/group block
*/
public function test_add_compatibility_layer_if_contains_blocks_not_related_to_the_single_product_template_and_not_grouped() {
$default_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:paragraph -->
<p>hello</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>hello1</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>hello2</p>
<!-- /wp:paragraph -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$expected_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<!-- wp:paragraph {"__wooCommerceIsFirstBlock":true} -->
<p>hello</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>hello1</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"__wooCommerceIsLastBlock":true} -->
<p>hello2</p>
<!-- /wp:paragraph -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';
$result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template );
$result_without_withespace = preg_replace( '/\s+/', '', $result );
$expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template );
$this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' );
}
}