woocommerce/plugins/woocommerce-admin/tests/remote-inbox-notifications/plugin-version-rule-process...

159 lines
3.6 KiB
PHP
Raw Normal View History

Remote inbox notification delivery (https://github.com/woocommerce/woocommerce-admin/pull/4143) * Poll and persist specs * Process specs into admin notes * Add send at time rule processor * Fix style issues * Clear actions before recreating them to avoid dupes * Trigger the RINDS engine when a plugin is activated * Unit test SendAtTimeRuleProcessor * Implement plugins activated rule processor * Don't throw exception for unrecognised rule type. Also unit test around this. * add url_is_action_query to tell whether to wrap the URL in wc_admin_url() call or not * Add NOT rule * revert change to install.php * Drop unimplemented resend after dismissal rule * Add OR rule * Explicitly make "fail" a type of rule that can be applied to a spec * Add plugin version rule processor * Tidy up, don't need to pass $spec everywhere * Remove meta record for action state - not really needed * Move spec runner into it's own class, add some checks around re-unactioning a note * Replace if..else with switch * Just update the option * Check that the JSON coming in is an array * Change OR rule to accept an array of operands * Add Pass rule processor * Fix specs that are initially not published * Rename send at rule to publish after * Add publish before rule * Remove unused interface * Can't use PHP7's anonymous classes * New notification: How to draw attention to your online store * Add feature flag for rule-base inbox notes * rename everything to RemoteInboxNotifications from RINDS * Fix merge fail * fix test * Change preunactioned to pending * Move feature flag check into Events.php * Refactor reading a data source * Rename poll_data_sources function * Refactor EvaluateAndGetStatus::evaluate to take the rule evaluator directly * Check that the response body exists * Add validation and defensive checks * Add rule processor interface * Update note created time on status change * Move non-test dependencies into processor constructors * Update to proposed live URL * Remove setting icon as it's being deprecated Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-05 01:51:25 +00:00
<?php
/**
* Plugin version rule processor tests.
*
* @package WooCommerce\Tests\RemoteInboxNotifications
*/
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\PluginVersionRuleProcessor;
/**
* class WC_Tests_RemoteInboxNotifications_PluginVersionRuleProcessor
*/
class WC_Tests_RemoteInboxNotifications_PluginVersionRuleProcessor extends WC_Unit_Test_Case {
/**
* Test that the processor does not pass if the plugin is not activated.
*
* @group fast
*/
public function test_spec_does_not_pass_if_plugin_not_activated() {
$mock_plugins_provider = new MockPluginsProvider( array(), array() );
$processor = new PluginVersionRuleProcessor( $mock_plugins_provider );
$rule = json_decode(
'{
"type": "plugin_version",
"plugin": "jetpack",
"version": "1.2.3",
"operator": "<"
}'
);
$result = $processor->process( $rule );
$this->assertEquals( false, $result );
}
/**
* Test that the processor does not pass if the plugin is not activated.
*
* @group fast
*/
public function test_spec_does_not_pass_if_plugin_not_in_data() {
$mock_plugins_provider = new MockPluginsProvider(
array(
'jetpack',
),
array()
);
$processor = new PluginVersionRuleProcessor( $mock_plugins_provider );
$rule = json_decode(
'{
"type": "plugin_version",
"plugin": "jetpack",
"version": "1.2.3",
"operator": "<"
}'
);
$result = $processor->process( $rule );
$this->assertEquals( false, $result );
}
/**
* Test that the processor does not pass if the installed version is less
* than the required version.
*
* @group fast
*/
public function test_spec_does_not_pass_if_installed_version_less_than_required_version() {
$mock_plugins_provider = new MockPluginsProvider(
array(
'jetpack',
),
array(
'jetpack/jetpack.php' => array(
'Version' => '1.2.4',
),
)
);
$processor = new PluginVersionRuleProcessor( $mock_plugins_provider );
$rule = json_decode(
'{
"type": "plugin_version",
"plugin": "jetpack",
"version": "1.2.3",
"operator": "<"
}'
);
$result = $processor->process( $rule );
$this->assertEquals( false, $result );
}
/**
* Test that the processor passes if the installed version is equal
* to the required version.
*
* @group fast
*/
public function test_spec_passes_if_installed_version_equals_required_version() {
$mock_plugins_provider = new MockPluginsProvider(
array(
'jetpack',
),
array(
'jetpack/jetpack.php' => array(
'Version' => '1.2.3',
),
)
);
$processor = new PluginVersionRuleProcessor( $mock_plugins_provider );
$rule = json_decode(
'{
"type": "plugin_version",
"plugin": "jetpack",
"version": "1.2.3",
"operator": "="
}'
);
$result = $processor->process( $rule );
$this->assertEquals( true, $result );
}
/**
* Test that the processor passes if the installed version is later than
* the required version.
*
* @group fast
*/
public function test_spec_passes_if_installed_version_is_later_than_required_version() {
$mock_plugins_provider = new MockPluginsProvider(
array(
'jetpack',
),
array(
'jetpack/jetpack.php' => array(
'Version' => '1.2.4',
),
)
);
$processor = new PluginVersionRuleProcessor( $mock_plugins_provider );
$rule = json_decode(
'{
"type": "plugin_version",
"plugin": "jetpack",
"version": "1.2.3",
"operator": ">"
}'
);
$result = $processor->process( $rule );
$this->assertEquals( true, $result );
}
}