woocommerce/plugins/woocommerce-blocks/tests/php/Utils/BlockTemplateUtilsTest.php

74 lines
2.2 KiB
PHP
Raw Normal View History

Add migration strategy and load blockified templates (https://github.com/woocommerce/woocommerce-blocks/pull/6538) * Increase `schema_version` to add the new `wc_blocks_use_blockified_templates` flag If the schema version stored on the db is <= 260 means the plugin is being updated to the new version and we should keep using the old templates, not the blockified ones. * After the theme is switched we check if we need to update the flag to start loading the blockified templates or not. * Get the templates from the blockified folder if the flag is set to true on the db * Add temporary blockified template for testing purposes * Inline variable * Improve comment * Use blockified templates on new installs with block themes only * Don't use blockified templates when switching to a non FSE theme * Fix condition * Add tests for the option value * Move the check to use blockified templates * WIP * WIP * Add migration strategy * Move the blockified templates to the templates folder and filter them depending on the option * Fix tests and start using the Options constants * Fix migration, the `should_use_blockified_product_grid_templates` and tests * Rename tests and move to Utils folder * add Migration class test * try * remove PHP * add composer * Replace the blockified templates with a temporary version * Fix tests * add comment * Add feature gating for experimental builds * Inject the package to the controller * test * Change blocks.ini * debug * Remove debug info * fix test * fix tests * try now * using composer cache * install deps * test * Remove unnecessary extra key * Add cache actions * Undo tests change * Fix readme format Co-authored-by: Luigi <gigitux@gmail.com>
2022-07-06 07:51:39 +00:00
<?php
namespace Automattic\WooCommerce\Blocks\Tests\Utils;
use Automattic\WooCommerce\Blocks\Migration;
use Automattic\WooCommerce\Blocks\Options;
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;
class BlockTemplateUtilsTest extends \WP_UnitTestCase {
public function setUp() {
parent::setUp();
delete_option( Options::WC_BLOCK_USE_BLOCKIFIED_PRODUCT_GRID_BLOCK_AS_TEMPLATE );
delete_option( Options::WC_BLOCK_VERSION );
}
public function test_new_installation_with_a_classic_theme_should_not_use_blockified_templates() {
switch_theme( 'storefront' );
$this->assertFalse( BlockTemplateUtils::should_use_blockified_product_grid_templates() );
}
public function test_new_installation_with_a_block_theme_should_use_blockified_templates() {
switch_theme( 'twentytwentytwo' );
$this->assertTrue( BlockTemplateUtils::should_use_blockified_product_grid_templates() );
}
public function test_new_installation_with_a_classic_theme_switching_to_a_block_should_use_blockified_templates() {
switch_theme( 'storefront' );
switch_theme( 'twentytwentytwo' );
check_theme_switched();
$this->assertTrue( BlockTemplateUtils::should_use_blockified_product_grid_templates() );
}
public function test_plugin_update_with_a_classic_theme_should_not_use_blockified_templates() {
switch_theme( 'storefront' );
$this->update_plugin();
$this->assertFalse( BlockTemplateUtils::should_use_blockified_product_grid_templates() );
}
public function test_plugin_update_with_a_block_theme_should_not_use_blockified_templates() {
switch_theme( 'twentytwentytwo' );
$this->update_plugin();
$this->assertFalse( BlockTemplateUtils::should_use_blockified_product_grid_templates() );
}
public function test_plugin_update_with_a_classic_theme_switching_to_a_block_should_use_blockified_templates() {
switch_theme( 'storefront' );
$this->update_plugin();
switch_theme( 'twentytwentytwo' );
check_theme_switched();
$this->assertTrue( BlockTemplateUtils::should_use_blockified_product_grid_templates() );
}
/**
* Runs the migration that happen after a plugin update
*
* @return void
*/
public function update_plugin(): void {
update_option( Options::WC_BLOCK_VERSION, 1 );
Migration::wc_blocks_update_710_blockified_product_grid_block();
}
}