diff --git a/extensions/blocks/opentable/opentable.php b/extensions/blocks/opentable/opentable.php index 145d6b8bc8117..c12f2548d6a66 100644 --- a/extensions/blocks/opentable/opentable.php +++ b/extensions/blocks/opentable/opentable.php @@ -94,7 +94,7 @@ function load_assets( $attributes ) { Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); $classes = array( sprintf( 'wp-block-jetpack-%s-theme-%s', FEATURE_NAME, get_attribute( $attributes, 'style' ) ) ); - if ( count( $attributes['rid'] ) > 1 ) { + if ( array_key_exists( 'rid', $attributes ) && is_array( $attributes['rid'] ) && count( $attributes['rid'] ) > 1 ) { $classes[] = 'is-multi'; } $classes = Jetpack_Gutenberg::block_classes( diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4d5b17fec1bbe..fc7f740b79576 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -104,6 +104,9 @@ tests/php/test_deprecation.php + + tests/php/extensions + diff --git a/tests/php/extensions/blocks/test-class.opentable.php b/tests/php/extensions/blocks/test-class.opentable.php new file mode 100644 index 0000000000000..3d5eca9e920e2 --- /dev/null +++ b/tests/php/extensions/blocks/test-class.opentable.php @@ -0,0 +1,45 @@ +assertTrue( is_string( $content ) ); + } + + /** + * `load_assets` with `rid` attribute set to null + */ + public function test_load_assets_rid_not_valid() { + $attributes = array( 'rid' => null ); + $content = OpenTable\load_assets( $attributes ); + + $this->assertTrue( is_string( $content ) ); + } + + /** + * `load_assets` with `rid` as array + */ + public function test_load_assets_rid_empty_array() { + $attributes = array( 'rid' => array() ); + $content = OpenTable\load_assets( $attributes ); + + $this->assertTrue( is_string( $content ) ); + } +}