-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ composer.lock | |
.phpunit.result.cache | ||
.php-cs-fixer.cache | ||
.vscode | ||
.DS_Store | ||
.idea |
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
32 changes: 32 additions & 0 deletions
32
src/alley/wp/alleyvate/features/class-enable-jetpack-safe-mode.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,32 @@ | ||
<?php | ||
/** | ||
* Class file for Enable_Jetpack_Safe_Mode | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Alley\WP\Types\Feature; | ||
|
||
/** | ||
* Enables Jetpack safe mode for non-production environments, currently only for Pantheon. | ||
*/ | ||
final class Enable_Jetpack_Safe_Mode implements Feature { | ||
/** | ||
* Boot the feature. | ||
*/ | ||
public function boot(): void { | ||
if ( | ||
isset( $_ENV['PANTHEON_ENVIRONMENT'] ) && | ||
$_ENV['PANTHEON_ENVIRONMENT'] !== 'live' | ||
) { | ||
add_filter( 'jetpack_is_development_site', '__return_true' ); | ||
} | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
tests/alley/wp/alleyvate/features/test-enable-jetpack-safe-mode.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,59 @@ | ||
<?php | ||
/** | ||
* Class file for Test_Enable_Jetpack_Safe_Mode | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
declare( strict_types=1 ); | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Mantle\Testkit\Test_Case; | ||
|
||
/** | ||
* Tests for the enabling of Jetpack safe mode. | ||
*/ | ||
final class Test_Enabled_Jetpack_Safe_Mode extends Test_Case { | ||
|
||
/** | ||
* Feature instance. | ||
* | ||
* @var Enable_Jetpack_Safe_Mode | ||
*/ | ||
private Enable_Jetpack_Safe_Mode $feature; | ||
|
||
/** | ||
* Set up. | ||
*/ | ||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->feature = new Enable_Jetpack_Safe_Mode(); | ||
} | ||
|
||
/** | ||
* Test that the feature enabled Jetpack safe mode. | ||
*/ | ||
public function test_enable_jetpack_safe_mode(): void { | ||
$this->assertFalse( apply_filters( 'jetpack_is_development_site', false ), 'jetpack_is_development_site should not be true prior to boot.' ); | ||
$this->setEnvironment( 'test' ); | ||
$this->feature->boot(); | ||
$this->assertTrue( apply_filters( 'jetpack_is_development_site', false ), 'jetpack_is_development_site should be true after boot.' ); | ||
} | ||
|
||
/** | ||
* Set the current environment value. | ||
* | ||
* @param string $environment The environment name to use. | ||
*/ | ||
protected function setEnvironment( string $environment ): void { | ||
putenv( 'PANTHEON_ENVIRONMENT=' . $environment ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv | ||
$_ENV['PANTHEON_ENVIRONMENT'] = $environment; | ||
} | ||
} |