From 7eda39fdbd06e3cb7e407729fb1d4058b20e9fce Mon Sep 17 00:00:00 2001 From: Yaroslav Kukharuk Date: Thu, 26 Mar 2020 12:04:04 +0200 Subject: [PATCH 1/4] fix possible warning when `ridz key is not defined --- extensions/blocks/opentable/opentable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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( From 4db64e230ae9c05276391ce7773ba131dc57fb7d Mon Sep 17 00:00:00 2001 From: Yaroslav Kukharuk Date: Thu, 26 Mar 2020 13:43:51 +0200 Subject: [PATCH 2/4] add tests to cover the bug --- phpunit.xml.dist | 3 ++ .../blocks/test-class.opentable.php | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/php/extensions/blocks/test-class.opentable.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4d5b17fec1bbe..3bbdce01f4d79 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -104,6 +104,9 @@ tests/php/test_deprecation.php + + tests/php/extensions/blocks + 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..761a00af2d1e3 --- /dev/null +++ b/tests/php/extensions/blocks/test-class.opentable.php @@ -0,0 +1,45 @@ +assertIsString( $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->assertIsString( $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->assertIsString( $content ); + } +} From 23e9bd9435ed3f61e1c0b0f72f3fc574856fa7f9 Mon Sep 17 00:00:00 2001 From: Yaroslav Kukharuk Date: Thu, 26 Mar 2020 14:14:40 +0200 Subject: [PATCH 3/4] update assert function to work in older phpunit versions --- tests/php/extensions/blocks/test-class.opentable.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/php/extensions/blocks/test-class.opentable.php b/tests/php/extensions/blocks/test-class.opentable.php index 761a00af2d1e3..3d5eca9e920e2 100644 --- a/tests/php/extensions/blocks/test-class.opentable.php +++ b/tests/php/extensions/blocks/test-class.opentable.php @@ -20,7 +20,7 @@ public function test_load_assets_with_empty_attributes() { $attributes = array(); $content = OpenTable\load_assets( $attributes ); - $this->assertIsString( $content ); + $this->assertTrue( is_string( $content ) ); } /** @@ -30,7 +30,7 @@ public function test_load_assets_rid_not_valid() { $attributes = array( 'rid' => null ); $content = OpenTable\load_assets( $attributes ); - $this->assertIsString( $content ); + $this->assertTrue( is_string( $content ) ); } /** @@ -40,6 +40,6 @@ public function test_load_assets_rid_empty_array() { $attributes = array( 'rid' => array() ); $content = OpenTable\load_assets( $attributes ); - $this->assertIsString( $content ); + $this->assertTrue( is_string( $content ) ); } } From 2513b695eb5fc42deb3fee689636e29eb7fa9b29 Mon Sep 17 00:00:00 2001 From: Yaroslav Kukharuk Date: Thu, 26 Mar 2020 14:22:23 +0200 Subject: [PATCH 4/4] update suite name --- phpunit.xml.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3bbdce01f4d79..fc7f740b79576 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -104,8 +104,8 @@ tests/php/test_deprecation.php - - tests/php/extensions/blocks + + tests/php/extensions