Skip to content
Closed
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
33 changes: 0 additions & 33 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,38 +161,6 @@ public function dismiss_new_tc_notice() {
$this->ensure_ajax_response( $response );
}

/**
* Decide if the business/agency variant of the onboarding promo text should be shown.
*
* @return bool
*/
private function should_show_business_agency_promo_text() {
$license_data = License::get_license_data();
$license_key = isset( $license_data->key ) ? strtolower( trim( (string) $license_data->key ) ) : '';
$license_tier = License::get_license_tier( 0 );
$raw_tier = isset( $license_data->tier ) ? absint( $license_data->tier ) : 0;
$neve_plan = $this->neve_license_plan();

if ( $license_key === '' || $license_key === 'free' ) {
return false;
}

if ( ! License::has_active_license() || ! $this->has_valid_addons() ) {
return false;
}

if ( -1 !== $neve_plan ) {
// The normalized Neve plan uses mapped TPC tiers, where Business and Agency are 2 and 3.
return in_array( $neve_plan, array( 2, 3 ), true );
}

if ( in_array( $raw_tier, array( 1, 2, 7, 12, 18 ), true ) ) {
return false;
}

return in_array( $license_tier, array( 2, 3 ), true );
}


/**
* Register hooks to prevent meta cloning for the templates.
Expand Down Expand Up @@ -837,7 +805,6 @@ private function get_localization() {
'upsellNotifications' => $this->get_upsell_notifications(),
'isValidLicense' => $this->has_valid_addons(),
'licenseTIOB' => License::get_license_data(),
'onboardingShowProNoticeText' => $this->should_show_business_agency_promo_text(),
'emailSubscribe' => array(
'ajaxURL' => esc_url( admin_url( 'admin-ajax.php' ) ),
'nonce' => wp_create_nonce( 'skip_subscribe_nonce' ),
Expand Down
202 changes: 0 additions & 202 deletions tests/tc-disabled-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,18 @@
class TC_Disabled_Test extends \WP_UnitTestCase {
private $admin;
private $license;
private $neve_pro_license_option;

public static function set_up_before_class(): void {
parent::set_up_before_class();
if ( ! defined( 'NEVE_PRO_BASEFILE' ) ) {
define( 'NEVE_PRO_BASEFILE', trailingslashit( sys_get_temp_dir() ) . 'neve-pro-addon/neve-pro-addon.php' );
}
}

public function set_up(): void {
parent::set_up();
$this->admin = new Admin();
$this->license = License::get_instance();
$this->neve_pro_license_option = 'neve_pro_addon_license_data';
}
Comment on lines 19 to 23

public function tear_down(): void {
parent::tear_down();
delete_option(Admin::TC_REMOVED_KEY);
delete_option(License::LICENSE_DATA_OPTIONS_KEY);
delete_option(License::LICENSE_KEY_OPTION_KEY);
delete_option( $this->neve_pro_license_option );
remove_all_filters( 'product_neve_license_plan' );
}

/**
Expand Down Expand Up @@ -114,195 +103,4 @@ public function test_keeps_tc_with_license_and_templates() {
$this->admin->maybe_remove_tc();
$this->assertEquals('no', get_option(Admin::TC_REMOVED_KEY));
}

/**
* Test that free licenses never show the business/agency onboarding promo text.
*
* @return void
*/
public function test_free_license_excludes_business_agency_onboarding_promo_text() {
$this->set_active_license_data(
array(
'key' => 'free',
'tier' => 0,
)
);
$this->set_active_neve_pro_addon();

$this->assertFalse( $this->invoke_admin_private_method( 'should_show_business_agency_promo_text' ) );
}

/**
* Test that personal tiers use the default onboarding promo text.
*
* @return void
*/
public function test_personal_license_does_not_show_business_agency_onboarding_promo_text() {
$this->set_active_license_data(
array(
'key' => 'personal-license',
'tier' => 2,
)
);
$this->set_active_neve_pro_addon();

$this->assertFalse( $this->invoke_admin_private_method( 'should_show_business_agency_promo_text' ) );
}

/**
* Test that business tiers show the business/agency onboarding promo text.
*
* @return void
*/
public function test_business_license_shows_business_agency_onboarding_promo_text() {
$this->set_active_license_data(
array(
'key' => 'business-license',
'tier' => 4,
)
);
$this->set_active_neve_pro_addon();

$this->assertTrue( $this->invoke_admin_private_method( 'should_show_business_agency_promo_text' ) );
}

/**
* Test that agency tiers show the business/agency onboarding promo text.
*
* @return void
*/
public function test_agency_license_shows_business_agency_onboarding_promo_text() {
$this->set_active_license_data(
array(
'key' => 'agency-license',
'tier' => 5,
)
);
$this->set_active_neve_pro_addon();

$this->assertTrue( $this->invoke_admin_private_method( 'should_show_business_agency_promo_text' ) );
}

/**
* Test that Neve category mappings override the TPC tier when deciding the promo text.
*
* @return void
*/
public function test_neve_personal_category_does_not_show_business_agency_onboarding_promo_text() {
$this->set_active_license_data(
array(
'key' => 'business-license',
'tier' => 4,
)
);
$this->set_active_neve_pro_addon();
add_filter(
'product_neve_license_plan',
function () {
return 2;
}
);

$this->assertFalse( $this->invoke_admin_private_method( 'should_show_business_agency_promo_text' ) );
}

/**
* Test that mapped Neve business plans show the business/agency onboarding promo text.
*
* @return void
*/
public function test_neve_business_category_shows_business_agency_onboarding_promo_text() {
$this->set_active_license_data(
array(
'key' => 'personal-license',
'tier' => 1,
)
);
$this->set_active_neve_pro_addon();
add_filter(
'product_neve_license_plan',
function () {
return 3;
}
);

$this->assertTrue( $this->invoke_admin_private_method( 'should_show_business_agency_promo_text' ) );
}

/**
* Test that the default Neve plan falls back to the TPC tier.
*
* @return void
*/
public function test_default_neve_plan_falls_back_to_tpc_tier() {
$this->set_active_license_data(
array(
'key' => 'business-license',
'tier' => 4,
)
);
$this->set_active_neve_pro_addon();
add_filter(
'product_neve_license_plan',
function () {
return -1;
}
);

$this->assertTrue( $this->invoke_admin_private_method( 'should_show_business_agency_promo_text' ) );
}

/**
* Set active TPC license data for onboarding promo tests.
*
* @param array $overrides License data overrides.
*
* @return void
*/
private function set_active_license_data( $overrides = array() ) {
update_option(
License::LICENSE_DATA_OPTIONS_KEY,
(object) array_merge(
array(
'license' => 'valid',
'key' => 'test-key',
'tier' => 0,
),
$overrides
)
);
}

/**
* Set an active Neve Pro addon license.
*
* @return void
*/
private function set_active_neve_pro_addon() {
update_option(
$this->neve_pro_license_option,
(object) array(
'license' => 'valid',
)
);
}

/**
* Invoke a private Admin method.
*
* @param string $method_name Method name.
*
* @return mixed
*/
private function invoke_admin_private_method( $method_name ) {
try {
$method = new ReflectionMethod( $this->admin, $method_name );
} catch ( ReflectionException $exception ) {
$this->fail( sprintf( 'Expected private Admin method "%s" to exist.', $method_name ) );
}

$method->setAccessible( true );

return $method->invoke( $this->admin );
}
}