Skip to content

Commit

Permalink
Fix append tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Camwyn committed Jan 15, 2024
1 parent 57048fa commit 5bc79a2
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tests/acceptance/LocalizeJSCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function it_should_localize( AcceptanceTester $I ) {
Assert::assertContains( 'var color', $contents );
}

public function immediate_localize_should_overwrite( AcceptanceTester $I ) {
public function immediate_localize_should_append( AcceptanceTester $I ) {
$code = file_get_contents( codecept_data_dir( 'enqueue-template.php' ) );
$code .= <<<PHP
add_action( 'wp_enqueue_scripts', function() {
Expand Down Expand Up @@ -71,7 +71,46 @@ public function immediate_localize_should_overwrite( AcceptanceTester $I ) {
Assert::assertContains( 'var animal', $contents );
Assert::assertContains( 'var color', $contents );
Assert::assertContains( 'brown', $contents );
Assert::assertNotContains( 'black', $contents );
Assert::assertContains( 'black', $contents );
}

public function immediate_localize_should_overwrite_with_force( AcceptanceTester $I ) {
$code = file_get_contents( codecept_data_dir( 'enqueue-template.php' ) );
$code .= <<<PHP
add_action( 'wp_enqueue_scripts', function() {
Asset::add( 'fake-js', 'fake.js' )
->enqueue_on( 'wp_enqueue_scripts' )
->add_localize_script(
'animal',
[
'cow' => 'black',
]
)
->add_localize_script(
'color',
[ 'blue' ]
)
->add_localize_script(
'animal',
[
'cow' => 'brown',
],
true
)
->register();
}, 100 );
PHP;

$I->haveMuPlugin( 'enqueue.php', $code );


$I->amOnPage( '/' );
$I->seeElement( '#fake-js-js-extra' );
$contents = $I->grabTextFrom( '#fake-js-js-extra' );
Assert::assertContains( 'var animal', $contents );
Assert::assertContains( 'var color', $contents );
Assert::assertContains( 'brown', $contents );
Assert::assertContains( 'black', $contents );
}

public function it_should_append_to_localize_with_same_handle() {
Expand Down Expand Up @@ -107,6 +146,8 @@ public function it_should_append_to_localize_with_same_handle() {
PHP;

$I->haveMuPlugin( 'enqueue_2.php', $code_2 );

$I->amOnPage( '/' );
$I->seeElement( '#fake-js-js-extra' );
$contents = $I->grabTextFrom( '#fake-js-js-extra' );
Expand Down

0 comments on commit 5bc79a2

Please sign in to comment.