Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTable Block: fix possible warning when rid key is not defined #15133

Merged
merged 4 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion extensions/blocks/opentable/opentable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
<testsuite name="deprecation">
<file>tests/php/test_deprecation.php</file>
</testsuite>
<testsuite name="extensions">
<directory prefix="test" suffix=".php">tests/php/extensions</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
Expand Down
45 changes: 45 additions & 0 deletions tests/php/extensions/blocks/test-class.opentable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* OpenTable Block tests.
*
* @package Jetpack
*/

use Automattic\Jetpack\Extensions\OpenTable;
require_once JETPACK__PLUGIN_DIR . '/extensions/blocks/opentable/opentable.php';

/**
* OpenTable block tests
*/
class WP_Test_OpenTable extends \WP_UnitTestCase {

/**
* `load_assets` with empty attributes
*/
public function test_load_assets_with_empty_attributes() {
$attributes = array();
$content = OpenTable\load_assets( $attributes );

$this->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 ) );
}
}