Skip to content

Commit

Permalink
fixup! fixup! fixup! Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Jan 24, 2024
1 parent a47d17a commit 4a8a7f3
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function test_missing_asset_file_register_block_script_handle() {
}

/**
* @expectedIncorrectUsage register_block_script_handle
* @expectedIncorrectUsage register_block_script_module_id
* @ticket 60233
*/
public function test_missing_asset_file_register_block_script_module_id() {
Expand Down Expand Up @@ -302,6 +302,35 @@ public function test_handles_passed_register_block_script_module_ids() {
$this->assertSame( 'test-id-2', $result, 1 );
}

/**
* @ticket 60233
*/
public function test_success_register_block_script_module_id() {
$metadata = array(
'file' => DIR_TESTDATA . '/blocks/notice/block.json',

Check warning on line 310 in tests/phpunit/tests/blocks/register.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 13 space(s) between "'file'" and double arrow, but found 3.
'name' => 'unit-tests/test-block',

Check warning on line 311 in tests/phpunit/tests/blocks/register.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 13 space(s) between "'name'" and double arrow, but found 3.
'viewScriptModule' => 'file:./block.js',
);
$result = register_block_script_module_id( $metadata, 'viewScriptModule' );

$this->assertSame( 'tests-notice-view-script-module', $result );

// Test the behavior directly within the unit test
$this->assertFalse(
strpos(
wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $metadata['viewScriptModule'] ) ),
trailingslashit( wp_normalize_path( get_template_directory() ) )
) === 0
);

$this->assertFalse(
strpos(
wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $metadata['viewScriptModule'] ) ),
trailingslashit( wp_normalize_path( get_stylesheet_directory() ) )
) === 0
);
}

/**
* @ticket 50263
*/
Expand Down

0 comments on commit 4a8a7f3

Please sign in to comment.