2020-06-05 01:51:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Or rule processor tests.
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin\Tests\RemoteInboxNotifications
|
2020-06-05 01:51:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\OrRuleProcessor;
|
|
|
|
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RuleEvaluator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class WC_Tests_RemoteInboxNotifications_OrRuleProcessor
|
|
|
|
*/
|
|
|
|
class WC_Tests_RemoteInboxNotifications_OrRuleProcessor extends WC_Unit_Test_Case {
|
|
|
|
/**
|
|
|
|
* Both operands evaluating to false and ORed together evaluates to false.
|
|
|
|
*
|
|
|
|
* @group fast
|
|
|
|
*/
|
|
|
|
public function test_spec_fails_for_both_operands_false() {
|
|
|
|
$get_rule_processor = new MockGetRuleProcessor();
|
|
|
|
$processor = new OrRuleProcessor(
|
|
|
|
new RuleEvaluator(
|
|
|
|
$get_rule_processor
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$rule = json_decode(
|
|
|
|
'{
|
|
|
|
"type": "or",
|
|
|
|
"operands": [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "publish_after_time",
|
|
|
|
"publish_after": "2020-04-24 11:00:00"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "publish_after_time",
|
|
|
|
"publish_after": "2020-04-24 11:00:00"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
2020-06-15 23:42:35 +00:00
|
|
|
$result = $processor->process( $rule, new stdClass() );
|
2020-06-05 01:51:25 +00:00
|
|
|
|
|
|
|
$this->assertEquals( false, $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* First operand evaluating to true and ORed together evaluates to true.
|
|
|
|
*
|
|
|
|
* @group fast
|
|
|
|
*/
|
|
|
|
public function test_spec_passes_for_first_operand_true() {
|
|
|
|
$get_rule_processor = new MockGetRuleProcessor();
|
|
|
|
$processor = new OrRuleProcessor(
|
|
|
|
new RuleEvaluator(
|
|
|
|
$get_rule_processor
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$rule = json_decode(
|
|
|
|
'{
|
|
|
|
"type": "or",
|
|
|
|
"operands": [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "publish_after_time",
|
|
|
|
"publish_after": "2020-04-24 09:00:00"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "publish_after_time",
|
|
|
|
"publish_after": "2020-04-24 11:00:00"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
2020-06-15 23:42:35 +00:00
|
|
|
$result = $processor->process( $rule, new stdClass() );
|
2020-06-05 01:51:25 +00:00
|
|
|
|
|
|
|
$this->assertEquals( true, $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Second operand evaluating to true and ORed together evaluates to true.
|
|
|
|
*
|
|
|
|
* @group fast
|
|
|
|
*/
|
|
|
|
public function test_spec_passes_for_second_operand_true() {
|
|
|
|
$get_rule_processor = new MockGetRuleProcessor();
|
|
|
|
$processor = new OrRuleProcessor(
|
|
|
|
new RuleEvaluator(
|
|
|
|
$get_rule_processor
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$rule = json_decode(
|
|
|
|
'{
|
|
|
|
"type": "or",
|
|
|
|
"operands": [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "publish_after_time",
|
|
|
|
"publish_after": "2020-04-24 11:00:00"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "publish_after_time",
|
|
|
|
"publish_after": "2020-04-24 09:00:00"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
2020-06-15 23:42:35 +00:00
|
|
|
$result = $processor->process( $rule, new stdClass() );
|
2020-06-05 01:51:25 +00:00
|
|
|
|
|
|
|
$this->assertEquals( true, $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Both operands evaluating to true and ORed together evaluates to true.
|
|
|
|
*
|
|
|
|
* @group fast
|
|
|
|
*/
|
|
|
|
public function test_spec_passes_for_both_operands_true() {
|
|
|
|
$get_rule_processor = new MockGetRuleProcessor();
|
|
|
|
$processor = new OrRuleProcessor(
|
|
|
|
new RuleEvaluator(
|
|
|
|
$get_rule_processor
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$rule = json_decode(
|
|
|
|
'{
|
|
|
|
"type": "or",
|
|
|
|
"operands": [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "publish_after_time",
|
|
|
|
"publish_after": "2020-04-24 09:00:00"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "publish_after_time",
|
|
|
|
"publish_after": "2020-04-24 09:00:00"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
2020-06-15 23:42:35 +00:00
|
|
|
$result = $processor->process( $rule, new stdClass() );
|
2020-06-05 01:51:25 +00:00
|
|
|
|
|
|
|
$this->assertEquals( true, $result );
|
|
|
|
}
|
|
|
|
}
|