diff --git a/src/Modules/Featured_plugins.php b/src/Modules/Featured_plugins.php index bf3315c1..326ac5e0 100644 --- a/src/Modules/Featured_plugins.php +++ b/src/Modules/Featured_plugins.php @@ -44,9 +44,7 @@ public function can_load( $product ) { return false; } - $slug = $product->get_slug(); - // only load for products that contain "pro" in the slug. - if ( strpos( $slug, 'pro' ) === false ) { + if ( $product->is_wordpress_available() ) { return false; } diff --git a/tests/featured-plugins-test.php b/tests/featured-plugins-test.php index cf61fd93..3a35c63a 100644 --- a/tests/featured-plugins-test.php +++ b/tests/featured-plugins-test.php @@ -97,6 +97,23 @@ public static function wpTearDownAfterClass() { self::delete_user( self::$admin_id ); } + /** + * Utility method to change the value of a protected property. + * + * @param \ThemeisleSDK\Product $object The object. + * @param string $property The property name. + * @param mixed $new_value The new value. + * + * @return void + * @throws ReflectionException Throws an exception if the property does not exist. + */ + private function set_protected_property( $object, $property, $new_value ) { + $reflection = new ReflectionClass( $object ); + $property = $reflection->getProperty( $property ); + $property->setAccessible( true ); + $property->setValue( $object, $new_value ); + } + /** * Test plugin not loading without config. */ @@ -104,6 +121,8 @@ public function test_plugin_not_loading_if_not_pro() { $plugin = dirname( __FILE__ ) . '/sample_products/sample_plugin/plugin_file.php'; $plugin_product = new \ThemeisleSDK\Product( $plugin ); + $this->set_protected_property( $plugin_product, 'wordpress_available', true ); + $this->assertFalse( ( new \ThemeisleSDK\Modules\Featured_Plugins() )->can_load( $plugin_product ) ); } @@ -117,6 +136,18 @@ public function test_plugin_loading_for_pro() { $this->assertTrue( ( new \ThemeisleSDK\Modules\Featured_Plugins() )->can_load( $plugin_product ) ); } + /** + * Test plugin not loading for slugs that contain pro as part of a word. Eg. Product. + */ + public function test_plugin_loading_for_words_w_pro() { + $plugin = dirname( __FILE__ ) . '/sample_products/sample_pro_plugin/plugin_file.php'; + $plugin_product = new \ThemeisleSDK\Product( $plugin ); + + $this->set_protected_property( $plugin_product, 'wordpress_available', true ); + + $this->assertFalse( ( new \ThemeisleSDK\Modules\Featured_Plugins() )->can_load( $plugin_product ) ); + } + /** * Test plugin not loading for pro if disabled. */