Skip to content

Commit

Permalink
Revert "Block Bindings: Refactor e2e tests (WordPress#65526)"
Browse files Browse the repository at this point in the history
This reverts commit b341373.
  • Loading branch information
huubl authored Oct 2, 2024
1 parent 6a8eece commit 1542693
Show file tree
Hide file tree
Showing 12 changed files with 2,472 additions and 1,979 deletions.
133 changes: 21 additions & 112 deletions packages/e2e-tests/plugins/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,158 +8,67 @@
*/

/**
* Code necessary for testing block bindings:
* - Enqueues a custom script to register sources in the client.
* - Registers sources in the server.
* - Registers a custom post type and custom fields.
*/
* Register custom fields and custom block bindings sources.
*/
function gutenberg_test_block_bindings_registration() {
// Define fields list.
$upload_dir = wp_upload_dir();
$testing_url = $upload_dir['url'] . '/1024x768_e2e_test_image_size.jpeg';
$fields_list = array(
'text_field' => array(
'label' => 'Text Field Label',
'value' => 'Text Field Value',
),
'url_field' => array(
'label' => 'URL Field Label',
'value' => $testing_url,
),
'empty_field' => array(
'label' => 'Empty Field Label',
'value' => '',
),
);

// Enqueue a custom script for the plugin.
wp_enqueue_script(
'gutenberg-test-block-bindings',
plugins_url( 'block-bindings/index.js', __FILE__ ),
array(
'wp-blocks',
'wp-private-apis',
),
filemtime( plugin_dir_path( __FILE__ ) . 'block-bindings/index.js' ),
true
);

// Pass data to the script.
wp_localize_script(
'gutenberg-test-block-bindings',
'testingBindings',
array(
'fieldsList' => $fields_list,
)
);

// Register custom block bindings sources.
register_block_bindings_source(
'testing/complete-source',
array(
'label' => 'Complete Source',
'get_value_callback' => function ( $source_args ) use ( $fields_list ) {
if ( ! isset( $source_args['key'] ) || ! isset( $fields_list[ $source_args['key'] ] ) ) {
return null;
}
return $fields_list[ $source_args['key'] ]['value']; },
)
);
register_block_bindings_source(
'testing/server-only-source',
'core/server-source',
array(
'label' => 'Server Source',
'get_value_callback' => function () {},
)
);

// Register "movie" custom post type.
register_post_type(
'movie',
array(
'label' => 'Movie',
'public' => true,
'supports' => array( 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes', 'thumbnail', 'custom-fields', 'post-formats' ),
'has_archive' => true,
'show_in_rest' => true,
)
);

// Register global custom fields.
// Register custom fields.
register_meta(
'post',
'text_custom_field',
array(
'default' => 'Value of the text custom field',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'single' => true,
'default' => 'Value of the text custom field',
)
);
register_meta(
'post',
'url_custom_field',
array(
'default' => '#url-custom-field',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
)
);
// Register CPT custom fields.
register_meta(
'post',
'movie_field',
array(
'label' => 'Movie field label',
'default' => 'Movie field default value',
'object_subtype' => 'movie',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
)
);
register_meta(
'post',
'field_with_only_label',
array(
'label' => 'Field with only label',
'object_subtype' => 'movie',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'single' => true,
'default' => '#url-custom-field',
)
);
register_meta(
'post',
'field_without_label_or_default',
'empty_field',
array(
'object_subtype' => 'movie',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'show_in_rest' => true,
'type' => 'string',
'single' => true,
'default' => '',
)
);
register_meta(
'post',
'_protected_field',
array(
'default' => 'Protected field value',
'object_subtype' => 'movie',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'type' => 'string',
'show_in_rest' => true,
'single' => true,
'default' => 'protected field value',
)
);
register_meta(
'post',
'show_in_rest_false_field',
array(
'default' => 'show_in_rest false field value',
'object_subtype' => 'movie',
'show_in_rest' => false,
'single' => true,
'type' => 'string',
'show_in_rest' => false,
'type' => 'string',
'single' => true,
'default' => 'show_in_rest false field value',
)
);
}
Expand Down
55 changes: 0 additions & 55 deletions packages/e2e-tests/plugins/block-bindings/index.js

This file was deleted.

Loading

0 comments on commit 1542693

Please sign in to comment.