Skip to content
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-includes/class-wp-block-bindings-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ public function get_registered( string $source_name ) {
*
* @since 6.5.0
*
* @param string $source_name The name of the source.
* @param string|null $source_name The name of the source.
* @return bool `true` if the block bindings source is registered, `false` otherwise.
*/
public function is_registered( $source_name ) {
return isset( $this->sources[ $source_name ] );
return isset( $source_name, $this->sources[ $source_name ] );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ public function get_all_registered( $outside_init_only = false ) {
*
* @since 5.5.0
*
* @param string $category_name Pattern category name including namespace.
* @param string|null $category_name Pattern category name including namespace.
* @return bool True if the pattern category is registered, false otherwise.
*/
public function is_registered( $category_name ) {
return isset( $this->registered_categories[ $category_name ] );
return isset( $category_name, $this->registered_categories[ $category_name ] );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/class-wp-block-patterns-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ public function get_all_registered( $outside_init_only = false ) {
*
* @since 5.5.0
*
* @param string $pattern_name Block pattern name including namespace.
* @param string|null $pattern_name Block pattern name including namespace.
* @return bool True if the pattern is registered, false otherwise.
*/
public function is_registered( $pattern_name ) {
return isset( $this->registered_patterns[ $pattern_name ] );
return isset( $pattern_name, $this->registered_patterns[ $pattern_name ] );
}

public function __wakeup() {
Expand Down
6 changes: 3 additions & 3 deletions src/wp-includes/class-wp-block-styles-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ public function get_registered_styles_for_block( $block_name ) {
*
* @since 5.3.0
*
* @param string $block_name Block type name including namespace.
* @param string $block_style_name Block style name.
* @param string|null $block_name Block type name including namespace.
* @param string|null $block_style_name Block style name.
* @return bool True if the block style is registered, false otherwise.
*/
public function is_registered( $block_name, $block_style_name ) {
return isset( $this->registered_block_styles[ $block_name ][ $block_style_name ] );
return isset( $block_name, $this->registered_block_styles[ $block_name ][ $block_style_name ] );
Comment thread
mukeshpanchal27 marked this conversation as resolved.
Outdated
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/class-wp-block-templates-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ public function get_by_query( $query = array() ) {
*
* @since 6.7.0
*
* @param string $template_name Template name.
* @param string|null $template_name Template name.
* @return bool True if the template is registered, false otherwise.
*/
public function is_registered( $template_name ) {
return isset( $this->registered_templates[ $template_name ] );
return isset( $template_name, $this->registered_templates[ $template_name ] );
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/phpunit/tests/block-bindings/wpBlockBindingsRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,16 @@ public function test_is_registered_for_known_source() {
$result = $this->registry->is_registered( self::$test_source_name );
$this->assertTrue( $result );
}

/**
* Should return false when checking registration with an empty source name.
*
* @ticket 63957
*
* @covers WP_Block_Bindings_Registry::is_registered
*/
public function test_is_registered_with_empty_source_name() {
$result = $this->registry->is_registered( '' );
$this->assertFalse( $result );
}
Comment thread
mukeshpanchal27 marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Unit tests for WP_Block_Pattern_Categories_Registry::is_registered().
*
* @package WordPress
* @subpackage Blocks
* @since 6.9.0
*
* @group block-patterns
* @covers WP_Block_Pattern_Categories_Registry::is_registered
*/

class Tests_Block_Pattern_WPBlockPatternCategoriesRegistry extends WP_UnitTestCase {

/**
* @ticket 63957
*/
public function test_is_registered_with_empty_param() {
$registry = WP_Block_Pattern_Categories_Registry::get_instance();

// Should return false when called with empty string.
$this->assertFalse( $registry->is_registered( '' ) );

// Should return false when called with null.
$this->assertFalse( $registry->is_registered( null ) );

// Should return false when called with false.
$this->assertFalse( $registry->is_registered( false ) );

// Should return false when called with 0.
$this->assertFalse( $registry->is_registered( 0 ) );
Comment thread
mukeshpanchal27 marked this conversation as resolved.
Outdated
}
}
81 changes: 81 additions & 0 deletions tests/phpunit/tests/block-pattern/wpBlockPatternsRegistry.php
Comment thread
mukeshpanchal27 marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Tests for WP_Block_Patterns_Registry::is_registered().
*
* @package WordPress
* @subpackage Blocks
* @since 6.9.0
*
* @group block-patterns
*
* @covers WP_Block_Patterns_Registry::is_registered
*/
class Tests_Block_Pattern_WPBlockPatternsRegistry extends WP_UnitTestCase {

/**
* Instance of the registry.
*
* @var WP_Block_Patterns_Registry
*/
protected $registry;

public function set_up() {
parent::set_up();
$this->registry = WP_Block_Patterns_Registry::get_instance();
}

public function tear_down() {
$this->registry = null;

parent::tear_down();
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_false_for_unregistered_pattern() {
$this->assertFalse( $this->registry->is_registered( 'my/pattern' ) );
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_true_for_registered_pattern() {
$this->registry->register(
'my/pattern',
array(
'title' => 'My Pattern',
'content' => '<!-- wp:paragraph --><p>Test</p><!-- /wp:paragraph -->',
)
);

$this->assertTrue( $this->registry->is_registered( 'my/pattern' ) );
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_false_after_unregistering_pattern() {
$this->registry->register(
'my/pattern',
array(
'title' => 'My Pattern',
'content' => '<!-- wp:paragraph --><p>Test</p><!-- /wp:paragraph -->',
)
);

$this->registry->unregister( 'my/pattern' );

$this->assertFalse( $this->registry->is_registered( 'my/pattern' ) );
}

/**
* @ticket 63957
*/
public function test_is_registered_with_invalid_pattern_name() {
$this->assertFalse( $this->registry->is_registered( '' ) );
$this->assertFalse( $this->registry->is_registered( null ) );
$this->assertFalse( $this->registry->is_registered( false ) );
$this->assertFalse( $this->registry->is_registered( 0 ) );
Comment thread
mukeshpanchal27 marked this conversation as resolved.
Outdated
}
}
137 changes: 137 additions & 0 deletions tests/phpunit/tests/block-styles/wpBlockStylesRegistry.php
Comment thread
mukeshpanchal27 marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* Unit tests for WP_Block_Styles_Registry::is_registered().
*
* @package WordPress
* @subpackage Blocks
* @since 6.9.0
*
* @group block-styles
*
* @covers WP_Block_Styles_Registry::is_registered
*/

class Tests_Block_Styles_WPBlockStylesRegistryTest extends WP_UnitTestCase {

/**
* WP_Block_Styles_Registry instance.
*
* @var WP_Block_Styles_Registry
*/
protected $registry;

public function setUp(): void {
parent::setUp();
$this->registry = WP_Block_Styles_Registry::get_instance();
}

public function tearDown(): void {
$this->registry = null;
parent::tearDown();
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_false_for_unregistered_style() {
$this->assertFalse(
$this->registry->is_registered( 'core/paragraph', 'fancy-style' ),
'Unregistered style should return false.'
);
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_true_for_registered_style() {
$block_name = 'core/paragraph';
$style_name = 'fancy-style';

$this->registry->register(
$block_name,
array(
'name' => $style_name,
'label' => 'Fancy Style',
)
);

$this->assertTrue(
$this->registry->is_registered( $block_name, $style_name ),
'Registered style should return true.'
);
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_false_for_wrong_block() {
$block_name = 'core/paragraph';
$style_name = 'fancy-style';

$this->registry->register(
$block_name,
array(
'name' => $style_name,
'label' => 'Fancy Style',
)
);

$this->assertFalse(
$this->registry->is_registered( 'core/image', $style_name ),
'Style registered for another block should return false.'
);
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_false_for_wrong_style_name() {
$block_name = 'core/paragraph';
$style_name = 'fancy-style';

$this->registry->register(
$block_name,
array(
'name' => $style_name,
'label' => 'Fancy Style',
)
);

$this->assertFalse(
$this->registry->is_registered( $block_name, 'other-style' ),
'Non-existent style name should return false.'
);
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_false_for_empty_block_name() {
$style_name = 'fancy-style';
$this->assertFalse(
$this->registry->is_registered( '', $style_name ),
'Empty block name should return false.'
);
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_false_for_empty_style_name() {
$block_name = 'core/paragraph';
$this->assertFalse(
$this->registry->is_registered( $block_name, '' ),
'Empty style name should return false.'
);
}

/**
* @ticket 63957
*/
public function test_is_registered_returns_false_for_both_empty_params() {
$this->assertFalse(
$this->registry->is_registered( '', '' ),
'Both empty block and style name should return false.'
);
}
}
10 changes: 10 additions & 0 deletions tests/phpunit/tests/block-templates/WpBlockTemplatesRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ public function test_is_registered() {
self::$registry->unregister( $template_name );
}

/**
* @ticket 63957
*
* @covers ::is_registered
*/
public function test_is_registered_with_invalid_param() {
$this->assertFalse( self::$registry->is_registered( '' ) );
$this->assertFalse( self::$registry->is_registered( null ) );
}

/**
* Tests that unregister() correctly unregisters a registered template.
*
Expand Down
Loading