-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate restriction checks and add tests
- Loading branch information
1 parent
d9e58ab
commit fb76ef2
Showing
3 changed files
with
112 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
tests/telemetry/pendo/test-class-pendo-javascript-library.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Automattic\VIP\Telemetry; | ||
|
||
use Automattic\Test\Constant_Mocker; | ||
use Automattic\VIP\Telemetry\Pendo\Pendo_JavaScript_Library; | ||
use WP_UnitTestCase; | ||
|
||
class Pendo_JavaScript_Library_Test extends WP_UnitTestCase { | ||
public function tearDown(): void { | ||
Constant_Mocker::clear(); | ||
parent::tearDown(); | ||
} | ||
|
||
public function test_enabled_for_users_with_edit_post_cap() { | ||
$user = $this->factory()->user->create_and_get( [ 'role' => 'author' ] ); | ||
wp_set_current_user( $user->ID ); | ||
|
||
Constant_Mocker::define( 'VIP_GO_APP_ENVIRONMENT', 'production' ); | ||
Constant_Mocker::define( 'WPCOM_IS_VIP_ENV', true ); | ||
|
||
$this->assertTrue( Pendo_JavaScript_Library::should_enqueue_script() ); | ||
} | ||
|
||
public function test_disabled_by_opt_out_constant() { | ||
$user = $this->factory()->user->create_and_get( [ 'role' => 'author' ] ); | ||
wp_set_current_user( $user->ID ); | ||
|
||
Constant_Mocker::define( 'VIP_DISABLE_PENDO_TELEMETRY', true ); | ||
Constant_Mocker::define( 'VIP_GO_APP_ENVIRONMENT', 'production' ); | ||
Constant_Mocker::define( 'WPCOM_IS_VIP_ENV', true ); | ||
|
||
$this->assertFalse( Pendo_JavaScript_Library::should_enqueue_script() ); | ||
} | ||
|
||
public function test_disabled_for_non_vip_environments() { | ||
$user = $this->factory()->user->create_and_get( [ 'role' => 'author' ] ); | ||
wp_set_current_user( $user->ID ); | ||
|
||
Constant_Mocker::define( 'VIP_GO_APP_ENVIRONMENT', 'production' ); | ||
|
||
$this->assertFalse( Pendo_JavaScript_Library::should_enqueue_script() ); | ||
} | ||
|
||
public function test_disabled_for_non_production_environments() { | ||
$user = $this->factory()->user->create_and_get( [ 'role' => 'author' ] ); | ||
wp_set_current_user( $user->ID ); | ||
|
||
Constant_Mocker::define( 'VIP_GO_APP_ENVIRONMENT', 'preprod' ); | ||
Constant_Mocker::define( 'WPCOM_IS_VIP_ENV', true ); | ||
|
||
$this->assertFalse( Pendo_JavaScript_Library::should_enqueue_script() ); | ||
} | ||
|
||
public function test_disabled_for_fedramp_environments() { | ||
$user = $this->factory()->user->create_and_get( [ 'role' => 'author' ] ); | ||
wp_set_current_user( $user->ID ); | ||
|
||
Constant_Mocker::define( 'VIP_GO_APP_ENVIRONMENT', 'production' ); | ||
Constant_Mocker::define( 'VIP_IS_FEDRAMP', true ); | ||
Constant_Mocker::define( 'WPCOM_IS_VIP_ENV', true ); | ||
|
||
$this->assertFalse( Pendo_JavaScript_Library::should_enqueue_script() ); | ||
} | ||
|
||
public function test_disabled_for_sandbox_environments() { | ||
$user = $this->factory()->user->create_and_get( [ 'role' => 'author' ] ); | ||
wp_set_current_user( $user->ID ); | ||
|
||
Constant_Mocker::define( 'VIP_GO_APP_ENVIRONMENT', 'production' ); | ||
Constant_Mocker::define( 'WPCOM_IS_VIP_ENV', true ); | ||
Constant_Mocker::define( 'WPCOM_SANDBOXED', true ); | ||
|
||
$this->assertFalse( Pendo_JavaScript_Library::should_enqueue_script() ); | ||
} | ||
|
||
public function test_disabled_for_users_without_edit_post_cap() { | ||
$user = $this->factory()->user->create_and_get( [ 'role' => 'subscriber' ] ); | ||
wp_set_current_user( $user->ID ); | ||
|
||
Constant_Mocker::define( 'VIP_GO_APP_ENVIRONMENT', 'production' ); | ||
Constant_Mocker::define( 'WPCOM_IS_VIP_ENV', true ); | ||
|
||
$this->assertFalse( Pendo_JavaScript_Library::should_enqueue_script() ); | ||
} | ||
} |