'blocks-page', 'title' => 'Checkout', 'content' => '
', ); $page_id = wc_create_page( $page['name'], '', $page['title'], $page['content'] ); $this->assertTrue( WC_Blocks_Utils::has_block_in_page( $page_id, 'woocommerce/checkout' ) ); $this->assertFalse( WC_Blocks_Utils::has_block_in_page( $page_id, 'woocommerce/cart' ) ); } /** * @group block-utils * Test: has_block_in_page. * */ public function test_has_block_in_page_on_page_with_no_blocks() { $page = array( 'name' => 'shortcode-page', 'title' => 'Checkout', 'content' => ' [woocommerce_checkout] ', ); $page_id = wc_create_page( $page['name'], '', $page['title'], $page['content'] ); $this->assertFalse( WC_Blocks_Utils::has_block_in_page( $page_id, 'woocommerce/checkout' ) ); $this->assertFalse( WC_Blocks_Utils::has_block_in_page( $page_id, 'woocommerce/cart' ) ); } /** * @group block-utils * Test: has_block_in_page. * */ public function test_has_block_in_page_on_page_with_multiple_blocks() { $page = array( 'name' => 'shortcode-page', 'title' => 'Checkout', 'content' => '
Shop now

test

', ); $page_id = wc_create_page( $page['name'], '', $page['title'], $page['content'] ); $this->assertTrue( WC_Blocks_Utils::has_block_in_page( $page_id, 'woocommerce/featured-product' ) ); $this->assertTrue( WC_Blocks_Utils::has_block_in_page( $page_id, 'core/heading' ) ); } /** * @group block-utils * Test: get_all_blocks_from_page. * */ public function test_get_all_blocks_from_page() { $page = array( 'name' => 'cart', 'title' => 'Checkout', 'content' => '

test1

test2

', ); wc_create_page( $page['name'], 'woocommerce_cart_page_id', $page['title'], $page['content'] ); $expected = array( 0 => array( 'blockName' => 'core/heading', 'attrs' => array(), 'innerBlocks' => array(), 'innerHTML' => '

test1

', 'innerContent' => array( 0 => '

test1

', ), ), 1 => array( 'blockName' => 'core/heading', 'attrs' => array(), 'innerBlocks' => array(), 'innerHTML' => '

test2

', 'innerContent' => array( 0 => '

test2

', ), ), ); $blocks = WC_Blocks_Utils::get_blocks_from_page( 'core/heading', 'cart' ); $this->assertEquals( $expected, $blocks ); } }