Revert valid operator methods back to instance methods
MAILPOET-4989
This commit is contained in:
committed by
Aschepikov
parent
8de46db560
commit
4d5b4885fe
@ -2,6 +2,7 @@
|
||||
|
||||
namespace MailPoet\Segments\DynamicSegments;
|
||||
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Entities\DynamicSegmentFilterData;
|
||||
use MailPoet\Segments\DynamicSegments\Exceptions\InvalidFilterException;
|
||||
use MailPoet\Segments\DynamicSegments\Filters\AutomationsEvents;
|
||||
@ -35,13 +36,21 @@ class FilterDataMapper {
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
/** @var DateFilterHelper */
|
||||
private $dateFilterHelper;
|
||||
|
||||
public function __construct(
|
||||
WPFunctions $wp = null
|
||||
WPFunctions $wp = null,
|
||||
DateFilterHelper $dateFilterHelper = null
|
||||
) {
|
||||
if (!$wp) {
|
||||
$wp = WPFunctions::get();
|
||||
}
|
||||
if (!$dateFilterHelper) {
|
||||
$dateFilterHelper = ContainerWrapper::getInstance()->get(DateFilterHelper::class);
|
||||
}
|
||||
$this->wp = $wp;
|
||||
$this->dateFilterHelper = $dateFilterHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,7 +237,7 @@ class FilterDataMapper {
|
||||
if (empty($data['operator'])) {
|
||||
throw new InvalidFilterException('Missing operator', InvalidFilterException::MISSING_OPERATOR);
|
||||
}
|
||||
if (!in_array($data['operator'], DateFilterHelper::getValidOperators())) {
|
||||
if (!in_array($data['operator'], $this->dateFilterHelper->getValidOperators())) {
|
||||
throw new InvalidFilterException('Invalid operator', InvalidFilterException::MISSING_OPERATOR);
|
||||
}
|
||||
return new DynamicSegmentFilterData(DynamicSegmentFilterData::TYPE_USER_ROLE, $data['action'], [
|
||||
|
@ -16,14 +16,14 @@ class DateFilterHelper {
|
||||
const IN_THE_LAST = 'inTheLast';
|
||||
const NOT_IN_THE_LAST = 'notInTheLast';
|
||||
|
||||
public static function getValidOperators(): array {
|
||||
public function getValidOperators(): array {
|
||||
return array_merge(
|
||||
self::getAbsoluteDateOperators(),
|
||||
self::getRelativeDateOperators()
|
||||
$this->getAbsoluteDateOperators(),
|
||||
$this->getRelativeDateOperators()
|
||||
);
|
||||
}
|
||||
|
||||
public static function getAbsoluteDateOperators(): array {
|
||||
public function getAbsoluteDateOperators(): array {
|
||||
return [
|
||||
self::BEFORE,
|
||||
self::AFTER,
|
||||
@ -34,7 +34,7 @@ class DateFilterHelper {
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRelativeDateOperators(): array {
|
||||
public function getRelativeDateOperators(): array {
|
||||
return [
|
||||
self::IN_THE_LAST,
|
||||
self::NOT_IN_THE_LAST,
|
||||
@ -68,7 +68,7 @@ class DateFilterHelper {
|
||||
public function getOperatorFromFilter(DynamicSegmentFilterEntity $filter): string {
|
||||
$filterData = $filter->getFilterData();
|
||||
$operator = $filterData->getParam('operator');
|
||||
if (!is_string($operator) || !in_array($operator, self::getValidOperators())) {
|
||||
if (!is_string($operator) || !in_array($operator, $this->getValidOperators())) {
|
||||
throw new InvalidFilterException('Incorrect value for operator', InvalidFilterException::MISSING_VALUE);
|
||||
}
|
||||
return $operator;
|
||||
|
@ -5,6 +5,7 @@ namespace MailPoet\Segments\DynamicSegments;
|
||||
use MailPoet\Entities\CustomFieldEntity;
|
||||
use MailPoet\Entities\DynamicSegmentFilterData;
|
||||
use MailPoet\Segments\DynamicSegments\Exceptions\InvalidFilterException;
|
||||
use MailPoet\Segments\DynamicSegments\Filters\DateFilterHelper;
|
||||
use MailPoet\Segments\DynamicSegments\Filters\EmailAction;
|
||||
use MailPoet\Segments\DynamicSegments\Filters\EmailActionClickAny;
|
||||
use MailPoet\Segments\DynamicSegments\Filters\EmailOpensAbsoluteCountAction;
|
||||
@ -32,7 +33,12 @@ class FilterDataMapperTest extends \MailPoetUnitTest {
|
||||
$wp = $this->makeEmpty(WPFunctions::class, [
|
||||
'hasFilter' => false,
|
||||
]);
|
||||
$this->mapper = new FilterDataMapper($wp);
|
||||
|
||||
$filterHelper = $this->getMockBuilder(DateFilterHelper::class)
|
||||
->setMethodsExcept(['getAbsoluteDateOperators', 'getRelativeDateOperators', 'getValidOperators'])
|
||||
->getMock();
|
||||
|
||||
$this->mapper = new FilterDataMapper($wp, $filterHelper);
|
||||
}
|
||||
|
||||
public function testItChecksFiltersArePresent(): void {
|
||||
|
Reference in New Issue
Block a user