snapshot of https://github.com/espocrm/espocrm.git (master, 2026-09-18; blobs > 131072B omitted)
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 1s
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 1s
This commit is contained in:
136
tests/unit/Espo/Core/Record/CreateParamsFetcherTest.php
Normal file
136
tests/unit/Espo/Core/Record/CreateParamsFetcherTest.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace tests\unit\Espo\Core\Record;
|
||||
|
||||
use Espo\Core\Record\CreateParamsFetcher;
|
||||
use Espo\Core\Api\RequestWrapper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CreateParamsFetcherTest extends TestCase
|
||||
{
|
||||
public function test1(): void
|
||||
{
|
||||
$request = $this->createMock(RequestWrapper::class);
|
||||
|
||||
$request
|
||||
->method('hasHeader')
|
||||
->with('X-Skip-Duplicate-Check')
|
||||
->willReturn(true);
|
||||
|
||||
$request
|
||||
->method('getHeader')
|
||||
->willReturnMap(
|
||||
[
|
||||
['X-Skip-Duplicate-Check', 'true'],
|
||||
['X-Duplicate-Source-Id', null],
|
||||
]
|
||||
);
|
||||
|
||||
$params = (new CreateParamsFetcher())->fetch($request);
|
||||
|
||||
$this->assertTrue($params->skipDuplicateCheck());
|
||||
}
|
||||
|
||||
public function test2(): void
|
||||
{
|
||||
$request = $this->createMock(RequestWrapper::class);
|
||||
|
||||
$request
|
||||
->method('hasHeader')
|
||||
->willReturn(true);
|
||||
|
||||
$request
|
||||
->method('getHeader')
|
||||
->willReturnMap(
|
||||
[
|
||||
['X-Skip-Duplicate-Check', 'false'],
|
||||
['X-Duplicate-Source-Id', null],
|
||||
]
|
||||
);
|
||||
|
||||
$params = (new CreateParamsFetcher())->fetch($request);
|
||||
|
||||
$this->assertFalse($params->skipDuplicateCheck());
|
||||
}
|
||||
|
||||
public function test3(): void
|
||||
{
|
||||
$request = $this->createMock(RequestWrapper::class);
|
||||
|
||||
$request
|
||||
->method('hasHeader')
|
||||
->willReturn(false);
|
||||
|
||||
$params = (new CreateParamsFetcher())->fetch($request);
|
||||
|
||||
$this->assertFalse($params->skipDuplicateCheck());
|
||||
}
|
||||
|
||||
public function test4(): void
|
||||
{
|
||||
$request = $this->createMock(RequestWrapper::class);
|
||||
|
||||
$request
|
||||
->method('hasHeader')
|
||||
->willReturn(true);
|
||||
|
||||
$request
|
||||
->method('getHeader')
|
||||
->willReturnMap(
|
||||
[
|
||||
['X-Skip-Duplicate-Check', 'TRUE'],
|
||||
['X-Duplicate-Source-Id', null],
|
||||
]
|
||||
);
|
||||
|
||||
$params = (new CreateParamsFetcher())->fetch($request);
|
||||
|
||||
$this->assertTrue($params->skipDuplicateCheck());
|
||||
}
|
||||
|
||||
public function test5(): void
|
||||
{
|
||||
$request = $this->createMock(RequestWrapper::class);
|
||||
|
||||
$request
|
||||
->method('hasHeader')
|
||||
->willReturn(false);
|
||||
|
||||
$request
|
||||
->method('getParsedBody')
|
||||
->willReturn((object) [
|
||||
'_skipDuplicateCheck' => true,
|
||||
]);
|
||||
|
||||
$params = (new CreateParamsFetcher())->fetch($request);
|
||||
|
||||
$this->assertTrue($params->skipDuplicateCheck());
|
||||
}
|
||||
}
|
||||
230
tests/unit/Espo/Core/Record/HookManagerTest.php
Normal file
230
tests/unit/Espo/Core/Record/HookManagerTest.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace tests\unit\Espo\Core\Record;
|
||||
|
||||
use Espo\Core\{
|
||||
Acl,
|
||||
Binding\BindingContainer,
|
||||
Binding\BindingContainerBuilder,
|
||||
Record\HookManager,
|
||||
Record\Hook\Provider,
|
||||
Record\Hook\Type,
|
||||
Record\CreateParams,
|
||||
Record\ReadParams,
|
||||
Record\UpdateParams,
|
||||
Record\DeleteParams,
|
||||
InjectableFactory,
|
||||
Utils\Metadata};
|
||||
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
use tests\unit\testClasses\Core\Record\Hooks\{
|
||||
BeforeReadHook,
|
||||
BeforeCreateHook,
|
||||
BeforeUpdateHook,
|
||||
BeforeDeleteHook,
|
||||
BeforeLinkHook,
|
||||
BeforeUnlinkHook,
|
||||
};
|
||||
|
||||
class HookManagerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var InjectableFactory
|
||||
*/
|
||||
private $injectableFactory;
|
||||
|
||||
/**
|
||||
* @var Metadata
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* @var HookManager
|
||||
*/
|
||||
private $manager;
|
||||
|
||||
/**
|
||||
* @var Entity
|
||||
*/
|
||||
private $entity;
|
||||
|
||||
private $entityType = 'Test';
|
||||
|
||||
private ?BindingContainer $bindingContainer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->injectableFactory = $this->createMock(InjectableFactory::class);
|
||||
$this->metadata = $this->createMock(Metadata::class);
|
||||
|
||||
$acl = $this->createMock(Acl::class);
|
||||
$user = $this->createMock(User::class);
|
||||
|
||||
$this->bindingContainer = BindingContainerBuilder::create()
|
||||
->bindInstance(User::class, $user)
|
||||
->bindInstance(Acl::class, $acl)
|
||||
->build();
|
||||
|
||||
$provider = new Provider($this->metadata, $this->injectableFactory, $acl, $user);
|
||||
|
||||
$this->manager = new HookManager($provider);
|
||||
|
||||
$this->entity = $this->createEntity($this->entityType);
|
||||
}
|
||||
|
||||
public function testBeforeRead(): void
|
||||
{
|
||||
$hook = $this->createMock(BeforeReadHook::class);
|
||||
|
||||
$this->initHooks(Type::BEFORE_READ, [BeforeReadHook::class], [$hook]);
|
||||
|
||||
$params = ReadParams::create();
|
||||
|
||||
$hook
|
||||
->expects($this->once())
|
||||
->method('process')
|
||||
->with($this->entity, $params);
|
||||
|
||||
$this->manager->processBeforeRead($this->entity, $params);
|
||||
}
|
||||
|
||||
public function testBeforeCreate(): void
|
||||
{
|
||||
$hook = $this->createMock(BeforeCreateHook::class);
|
||||
|
||||
$this->initHooks(Type::BEFORE_CREATE, [BeforeCreateHook::class], [$hook]);
|
||||
|
||||
$params = CreateParams::create();
|
||||
|
||||
$hook
|
||||
->expects($this->once())
|
||||
->method('process')
|
||||
->with($this->entity, $params);
|
||||
|
||||
$this->manager->processBeforeCreate($this->entity, $params);
|
||||
}
|
||||
|
||||
public function testBeforeUpdate(): void
|
||||
{
|
||||
$hook = $this->createMock(BeforeUpdateHook::class);
|
||||
|
||||
$this->initHooks(Type::BEFORE_UPDATE, [BeforeUpdateHook::class], [$hook]);
|
||||
|
||||
$params = UpdateParams::create();
|
||||
|
||||
$hook
|
||||
->expects($this->once())
|
||||
->method('process')
|
||||
->with($this->entity, $params);
|
||||
|
||||
$this->manager->processBeforeUpdate($this->entity, $params);
|
||||
}
|
||||
|
||||
public function testBeforeDelete(): void
|
||||
{
|
||||
$hook = $this->createMock(BeforeDeleteHook::class);
|
||||
|
||||
$this->initHooks(Type::BEFORE_DELETE, [BeforeDeleteHook::class], [$hook]);
|
||||
|
||||
$params = DeleteParams::create();
|
||||
|
||||
$hook
|
||||
->expects($this->once())
|
||||
->method('process')
|
||||
->with($this->entity, $params);
|
||||
|
||||
$this->manager->processBeforeDelete($this->entity, $params);
|
||||
}
|
||||
|
||||
public function testBeforeLink(): void
|
||||
{
|
||||
$hook = $this->createMock(BeforeLinkHook::class);
|
||||
|
||||
$this->initHooks(Type::BEFORE_LINK, [BeforeLinkHook::class], [$hook]);
|
||||
|
||||
$link = 'test';
|
||||
|
||||
$hook
|
||||
->expects($this->once())
|
||||
->method('process')
|
||||
->with($this->entity, $link, $this->entity);
|
||||
|
||||
$this->manager->processBeforeLink($this->entity, $link, $this->entity);
|
||||
}
|
||||
|
||||
public function testBeforeUnlink(): void
|
||||
{
|
||||
$hook = $this->createMock(BeforeUnlinkHook::class);
|
||||
|
||||
$this->initHooks(Type::BEFORE_UNLINK, [BeforeUnlinkHook::class], [$hook]);
|
||||
|
||||
$link = 'test';
|
||||
|
||||
$hook
|
||||
->expects($this->once())
|
||||
->method('process')
|
||||
->with($this->entity, $link, $this->entity);
|
||||
|
||||
$this->manager->processBeforeUnlink($this->entity, $link, $this->entity);
|
||||
}
|
||||
|
||||
private function createEntity(string $entityType): Entity
|
||||
{
|
||||
$entity = $this->createMock(Entity::class);
|
||||
|
||||
$entity
|
||||
->expects($this->any())
|
||||
->method('getEntityType')
|
||||
->willReturn($entityType);
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
private function initHooks(string $type, array $hookClassNameList, array $hookList): void
|
||||
{
|
||||
$this->metadata
|
||||
->expects($this->any())
|
||||
->method('get')
|
||||
->willReturnMap([
|
||||
["app.record.{$type}HookClassNameList", [], []],
|
||||
["recordDefs.$this->entityType.{$type}HookClassNameList", [], $hookClassNameList],
|
||||
]);
|
||||
|
||||
foreach ($hookClassNameList as $i => $className) {
|
||||
$this->injectableFactory
|
||||
->expects($this->any())
|
||||
->method('createWithBinding')
|
||||
->with($className, $this->bindingContainer)
|
||||
->willReturn($hookList[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
88
tests/unit/Espo/Core/Record/SearchParamsFetcherTest.php
Normal file
88
tests/unit/Espo/Core/Record/SearchParamsFetcherTest.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace tests\unit\Espo\Core\Record;
|
||||
|
||||
use Espo\Core\Record\SearchParamsFetcher;
|
||||
use Espo\Core\Api\RequestWrapper;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Select\Text\MetadataProvider as TextMetadataProvider;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Slim\Psr7\Factory\RequestFactory;
|
||||
|
||||
class SearchParamsFetcherTest extends TestCase
|
||||
{
|
||||
private $config;
|
||||
private $textMetadataProvider;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->config = $this->createMocK(Config::class);
|
||||
$this->textMetadataProvider = $this->createMocK(TextMetadataProvider::class);
|
||||
|
||||
$this->config
|
||||
->method('get')
|
||||
->with('recordListMaxSizeLimit')
|
||||
->willReturn(null);
|
||||
}
|
||||
|
||||
public function testFetchJson1(): void
|
||||
{
|
||||
$raw = [
|
||||
'textFilter' => 'test*',
|
||||
'maxSize' => 10,
|
||||
];
|
||||
|
||||
$q = http_build_query(['searchParams' => json_encode($raw)]);
|
||||
|
||||
$request = (new RequestFactory)->createRequest('GET', 'http://localhost/?' . $q);
|
||||
|
||||
$fetcher = new SearchParamsFetcher($this->config, $this->textMetadataProvider);
|
||||
|
||||
$params = $fetcher->fetch(new RequestWrapper($request));
|
||||
|
||||
$this->assertEquals($raw['textFilter'], $params->getTextFilter());
|
||||
$this->assertEquals($raw['maxSize'], $params->getMaxSize());
|
||||
}
|
||||
|
||||
public function testFetchQuery(): void
|
||||
{
|
||||
$q = http_build_query(['attributeSelect' => 'a,b']);
|
||||
|
||||
$request = (new RequestFactory)->createRequest('GET', 'http://localhost/?' . $q);
|
||||
|
||||
$fetcher = new SearchParamsFetcher($this->config, $this->textMetadataProvider);
|
||||
|
||||
$params = $fetcher->fetch(new RequestWrapper($request));
|
||||
|
||||
$this->assertEquals(['a', 'b'], $params->getSelect());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user