woocommerce/plugins/woocommerce-admin/tests/remote-inbox-notifications/evaluate-and-get-status.php

215 lines
4.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
/**
* Evaluate and get status tests.
*
* @package WooCommerce\Admin\Tests\RemoteInboxNotifications
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
*/
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\EvaluateAndGetStatus;
/**
* class WC_Tests_RemoteInboxNotifications_EvaluateAndGetStatus
*/
class WC_Tests_RemoteInboxNotifications_EvaluateAndGetStatus extends WC_Unit_Test_Case {
/**
* Build up a spec given the supplied parameters.
*
* @param bool $allow_redisplay Allow note redisplay after it has been actioned.
*
* @return object The spec object.
*/
private function get_spec( $allow_redisplay ) {
return json_decode(
'{
"status": "unactioned",
"rules": [],
"allow_redisplay": ' . ( $allow_redisplay ? 'true' : 'false' ) . '
}'
);
}
/**
* Get a spec with no rules property.
*
* @return object The spec object.
*/
private function get_no_rules_spec() {
return json_decode(
'{
"status": "unactioned",
"allow_redisplay": false
}'
);
}
/**
* Tests that for a pending note evaling to true, status is changed
* to the spec status.
*
* @group fast
*/
public function test_pending_note_eval_to_true() {
$spec = $this->get_spec( false );
$result = EvaluateAndGetStatus::evaluate(
$spec,
'unactioned',
Add stored state between remote inbox notification runs (https://github.com/woocommerce/woocommerce-admin/pull/4260) * Fix comment and convert if..elseif to switch * Take out intermediate function * make ProductsProvider a non-static class * Adds RINDS data rule, and set up for woocommerce/woocommerce-admin#4223 # Conflicts: # src/RemoteInboxNotifications/EvaluateAndGetStatus.php * Fix rebase issues # Conflicts: # src/RemoteInboxNotifications/DataRuleProcessor.php * Split product data setup out, use product query # Conflicts: # src/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php * Remove RINDS references * Remove unused products provider * Add validation to the data rule processor * Fix some issues that were failing tests * Remove unused var * Make data setup for products return the data object * Rework product query * Rename $data to $stored_state * Fix condition in query * Add time after wcadmin activation rule (https://github.com/woocommerce/woocommerce-admin/pull/4337) * Add wcadmin active for rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use DAY_IN_SECONDS constant * Fix logic error * Fix test naming Co-authored-by: Rebecca Scott <me@becdetat.com> * Add order count rule (https://github.com/woocommerce/woocommerce-admin/pull/4335) * Order count rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use default provider Co-authored-by: Rebecca Scott <me@becdetat.com> * Use correct 'return' value * Move back to using a SQL query to get the product count as the WC_Product_Query has issues during the product publish lifecycle. The product is initially published with a taxonomy term of uncategorized which isn't accepted by the query's filter. * Change back to using WC_Product_Query, and do prelim init via admin_init action * If there are no specs when running the engine, run the poller first then retry * Fix some failing tests * Don't perform init if we're feature toggled off * Move feature check inside RIN engine class because the feature filter isn't ready during FeaturePlugin init Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-15 23:42:35 +00:00
new stdClass(),
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
new PassingRuleEvaluator()
);
$this->assertEquals( 'unactioned', $result );
}
/**
* Tests that for a pending note evaluating to false, status is
* left at pending.
*
* @group fast
*/
public function test_pending_note_eval_to_false() {
$spec = $this->get_spec( false );
$result = EvaluateAndGetStatus::evaluate(
$spec,
'pending',
Add stored state between remote inbox notification runs (https://github.com/woocommerce/woocommerce-admin/pull/4260) * Fix comment and convert if..elseif to switch * Take out intermediate function * make ProductsProvider a non-static class * Adds RINDS data rule, and set up for woocommerce/woocommerce-admin#4223 # Conflicts: # src/RemoteInboxNotifications/EvaluateAndGetStatus.php * Fix rebase issues # Conflicts: # src/RemoteInboxNotifications/DataRuleProcessor.php * Split product data setup out, use product query # Conflicts: # src/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php * Remove RINDS references * Remove unused products provider * Add validation to the data rule processor * Fix some issues that were failing tests * Remove unused var * Make data setup for products return the data object * Rework product query * Rename $data to $stored_state * Fix condition in query * Add time after wcadmin activation rule (https://github.com/woocommerce/woocommerce-admin/pull/4337) * Add wcadmin active for rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use DAY_IN_SECONDS constant * Fix logic error * Fix test naming Co-authored-by: Rebecca Scott <me@becdetat.com> * Add order count rule (https://github.com/woocommerce/woocommerce-admin/pull/4335) * Order count rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use default provider Co-authored-by: Rebecca Scott <me@becdetat.com> * Use correct 'return' value * Move back to using a SQL query to get the product count as the WC_Product_Query has issues during the product publish lifecycle. The product is initially published with a taxonomy term of uncategorized which isn't accepted by the query's filter. * Change back to using WC_Product_Query, and do prelim init via admin_init action * If there are no specs when running the engine, run the poller first then retry * Fix some failing tests * Don't perform init if we're feature toggled off * Move feature check inside RIN engine class because the feature filter isn't ready during FeaturePlugin init Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-15 23:42:35 +00:00
new stdClass(),
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
new FailingRuleEvaluator()
);
$this->assertEquals( 'pending', $result );
}
/**
* Tests that for a snoozed note evaluating to true without allow_redisplay
* set, status is left as snoozed.
*
* @group fast
*/
public function test_snoozed_note_eval_to_true_without_allow_redisplay() {
$spec = $this->get_spec( false );
$result = EvaluateAndGetStatus::evaluate(
$spec,
'snoozed',
Add stored state between remote inbox notification runs (https://github.com/woocommerce/woocommerce-admin/pull/4260) * Fix comment and convert if..elseif to switch * Take out intermediate function * make ProductsProvider a non-static class * Adds RINDS data rule, and set up for woocommerce/woocommerce-admin#4223 # Conflicts: # src/RemoteInboxNotifications/EvaluateAndGetStatus.php * Fix rebase issues # Conflicts: # src/RemoteInboxNotifications/DataRuleProcessor.php * Split product data setup out, use product query # Conflicts: # src/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php * Remove RINDS references * Remove unused products provider * Add validation to the data rule processor * Fix some issues that were failing tests * Remove unused var * Make data setup for products return the data object * Rework product query * Rename $data to $stored_state * Fix condition in query * Add time after wcadmin activation rule (https://github.com/woocommerce/woocommerce-admin/pull/4337) * Add wcadmin active for rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use DAY_IN_SECONDS constant * Fix logic error * Fix test naming Co-authored-by: Rebecca Scott <me@becdetat.com> * Add order count rule (https://github.com/woocommerce/woocommerce-admin/pull/4335) * Order count rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use default provider Co-authored-by: Rebecca Scott <me@becdetat.com> * Use correct 'return' value * Move back to using a SQL query to get the product count as the WC_Product_Query has issues during the product publish lifecycle. The product is initially published with a taxonomy term of uncategorized which isn't accepted by the query's filter. * Change back to using WC_Product_Query, and do prelim init via admin_init action * If there are no specs when running the engine, run the poller first then retry * Fix some failing tests * Don't perform init if we're feature toggled off * Move feature check inside RIN engine class because the feature filter isn't ready during FeaturePlugin init Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-15 23:42:35 +00:00
new stdClass(),
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
new PassingRuleEvaluator()
);
$this->assertEquals( 'snoozed', $result );
}
/**
* Tests that for a snoozed note evaluating to false without
* allow_redisplay set, status is left as snoozed
*
* @group fast
*/
public function test_snoozed_note_eval_to_false_without_allow_redisplay() {
$spec = $this->get_spec( false );
$result = EvaluateAndGetStatus::evaluate(
$spec,
'snoozed',
Add stored state between remote inbox notification runs (https://github.com/woocommerce/woocommerce-admin/pull/4260) * Fix comment and convert if..elseif to switch * Take out intermediate function * make ProductsProvider a non-static class * Adds RINDS data rule, and set up for woocommerce/woocommerce-admin#4223 # Conflicts: # src/RemoteInboxNotifications/EvaluateAndGetStatus.php * Fix rebase issues # Conflicts: # src/RemoteInboxNotifications/DataRuleProcessor.php * Split product data setup out, use product query # Conflicts: # src/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php * Remove RINDS references * Remove unused products provider * Add validation to the data rule processor * Fix some issues that were failing tests * Remove unused var * Make data setup for products return the data object * Rework product query * Rename $data to $stored_state * Fix condition in query * Add time after wcadmin activation rule (https://github.com/woocommerce/woocommerce-admin/pull/4337) * Add wcadmin active for rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use DAY_IN_SECONDS constant * Fix logic error * Fix test naming Co-authored-by: Rebecca Scott <me@becdetat.com> * Add order count rule (https://github.com/woocommerce/woocommerce-admin/pull/4335) * Order count rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use default provider Co-authored-by: Rebecca Scott <me@becdetat.com> * Use correct 'return' value * Move back to using a SQL query to get the product count as the WC_Product_Query has issues during the product publish lifecycle. The product is initially published with a taxonomy term of uncategorized which isn't accepted by the query's filter. * Change back to using WC_Product_Query, and do prelim init via admin_init action * If there are no specs when running the engine, run the poller first then retry * Fix some failing tests * Don't perform init if we're feature toggled off * Move feature check inside RIN engine class because the feature filter isn't ready during FeaturePlugin init Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-15 23:42:35 +00:00
new stdClass(),
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
new FailingRuleEvaluator()
);
$this->assertEquals( 'snoozed', $result );
}
/**
* Tests that for an actioned note eval to true with allow_redisplay set,
* status is changed to unactioned.
*
* @group fast
*/
public function test_actioned_note_eval_to_true_with_allow_redisplay_set() {
$spec = $this->get_spec( true );
$result = EvaluateAndGetStatus::evaluate(
$spec,
'actioned',
Add stored state between remote inbox notification runs (https://github.com/woocommerce/woocommerce-admin/pull/4260) * Fix comment and convert if..elseif to switch * Take out intermediate function * make ProductsProvider a non-static class * Adds RINDS data rule, and set up for woocommerce/woocommerce-admin#4223 # Conflicts: # src/RemoteInboxNotifications/EvaluateAndGetStatus.php * Fix rebase issues # Conflicts: # src/RemoteInboxNotifications/DataRuleProcessor.php * Split product data setup out, use product query # Conflicts: # src/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php * Remove RINDS references * Remove unused products provider * Add validation to the data rule processor * Fix some issues that were failing tests * Remove unused var * Make data setup for products return the data object * Rework product query * Rename $data to $stored_state * Fix condition in query * Add time after wcadmin activation rule (https://github.com/woocommerce/woocommerce-admin/pull/4337) * Add wcadmin active for rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use DAY_IN_SECONDS constant * Fix logic error * Fix test naming Co-authored-by: Rebecca Scott <me@becdetat.com> * Add order count rule (https://github.com/woocommerce/woocommerce-admin/pull/4335) * Order count rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use default provider Co-authored-by: Rebecca Scott <me@becdetat.com> * Use correct 'return' value * Move back to using a SQL query to get the product count as the WC_Product_Query has issues during the product publish lifecycle. The product is initially published with a taxonomy term of uncategorized which isn't accepted by the query's filter. * Change back to using WC_Product_Query, and do prelim init via admin_init action * If there are no specs when running the engine, run the poller first then retry * Fix some failing tests * Don't perform init if we're feature toggled off * Move feature check inside RIN engine class because the feature filter isn't ready during FeaturePlugin init Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-15 23:42:35 +00:00
new stdClass(),
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
new PassingRuleEvaluator()
);
$this->assertEquals( 'unactioned', $result );
}
/**
* Tests that for an actioned note eval to false with allow_redirect set,
* status is left at actioned.
*
* @group fast
*/
public function test_actioned_note_eval_to_false_with_allow_redisplay_set() {
$spec = $this->get_spec( true );
$result = EvaluateAndGetStatus::evaluate(
$spec,
'actioned',
Add stored state between remote inbox notification runs (https://github.com/woocommerce/woocommerce-admin/pull/4260) * Fix comment and convert if..elseif to switch * Take out intermediate function * make ProductsProvider a non-static class * Adds RINDS data rule, and set up for woocommerce/woocommerce-admin#4223 # Conflicts: # src/RemoteInboxNotifications/EvaluateAndGetStatus.php * Fix rebase issues # Conflicts: # src/RemoteInboxNotifications/DataRuleProcessor.php * Split product data setup out, use product query # Conflicts: # src/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php * Remove RINDS references * Remove unused products provider * Add validation to the data rule processor * Fix some issues that were failing tests * Remove unused var * Make data setup for products return the data object * Rework product query * Rename $data to $stored_state * Fix condition in query * Add time after wcadmin activation rule (https://github.com/woocommerce/woocommerce-admin/pull/4337) * Add wcadmin active for rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use DAY_IN_SECONDS constant * Fix logic error * Fix test naming Co-authored-by: Rebecca Scott <me@becdetat.com> * Add order count rule (https://github.com/woocommerce/woocommerce-admin/pull/4335) * Order count rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use default provider Co-authored-by: Rebecca Scott <me@becdetat.com> * Use correct 'return' value * Move back to using a SQL query to get the product count as the WC_Product_Query has issues during the product publish lifecycle. The product is initially published with a taxonomy term of uncategorized which isn't accepted by the query's filter. * Change back to using WC_Product_Query, and do prelim init via admin_init action * If there are no specs when running the engine, run the poller first then retry * Fix some failing tests * Don't perform init if we're feature toggled off * Move feature check inside RIN engine class because the feature filter isn't ready during FeaturePlugin init Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-15 23:42:35 +00:00
new stdClass(),
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
new FailingRuleEvaluator()
);
$this->assertEquals( 'actioned', $result );
}
/**
* Tests that for a pending note eval to true with allow_redirect
* set, status is changed to unactioned.
*
* @group fast
*/
public function test_pending_note_eval_to_true_with_allow_redirect_set() {
$spec = $this->get_spec( true );
$result = EvaluateAndGetStatus::evaluate(
$spec,
'pending',
Add stored state between remote inbox notification runs (https://github.com/woocommerce/woocommerce-admin/pull/4260) * Fix comment and convert if..elseif to switch * Take out intermediate function * make ProductsProvider a non-static class * Adds RINDS data rule, and set up for woocommerce/woocommerce-admin#4223 # Conflicts: # src/RemoteInboxNotifications/EvaluateAndGetStatus.php * Fix rebase issues # Conflicts: # src/RemoteInboxNotifications/DataRuleProcessor.php * Split product data setup out, use product query # Conflicts: # src/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php * Remove RINDS references * Remove unused products provider * Add validation to the data rule processor * Fix some issues that were failing tests * Remove unused var * Make data setup for products return the data object * Rework product query * Rename $data to $stored_state * Fix condition in query * Add time after wcadmin activation rule (https://github.com/woocommerce/woocommerce-admin/pull/4337) * Add wcadmin active for rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use DAY_IN_SECONDS constant * Fix logic error * Fix test naming Co-authored-by: Rebecca Scott <me@becdetat.com> * Add order count rule (https://github.com/woocommerce/woocommerce-admin/pull/4335) * Order count rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use default provider Co-authored-by: Rebecca Scott <me@becdetat.com> * Use correct 'return' value * Move back to using a SQL query to get the product count as the WC_Product_Query has issues during the product publish lifecycle. The product is initially published with a taxonomy term of uncategorized which isn't accepted by the query's filter. * Change back to using WC_Product_Query, and do prelim init via admin_init action * If there are no specs when running the engine, run the poller first then retry * Fix some failing tests * Don't perform init if we're feature toggled off * Move feature check inside RIN engine class because the feature filter isn't ready during FeaturePlugin init Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-15 23:42:35 +00:00
new stdClass(),
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
new PassingRuleEvaluator()
);
$this->assertEquals( 'unactioned', $result );
}
/**
* Tests that for a pending note eval to false with allow_redirect
* set, status is left as pending.
*
* @group fast
*/
public function test_pending_note_eval_to_false_with_allow_redirect_set() {
$spec = $this->get_spec( true );
$result = EvaluateAndGetStatus::evaluate(
$spec,
'pending',
Add stored state between remote inbox notification runs (https://github.com/woocommerce/woocommerce-admin/pull/4260) * Fix comment and convert if..elseif to switch * Take out intermediate function * make ProductsProvider a non-static class * Adds RINDS data rule, and set up for woocommerce/woocommerce-admin#4223 # Conflicts: # src/RemoteInboxNotifications/EvaluateAndGetStatus.php * Fix rebase issues # Conflicts: # src/RemoteInboxNotifications/DataRuleProcessor.php * Split product data setup out, use product query # Conflicts: # src/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php * Remove RINDS references * Remove unused products provider * Add validation to the data rule processor * Fix some issues that were failing tests * Remove unused var * Make data setup for products return the data object * Rework product query * Rename $data to $stored_state * Fix condition in query * Add time after wcadmin activation rule (https://github.com/woocommerce/woocommerce-admin/pull/4337) * Add wcadmin active for rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use DAY_IN_SECONDS constant * Fix logic error * Fix test naming Co-authored-by: Rebecca Scott <me@becdetat.com> * Add order count rule (https://github.com/woocommerce/woocommerce-admin/pull/4335) * Order count rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use default provider Co-authored-by: Rebecca Scott <me@becdetat.com> * Use correct 'return' value * Move back to using a SQL query to get the product count as the WC_Product_Query has issues during the product publish lifecycle. The product is initially published with a taxonomy term of uncategorized which isn't accepted by the query's filter. * Change back to using WC_Product_Query, and do prelim init via admin_init action * If there are no specs when running the engine, run the poller first then retry * Fix some failing tests * Don't perform init if we're feature toggled off * Move feature check inside RIN engine class because the feature filter isn't ready during FeaturePlugin init Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-15 23:42:35 +00:00
new stdClass(),
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
new FailingRuleEvaluator()
);
$this->assertEquals( 'pending', $result );
}
/**
* Tests that for a spec with no rules the current status is returned.
*
* @group fast
*/
public function test_spec_with_no_rules_returns_current_status() {
$spec = $this->get_no_rules_spec();
$result = EvaluateAndGetStatus::evaluate(
$spec,
'unactioned',
Add stored state between remote inbox notification runs (https://github.com/woocommerce/woocommerce-admin/pull/4260) * Fix comment and convert if..elseif to switch * Take out intermediate function * make ProductsProvider a non-static class * Adds RINDS data rule, and set up for woocommerce/woocommerce-admin#4223 # Conflicts: # src/RemoteInboxNotifications/EvaluateAndGetStatus.php * Fix rebase issues # Conflicts: # src/RemoteInboxNotifications/DataRuleProcessor.php * Split product data setup out, use product query # Conflicts: # src/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php * Remove RINDS references * Remove unused products provider * Add validation to the data rule processor * Fix some issues that were failing tests * Remove unused var * Make data setup for products return the data object * Rework product query * Rename $data to $stored_state * Fix condition in query * Add time after wcadmin activation rule (https://github.com/woocommerce/woocommerce-admin/pull/4337) * Add wcadmin active for rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use DAY_IN_SECONDS constant * Fix logic error * Fix test naming Co-authored-by: Rebecca Scott <me@becdetat.com> * Add order count rule (https://github.com/woocommerce/woocommerce-admin/pull/4335) * Order count rule # Conflicts: # src/RemoteInboxNotifications/GetRuleProcessor.php * Use default provider Co-authored-by: Rebecca Scott <me@becdetat.com> * Use correct 'return' value * Move back to using a SQL query to get the product count as the WC_Product_Query has issues during the product publish lifecycle. The product is initially published with a taxonomy term of uncategorized which isn't accepted by the query's filter. * Change back to using WC_Product_Query, and do prelim init via admin_init action * If there are no specs when running the engine, run the poller first then retry * Fix some failing tests * Don't perform init if we're feature toggled off * Move feature check inside RIN engine class because the feature filter isn't ready during FeaturePlugin init Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-15 23:42:35 +00:00
new stdClass(),
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
new FailingRuleEvaluator()
);
$this->assertEquals( 'unactioned', $result );
}
}