-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the governance plugin #4907
Changes from 14 commits
c65fc84
aca91c1
75e0835
a76a4ad
d88d711
4d85e34
ae3da86
d3e214a
88f53e3
03e135c
1ee05fd
d0027f0
9befca9
555952e
f9cf630
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Integration: VIP Governance. | ||
* | ||
* @package Automattic\VIP\Integrations | ||
*/ | ||
|
||
namespace Automattic\VIP\Integrations; | ||
|
||
/** | ||
* Loads VIP Governance. | ||
* | ||
* @private | ||
*/ | ||
class VipGovernanceIntegration extends Integration { | ||
|
||
/** | ||
* The version of the VIP Governance plugin to load, that's set to the latest version. | ||
* This should be higher than the lowestVersion set in "vip-governance" config (https://github.com/Automattic/vip-go-mu-plugins-ext/blob/trunk/config.json) | ||
* | ||
* @var string | ||
*/ | ||
protected string $version = '1.0'; | ||
|
||
/** | ||
* Returns `true` if `VIP Governance` is already available e.g. via customer code. We will use | ||
* this function to prevent activating of integration from platform side. | ||
*/ | ||
public function is_loaded(): bool { | ||
return defined( 'VIP_GOVERNANCE_LOADED' ); | ||
} | ||
|
||
/** | ||
* Applies hooks to load VIP Governance plugin. | ||
* | ||
* @private | ||
*/ | ||
public function load(): void { | ||
// Wait until plugins_loaded to give precedence to the plugin in the customer repo. | ||
add_action( 'plugins_loaded', function () { | ||
// Return if the integration is already loaded. | ||
// | ||
// In activate() method we do make sure to not activate the integration if its already loaded | ||
// but still adding it here as a safety measure i.e. if load() is called directly. | ||
if ( $this->is_loaded() ) { | ||
return; | ||
} | ||
|
||
// Load the version of the plugin that should be set to the latest version, otherwise if it's not found deactivate the integration. | ||
$load_path = WPMU_PLUGIN_DIR . '/vip-integrations/vip-governance-' . $this->version . '/vip-governance.php'; | ||
if ( file_exists( $load_path ) ) { | ||
require_once $load_path; | ||
} else { | ||
$this->is_active = false; | ||
} | ||
} ); | ||
} | ||
|
||
/** | ||
* Configure `VIP Governance` for VIP Platform. | ||
*/ | ||
public function configure(): void {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Test: Block Data API Integration. | ||
* | ||
* @package Automattic\VIP\Integrations | ||
*/ | ||
|
||
namespace Automattic\VIP\Integrations; | ||
|
||
use WP_UnitTestCase; | ||
|
||
// phpcs:disable Squiz.Commenting.ClassComment.Missing, Squiz.Commenting.FunctionComment.Missing, Squiz.Commenting.VariableComment.Missing | ||
|
||
class Block_Data_API_Integration_Test extends WP_UnitTestCase { | ||
private string $slug = 'block-data-api'; | ||
|
||
public function test__load_call_returns_inactive_because_no_block_data_api_plugin_loaded(): void { | ||
$block_data_api_integration = new BlockDataApiIntegration( $this->slug ); | ||
|
||
$block_data_api_integration->load(); | ||
|
||
$this->assertFalse( $block_data_api_integration->is_active() ); | ||
} | ||
|
||
public function test__if_is_loaded_gives_back_true_when_loaded(): void { | ||
$block_data_api_integration = new BlockDataApiIntegration( $this->slug ); | ||
|
||
$this->assertFalse( $block_data_api_integration->is_loaded() ); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Test: VIP Governance Integration. | ||
* | ||
* @package Automattic\VIP\Integrations | ||
*/ | ||
|
||
namespace Automattic\VIP\Integrations; | ||
|
||
use WP_UnitTestCase; | ||
|
||
// phpcs:disable Squiz.Commenting.ClassComment.Missing, Squiz.Commenting.FunctionComment.Missing, Squiz.Commenting.VariableComment.Missing | ||
|
||
class VIP_Governance_Integration_Test extends WP_UnitTestCase { | ||
private string $slug = 'vip-governance'; | ||
|
||
public function test__load_call_returns_inactive_because_no_governance_plugin_loaded(): void { | ||
$vip_governance_integration = new VipGovernanceIntegration( $this->slug ); | ||
|
||
$vip_governance_integration->load(); | ||
|
||
$this->assertFalse( $vip_governance_integration->is_active() ); | ||
} | ||
|
||
public function test__if_is_loaded_gives_back_true_when_loaded(): void { | ||
$vip_governance_integration = new VipGovernanceIntegration( $this->slug ); | ||
|
||
$this->assertFalse( $vip_governance_integration->is_loaded() ); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,22 @@ | |
|
||
defined( 'ABSPATH' ) || die(); | ||
|
||
// @codeCoverageIgnoreStart - the actual code here is tested individually in the unit tests. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up adding this here as this is where the registrations happen for the actual plugins. The underlying logic with the real plugins is better tested with the fake-integration that's in the unit tests. Instead, I added two tests for two of the integrations that didn't have unit tests and attempted to add what I could in there. So for next time if an integration is added, what would be done is:
So that way as much of the new code is covered via the unit test. Hope that makes sense, and makes it clear why I did this. |
||
|
||
require_once __DIR__ . '/integrations/integration.php'; | ||
require_once __DIR__ . '/integrations/integrations.php'; | ||
require_once __DIR__ . '/integrations/enums.php'; | ||
require_once __DIR__ . '/integrations/integration-vip-config.php'; | ||
require_once __DIR__ . '/integrations/block-data-api.php'; | ||
require_once __DIR__ . '/integrations/parsely.php'; | ||
require_once __DIR__ . '/integrations/vip-governance.php'; | ||
|
||
// Register VIP integrations here. | ||
IntegrationsSingleton::instance()->register( new BlockDataApiIntegration( 'block-data-api' ) ); | ||
IntegrationsSingleton::instance()->register( new ParselyIntegration( 'parsely' ) ); | ||
IntegrationsSingleton::instance()->register( new VipGovernanceIntegration( 'vip-governance' ) ); | ||
WPprodigy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// @codeCoverageIgnoreEnd | ||
|
||
/** | ||
* Activates an integration with an optional configuration value. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the function name is not matching with assert statement.