refactoring
This commit is contained in:
+2
-2
@@ -27,7 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Select\Applier\Appliers;
|
||||
namespace Espo\Core\Select\AccessControl;
|
||||
|
||||
use Espo\Core\Select\OrmSelectBuilder;
|
||||
|
||||
@@ -43,7 +43,7 @@ use Espo\{
|
||||
Entities\User,
|
||||
};
|
||||
|
||||
class AccessControlFilter
|
||||
class Applier
|
||||
{
|
||||
private string $entityType;
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
|
||||
namespace Espo\Core\Select\Applier\Appliers;
|
||||
|
||||
use Espo\{
|
||||
ORM\Query\SelectBuilder as QueryBuilder,
|
||||
};
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Limit
|
||||
{
|
||||
|
||||
@@ -29,6 +29,18 @@
|
||||
|
||||
namespace Espo\Core\Select\Applier;
|
||||
|
||||
use Espo\Core\Select\Text\Applier as TextFilterApplier;
|
||||
use Espo\Core\Select\AccessControl\Applier as AccessControlFilterApplier;
|
||||
use Espo\Core\Select\Where\Applier as WhereApplier;
|
||||
use Espo\Core\Select\Select\Applier as SelectApplier;
|
||||
use Espo\Core\Select\Primary\Applier as PrimaryFilterApplier;
|
||||
use Espo\Core\Select\Order\Applier as OrderApplier;
|
||||
use Espo\Core\Select\Bool\Applier as BoolFilterListApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\Additional as AdditionalApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\Limit as LimitApplier;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Core\{
|
||||
InjectableFactory,
|
||||
Utils\Metadata,
|
||||
@@ -44,23 +56,30 @@ use Espo\Entities\User;
|
||||
class Factory
|
||||
{
|
||||
public const SELECT = 'select';
|
||||
|
||||
public const WHERE = 'where';
|
||||
|
||||
public const ORDER = 'order';
|
||||
|
||||
public const LIMIT = 'limit';
|
||||
|
||||
public const ACCESS_CONTROL_FILTER = 'accessControlFilter';
|
||||
|
||||
public const TEXT_FILTER = 'textFilter';
|
||||
|
||||
public const PRIMARY_FILTER = 'primaryFilter';
|
||||
|
||||
public const BOOL_FILTER_LIST = 'boolFilterList';
|
||||
|
||||
public const ADDITIONAL = 'additional';
|
||||
|
||||
/**
|
||||
* @var array<string,class-string<object>>
|
||||
*/
|
||||
private array $defaultClassNameMap = [
|
||||
self::TEXT_FILTER => TextFilterApplier::class,
|
||||
self::ACCESS_CONTROL_FILTER => AccessControlFilterApplier::class,
|
||||
self::WHERE => WhereApplier::class,
|
||||
self::SELECT => SelectApplier::class,
|
||||
self::PRIMARY_FILTER => PrimaryFilterApplier::class,
|
||||
self::ORDER => OrderApplier::class,
|
||||
self::BOOL_FILTER_LIST => BoolFilterListApplier::class,
|
||||
self::ADDITIONAL => AdditionalApplier::class,
|
||||
self::LIMIT => LimitApplier::class,
|
||||
];
|
||||
|
||||
private InjectableFactory $injectableFactory;
|
||||
|
||||
private Metadata $metadata;
|
||||
@@ -77,7 +96,7 @@ class Factory
|
||||
$this->selectManagerFactory = $selectManagerFactory;
|
||||
}
|
||||
|
||||
public function create(string $entityType, User $user, string $type): object
|
||||
private function create(string $entityType, User $user, string $type): object
|
||||
{
|
||||
/** @var class-string */
|
||||
$className = $this->metadata->get(
|
||||
@@ -108,14 +127,69 @@ class Factory
|
||||
return $this->injectableFactory->createWithBinding($className, $bindingContainer);
|
||||
}
|
||||
|
||||
public function createWhere(string $entityType, User $user): WhereApplier
|
||||
{
|
||||
/** @var WhereApplier */
|
||||
return $this->create($entityType, $user, self::WHERE);
|
||||
}
|
||||
|
||||
public function createSelect(string $entityType, User $user): SelectApplier
|
||||
{
|
||||
/** @var SelectApplier */
|
||||
return $this->create($entityType, $user, self::SELECT);
|
||||
}
|
||||
|
||||
public function createOrder(string $entityType, User $user): OrderApplier
|
||||
{
|
||||
/** @var OrderApplier */
|
||||
return $this->create($entityType, $user, self::ORDER);
|
||||
}
|
||||
|
||||
public function createLimit(string $entityType, User $user): LimitApplier
|
||||
{
|
||||
/** @var LimitApplier */
|
||||
return $this->create($entityType, $user, self::LIMIT);
|
||||
}
|
||||
|
||||
public function createAccessControlFilter(string $entityType, User $user): AccessControlFilterApplier
|
||||
{
|
||||
/** @var AccessControlFilterApplier */
|
||||
return $this->create($entityType, $user, self::ACCESS_CONTROL_FILTER);
|
||||
}
|
||||
|
||||
public function createTextFilter(string $entityType, User $user): TextFilterApplier
|
||||
{
|
||||
/** @var TextFilterApplier */
|
||||
return $this->create($entityType, $user, self::TEXT_FILTER);
|
||||
}
|
||||
|
||||
public function createPrimaryFilter(string $entityType, User $user): PrimaryFilterApplier
|
||||
{
|
||||
/** @var PrimaryFilterApplier */
|
||||
return $this->create($entityType, $user, self::PRIMARY_FILTER);
|
||||
}
|
||||
|
||||
public function createBoolFilterList(string $entityType, User $user): BoolFilterListApplier
|
||||
{
|
||||
/** @var BoolFilterListApplier */
|
||||
return $this->create($entityType, $user, self::BOOL_FILTER_LIST);
|
||||
}
|
||||
|
||||
public function createAdditional(string $entityType, User $user): AdditionalApplier
|
||||
{
|
||||
/** @var AdditionalApplier */
|
||||
return $this->create($entityType, $user, self::ADDITIONAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<object>
|
||||
*/
|
||||
protected function getDefaultClassName(string $type): string
|
||||
private function getDefaultClassName(string $type): string
|
||||
{
|
||||
/** @var class-string<object> */
|
||||
$className = 'Espo\\Core\\Select\\Applier\Appliers\\' . ucfirst($type);
|
||||
if (array_key_exists($type, $this->defaultClassNameMap)) {
|
||||
return $this->defaultClassNameMap[$type];
|
||||
}
|
||||
|
||||
return $className;
|
||||
throw new Error("Applier `$type` does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -27,7 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Select\Applier\Appliers;
|
||||
namespace Espo\Core\Select\Bool;
|
||||
|
||||
use Espo\Core\Select\OrmSelectBuilder;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
@@ -41,15 +41,15 @@ use Espo\ORM\Query\Part\WhereClause;
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
class BoolFilterList
|
||||
class Applier
|
||||
{
|
||||
protected string $entityType;
|
||||
private string $entityType;
|
||||
|
||||
protected User $user;
|
||||
private User $user;
|
||||
|
||||
protected SelectManager $selectManager;
|
||||
private SelectManager $selectManager;
|
||||
|
||||
protected BoolFilterFactory $boolFilterFactory;
|
||||
private BoolFilterFactory $boolFilterFactory;
|
||||
|
||||
public function __construct(
|
||||
string $entityType,
|
||||
@@ -89,7 +89,7 @@ class BoolFilterList
|
||||
);
|
||||
}
|
||||
|
||||
protected function applyBoolFilter(
|
||||
private function applyBoolFilter(
|
||||
QueryBuilder $queryBuilder,
|
||||
OrGroupBuilder $orGroupBuilder,
|
||||
string $filterName
|
||||
+2
-2
@@ -27,7 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Select\Applier\Appliers;
|
||||
namespace Espo\Core\Select\Order;
|
||||
|
||||
use Espo\ORM\Query\Part\OrderList;
|
||||
|
||||
@@ -44,7 +44,7 @@ use Espo\Core\{
|
||||
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
class Order
|
||||
class Applier
|
||||
{
|
||||
private string $entityType;
|
||||
|
||||
+11
-16
@@ -27,30 +27,25 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Select\Applier\Appliers;
|
||||
namespace Espo\Core\Select\Primary;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Select\SelectManager;
|
||||
use Espo\Core\Select\Primary\FilterFactory;
|
||||
use Espo\Core\Select\OrmSelectBuilder;
|
||||
|
||||
use Espo\Core\{
|
||||
Exceptions\Error,
|
||||
Select\SelectManager,
|
||||
Select\Primary\FilterFactory,
|
||||
};
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
use Espo\Entities\User;
|
||||
|
||||
use Espo\{
|
||||
ORM\Query\SelectBuilder as QueryBuilder,
|
||||
Entities\User,
|
||||
};
|
||||
|
||||
class PrimaryFilter
|
||||
class Applier
|
||||
{
|
||||
protected string $entityType;
|
||||
private string $entityType;
|
||||
|
||||
protected User $user;
|
||||
private User $user;
|
||||
|
||||
protected SelectManager $selectManager;
|
||||
private SelectManager $selectManager;
|
||||
|
||||
protected FilterFactory $primaryFilterFactory;
|
||||
private FilterFactory $primaryFilterFactory;
|
||||
|
||||
public function __construct(
|
||||
string $entityType,
|
||||
+11
-20
@@ -27,7 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Select\Applier\Appliers;
|
||||
namespace Espo\Core\Select\Select;
|
||||
|
||||
use Espo\Core\{
|
||||
Select\SearchParams,
|
||||
@@ -41,12 +41,12 @@ use Espo\{
|
||||
Entities\User,
|
||||
};
|
||||
|
||||
class Select
|
||||
class Applier
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $aclAttributeList = [
|
||||
private $aclAttributeList = [
|
||||
'assignedUserId',
|
||||
'createdById',
|
||||
];
|
||||
@@ -54,29 +54,20 @@ class Select
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $aclPortalAttributeList = [
|
||||
private $aclPortalAttributeList = [
|
||||
'assignedUserId',
|
||||
'createdById',
|
||||
'contactId',
|
||||
'accountId',
|
||||
];
|
||||
|
||||
protected string $entityType;
|
||||
private string $entityType;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* @var FieldUtil
|
||||
*/
|
||||
protected $fieldUtil;
|
||||
private FieldUtil $fieldUtil;
|
||||
|
||||
/**
|
||||
* @var MetadataProvider
|
||||
*/
|
||||
protected $metadataProvider;
|
||||
private MetadataProvider $metadataProvider;
|
||||
|
||||
public function __construct(
|
||||
string $entityType,
|
||||
@@ -105,7 +96,7 @@ class Select
|
||||
* @param string[] $attributeList
|
||||
* @return array<int,array{string,string}|string>
|
||||
*/
|
||||
protected function prepareAttributeList(array $attributeList, SearchParams $searchParams): array
|
||||
private function prepareAttributeList(array $attributeList, SearchParams $searchParams): array
|
||||
{
|
||||
$limit = $searchParams->getMaxTextAttributeLength();
|
||||
|
||||
@@ -138,7 +129,7 @@ class Select
|
||||
/**
|
||||
* @return ?string[]
|
||||
*/
|
||||
protected function getSelectAttributeList(SearchParams $searchParams): ?array
|
||||
private function getSelectAttributeList(SearchParams $searchParams): ?array
|
||||
{
|
||||
$passedAttributeList = $searchParams->getSelect();
|
||||
|
||||
@@ -217,7 +208,7 @@ class Select
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getAclAttributeList(): array
|
||||
private function getAclAttributeList(): array
|
||||
{
|
||||
if ($this->user->isPortal()) {
|
||||
return
|
||||
@@ -30,21 +30,21 @@
|
||||
namespace Espo\Core\Select;
|
||||
|
||||
use Espo\Core\Select\Applier\Factory as ApplierFactory;
|
||||
use Espo\Core\Select\Applier\Appliers\Where as WhereApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\Select as SelectApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\Order as OrderApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\Limit as LimitApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\AccessControlFilter as AccessControlFilterApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\PrimaryFilter as PrimaryFilterApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\BoolFilterList as BoolFilterListApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\TextFilter as TextFilterApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\Additional as AdditionalApplier;
|
||||
|
||||
use Espo\Core\Select\Where\Params as WhereParams;
|
||||
use Espo\Core\Select\Where\Item as WhereItem;
|
||||
use Espo\Core\Select\Order\Params as OrderParams;
|
||||
use Espo\Core\Select\Text\FilterParams as TextFilterParams;
|
||||
|
||||
use Espo\Core\Select\Where\Applier as WhereApplier;
|
||||
use Espo\Core\Select\Select\Applier as SelectApplier;
|
||||
use Espo\Core\Select\Order\Applier as OrderApplier;
|
||||
use Espo\Core\Select\AccessControl\Applier as AccessControlFilterApplier;
|
||||
use Espo\Core\Select\Primary\Applier as PrimaryFilterApplier;
|
||||
use Espo\Core\Select\Bool\Applier as BoolFilterListApplier;
|
||||
use Espo\Core\Select\Text\Applier as TextFilterApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\Limit as LimitApplier;
|
||||
use Espo\Core\Select\Applier\Appliers\Additional as AdditionalApplier;
|
||||
|
||||
use Espo\ORM\Query\Select as Query;
|
||||
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
|
||||
|
||||
@@ -525,107 +525,62 @@ class SelectBuilder
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var WhereApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
$this->user,
|
||||
ApplierFactory::WHERE
|
||||
);
|
||||
return $this->applierFactory->createWhere($this->entityType, $this->user);
|
||||
}
|
||||
|
||||
private function createSelectApplier(): SelectApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var SelectApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
$this->user,
|
||||
ApplierFactory::SELECT
|
||||
);
|
||||
return $this->applierFactory->createSelect($this->entityType, $this->user);
|
||||
}
|
||||
|
||||
private function createOrderApplier(): OrderApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var OrderApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
$this->user,
|
||||
ApplierFactory::ORDER
|
||||
);
|
||||
return $this->applierFactory->createOrder($this->entityType, $this->user);
|
||||
}
|
||||
|
||||
private function createLimitApplier(): LimitApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var LimitApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
$this->user,
|
||||
ApplierFactory::LIMIT
|
||||
);
|
||||
return $this->applierFactory->createLimit($this->entityType, $this->user);
|
||||
}
|
||||
|
||||
private function createAccessControlFilterApplier(): AccessControlFilterApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var AccessControlFilterApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
$this->user,
|
||||
ApplierFactory::ACCESS_CONTROL_FILTER
|
||||
);
|
||||
return $this->applierFactory->createAccessControlFilter($this->entityType, $this->user);
|
||||
}
|
||||
|
||||
private function createTextFilterApplier(): TextFilterApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var TextFilterApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
$this->user,
|
||||
ApplierFactory::TEXT_FILTER
|
||||
);
|
||||
return $this->applierFactory->createTextFilter($this->entityType, $this->user);
|
||||
}
|
||||
|
||||
private function createPrimaryFilterApplier(): PrimaryFilterApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var PrimaryFilterApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
$this->user,
|
||||
ApplierFactory::PRIMARY_FILTER
|
||||
);
|
||||
return $this->applierFactory->createPrimaryFilter($this->entityType, $this->user);
|
||||
}
|
||||
|
||||
private function createBoolFilterListApplier(): BoolFilterListApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var BoolFilterListApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
$this->user,
|
||||
ApplierFactory::BOOL_FILTER_LIST
|
||||
);
|
||||
return $this->applierFactory->createBoolFilterList($this->entityType, $this->user);
|
||||
}
|
||||
|
||||
private function createAdditionalApplier(): AdditionalApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var AdditionalApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
$this->user,
|
||||
ApplierFactory::ADDITIONAL
|
||||
);
|
||||
return $this->applierFactory->createAdditional($this->entityType, $this->user);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Select\Applier\Appliers;
|
||||
namespace Espo\Core\Select\Text;
|
||||
|
||||
use Espo\Core\Select\Text\MetadataProvider;
|
||||
use Espo\Core\Select\Text\FilterParams;
|
||||
@@ -44,7 +44,7 @@ use Espo\ORM\Query\Part\WhereItem;
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
class TextFilter
|
||||
class Applier
|
||||
{
|
||||
/** @todo Move to metadata. */
|
||||
private ?int $fullTextRelevanceThreshold = null;
|
||||
+6
-6
@@ -27,7 +27,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Select\Applier\Appliers;
|
||||
namespace Espo\Core\Select\Where;
|
||||
|
||||
use Espo\Core\{
|
||||
Select\Where\Params,
|
||||
@@ -41,15 +41,15 @@ use Espo\{
|
||||
Entities\User,
|
||||
};
|
||||
|
||||
class Where
|
||||
class Applier
|
||||
{
|
||||
protected string $entityType;
|
||||
private string $entityType;
|
||||
|
||||
protected User $user;
|
||||
private User $user;
|
||||
|
||||
protected ConverterFactory $converterFactory;
|
||||
private ConverterFactory $converterFactory;
|
||||
|
||||
protected CheckerFactory $checkerFactory;
|
||||
private CheckerFactory $checkerFactory;
|
||||
|
||||
public function __construct(
|
||||
string $entityType,
|
||||
@@ -31,7 +31,7 @@ namespace tests\unit\Espo\Core\Select\Applier\Appliers;
|
||||
|
||||
use Espo\Core\{
|
||||
Exceptions\Error,
|
||||
Select\Applier\Appliers\AccessControlFilter as AccessControlFilterApplier,
|
||||
Select\AccessControl\Applier as AccessControlFilterApplier,
|
||||
Select\SelectManager,
|
||||
Select\AccessControl\FilterFactory as AccessControlFilterFactory,
|
||||
Select\AccessControl\FilterResolverFactory as AccessControlFilterResolverFactory,
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace tests\unit\Espo\Core\Select\Applier\Appliers;
|
||||
|
||||
use Espo\Core\{
|
||||
Exceptions\Error,
|
||||
Select\Applier\Appliers\BoolFilterList as BoolFilterListApplier,
|
||||
Select\Bool\Applier as BoolFilterListApplier,
|
||||
Select\Bool\FilterFactory as BoolFilterFactory,
|
||||
Select\Bool\Filter as BoolFilter,
|
||||
Select\SelectManager,
|
||||
|
||||
@@ -34,7 +34,7 @@ use Espo\ORM\Query\Part\Order;
|
||||
|
||||
use Espo\Core\{
|
||||
Exceptions\Error,
|
||||
Select\Applier\Appliers\Order as OrderApplier,
|
||||
Select\Order\Applier as OrderApplier,
|
||||
Select\SearchParams,
|
||||
Select\Order\Params as OrderParams,
|
||||
Select\Order\Item,
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace tests\unit\Espo\Core\Select\Applier\Appliers;
|
||||
|
||||
use Espo\Core\{
|
||||
Exceptions\Error,
|
||||
Select\Applier\Appliers\PrimaryFilter as PrimaryFilterApplier,
|
||||
Select\Primary\Applier as PrimaryFilterApplier,
|
||||
Select\Primary\FilterFactory as PrimaryFilterFactory,
|
||||
Select\Primary\Filter as PrimaryFilter,
|
||||
Select\SelectManager,
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
namespace tests\unit\Espo\Core\Select\Applier\Appliers;
|
||||
|
||||
use Espo\Core\{
|
||||
Select\Applier\Appliers\Select as SelectApplier,
|
||||
Select\Select\Applier as SelectApplier,
|
||||
Select\SearchParams,
|
||||
Select\Select\MetadataProvider,
|
||||
Utils\FieldUtil,
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
namespace tests\unit\Espo\Core\Select\Applier\Appliers;
|
||||
|
||||
use Espo\Core\{
|
||||
Select\Applier\Appliers\TextFilter as TextFilterApplier,
|
||||
Select\Text\Applier as TextFilterApplier,
|
||||
Utils\Config,
|
||||
Select\Text\MetadataProvider,
|
||||
Select\Text\FilterParams,
|
||||
|
||||
@@ -36,7 +36,7 @@ use Espo\Core\{
|
||||
Select\Where\ConverterFactory,
|
||||
Select\Where\CheckerFactory,
|
||||
Select\Where\Item as WhereItem,
|
||||
Select\Applier\Appliers\Where as WhereApplier,
|
||||
Select\Where\Applier as WhereApplier,
|
||||
};
|
||||
|
||||
use Espo\{
|
||||
|
||||
@@ -33,14 +33,14 @@ use Espo\Core\{
|
||||
Select\Applier\Factory as ApplierFactory,
|
||||
Select\SelectManagerFactory,
|
||||
Select\SelectManager,
|
||||
Select\Applier\Appliers\Where as WhereApplier,
|
||||
Select\Applier\Appliers\Select as SelectApplier,
|
||||
Select\Applier\Appliers\Order as OrderApplier,
|
||||
Select\Where\Applier as WhereApplier,
|
||||
Select\Select\Applier as SelectApplier,
|
||||
Select\Order\Applier as OrderApplier,
|
||||
Select\Applier\Appliers\Limit as LimitApplier,
|
||||
Select\Applier\Appliers\AccessControlFilter as AccessControlFilterApplier,
|
||||
Select\Applier\Appliers\PrimaryFilter as PrimaryFilterApplier,
|
||||
Select\Applier\Appliers\BoolFilterList as BoolFilterListApplier,
|
||||
Select\Applier\Appliers\TextFilter as TextFilterApplier,
|
||||
Select\AccessControl\Applier as AccessControlFilterApplier,
|
||||
Select\Primary\Applier as PrimaryFilterApplier,
|
||||
Select\Bool\Applier as BoolFilterListApplier,
|
||||
Select\Text\Applier as TextFilterApplier,
|
||||
Select\Applier\Appliers\Additional as AdditionalApplier,
|
||||
Utils\Metadata,
|
||||
InjectableFactory,
|
||||
@@ -55,7 +55,7 @@ use Espo\{
|
||||
|
||||
class FactoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected function setUp() : void
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->injectableFactory = $this->createMock(InjectableFactory::class);
|
||||
$this->metadata = $this->createMock(Metadata::class);
|
||||
@@ -73,50 +73,53 @@ class FactoryTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
public function testCreate1()
|
||||
{
|
||||
$this->prepareFactoryTest(null, SelectApplier::class, ApplierFactory::SELECT);
|
||||
$this->prepareFactoryTest(null, SelectApplier::class, ApplierFactory::SELECT, 'createSelect');
|
||||
}
|
||||
|
||||
public function testCreate2()
|
||||
{
|
||||
$this->prepareFactoryTest('SomeClass', BoolFilterListApplier::class, ApplierFactory::BOOL_FILTER_LIST);
|
||||
$this->prepareFactoryTest(
|
||||
'SomeClass', BoolFilterListApplier::class, ApplierFactory::BOOL_FILTER_LIST, 'createBoolFilterList');
|
||||
}
|
||||
|
||||
public function testCreate3()
|
||||
{
|
||||
$this->prepareFactoryTest(null, TextFilterApplier::class, ApplierFactory::TEXT_FILTER);
|
||||
$this->prepareFactoryTest(null, TextFilterApplier::class, ApplierFactory::TEXT_FILTER, 'createTextFilter');
|
||||
}
|
||||
|
||||
public function testCreate4()
|
||||
{
|
||||
$this->prepareFactoryTest(null, WhereApplier::class, ApplierFactory::WHERE);
|
||||
$this->prepareFactoryTest(null, WhereApplier::class, ApplierFactory::WHERE, 'createWhere');
|
||||
}
|
||||
|
||||
public function testCreate5()
|
||||
{
|
||||
$this->prepareFactoryTest(null, OrderApplier::class, ApplierFactory::ORDER);
|
||||
$this->prepareFactoryTest(null, OrderApplier::class, ApplierFactory::ORDER, 'createOrder');
|
||||
}
|
||||
|
||||
public function testCreate6()
|
||||
{
|
||||
$this->prepareFactoryTest(null, LimitApplier::class, ApplierFactory::LIMIT);
|
||||
$this->prepareFactoryTest(null, LimitApplier::class, ApplierFactory::LIMIT, 'createLimit');
|
||||
}
|
||||
|
||||
public function testCreate7()
|
||||
{
|
||||
$this->prepareFactoryTest(null, AdditionalApplier::class, ApplierFactory::ADDITIONAL);
|
||||
$this->prepareFactoryTest(null, AdditionalApplier::class, ApplierFactory::ADDITIONAL, 'createAdditional');
|
||||
}
|
||||
|
||||
public function testCreate8()
|
||||
{
|
||||
$this->prepareFactoryTest(null, PrimaryFilterApplier::class, ApplierFactory::PRIMARY_FILTER);
|
||||
$this->prepareFactoryTest(
|
||||
null, PrimaryFilterApplier::class, ApplierFactory::PRIMARY_FILTER, 'createPrimaryFilter');
|
||||
}
|
||||
|
||||
public function testCreate9()
|
||||
{
|
||||
$this->prepareFactoryTest(null, AccessControlFilterApplier::class, ApplierFactory::ACCESS_CONTROL_FILTER);
|
||||
$this->prepareFactoryTest
|
||||
(null, AccessControlFilterApplier::class, ApplierFactory::ACCESS_CONTROL_FILTER, 'createAccessControlFilter');
|
||||
}
|
||||
|
||||
protected function prepareFactoryTest(?string $className, string $defaultClassName, string $type)
|
||||
protected function prepareFactoryTest(?string $className, string $defaultClassName, string $type, string $method)
|
||||
{
|
||||
$entityType = 'Test';
|
||||
|
||||
@@ -155,7 +158,7 @@ class FactoryTest extends \PHPUnit\Framework\TestCase
|
||||
->with($applierClassName, $bindingContainer)
|
||||
->willReturn($applier);
|
||||
|
||||
$resultApplier = $this->factory->create(
|
||||
$resultApplier = $this->factory->$method(
|
||||
$entityType,
|
||||
$this->user,
|
||||
$type
|
||||
|
||||
@@ -33,14 +33,15 @@ use Espo\Core\Select\{
|
||||
SelectBuilder,
|
||||
SearchParams,
|
||||
Applier\Factory as ApplierFactory,
|
||||
Applier\Appliers\Where as WhereApplier,
|
||||
Applier\Appliers\Select as SelectApplier,
|
||||
Applier\Appliers\Order as OrderApplier,
|
||||
Applier\Appliers\AccessControlFilter as AccessControlFilterApplier,
|
||||
Applier\Appliers\PrimaryFilter as PrimaryFilterApplier,
|
||||
Applier\Appliers\TextFilter as TextFilterApplier,
|
||||
Where\Applier as WhereApplier,
|
||||
Select\Applier as SelectApplier,
|
||||
Order\Applier as OrderApplier,
|
||||
AccessControl\Applier as AccessControlFilterApplier,
|
||||
Primary\Applier as PrimaryFilterApplier,
|
||||
Text\Applier as TextFilterApplier,
|
||||
Applier\Appliers\Additional as AdditionalApplier,
|
||||
Applier\Appliers\BoolFilterList as BoolFilterListApplier,
|
||||
Applier\Appliers\Limit as LimitApplier,
|
||||
Bool\Applier as BoolFilterListApplier,
|
||||
Where\Params as WhereParams,
|
||||
Order\Params as OrderParams,
|
||||
Text\FilterParams as TextFilterParams,
|
||||
@@ -58,7 +59,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase
|
||||
*/
|
||||
private $selectBuilder;
|
||||
|
||||
protected function setUp() : void
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->user = $this->createMock(User::class);
|
||||
$this->applierFactory = $this->createMock(ApplierFactory::class);
|
||||
@@ -68,7 +69,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase
|
||||
$this->whereApplier = $this->createMock(WhereApplier::class);
|
||||
$this->selectApplier = $this->createMock(SelectApplier::class);
|
||||
$this->orderApplier = $this->createMock(OrderApplier::class);
|
||||
$this->limitApplier = $this->createMock(WhereApplier::class);
|
||||
$this->limitApplier = $this->createMock(LimitApplier::class);
|
||||
$this->accessControlFilterApplier = $this->createMock(AccessControlFilterApplier::class);
|
||||
$this->textFilterApplier = $selectApplier = $this->createMock(TextFilterApplier::class);
|
||||
$this->primaryFilterApplier = $selectApplier = $this->createMock(PrimaryFilterApplier::class);
|
||||
@@ -77,20 +78,57 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->applierFactory
|
||||
->expects($this->any())
|
||||
->method('create')
|
||||
->will(
|
||||
$this->returnValueMap([
|
||||
[$this->entityType, $this->user, ApplierFactory::WHERE, $this->whereApplier],
|
||||
[$this->entityType, $this->user, ApplierFactory::SELECT, $this->selectApplier],
|
||||
[$this->entityType, $this->user, ApplierFactory::ORDER, $this->orderApplier],
|
||||
[$this->entityType, $this->user, ApplierFactory::LIMIT, $this->limitApplier],
|
||||
[$this->entityType, $this->user, ApplierFactory::ACCESS_CONTROL_FILTER, $this->accessControlFilterApplier],
|
||||
[$this->entityType, $this->user, ApplierFactory::TEXT_FILTER, $this->textFilterApplier],
|
||||
[$this->entityType, $this->user, ApplierFactory::PRIMARY_FILTER, $this->primaryFilterApplier],
|
||||
[$this->entityType, $this->user, ApplierFactory::BOOL_FILTER_LIST, $this->boolFilterListApplier],
|
||||
[$this->entityType, $this->user, ApplierFactory::ADDITIONAL, $this->additionalApplier],
|
||||
])
|
||||
);
|
||||
->method('createWhere')
|
||||
->with($this->entityType, $this->user)
|
||||
->willReturn($this->whereApplier);
|
||||
|
||||
$this->applierFactory
|
||||
->expects($this->any())
|
||||
->method('createSelect')
|
||||
->with($this->entityType, $this->user)
|
||||
->willReturn($this->selectApplier);
|
||||
|
||||
$this->applierFactory
|
||||
->expects($this->any())
|
||||
->method('createOrder')
|
||||
->with($this->entityType, $this->user)
|
||||
->willReturn($this->orderApplier);
|
||||
|
||||
$this->applierFactory
|
||||
->expects($this->any())
|
||||
->method('createLimit')
|
||||
->with($this->entityType, $this->user)
|
||||
->willReturn($this->limitApplier);
|
||||
|
||||
$this->applierFactory
|
||||
->expects($this->any())
|
||||
->method('createAccessControlFilter')
|
||||
->with($this->entityType, $this->user)
|
||||
->willReturn($this->accessControlFilterApplier);
|
||||
|
||||
$this->applierFactory
|
||||
->expects($this->any())
|
||||
->method('createTextFilter')
|
||||
->with($this->entityType, $this->user)
|
||||
->willReturn($this->textFilterApplier);
|
||||
|
||||
$this->applierFactory
|
||||
->expects($this->any())
|
||||
->method('createPrimaryFilter')
|
||||
->with($this->entityType, $this->user)
|
||||
->willReturn($this->primaryFilterApplier);
|
||||
|
||||
$this->applierFactory
|
||||
->expects($this->any())
|
||||
->method('createBoolFilterList')
|
||||
->with($this->entityType, $this->user)
|
||||
->willReturn($this->boolFilterListApplier);
|
||||
|
||||
$this->applierFactory
|
||||
->expects($this->any())
|
||||
->method('createAdditional')
|
||||
->with($this->entityType, $this->user)
|
||||
->willReturn($this->additionalApplier);
|
||||
|
||||
$this->selectBuilder = new SelectBuilder($this->user, $this->applierFactory);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user