diff --git a/inc/class-main.php b/inc/class-main.php index 2edbf5ecb..f32447301 100644 --- a/inc/class-main.php +++ b/inc/class-main.php @@ -631,11 +631,16 @@ public function ai_connect_metadata() { /** * Set Black Friday data. * - * @param array $configs The configuration array for the loaded products. + * @param array> $configs The configuration array for the loaded products. * - * @return array + * @return array> */ public function add_black_friday_data( $configs ) { + // An earlier filter may drop the default entry, or empty the list to opt out of the sale. + if ( empty( $configs['default'] ) ) { + return $configs; + } + $config = $configs['default']; $message = __( 'Advanced blocks, custom CSS, WooCommerce integration. Everything you need to build better pages, without code. Exclusively for existing Otter users.', 'otter-blocks' ); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 07ecccbbf..880e0655b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -204,18 +204,6 @@ parameters: count: 1 path: inc/class-main.php - - - rawMessage: 'Method ThemeIsle\GutenbergBlocks\Main::add_black_friday_data() has parameter $configs with no value type specified in iterable type array.' - identifier: missingType.iterableValue - count: 1 - path: inc/class-main.php - - - - rawMessage: 'Method ThemeIsle\GutenbergBlocks\Main::add_black_friday_data() return type has no value type specified in iterable type array.' - identifier: missingType.iterableValue - count: 1 - path: inc/class-main.php - - rawMessage: 'Method ThemeIsle\GutenbergBlocks\Main::add_random_orderby_param() has parameter $params with no value type specified in iterable type array.' identifier: missingType.iterableValue diff --git a/plugins/blocks-animation/blocks-animation.php b/plugins/blocks-animation/blocks-animation.php index c3028f04c..625833736 100644 --- a/plugins/blocks-animation/blocks-animation.php +++ b/plugins/blocks-animation/blocks-animation.php @@ -67,7 +67,7 @@ function () { add_filter( 'themeisle_sdk_blackfriday_data', function ( $configs ) { - if ( defined( 'OTTER_BLOCKS_PATH' ) ) { + if ( defined( 'OTTER_BLOCKS_PATH' ) || empty( $configs['default'] ) ) { return $configs; } diff --git a/plugins/blocks-css/blocks-css.php b/plugins/blocks-css/blocks-css.php index a2339aaa8..92de7875f 100644 --- a/plugins/blocks-css/blocks-css.php +++ b/plugins/blocks-css/blocks-css.php @@ -63,7 +63,7 @@ function () { add_filter( 'themeisle_sdk_blackfriday_data', function ( $configs ) { - if ( defined( 'OTTER_BLOCKS_PATH' ) ) { + if ( defined( 'OTTER_BLOCKS_PATH' ) || empty( $configs['default'] ) ) { return $configs; } diff --git a/tests/test-black-friday-data.php b/tests/test-black-friday-data.php new file mode 100644 index 000000000..8283d8a99 --- /dev/null +++ b/tests/test-black-friday-data.php @@ -0,0 +1,69 @@ +assertSame( array(), ( new Main() )->add_black_friday_data( array() ) ); + } + + /** + * Configs whose default entry was removed upstream are passed through untouched. + */ + public function test_configs_without_default_are_returned_unchanged(): void { + $configs = array( + 'other-plugin' => array( 'message' => 'Other plugin sale' ), + ); + + $this->assertSame( $configs, ( new Main() )->add_black_friday_data( $configs ) ); + } + + /** + * The SDK default entry is extended into an Otter entry. + */ + public function test_default_config_adds_otter_entry(): void { + $default = array( + 'title' => 'Default title', + 'message' => 'Default message', + ); + + $configs = ( new Main() )->add_black_friday_data( array( 'default' => $default ) ); + + $this->assertSame( $default, $configs['default'] ); + $this->assertArrayHasKey( OTTER_PRODUCT_SLUG, $configs ); + $this->assertStringContainsString( 'otter-bf', $configs[ OTTER_PRODUCT_SLUG ]['sale_url'] ); + $this->assertNotSame( $default['message'], $configs[ OTTER_PRODUCT_SLUG ]['message'] ); + } +}