Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jun 6, 2024
1 parent 7220c11 commit 041b751
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/phpunit/data/blocks/notice/variations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return array(
array(
'name' => 'warning',
'title' => 'warning',
'description' => 'Shows warning.',
'keywords' => array( 'warning' )
)
);
33 changes: 33 additions & 0 deletions tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,39 @@ public function data_register_block_registers_with_args_override_returns_false_w
);
}

/**
* Tests registering a block with variations from a PHP file.
*
* @ticket 61280
*
* @covers ::register_block_type_from_metadata
*/
public function test_register_block_type_from_metadata_with_variations_php_file() {
$result = register_block_type_from_metadata(
DIR_TESTDATA . '/blocks/notice',
array(
'api_version' => 2,
'name' => 'tests/notice-with-variations-php',
'title' => 'Notice with variations from a PHP file',
'variations' => 'variations.php'

Check failure on line 974 in tests/phpunit/tests/blocks/register.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

There should be a comma after the last array item in a multi-line array.
)
);

$this->assertInstanceOf( 'WP_Block_Type', $result, 'The block was not registered' );
$this->assertSame( 2, $result->api_version, 'The API version is incorrect' );
$this->assertSame( 'tests/notice-with-variations-php', $result->name, 'The block name is incorrect' );
$this->assertSame( 'Notice with variations from a PHP file', $result->title, 'The block title is incorrect' );
$this->assertSame( 'variations.php', $result->variations, 'The block variations are incorrect' );
$this->assertIsCallable( $result->variation_callback, 'The variation callback hasn\'t been set' );

$expected_variations = require DIR_TESTDATA . '/blocks/notice/variations.php';
$this->assertSame(
$expected_variations,
call_user_func( $result->variation_callback ),
'The variation callback hasn\'t been set correctly'
);
}

/**
* Tests that the function returns the registered block when the `block.json`
* is found in the fixtures directory.
Expand Down

0 comments on commit 041b751

Please sign in to comment.