Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
Add a test for block_lab_add_field()
Browse files Browse the repository at this point in the history
This is similar to block_lab_add_block(),
and uses Mockery.
  • Loading branch information
kienstra committed Oct 19, 2019
1 parent 074f61d commit 2cfd4ad
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/php/unit/test-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,45 @@ public function test_block_lab_add_block() {
$loader->expects()->add_block( $expected_config );
block_lab_add_block( $block_name, $block_config );
}

/**
* Test block_lab_add_field.
*
* @covers ::block_lab_add_field()
*/
public function test_block_lab_add_field() {
// Test calling this without the optional third argument.
$block_name = 'baz-block';
$field_name = 'another-field';
$expected_default_config = [
'control' => 'text',
'label' => 'Another Field',
'name' => $field_name,
'order' => 0,
'settings' => [],
];

$loader = Mockery::mock( Blocks\Loader::class );
block_lab()->loader = $loader;
$loader->expects()->add_field( $block_name, $expected_default_config )->once();
block_lab_add_field( $block_name, $field_name );

// Test passing a full $field_config.
$block_name = 'example-block-name-here';
$field_name = 'here_is_a_long_field_name';
$field_config = [
'control' => 'rich_text',
'label' => 'Here Is Another Field',
'order' => 3,
'settings' => [ 'foo' => 'baz' ],
];

$expected_field_config = array_merge(
$field_config,
[ 'name' => 'here-is-a-long-field-name' ]
);

$loader->expects()->add_field( $block_name, $expected_field_config )->once();
block_lab_add_field( $block_name, $field_name, $field_config );
}
}

0 comments on commit 2cfd4ad

Please sign in to comment.