Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/gemini.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: "8.4"
extensions: mysqli, uopz
extensions: mysqli
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get Composer Cache Directory
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php-lint-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ jobs:
- name: Setup PHP for Tests
uses: shivammathur/setup-php@v2
with:
extensions: mysqli, uopz
extensions: mysqli
php-version: ${{ matrix.php_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

class Tag_Environment_Type_GuardTest extends TestCase {

public function tear_down() {
remove_all_filters( 'googlesitekit_allowed_tag_environment_types' );
parent::tear_down();
}

public function test_can_activate_on_post_5_5_version() {
if ( ! function_exists( 'wp_get_environment_type' ) ) {
// This environment is pre WP-5.5.0 and is skipped.
Expand All @@ -33,44 +38,45 @@ public function test_can_activate_on_older_versions() {
$this->assertTrue( $tagproduction->can_activate(), 'Tag should be able to activate on older versions.' );
}

public function test_can_not_activate_in_development() {
// Pre WP-5.5.0
public function test_can_not_activate_when_environment_not_allowed() {
if ( ! function_exists( 'wp_get_environment_type' ) ) {
$this->markTestSkipped( 'Missing wp_get_environment_type() function.' );
}
if ( ! function_exists( 'uopz_set_static' ) ) {
$this->markTestSkipped( 'The uopz extension is not available.' );
}
$env_type = wp_get_environment_type();
$tagproduction = new Tag_Environment_Type_Guard();
uopz_set_static( 'wp_get_environment_type', array( 'current_env' => 'development' ) );
$this->assertFalse( $tagproduction->can_activate(), 'Tag should not be able to activate in development environment.' );
uopz_set_static( 'wp_get_environment_type', array( 'current_env' => $env_type ) );

$current_env = wp_get_environment_type();

add_filter(
'googlesitekit_allowed_tag_environment_types',
function () use ( $current_env ) {
return array_values(
array_diff( array( 'local', 'development', 'staging', 'production' ), array( $current_env ) )
);
}
);

$this->assertFalse(
( new Tag_Environment_Type_Guard() )->can_activate(),
'Tag should not activate when the current environment is excluded from the allowed list.'
);
}

public function test_can_activate_in_development() {
// Pre WP-5.5.0
public function test_can_activate_when_environment_is_allowed() {
if ( ! function_exists( 'wp_get_environment_type' ) ) {
$this->markTestSkipped( 'Missing wp_get_environment_type() function.' );
}
if ( ! function_exists( 'uopz_set_static' ) ) {
$this->markTestSkipped( 'The uopz extension is not available.' );
}
$env_type = wp_get_environment_type();
$tagproduction = new Tag_Environment_Type_Guard();
uopz_set_static( 'wp_get_environment_type', array( 'current_env' => 'development' ) );
$this->assertFalse( $tagproduction->can_activate(), 'Tag should not be able to activate in development environment by default.' );

remove_all_filters( 'googlesitekit_allowed_tag_environment_types' );
$current_env = wp_get_environment_type();

add_filter(
'googlesitekit_allowed_tag_environment_types',
function ( $allowed_environments ) {
$allowed_environments[] = 'development';
return $allowed_environments;
function () use ( $current_env ) {
return array( $current_env );
}
);
$this->assertTrue( $tagproduction->can_activate(), 'Tag should be able to activate in development environment when allowed.' );

uopz_set_static( 'wp_get_environment_type', array( 'current_env' => $env_type ) );
$this->assertTrue(
( new Tag_Environment_Type_Guard() )->can_activate(),
'Tag should activate when the current environment is in the allowed list.'
);
}
}