Skip to content

Commit 5b592e7

Browse files
committed
Script Modules: Add failure messages to multi-assertion translation tests.
1 parent 0cd71d3 commit 5b592e7

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

tests/phpunit/tests/script-modules/wpScriptModules.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,12 +2641,12 @@ public function test_get_registered_returns_null_for_unregistered_module() {
26412641
public function test_get_registered_returns_array_for_registered_module() {
26422642
$this->script_modules->register( 'test-module', '/test-module.js' );
26432643
$result = $this->script_modules->get_registered( 'test-module' );
2644-
$this->assertIsArray( $result );
2645-
$this->assertSame( '/test-module.js', $result['src'] );
2646-
$this->assertFalse( $result['version'] );
2647-
$this->assertSame( array(), $result['dependencies'] );
2648-
$this->assertFalse( $result['in_footer'] );
2649-
$this->assertSame( 'auto', $result['fetchpriority'] );
2644+
$this->assertIsArray( $result, 'get_registered() should return an array for a registered module.' );
2645+
$this->assertSame( '/test-module.js', $result['src'], 'src should match the value passed to register().' );
2646+
$this->assertFalse( $result['version'], 'version should default to false.' );
2647+
$this->assertSame( array(), $result['dependencies'], 'dependencies should default to an empty array.' );
2648+
$this->assertFalse( $result['in_footer'], 'in_footer should default to false.' );
2649+
$this->assertSame( 'auto', $result['fetchpriority'], 'fetchpriority should default to auto.' );
26502650
}
26512651

26522652
/**
@@ -2734,15 +2734,15 @@ static function ( $relative, $src, $is_module ) use ( &$filtered ) {
27342734

27352735
$output = get_echo( array( $this->script_modules, 'print_script_module_translations' ) );
27362736

2737-
$this->assertCount( 1, $filtered );
2737+
$this->assertCount( 1, $filtered, 'load_script_textdomain_relative_path filter should fire once for the enqueued module.' );
27382738
foreach ( $filtered as $filter_args ) {
2739-
$this->assertIsString( $filter_args['relative'] );
2740-
$this->assertIsString( $filter_args['src'] );
2741-
$this->assertTrue( $filter_args['is_module'] );
2739+
$this->assertIsString( $filter_args['relative'], 'Filter should receive a string $relative argument.' );
2740+
$this->assertIsString( $filter_args['src'], 'Filter should receive a string $src argument.' );
2741+
$this->assertTrue( $filter_args['is_module'], 'Filter should receive $is_module=true for script modules.' );
27422742
}
27432743

27442744
$processor = new WP_HTML_Tag_Processor( $output );
2745-
$this->assertTrue( $processor->next_tag( 'SCRIPT' ) );
2745+
$this->assertTrue( $processor->next_tag( 'SCRIPT' ), 'Output should contain a SCRIPT tag.' );
27462746
$script_text = $processor->get_modifiable_text();
27472747
$this->assertStringContainsString( 'wp-script-module-translation-data-test-module', $script_text, 'Translation inline script should be printed with the expected ID.' );
27482748
$this->assertStringContainsString( 'wp.i18n.setLocaleData', $script_text, 'Output should call wp.i18n.setLocaleData().' );
@@ -2801,15 +2801,15 @@ static function ( $relative, $src, $is_module ) use ( &$filtered ) {
28012801
$output = get_echo( array( $this->script_modules, 'print_script_module_translations' ) );
28022802

28032803
// With auto-detection, the filter fires for every enqueued module and its dependencies.
2804-
$this->assertCount( 2, $filtered );
2804+
$this->assertCount( 2, $filtered, 'load_script_textdomain_relative_path filter should fire for the enqueued module and its dependency.' );
28052805
foreach ( $filtered as $filter_args ) {
2806-
$this->assertIsString( $filter_args['relative'] );
2807-
$this->assertIsString( $filter_args['src'] );
2808-
$this->assertTrue( $filter_args['is_module'] );
2806+
$this->assertIsString( $filter_args['relative'], 'Filter should receive a string $relative argument.' );
2807+
$this->assertIsString( $filter_args['src'], 'Filter should receive a string $src argument.' );
2808+
$this->assertTrue( $filter_args['is_module'], 'Filter should receive $is_module=true for script modules.' );
28092809
}
28102810

28112811
$processor = new WP_HTML_Tag_Processor( $output );
2812-
$this->assertTrue( $processor->next_tag( 'SCRIPT' ) );
2812+
$this->assertTrue( $processor->next_tag( 'SCRIPT' ), 'Output should contain a SCRIPT tag.' );
28132813
$script_text = $processor->get_modifiable_text();
28142814
$this->assertStringContainsString( 'wp-script-module-translation-data-dep-module', $script_text, 'Dependency module translations should be printed.' );
28152815
$this->assertStringContainsString( 'Mundo', $script_text, 'Output should contain the dependency translation.' );
@@ -2857,6 +2857,6 @@ static function ( $translations, $file, $handle, $domain ) use ( &$seen_domain )
28572857
$output = get_echo( array( $this->script_modules, 'print_script_module_translations' ) );
28582858

28592859
$this->assertSame( 'my-plugin', $seen_domain, 'load_script_module_textdomain() should be called with the overridden domain.' );
2860-
$this->assertStringContainsString( 'Hola', $output );
2860+
$this->assertStringContainsString( 'Hola', $output, 'Output should contain the translated string loaded under the overridden domain.' );
28612861
}
28622862
}

0 commit comments

Comments
 (0)