Skip to content

Commit

Permalink
Make test more similar to client-side one
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed May 28, 2024
1 parent 9d54dd6 commit edd7784
Showing 1 changed file with 60 additions and 20 deletions.
80 changes: 60 additions & 20 deletions tests/phpunit/tests/blocks/getActiveBlockVariation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ class Tests_Blocks_GetActiveBlockVariation extends WP_UnitTestCase {
*/
public static function wpSetUpBeforeClass() {
self::$block_type = new WP_Block_Type(
'tests/block-type',
'block/name',
array(
'attributes' => array(
'attribute1' => array(
'type' => 'string',
'testAttribute' => array(
'type' => 'number',
),
'attribute2' => array(
'type' => 'string',
'firstTestAttribute' => array(
'type' => 'number',
),
'secondTestAttribute' => array(
'type' => 'number',
),
),
'variations' => self::mock_variation_callback(),
Expand All @@ -44,9 +47,7 @@ public static function wpSetUpBeforeClass() {
*/
public function test_get_active_block_variation_no_match() {
$block_attributes = array(
'attribute1' => 'var1-attr1',
'attribute2' => 'var1-attr2',
'attribute3' => 'mismatch',
'testAttribute' => 5555,
);

$active_variation = get_active_block_variation( self::$block_type, $block_attributes );
Expand All @@ -57,14 +58,32 @@ public function test_get_active_block_variation_no_match() {
* @ticket 61265
*/
public function test_get_active_block_variation_match_with_is_active() {
$block_attributes = array(
'attribute1' => 'var1-attr1',
'attribute2' => 'var1-attr2',
'attribute3' => 'var1-attr3',
$active_variation = get_active_block_variation(
self::$block_type,
array(
'firstTestAttribute' => 1,
'secondTestAttribute' => 10,
),
);
$this->assertSame( 'variation-1', $active_variation['name'] );

$active_variation = get_active_block_variation( self::$block_type, $block_attributes );
$this->assertSame( 'variation_with_is_active', $active_variation['name'] );
$active_variation = get_active_block_variation(
self::$block_type,
array(
'firstTestAttribute' => 2,
'secondTestAttribute' => 20,
),
);
$this->assertSame( 'variation-2', $active_variation['name'] );

$active_variation = get_active_block_variation(
self::$block_type,
array(
'firstTestAttribute' => 1,
'secondTestAttribute' => 20,
),
);
$this->assertSame( 'variation-3', $active_variation['name'] );
}

/**
Expand All @@ -75,15 +94,36 @@ public function test_get_active_block_variation_match_with_is_active() {
public static function mock_variation_callback() {
return array(
array(
'name' => 'variation_with_is_active',
'name' => 'variation-1',
'attributes' => array(
'firstTestAttribute' => 1,
'secondTestAttribute' => 10,
),
'isActive' => array(
'firstTestAttribute',
'secondTestAttribute',
),
),
array(
'name' => 'variation-2',
'attributes' => array(
'firstTestAttribute' => 2,
'secondTestAttribute' => 20,
),
'isActive' => array(
'firstTestAttribute',
'secondTestAttribute',
),
),
array(
'name' => 'variation-3',
'attributes' => array(
'attribute1' => 'var1-attr1',
'attribute2' => 'var1-attr2',
'attribute3' => 'var1-attr3',
'firstTestAttribute' => 1,
'secondTestAttribute' => 20,
),
'isActive' => array(
'attribute1',
'attribute3',
'firstTestAttribute',
'secondTestAttribute',
),
),
);
Expand Down

0 comments on commit edd7784

Please sign in to comment.