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

fix: featured available on in some free plugins #237

Merged
merged 6 commits into from
Jun 25, 2024
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
4 changes: 1 addition & 3 deletions src/Modules/Featured_plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
31 changes: 31 additions & 0 deletions tests/featured-plugins-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,32 @@ 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.
*/
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 ) );
}

Expand All @@ -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.
*/
Expand Down
Loading