Add "of" preposition to matches any/all/none

[MAILPOET-5257]
This commit is contained in:
Jan Jakes
2023-04-21 12:34:58 +02:00
committed by Aschepikov
parent 761c28ef01
commit a6fcc60de3
3 changed files with 44 additions and 44 deletions

View File

@@ -9,9 +9,9 @@ use MailPoet\Validator\Builder;
use MailPoet\Validator\Schema\ObjectSchema; use MailPoet\Validator\Schema\ObjectSchema;
class EnumArrayFilter implements Filter { class EnumArrayFilter implements Filter {
public const CONDITION_MATCHES_ANY = 'matches-any'; public const CONDITION_MATCHES_ANY_OF = 'matches-any-of';
public const CONDITION_MATCHES_ALL = 'matches-all'; public const CONDITION_MATCHES_ALL_OF = 'matches-all-of';
public const CONDITION_MATCHES_NONE = 'matches-none'; public const CONDITION_MATCHES_NONE_OF = 'matches-none-of';
public function getFieldType(): string { public function getFieldType(): string {
return Field::TYPE_ENUM_ARRAY; return Field::TYPE_ENUM_ARRAY;
@@ -19,9 +19,9 @@ class EnumArrayFilter implements Filter {
public function getConditions(): array { public function getConditions(): array {
return [ return [
self::CONDITION_MATCHES_ANY => __('matches any', 'mailpoet'), self::CONDITION_MATCHES_ANY_OF => __('matches any of', 'mailpoet'),
self::CONDITION_MATCHES_ALL => __('matches all', 'mailpoet'), self::CONDITION_MATCHES_ALL_OF => __('matches all of', 'mailpoet'),
self::CONDITION_MATCHES_NONE => __('matches none', 'mailpoet'), self::CONDITION_MATCHES_NONE_OF => __('matches none of', 'mailpoet'),
]; ];
} }
@@ -46,11 +46,11 @@ class EnumArrayFilter implements Filter {
$filterCount = count($filterValue); $filterCount = count($filterValue);
$matchedCount = count(array_intersect($value, $filterValue)); $matchedCount = count(array_intersect($value, $filterValue));
switch ($data->getCondition()) { switch ($data->getCondition()) {
case self::CONDITION_MATCHES_ANY: case self::CONDITION_MATCHES_ANY_OF:
return $filterCount > 0 && $matchedCount > 0; return $filterCount > 0 && $matchedCount > 0;
case self::CONDITION_MATCHES_ALL: case self::CONDITION_MATCHES_ALL_OF:
return $filterCount > 0 && $matchedCount === count($filterValue); return $filterCount > 0 && $matchedCount === count($filterValue);
case self::CONDITION_MATCHES_NONE: case self::CONDITION_MATCHES_NONE_OF:
return $matchedCount === 0; return $matchedCount === 0;
default: default:
return false; return false;

View File

@@ -171,7 +171,7 @@ class TriggerHandlerTest extends \MailPoetTest {
// automation that doesn't match segments filter // automation that doesn't match segments filter
$unknownId = $segment->getId() + 1; $unknownId = $segment->getId() + 1;
$filter = new Filter('enum_array', 'mailpoet:subscriber:segments', 'matches-any', ['value' => [$unknownId]]); $filter = new Filter('enum_array', 'mailpoet:subscriber:segments', 'matches-any-of', ['value' => [$unknownId]]);
$automation = $this->tester->createAutomation( $automation = $this->tester->createAutomation(
'Will not run', 'Will not run',
new Step('trigger', Step::TYPE_TRIGGER, $trigger->getKey(), [], [], [$filter]) new Step('trigger', Step::TYPE_TRIGGER, $trigger->getKey(), [], [], [$filter])
@@ -182,7 +182,7 @@ class TriggerHandlerTest extends \MailPoetTest {
$this->assertCount(0, $this->automationRunStorage->getAutomationRunsForAutomation($automation)); $this->assertCount(0, $this->automationRunStorage->getAutomationRunsForAutomation($automation));
// matches segments filter // matches segments filter
$filter = new Filter('enum_array', 'mailpoet:subscriber:segments', 'matches-any', ['value' => [$segment->getId()]]); $filter = new Filter('enum_array', 'mailpoet:subscriber:segments', 'matches-any-of', ['value' => [$segment->getId()]]);
$automation = $this->tester->createAutomation( $automation = $this->tester->createAutomation(
'Will run', 'Will run',
new Step('trigger', Step::TYPE_TRIGGER, $trigger->getKey(), [], [], [$filter]) new Step('trigger', Step::TYPE_TRIGGER, $trigger->getKey(), [], [], [$filter])

View File

@@ -13,9 +13,9 @@ class EnumArrayFilterTest extends MailPoetUnitTest {
$this->assertSame('enum_array', $filter->getFieldType()); $this->assertSame('enum_array', $filter->getFieldType());
$this->assertSame([ $this->assertSame([
'matches-any' => 'matches any', 'matches-any-of' => 'matches any of',
'matches-all' => 'matches all', 'matches-all-of' => 'matches all of',
'matches-none' => 'matches none', 'matches-none-of' => 'matches none of',
], $filter->getConditions()); ], $filter->getConditions());
$this->assertSame([ $this->assertSame([
@@ -49,42 +49,42 @@ class EnumArrayFilterTest extends MailPoetUnitTest {
} }
public function testMatchesAnyCondition(): void { public function testMatchesAnyCondition(): void {
$this->assertMatches('matches-any', [1, 2, 3], [1]); $this->assertMatches('matches-any-of', [1, 2, 3], [1]);
$this->assertMatches('matches-any', [1, 2, 3], [1, 3, 9]); $this->assertMatches('matches-any-of', [1, 2, 3], [1, 3, 9]);
$this->assertMatches('matches-any', [1], [1, 1, 1]); $this->assertMatches('matches-any-of', [1], [1, 1, 1]);
$this->assertMatches('matches-any', [1, 1, 1], [1]); $this->assertMatches('matches-any-of', [1, 1, 1], [1]);
$this->assertNotMatches('matches-any', [], []); $this->assertNotMatches('matches-any-of', [], []);
$this->assertNotMatches('matches-any', [], [1]); $this->assertNotMatches('matches-any-of', [], [1]);
$this->assertNotMatches('matches-any', [1, 2, 3], []); $this->assertNotMatches('matches-any-of', [1, 2, 3], []);
$this->assertNotMatches('matches-any', [1, 2, 3], [7, 8, 9]); $this->assertNotMatches('matches-any-of', [1, 2, 3], [7, 8, 9]);
} }
public function testMatchesAllCondition(): void { public function testMatchesAllCondition(): void {
$this->assertMatches('matches-all', [1], [1]); $this->assertMatches('matches-all-of', [1], [1]);
$this->assertMatches('matches-all', [1, 2], [2, 1]); $this->assertMatches('matches-all-of', [1, 2], [2, 1]);
$this->assertMatches('matches-all', [1, 2], [2, 1, 3]); $this->assertMatches('matches-all-of', [1, 2], [2, 1, 3]);
$this->assertMatches('matches-all', [1], [1, 1, 1]); $this->assertMatches('matches-all-of', [1], [1, 1, 1]);
$this->assertMatches('matches-all', [1, 1, 1], [1]); $this->assertMatches('matches-all-of', [1, 1, 1], [1]);
$this->assertNotMatches('matches-all', [], []); $this->assertNotMatches('matches-all-of', [], []);
$this->assertNotMatches('matches-all', [], [1]); $this->assertNotMatches('matches-all-of', [], [1]);
$this->assertNotMatches('matches-all', [1, 2, 3], []); $this->assertNotMatches('matches-all-of', [1, 2, 3], []);
$this->assertNotMatches('matches-all', [1, 2, 3], [2, 3, 4]); $this->assertNotMatches('matches-all-of', [1, 2, 3], [2, 3, 4]);
} }
public function testMatchesNoneCondition(): void { public function testMatchesNoneCondition(): void {
$this->assertMatches('matches-none', [], []); $this->assertMatches('matches-none-of', [], []);
$this->assertMatches('matches-none', [], [1]); $this->assertMatches('matches-none-of', [], [1]);
$this->assertMatches('matches-none', [1], []); $this->assertMatches('matches-none-of', [1], []);
$this->assertMatches('matches-none', [1], [2]); $this->assertMatches('matches-none-of', [1], [2]);
$this->assertMatches('matches-none', [1, 2, 3], []); $this->assertMatches('matches-none-of', [1, 2, 3], []);
$this->assertMatches('matches-none', [1, 2, 3], [4, 5, 6]); $this->assertMatches('matches-none-of', [1, 2, 3], [4, 5, 6]);
$this->assertMatches('matches-none', [1], [2, 2, 2]); $this->assertMatches('matches-none-of', [1], [2, 2, 2]);
$this->assertMatches('matches-none', [1, 1, 1], [2]); $this->assertMatches('matches-none-of', [1, 1, 1], [2]);
$this->assertNotMatches('matches-none', [1], [1]); $this->assertNotMatches('matches-none-of', [1], [1]);
$this->assertNotMatches('matches-none', [1, 2, 3], [2]); $this->assertNotMatches('matches-none-of', [1, 2, 3], [2]);
$this->assertNotMatches('matches-none', [1, 2, 3], [3, 4, 5]); $this->assertNotMatches('matches-none-of', [1, 2, 3], [3, 4, 5]);
$this->assertNotMatches('matches-none', [1], [1, 1, 1]); $this->assertNotMatches('matches-none-of', [1], [1, 1, 1]);
$this->assertNotMatches('matches-none', [1, 1, 1], [1]); $this->assertNotMatches('matches-none-of', [1, 1, 1], [1]);
} }
public function testUnknownCondition(): void { public function testUnknownCondition(): void {