Skip to content

Commit

Permalink
Register sources in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Jul 22, 2024
1 parent ac767be commit 2b2bed5
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions tests/phpunit/tests/blocks/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,27 +725,31 @@ public function data_block_editor_rest_api_preload_adds_missing_leading_slash()
* @ticket 61641
*/
public function test_get_block_editor_settings_block_bindings_sources() {
$block_editor_context = new WP_Block_Editor_Context();
$settings = get_block_editor_settings( array(), $block_editor_context );
$registered_block_bindings_sources = get_all_registered_block_bindings_sources();

foreach ( $registered_block_bindings_sources as $name => $properties ) {
// Check all the registered sources are exposed.
$this->assertArrayHasKey( $name, $settings['blockBindingsSources'] );

// Check only the expected properties are included, and they have the proper value.
$expected_properties = array(
'label' => $properties->label,
);
// Add optional properties if they are defined.
if ( ! empty( $properties->uses_context ) ) {
$expected_properties['usesContext'] = $properties->uses_context;
}

$this->assertSameSets(
$expected_properties,
$settings['blockBindingsSources'][ $name ]
);
}
$block_editor_context = new WP_Block_Editor_Context();
register_block_bindings_source(
'test/source-one',
array(
'label' => 'Source One',
'get_value_callback' => function () {},
'uses_context' => array( 'postId' ),
)
);
register_block_bindings_source(
'test/source-two',
array(
'label' => 'Source Two',
'get_value_callback' => function () {},
)
);
$settings = get_block_editor_settings( array(), $block_editor_context );
$exposed_sources = $settings['blockBindingsSources'];
// It is expected to have 4 sources: the 2 registered sources in the test, and the 2 core sources.
$this->assertCount( 4, $exposed_sources );
$source_one = $exposed_sources['test/source-one'];
$this->assertSame( 'Source One', $source_one['label'] );
$this->assertSameSets( array( 'postId' ), $source_one['usesContext'] );
$source_two = $exposed_sources['test/source-two'];
$this->assertSame( 'Source Two', $source_two['label'] );
$this->assertArrayNotHasKey( 'usesContext', $source_two );
}
}

0 comments on commit 2b2bed5

Please sign in to comment.