-
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.
Merge branch 'main' into 97-set-jetpack-to-staging-on-non-production-…
…sites
- Loading branch information
Showing
6 changed files
with
156 additions
and
1 deletion.
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
42 changes: 42 additions & 0 deletions
42
src/alley/wp/alleyvate/features/class-disable-apple-news-non-prod-push.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,42 @@ | ||
<?php | ||
/** | ||
* Class file for Disable_Apple_News_Non_Prod_Push | ||
* | ||
* (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; | ||
|
||
/** | ||
* Disables Apple News Push on Non Production Environments. | ||
*/ | ||
final class Disable_Apple_News_Non_Prod_Push implements Feature { | ||
/** | ||
* Boot the feature. | ||
*/ | ||
public function boot(): void { | ||
add_filter( 'apple_news_skip_push', [ $this, 'filter_apple_news_skip_push' ], 9999 ); | ||
} | ||
|
||
/** | ||
* Filter the Apple News push skip flag. If we are not on a production environment, skip the push. | ||
* | ||
* @param bool $skip Should we skip the Apple News push. | ||
*/ | ||
public function filter_apple_news_skip_push( bool $skip ): bool { | ||
// If we are on a production environment, don't modify the value. | ||
if ( 'production' === wp_get_environment_type() ) { | ||
return $skip; | ||
} | ||
|
||
// All other cases, return true. | ||
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
98 changes: 98 additions & 0 deletions
98
tests/alley/wp/alleyvate/features/test-disable-apple-news-non-prod-push.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,98 @@ | ||
<?php | ||
/** | ||
* Class file for Disable_Apple_News_Non_Prod_Push | ||
* | ||
* (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\Alleyvate\Feature; | ||
use Mantle\Testkit\Test_Case; | ||
|
||
/** | ||
* Test Disable_Apple_News_Non_Prod_Push | ||
*/ | ||
final class Disable_Apple_News_Non_Prod_Push_Test extends Test_Case { | ||
/** | ||
* The Feature class. | ||
* | ||
* @var Disable_Apple_News_Non_Prod_Push | ||
*/ | ||
protected $feature; | ||
|
||
/** | ||
* Setup before test. | ||
*/ | ||
protected function setUp(): void { | ||
$this->feature = new Disable_Apple_News_Non_Prod_Push(); | ||
} | ||
|
||
/** | ||
* Set the current environment value. | ||
* | ||
* @param string $environment The environment name to use. | ||
*/ | ||
protected function setEnvironment( string $environment ): void { | ||
// Required because `wp_get_environment_type` uses `getenv` to retrieve the value. | ||
putenv( 'WP_ENVIRONMENT_TYPE=' . $environment ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv | ||
$_ENV['WP_ENVIRONMENT_TYPE'] = $environment; | ||
} | ||
|
||
/** | ||
* Test that the filter_apple_news_skip_push method returns false when passed false on a production_ environment. | ||
*/ | ||
public function testFalseFilterAppleNewsSkipPushProductionEnvironment() { | ||
$skip = false; | ||
|
||
$this->setEnvironment( 'production' ); | ||
|
||
$result = $this->feature->filter_apple_news_skip_push( $skip ); | ||
|
||
$this->assertFalse( $result ); | ||
} | ||
|
||
/** | ||
* Test that the filter_apple_news_skip_push method returns true when passed true on a production_ environment. | ||
*/ | ||
public function testTrueFilterAppleNewsSkipPushProductionEnvironment() { | ||
$skip = true; | ||
|
||
$this->setEnvironment( 'production' ); | ||
|
||
$result = $this->feature->filter_apple_news_skip_push( $skip ); | ||
|
||
$this->assertTrue( $result ); | ||
} | ||
|
||
/** | ||
* Test that the filter_apple_news_skip_push method returns true when passed false on a non-production_ environment. | ||
*/ | ||
public function testFalseFilterAppleNewsSkipPushOtherEnvironments() { | ||
$skip = false; | ||
|
||
$this->setEnvironment( 'local' ); | ||
|
||
$result = $this->feature->filter_apple_news_skip_push( $skip ); | ||
|
||
$this->assertTrue( $result ); | ||
} | ||
|
||
/** | ||
* Test that the filter_apple_news_skip_push method returns true when passed true on a non-production_ environment. | ||
*/ | ||
public function testTrueFilterAppleNewsSkipPushOtherEnvironments() { | ||
$skip = true; | ||
|
||
$this->setEnvironment( 'local' ); | ||
|
||
$result = $this->feature->filter_apple_news_skip_push( $skip ); | ||
|
||
$this->assertTrue( $result ); | ||
} | ||
} |
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