diff --git a/projects/packages/podcast/changelog/pods-141-add-gate b/projects/packages/podcast/changelog/pods-141-add-gate new file mode 100644 index 000000000000..dd6095cbca78 --- /dev/null +++ b/projects/packages/podcast/changelog/pods-141-add-gate @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Podcast: add product-access gate (Podcast_Gate::has_product_access) and grandfather sticker constant. diff --git a/projects/packages/podcast/composer.json b/projects/packages/podcast/composer.json index e6a74bba2ce6..402b8089d8cd 100644 --- a/projects/packages/podcast/composer.json +++ b/projects/packages/podcast/composer.json @@ -8,6 +8,7 @@ "automattic/jetpack-assets": "@dev", "automattic/jetpack-blocks": "@dev", "automattic/jetpack-connection": "@dev", + "automattic/jetpack-plans": "@dev", "automattic/jetpack-status": "@dev", "automattic/jetpack-wp-build-polyfills": "@dev" }, diff --git a/projects/packages/podcast/src/class-podcast-gate.php b/projects/packages/podcast/src/class-podcast-gate.php new file mode 100644 index 000000000000..d91d8fc87663 --- /dev/null +++ b/projects/packages/podcast/src/class-podcast-gate.php @@ -0,0 +1,45 @@ +clear_options(); + self::reset_active_plan_cache(); + parent::tearDown(); + } + + /** + * `Current_Plan::get()` memoizes for the request, leaking option writes between tests. + */ + private static function reset_active_plan_cache(): void { + $property = ( new \ReflectionClass( Current_Plan::class ) )->getProperty( 'active_plan_cache' ); + // @todo Remove once we drop PHP < 8.1 support. + if ( PHP_VERSION_ID < 80100 ) { + $property->setAccessible( true ); + } + $property->setValue( null, null ); + } + + public function test_grandfather_sticker_grants_access(): void { + $GLOBALS['jetpack_podcast_test_stickers'][ get_current_blog_id() ] = array( Podcast_Gate::GRANDFATHER_STICKER ); + + $this->assertTrue( Podcast_Gate::has_product_access() ); + } + + public function test_plan_supports_feature_grants_access(): void { + $plan = Current_Plan::PLAN_DATA['free']; + $plan['features']['active'] = array( Podcast_Gate::FEATURE_SLUG ); + update_option( Current_Plan::PLAN_OPTION, $plan, true ); + + $this->assertTrue( Podcast_Gate::has_product_access() ); + } + + public function test_no_sticker_and_unsupported_plan_denies_access(): void { + $plan = Current_Plan::PLAN_DATA['free']; + $plan['features']['active'] = array(); + update_option( Current_Plan::PLAN_OPTION, $plan, true ); + + $this->assertFalse( Podcast_Gate::has_product_access() ); + } +} diff --git a/projects/packages/podcast/tests/php/bootstrap.php b/projects/packages/podcast/tests/php/bootstrap.php index 0417e0a852e4..dea0c2c62cbd 100644 --- a/projects/packages/podcast/tests/php/bootstrap.php +++ b/projects/packages/podcast/tests/php/bootstrap.php @@ -26,3 +26,13 @@ function tracks_record_event( $user, $event_name, $properties = array() ) { return true; } } + +/** + * Mirror the jetpack-mu-wpcom sticker dispatcher. + */ +if ( ! function_exists( 'wpcom_has_blog_sticker' ) ) { + function wpcom_has_blog_sticker( $sticker, $blog_id ) { + $stickers = $GLOBALS['jetpack_podcast_test_stickers'][ $blog_id ] ?? array(); + return in_array( $sticker, $stickers, true ); + } +} diff --git a/projects/plugins/jetpack/changelog/pods-141-add-gate b/projects/plugins/jetpack/changelog/pods-141-add-gate new file mode 100644 index 000000000000..34e4a48b95ae --- /dev/null +++ b/projects/plugins/jetpack/changelog/pods-141-add-gate @@ -0,0 +1,3 @@ +Significance: patch +Type: other +Comment: Podcast: composer.lock picks up jetpack-plans transitively from the podcast package; no plugin-level behavior change. diff --git a/projects/plugins/jetpack/composer.lock b/projects/plugins/jetpack/composer.lock index 540c4862a0a3..689d7cccbf31 100644 --- a/projects/plugins/jetpack/composer.lock +++ b/projects/plugins/jetpack/composer.lock @@ -2575,12 +2575,13 @@ "dist": { "type": "path", "url": "../../packages/podcast", - "reference": "99472f9cf83ec522499746f7736c5282bb3c70ba" + "reference": "165176b0f879970e605cf1219a0c286a0f3fcb0d" }, "require": { "automattic/jetpack-assets": "@dev", "automattic/jetpack-blocks": "@dev", "automattic/jetpack-connection": "@dev", + "automattic/jetpack-plans": "@dev", "automattic/jetpack-status": "@dev", "automattic/jetpack-wp-build-polyfills": "@dev", "php": ">=7.2" diff --git a/projects/plugins/mu-wpcom-plugin/changelog/pods-141-add-gate b/projects/plugins/mu-wpcom-plugin/changelog/pods-141-add-gate new file mode 100644 index 000000000000..3c47617223e1 --- /dev/null +++ b/projects/plugins/mu-wpcom-plugin/changelog/pods-141-add-gate @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Updated composer.lock to pick up jetpack-plans transitively via jetpack-podcast. diff --git a/projects/plugins/mu-wpcom-plugin/composer.lock b/projects/plugins/mu-wpcom-plugin/composer.lock index c9860b768083..7db7f63877d2 100644 --- a/projects/plugins/mu-wpcom-plugin/composer.lock +++ b/projects/plugins/mu-wpcom-plugin/composer.lock @@ -1431,12 +1431,13 @@ "dist": { "type": "path", "url": "../../packages/podcast", - "reference": "99472f9cf83ec522499746f7736c5282bb3c70ba" + "reference": "165176b0f879970e605cf1219a0c286a0f3fcb0d" }, "require": { "automattic/jetpack-assets": "@dev", "automattic/jetpack-blocks": "@dev", "automattic/jetpack-connection": "@dev", + "automattic/jetpack-plans": "@dev", "automattic/jetpack-status": "@dev", "automattic/jetpack-wp-build-polyfills": "@dev", "php": ">=7.2" diff --git a/projects/plugins/wpcomsh/changelog/pods-141-add-gate b/projects/plugins/wpcomsh/changelog/pods-141-add-gate new file mode 100644 index 000000000000..3c47617223e1 --- /dev/null +++ b/projects/plugins/wpcomsh/changelog/pods-141-add-gate @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Updated composer.lock to pick up jetpack-plans transitively via jetpack-podcast. diff --git a/projects/plugins/wpcomsh/composer.lock b/projects/plugins/wpcomsh/composer.lock index 3a5499ef29e2..1e93ef48358c 100644 --- a/projects/plugins/wpcomsh/composer.lock +++ b/projects/plugins/wpcomsh/composer.lock @@ -1638,12 +1638,13 @@ "dist": { "type": "path", "url": "../../packages/podcast", - "reference": "99472f9cf83ec522499746f7736c5282bb3c70ba" + "reference": "165176b0f879970e605cf1219a0c286a0f3fcb0d" }, "require": { "automattic/jetpack-assets": "@dev", "automattic/jetpack-blocks": "@dev", "automattic/jetpack-connection": "@dev", + "automattic/jetpack-plans": "@dev", "automattic/jetpack-status": "@dev", "automattic/jetpack-wp-build-polyfills": "@dev", "php": ">=7.2"