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 MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 0s
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
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 MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 0s
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
This commit is contained in:
309
tests/integration/Espo/Core/Acl/AclTest.php
Normal file
309
tests/integration/Espo/Core/Acl/AclTest.php
Normal file
@@ -0,0 +1,309 @@
|
||||
<?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\integration\Espo\Core\Acl;
|
||||
|
||||
use Espo\Core\AclManager;
|
||||
use Espo\Core\Acl;
|
||||
use Espo\Core\Field\LinkMultiple;
|
||||
use Espo\Entities\Role;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Call;
|
||||
use Espo\Modules\Crm\Entities\Meeting;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use RuntimeException;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class AclTest extends BaseTestCase
|
||||
{
|
||||
public function testGetReadOwnerUserField()
|
||||
{
|
||||
$aclManager = $this->getContainer()->getByClass(AclManager::class);
|
||||
|
||||
$this->assertEquals(
|
||||
'assignedUser',
|
||||
$aclManager->getReadOwnerUserField('Account')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'createdBy',
|
||||
$aclManager->getReadOwnerUserField('Import')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'users',
|
||||
$aclManager->getReadOwnerUserField('Email')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'users',
|
||||
$aclManager->getReadOwnerUserField('Meeting')
|
||||
);
|
||||
}
|
||||
|
||||
public function testTryCheck(): void
|
||||
{
|
||||
/* @var $Acl Acl */
|
||||
$acl = $this->getContainer()->get('acl');
|
||||
|
||||
$this->assertFalse($acl->tryCheck('NonExistingEntityType'));
|
||||
}
|
||||
|
||||
public function testCheckScopeAccess(): void
|
||||
{
|
||||
$this->createUser('tester', [
|
||||
'data' => [
|
||||
Task::ENTITY_TYPE => false,
|
||||
Call::ENTITY_TYPE => [
|
||||
'create' => Acl\Table::LEVEL_NO,
|
||||
'read' => Acl\Table::LEVEL_NO,
|
||||
'edit' => Acl\Table::LEVEL_NO,
|
||||
'delete' => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
Meeting::ENTITY_TYPE => [
|
||||
'create' => Acl\Table::LEVEL_YES,
|
||||
'read' => Acl\Table::LEVEL_YES,
|
||||
'edit' => Acl\Table::LEVEL_NO,
|
||||
'delete' => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->authenticate('tester');
|
||||
|
||||
$acl = $this->getContainer()->getByClass(Acl::class);
|
||||
|
||||
$this->assertFalse($acl->checkScope(Task::ENTITY_TYPE));
|
||||
$this->assertTrue($acl->checkScope(Call::ENTITY_TYPE));
|
||||
$this->assertTrue($acl->checkScope(Meeting::ENTITY_TYPE));
|
||||
|
||||
$this->assertFalse($acl->check(Task::ENTITY_TYPE, Acl\Table::ACTION_READ));
|
||||
$this->assertFalse($acl->check(Call::ENTITY_TYPE, Acl\Table::ACTION_READ));
|
||||
$this->assertTrue($acl->check(Meeting::ENTITY_TYPE, Acl\Table::ACTION_READ));
|
||||
}
|
||||
|
||||
public function testCheckField(): void
|
||||
{
|
||||
$user = $this->createUser('tester', [
|
||||
'fieldData' => [
|
||||
'Call' => [
|
||||
'direction' => [
|
||||
'read' => Acl\Table::LEVEL_NO,
|
||||
'edit' => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
'contacts' => [
|
||||
'read' => Acl\Table::LEVEL_YES,
|
||||
'edit' => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getEntityManager()->getEntityById(User::ENTITY_TYPE, $user->getId());
|
||||
|
||||
$aclManager = $this->getContainer()->getByClass(AclManager::class);
|
||||
|
||||
$this->assertFalse($aclManager->checkField($user, 'Call', 'direction'));
|
||||
$this->assertTrue($aclManager->checkField($user, 'Call', 'contacts'));
|
||||
$this->assertFalse($aclManager->checkField($user, 'Call', 'contacts', Acl\Table::ACTION_EDIT));
|
||||
}
|
||||
|
||||
public function testDisabledField(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
|
||||
$metadata->set('entityDefs', 'Account', [
|
||||
'fields' => [
|
||||
'assignedUser' => [
|
||||
'disabled' => true,
|
||||
]
|
||||
]
|
||||
]);
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication(reuse: true);
|
||||
|
||||
$acl = $this->getContainer()->getByClass(Acl::class);
|
||||
|
||||
$this->assertFalse($acl->checkField(Account::ENTITY_TYPE, 'assignedUser'));
|
||||
$this->assertTrue($acl->checkField(Account::ENTITY_TYPE, 'name'));
|
||||
}
|
||||
|
||||
public function testDisabledLink(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
|
||||
$metadata->set('entityDefs', 'Account', [
|
||||
'links' => [
|
||||
'opportunities' => [
|
||||
'disabled' => true,
|
||||
]
|
||||
]
|
||||
]);
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication(reuse: true);
|
||||
|
||||
$acl = $this->getContainer()->getByClass(Acl::class);
|
||||
|
||||
$this->assertFalse($acl->checkLink('Account', 'opportunities'));
|
||||
}
|
||||
|
||||
public function testMultipleRoles(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$role1 = $em->getRDBRepositoryByClass(Role::class)->getNew();
|
||||
$role1->setRawData([
|
||||
'Lead' => [
|
||||
Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_YES,
|
||||
],
|
||||
'Opportunity' => [
|
||||
Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
'Account' => [
|
||||
Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
'Meeting' => [
|
||||
Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_YES,
|
||||
Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_NO,
|
||||
Acl\Table::ACTION_STREAM => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
'Call' => [
|
||||
Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_NO,
|
||||
Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_ALL,
|
||||
],
|
||||
]);
|
||||
$em->saveEntity($role1);
|
||||
|
||||
$role2 = $em->getRDBRepositoryByClass(Role::class)->getNew();
|
||||
$role2->setRawData([
|
||||
'Lead' => [
|
||||
Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
'Opportunity' => [
|
||||
Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_YES,
|
||||
],
|
||||
'Account' => [
|
||||
Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
'Meeting' => [
|
||||
Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_NO,
|
||||
Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_ALL,
|
||||
Acl\Table::ACTION_STREAM => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
'Call' => [
|
||||
Acl\Table::ACTION_CREATE => Acl\Table::LEVEL_YES,
|
||||
Acl\Table::ACTION_EDIT => Acl\Table::LEVEL_NO,
|
||||
],
|
||||
]);
|
||||
$em->saveEntity($role2);
|
||||
|
||||
$user = $em->getRDBRepositoryByClass(User::class)->getNew();
|
||||
$user
|
||||
->setUserName('test-1')
|
||||
->setRoles(LinkMultiple::create()->withAddedIdList([$role1->getId(), $role2->getId()]));
|
||||
$em->saveEntity($user);
|
||||
|
||||
$em->refreshEntity($user);
|
||||
|
||||
$aclManager = $this->getContainer()->getByClass(AclManager::class);
|
||||
|
||||
$this->assertTrue($aclManager->checkScope($user, 'Lead', Acl\Table::ACTION_CREATE));
|
||||
$this->assertTrue($aclManager->checkScope($user, 'Opportunity', Acl\Table::ACTION_CREATE));
|
||||
$this->assertFalse($aclManager->checkScope($user, 'Account', Acl\Table::ACTION_CREATE));
|
||||
$this->assertFalse($aclManager->checkScope($user, 'Opportunity', Acl\Table::ACTION_EDIT));
|
||||
$this->assertFalse($aclManager->checkScope($user, 'Account', Acl\Table::ACTION_EDIT));
|
||||
$this->assertTrue($aclManager->checkScope($user, 'Meeting', Acl\Table::ACTION_CREATE));
|
||||
$this->assertTrue($aclManager->checkScope($user, 'Meeting', Acl\Table::ACTION_EDIT));
|
||||
$this->assertFalse($aclManager->checkScope($user, 'Meeting', Acl\Table::ACTION_STREAM));
|
||||
$this->assertTrue($aclManager->checkScope($user, 'Call', Acl\Table::ACTION_CREATE));
|
||||
$this->assertTrue($aclManager->checkScope($user, 'Call', Acl\Table::ACTION_EDIT));
|
||||
}
|
||||
|
||||
public function testCheckAdmin(): void
|
||||
{
|
||||
$user = $this->createUser(
|
||||
userData: [
|
||||
User::FIELD_USER_NAME => 'test',
|
||||
],
|
||||
);
|
||||
|
||||
$admin = $this->createUser(
|
||||
userData: [
|
||||
User::FIELD_USER_NAME => 'admin-test',
|
||||
User::FIELD_TYPE => User::TYPE_ADMIN,
|
||||
],
|
||||
);
|
||||
|
||||
$aclManager = $this->getInjectableFactory()->create(AclManager::class);
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
$admin = $this->reFetchUser($admin);
|
||||
|
||||
$this->assertFalse($aclManager->checkAdmin($user));
|
||||
$this->assertTrue($aclManager->checkAdmin($admin));
|
||||
|
||||
$this->assertFalse($aclManager->createUserAcl($user)->checkAdmin());
|
||||
$this->assertTrue($aclManager->createUserAcl($admin)->checkAdmin());
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
$admin = $this->reFetchUser($admin);
|
||||
|
||||
$user->setScopes([Acl\Scope::ADMIN]);
|
||||
$admin->setScopes([Acl\Scope::ADMIN]);
|
||||
|
||||
$this->assertFalse($aclManager->checkAdmin($user));
|
||||
$this->assertTrue($aclManager->checkAdmin($admin));
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
$admin = $this->reFetchUser($admin);
|
||||
|
||||
$user->setScopes([]);
|
||||
$admin->setScopes([]);
|
||||
|
||||
$this->assertFalse($aclManager->checkAdmin($user));
|
||||
$this->assertFalse($aclManager->checkAdmin($admin));
|
||||
}
|
||||
|
||||
private function reFetchUser(User $user): User
|
||||
{
|
||||
return $this->getEntityManager()
|
||||
->getRDBRepositoryByClass(User::class)
|
||||
->getById($user->getId()) ?? throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
247
tests/integration/Espo/Core/Acl/TableTest.php
Normal file
247
tests/integration/Espo/Core/Acl/TableTest.php
Normal file
@@ -0,0 +1,247 @@
|
||||
<?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 integration\Espo\Core\Acl;
|
||||
|
||||
use Espo\Core\Acl\Scope;
|
||||
use Espo\Core\Acl\Table;
|
||||
use Espo\Entities\Role;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use Espo\Tools\Stream\GlobalRecordService;
|
||||
use RuntimeException;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class TableTest extends BaseTestCase
|
||||
{
|
||||
public function testScopesRegular(): void
|
||||
{
|
||||
$roleData = [
|
||||
Account::ENTITY_TYPE => [
|
||||
Table::ACTION_CREATE => Table::LEVEL_YES,
|
||||
Table::ACTION_READ => Table::LEVEL_ALL,
|
||||
Table::ACTION_EDIT => Table::LEVEL_ALL,
|
||||
Table::ACTION_DELETE => Table::LEVEL_ALL,
|
||||
Table::ACTION_STREAM => Table::LEVEL_ALL,
|
||||
],
|
||||
Contact::ENTITY_TYPE => false,
|
||||
Lead::ENTITY_TYPE => [
|
||||
Table::ACTION_CREATE => Table::LEVEL_YES,
|
||||
Table::ACTION_READ => Table::LEVEL_ALL,
|
||||
Table::ACTION_EDIT => Table::LEVEL_ALL,
|
||||
Table::ACTION_DELETE => Table::LEVEL_ALL,
|
||||
Table::ACTION_STREAM => Table::LEVEL_ALL,
|
||||
],
|
||||
GlobalRecordService::SCOPE_NAME => true,
|
||||
];
|
||||
|
||||
$user = $this->createUser(
|
||||
userData: [
|
||||
User::FIELD_USER_NAME => 'test',
|
||||
],
|
||||
role: [
|
||||
Role::FIELD_DATA => $roleData,
|
||||
],
|
||||
);
|
||||
|
||||
$factory = $this->getInjectableFactory()->create(Table\DefaultTableFactory::class);
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
|
||||
$table = $factory->create($user);
|
||||
|
||||
$this->assertEquals(Table::LEVEL_YES, $table->getScopeData(Account::ENTITY_TYPE)->getCreate());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getRead());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getEdit());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getDelete());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getStream());
|
||||
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Lead::ENTITY_TYPE)->getRead());
|
||||
|
||||
$this->assertFalse($table->getScopeData(Contact::ENTITY_TYPE)->isTrue());
|
||||
$this->assertTrue($table->getScopeData(GlobalRecordService::SCOPE_NAME)->isTrue());
|
||||
|
||||
//
|
||||
|
||||
$user->setScopes([
|
||||
Lead::ENTITY_TYPE,
|
||||
GlobalRecordService::SCOPE_NAME,
|
||||
]);
|
||||
|
||||
$table = $factory->create($user);
|
||||
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getCreate());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getRead());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getEdit());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getDelete());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getStream());
|
||||
|
||||
$this->assertEquals(Table::LEVEL_YES, $table->getScopeData(Lead::ENTITY_TYPE)->getCreate());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Lead::ENTITY_TYPE)->getRead());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Lead::ENTITY_TYPE)->getEdit());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Lead::ENTITY_TYPE)->getDelete());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Lead::ENTITY_TYPE)->getStream());
|
||||
|
||||
$this->assertTrue($table->getScopeData(GlobalRecordService::SCOPE_NAME)->isTrue());
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
|
||||
$user->setScopes([
|
||||
Scope::GLOBAL,
|
||||
]);
|
||||
|
||||
$table = $factory->create($user);
|
||||
|
||||
$this->assertEquals(Table::LEVEL_YES, $table->getScopeData(Account::ENTITY_TYPE)->getCreate());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getRead());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getEdit());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getDelete());
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getStream());
|
||||
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Lead::ENTITY_TYPE)->getRead());
|
||||
|
||||
$this->assertFalse($table->getScopeData(Contact::ENTITY_TYPE)->isTrue());
|
||||
$this->assertTrue($table->getScopeData(GlobalRecordService::SCOPE_NAME)->isTrue());
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
|
||||
$user->setScopes([]);
|
||||
|
||||
$table = $factory->create($user);
|
||||
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getCreate());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getRead());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getEdit());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getDelete());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Account::ENTITY_TYPE)->getStream());
|
||||
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Lead::ENTITY_TYPE)->getCreate());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Lead::ENTITY_TYPE)->getRead());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Lead::ENTITY_TYPE)->getEdit());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Lead::ENTITY_TYPE)->getDelete());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Lead::ENTITY_TYPE)->getStream());
|
||||
|
||||
$this->assertFalse($table->getScopeData(Contact::ENTITY_TYPE)->isTrue());
|
||||
$this->assertFalse($table->getScopeData(GlobalRecordService::SCOPE_NAME)->isTrue());
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
|
||||
$user->setScopes([
|
||||
Scope::ADMIN,
|
||||
]);
|
||||
|
||||
$table = $factory->create($user);
|
||||
|
||||
$this->assertFalse($table->getScopeData(Scope::ADMIN)->isTrue());
|
||||
|
||||
$this->assertFalse($user->isEffectiveAdmin());
|
||||
}
|
||||
|
||||
public function testScopesAdmin(): void
|
||||
{
|
||||
$user = $this->createUser(
|
||||
userData: [
|
||||
User::FIELD_USER_NAME => 'test',
|
||||
User::FIELD_TYPE => User::TYPE_ADMIN,
|
||||
]
|
||||
);
|
||||
|
||||
$factory = $this->getInjectableFactory()->create(Table\DefaultTableFactory::class);
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
|
||||
$table = $factory->create($user);
|
||||
|
||||
$this->assertTrue($table->getScopeData(Scope::ADMIN)->isTrue());
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
|
||||
$user->setScopes([
|
||||
Scope::ADMIN,
|
||||
]);
|
||||
|
||||
$table = $factory->create($user);
|
||||
|
||||
$this->assertTrue($table->getScopeData(Scope::ADMIN)->isTrue());
|
||||
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getRead());
|
||||
$this->assertTrue($table->getScopeData(GlobalRecordService::SCOPE_NAME)->isTrue());
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
|
||||
$user->setScopes([
|
||||
Scope::GLOBAL,
|
||||
]);
|
||||
|
||||
$table = $factory->create($user);
|
||||
|
||||
$this->assertFalse($table->getScopeData(Scope::ADMIN)->isTrue());
|
||||
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getRead());
|
||||
$this->assertTrue($table->getScopeData(GlobalRecordService::SCOPE_NAME)->isTrue());
|
||||
|
||||
//
|
||||
|
||||
$user = $this->reFetchUser($user);
|
||||
|
||||
$user->setScopes([
|
||||
Account::ENTITY_TYPE,
|
||||
]);
|
||||
|
||||
$table = $factory->create($user);
|
||||
|
||||
$this->assertFalse($table->getScopeData(Scope::ADMIN)->isTrue());
|
||||
|
||||
$this->assertEquals(Table::LEVEL_ALL, $table->getScopeData(Account::ENTITY_TYPE)->getRead());
|
||||
$this->assertEquals(Table::LEVEL_NO, $table->getScopeData(Lead::ENTITY_TYPE)->getRead());
|
||||
}
|
||||
|
||||
private function reFetchUser(User $user): User
|
||||
{
|
||||
return $this->getEntityManager()
|
||||
->getRDBRepositoryByClass(User::class)
|
||||
->getById($user->getId()) ?? throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?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\integration\Espo\Core\Authentication\AuthToken;
|
||||
|
||||
use Espo\Core\Authentication\AuthToken\Data;
|
||||
use Espo\Core\Authentication\AuthToken\Manager;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class AuthTokenManagerTest extends BaseTestCase
|
||||
{
|
||||
public function testCreateWithSecret()
|
||||
{
|
||||
$authTokenManager = $this->getContainer()->getByClass(Manager::class);
|
||||
|
||||
$authTokenData = Data::create([
|
||||
'passwordVersion' => 1,
|
||||
'ipAddress' => 'ip-address',
|
||||
'userId' => 'user-id',
|
||||
'portalId' => 'portal-id',
|
||||
'createSecret' => true,
|
||||
]);
|
||||
|
||||
$authToken = $authTokenManager->create($authTokenData);
|
||||
|
||||
$this->assertEquals($authTokenData->getPasswordVersion(), $authToken->getPasswordVersion());
|
||||
$this->assertEquals($authTokenData->getUserId(), $authToken->getUserId());
|
||||
$this->assertEquals($authTokenData->getPortalId(), $authToken->getPortalId());
|
||||
|
||||
$this->assertTrue($authToken->isActive());
|
||||
|
||||
$this->assertNotEmpty($authToken->getToken());
|
||||
$this->assertNotEmpty($authToken->getSecret());
|
||||
|
||||
$this->assertNotEmpty($authToken->get('lastAccess'));
|
||||
}
|
||||
|
||||
public function testCreateWithNoSecretNoPortal()
|
||||
{
|
||||
$authTokenManager = $this->getContainer()->getByClass(Manager::class);
|
||||
|
||||
$authTokenData = Data::create([
|
||||
'passwordVersion' => 1,
|
||||
'ipAddress' => 'ip-address',
|
||||
'userId' => 'user-id',
|
||||
'portalId' => null,
|
||||
'createSecret' => false,
|
||||
]);
|
||||
|
||||
$authToken = $authTokenManager->create($authTokenData);
|
||||
|
||||
$this->assertEquals($authTokenData->getPasswordVersion(), $authToken->getPasswordVersion());
|
||||
$this->assertEquals($authTokenData->getUserId(), $authToken->getUserId());
|
||||
|
||||
$this->assertEmpty($authToken->getPortalId());
|
||||
|
||||
$this->assertNotEmpty($authToken->getToken());
|
||||
$this->assertEmpty($authToken->getSecret());
|
||||
}
|
||||
|
||||
public function testRenew()
|
||||
{
|
||||
$authTokenManager = $this->getContainer()->getByClass(Manager::class);
|
||||
|
||||
$authTokenData = Data::create([
|
||||
'passwordVersion' => 1,
|
||||
'userId' => 'user-id',
|
||||
]);
|
||||
|
||||
$authToken = $authTokenManager->create($authTokenData);
|
||||
|
||||
$authToken = $authTokenManager->get($authToken->getToken());
|
||||
|
||||
$authTokenManager->renew($authToken);
|
||||
|
||||
$this->assertNotEmpty($authToken->get('lastAccess'));
|
||||
}
|
||||
|
||||
public function testInactivate()
|
||||
{
|
||||
$authTokenManager = $this->getContainer()->getByClass(Manager::class);
|
||||
|
||||
$authTokenData = Data::create([
|
||||
'passwordVersion' => 1,
|
||||
'userId' => 'user-id',
|
||||
]);
|
||||
|
||||
$authToken = $authTokenManager->create($authTokenData);
|
||||
|
||||
$authToken = $authTokenManager->get($authToken->getToken());
|
||||
|
||||
$authTokenManager->inactivate($authToken);
|
||||
|
||||
$this->assertFalse($authToken->isActive());
|
||||
}
|
||||
}
|
||||
1003
tests/integration/Espo/Core/Authentication/AuthenticationTest.php
Normal file
1003
tests/integration/Espo/Core/Authentication/AuthenticationTest.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,121 @@
|
||||
<?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\integration\Espo\Core\Authentication;
|
||||
|
||||
use Espo\Core\Api\RequestWrapper;
|
||||
use Espo\Core\Api\Response;
|
||||
use Espo\Core\Authentication\Authentication;
|
||||
use Espo\Core\Authentication\AuthenticationData;
|
||||
use Espo\Core\Authentication\HeaderKey;
|
||||
use Espo\Core\Authentication\Util\DelayUtil;
|
||||
use Espo\Core\Binding\Binder;
|
||||
use Espo\Core\Binding\BindingProcessor;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
use Slim\Psr7\Factory\ServerRequestFactory;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class FailedLoginAttemptsTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testUsernameFailedLogin(): void
|
||||
{
|
||||
$delay = 5;
|
||||
|
||||
$configWriter = $this->getInjectableFactory()->create(ConfigWriter::class);
|
||||
$configWriter->setMultiple([
|
||||
'authUsernameFailedAttemptsLimitEnabled' => true,
|
||||
'authUsernameFailedAttemptsDelay' => $delay,
|
||||
'authMaxUsernameFailedAttemptNumber' => 3,
|
||||
]);
|
||||
$configWriter->save();
|
||||
|
||||
$delayUtil = $this->createMock(DelayUtil::class);
|
||||
|
||||
$app = $this->createApplication(
|
||||
binding: new class ($delayUtil) implements BindingProcessor {
|
||||
|
||||
public function __construct(private DelayUtil $delayUtil) {}
|
||||
|
||||
public function process(Binder $binder): void
|
||||
{
|
||||
$binder->bindInstance(DelayUtil::class, $this->delayUtil);
|
||||
}
|
||||
},
|
||||
reuse: true,
|
||||
);
|
||||
$this->setApplication($app);
|
||||
|
||||
$delayUtil->expects($this->once())
|
||||
->method('delay')
|
||||
->with($delay * 1000);
|
||||
|
||||
$username = 'test';
|
||||
|
||||
$data = AuthenticationData::create()
|
||||
->withUsername($username)
|
||||
->withPassword('1');
|
||||
|
||||
$time = microtime(true);
|
||||
|
||||
$authentication = $this->getInjectableFactory()->create(Authentication::class);
|
||||
|
||||
$request = $this->createApiRequest($time, '1.0.0.1', $username);
|
||||
$response = $this->createMock(Response::class);
|
||||
$authentication->login($data, $request, $response);
|
||||
|
||||
$request = $this->createApiRequest($time, '1.0.0.2', $username);
|
||||
$response = $this->createMock(Response::class);
|
||||
$authentication->login($data, $request, $response);
|
||||
|
||||
$request = $this->createApiRequest($time, '1.0.0.3', $username);
|
||||
$response = $this->createMock(Response::class);
|
||||
$authentication->login($data, $request, $response);
|
||||
|
||||
$request = $this->createApiRequest($time, '1.0.0.4', $username);
|
||||
$response = $this->createMock(Response::class);
|
||||
$authentication->login($data, $request, $response);
|
||||
}
|
||||
|
||||
private function createApiRequest(float $time, string $ipAddress, string $username): RequestWrapper
|
||||
{
|
||||
$authorization = 'Basic ' . base64_encode($username . ':1');
|
||||
|
||||
$request = (new ServerRequestFactory())->createServerRequest('POST', 'http://localhost/api/v1/App/user', [
|
||||
'REMOTE_ADDR' => $ipAddress,
|
||||
'REQUEST_TIME_FLOAT' => $time,
|
||||
]);
|
||||
|
||||
$request = $request->withHeader(HeaderKey::AUTHORIZATION, $authorization);
|
||||
|
||||
return new RequestWrapper($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?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 integration\Espo\Core\Authentication\Oidc;
|
||||
|
||||
use Espo\Core\Authentication\Oidc\UserProvider\DefaultUserInfoPopulator;
|
||||
use Espo\Core\Authentication\Oidc\UserProvider\UserInfo;
|
||||
use Espo\Core\Field\EmailAddress;
|
||||
use Espo\Core\Field\EmailAddressGroup;
|
||||
use Espo\Core\Field\PhoneNumber;
|
||||
use Espo\Core\Field\PhoneNumberGroup;
|
||||
use Espo\Entities\User;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class UserInfoPopulatorTest extends BaseTestCase
|
||||
{
|
||||
public function testPopulate(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$user = $em->getRDBRepositoryByClass(User::class)->getNew();
|
||||
|
||||
$user
|
||||
->setUserName('name')
|
||||
->setPhoneNumberGroup(
|
||||
PhoneNumberGroup::create([
|
||||
PhoneNumber::create('+100'),
|
||||
PhoneNumber::create('+200'),
|
||||
])
|
||||
)
|
||||
->setEmailAddressGroup(
|
||||
EmailAddressGroup::create([
|
||||
EmailAddress::create('test1@test.com'),
|
||||
EmailAddress::create('test2@test.com'),
|
||||
]),
|
||||
);
|
||||
|
||||
$em->saveEntity($user);
|
||||
|
||||
$userInfo = $this->createMock(UserInfo::class);
|
||||
$userInfo
|
||||
->method('get')
|
||||
->willReturnMap([
|
||||
['email', 'test3@test.com'],
|
||||
['phone_number', '+300'],
|
||||
]);
|
||||
|
||||
$populator = $this->getInjectableFactory()->create(DefaultUserInfoPopulator::class);
|
||||
|
||||
//
|
||||
|
||||
$populator->populate($userInfo, $user);
|
||||
|
||||
$em->saveEntity($user);
|
||||
$em->refreshEntity($user);
|
||||
|
||||
$this->assertCount(2, $user->getEmailAddressGroup()->getList());
|
||||
$this->assertCount(2, $user->getPhoneNumberGroup()->getList());
|
||||
|
||||
$this->assertEquals('test3@test.com', $user->getEmailAddress());
|
||||
$this->assertEquals('+300', $user->getPhoneNumber());
|
||||
|
||||
$this->assertEquals('test2@test.com', $user->getEmailAddressGroup()->getList()[1]->getAddress());
|
||||
$this->assertEquals('+200', $user->getPhoneNumberGroup()->getList()[1]->getNumber());
|
||||
|
||||
//
|
||||
|
||||
$userInfo = $this->createMock(UserInfo::class);
|
||||
$userInfo
|
||||
->method('get')
|
||||
->willReturnMap([
|
||||
['email', null],
|
||||
['phone_number', null],
|
||||
]);
|
||||
|
||||
$populator->populate($userInfo, $user);
|
||||
|
||||
$em->saveEntity($user);
|
||||
$em->refreshEntity($user);
|
||||
|
||||
$this->assertEquals('test2@test.com', $user->getEmailAddress());
|
||||
$this->assertEquals('+200', $user->getPhoneNumber());
|
||||
|
||||
$this->assertCount(1, $user->getEmailAddressGroup()->getList());
|
||||
$this->assertCount(1, $user->getPhoneNumberGroup()->getList());
|
||||
}
|
||||
}
|
||||
329
tests/integration/Espo/Core/Binding/BindingTest.php
Normal file
329
tests/integration/Espo/Core/Binding/BindingTest.php
Normal file
@@ -0,0 +1,329 @@
|
||||
<?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\integration\Espo\Core\Binding;
|
||||
|
||||
use Espo\Core\Application\ApplicationParams;
|
||||
use Espo\Core\Binding\Binder;
|
||||
use Espo\Core\Binding\Binding;
|
||||
use Espo\Core\Binding\BindingData;
|
||||
use Espo\Core\Binding\BindingLoader;
|
||||
use Espo\Core\Binding\Key\QualifiedClassKey;
|
||||
use Espo\Core\Container\ContainerBuilder;
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\Utils\Cache\FileCacheItemPool;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
use tests\integration\testClasses\Binding\SomeClass;
|
||||
use tests\integration\testClasses\Binding\SomeClassRequiringService;
|
||||
use tests\integration\testClasses\Binding\SomeClassRequiringServiceAlt;
|
||||
use tests\integration\testClasses\Binding\SomeClassRequiringValue;
|
||||
use tests\integration\testClasses\Binding\SomeFactory;
|
||||
use tests\integration\testClasses\Binding\SomeImplementation;
|
||||
use tests\integration\testClasses\Binding\SomeInterface;
|
||||
use tests\integration\testClasses\Binding\SomeService;
|
||||
|
||||
class BindingTest extends BaseTestCase
|
||||
{
|
||||
public function testImplementation(): void
|
||||
{
|
||||
$bindingLoader = new class() implements BindingLoader
|
||||
{
|
||||
public function load(): BindingData
|
||||
{
|
||||
$data = new BindingData();
|
||||
|
||||
$binder = new Binder($data);
|
||||
|
||||
$binder->bindImplementation(
|
||||
CacheItemPoolInterface::class,
|
||||
FileCacheItemPool::class
|
||||
);
|
||||
|
||||
$data->addGlobal(
|
||||
SomeInterface::class,
|
||||
Binding::createFromImplementationClassName(
|
||||
SomeImplementation::class
|
||||
)
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
};
|
||||
|
||||
$container = (new ContainerBuilder())
|
||||
->withBindingLoader($bindingLoader)
|
||||
->withParams(new ApplicationParams(noErrorHandler: true))
|
||||
->build();
|
||||
|
||||
$injectableFactory = $container->get('injectableFactory');
|
||||
|
||||
$this->assertInstanceOf(InjectableFactory::class, $injectableFactory);
|
||||
|
||||
$obj = $injectableFactory->create(SomeClass::class);
|
||||
|
||||
$this->assertNotNull($obj);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
SomeImplementation::class,
|
||||
$obj->get()
|
||||
);
|
||||
}
|
||||
|
||||
public function testFactory(): void
|
||||
{
|
||||
$bindingLoader = new class() implements BindingLoader
|
||||
{
|
||||
public function load(): BindingData
|
||||
{
|
||||
$data = new BindingData();
|
||||
|
||||
$binder = new Binder($data);
|
||||
|
||||
$binder->bindImplementation(
|
||||
CacheItemPoolInterface::class,
|
||||
FileCacheItemPool::class
|
||||
);
|
||||
|
||||
$data->addGlobal(
|
||||
SomeInterface::class,
|
||||
Binding::createFromFactoryClassName(
|
||||
SomeFactory::class
|
||||
)
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
};
|
||||
|
||||
$container = (new ContainerBuilder())
|
||||
->withBindingLoader($bindingLoader)
|
||||
->withParams(new ApplicationParams(noErrorHandler: true))
|
||||
->build();
|
||||
|
||||
$injectableFactory = $container->get('injectableFactory');
|
||||
|
||||
$this->assertInstanceOf(InjectableFactory::class, $injectableFactory);
|
||||
|
||||
$obj = $injectableFactory->create(SomeClass::class);
|
||||
|
||||
$this->assertNotNull($obj);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
SomeImplementation::class,
|
||||
$obj->get()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCallback()
|
||||
{
|
||||
$bindingLoader = new class() implements BindingLoader
|
||||
{
|
||||
public function load(): BindingData
|
||||
{
|
||||
$data = new BindingData();
|
||||
|
||||
$binder = new Binder($data);
|
||||
|
||||
$binder->bindImplementation(
|
||||
CacheItemPoolInterface::class,
|
||||
FileCacheItemPool::class
|
||||
);
|
||||
|
||||
$data->addGlobal(
|
||||
SomeInterface::class,
|
||||
Binding::createFromCallback(
|
||||
function (SomeImplementation $some) {
|
||||
return $some;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
};
|
||||
|
||||
$container = (new ContainerBuilder())
|
||||
->withBindingLoader($bindingLoader)
|
||||
->withParams(new ApplicationParams(noErrorHandler: true))
|
||||
->build();
|
||||
|
||||
$injectableFactory = $container->get('injectableFactory');
|
||||
|
||||
$this->assertInstanceOf(InjectableFactory::class, $injectableFactory);
|
||||
|
||||
$obj = $injectableFactory->create(SomeClass::class);
|
||||
|
||||
$this->assertNotNull($obj);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
SomeImplementation::class,
|
||||
$obj->get()
|
||||
);
|
||||
}
|
||||
|
||||
public function testService()
|
||||
{
|
||||
$bindingLoader = new class() implements BindingLoader
|
||||
{
|
||||
public function load(): BindingData
|
||||
{
|
||||
$data = new BindingData();
|
||||
|
||||
$binder = new Binder($data);
|
||||
|
||||
$binder->bindImplementation(
|
||||
CacheItemPoolInterface::class,
|
||||
FileCacheItemPool::class
|
||||
);
|
||||
|
||||
$data->addGlobal(
|
||||
SomeService::class,
|
||||
Binding::createFromServiceName('someService')
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
};
|
||||
|
||||
$someService = new SomeService();
|
||||
|
||||
$container = (new ContainerBuilder())
|
||||
->withServices([
|
||||
'someService' => $someService,
|
||||
])
|
||||
->withBindingLoader($bindingLoader)
|
||||
->withParams(new ApplicationParams(noErrorHandler: true))
|
||||
->build();
|
||||
|
||||
$injectableFactory = $container->get('injectableFactory');
|
||||
|
||||
$this->assertInstanceOf(InjectableFactory::class, $injectableFactory);
|
||||
|
||||
$obj = $injectableFactory->create(SomeClassRequiringService::class);
|
||||
|
||||
$this->assertNotNull($obj);
|
||||
|
||||
$this->assertSame(
|
||||
$someService,
|
||||
$obj->getService()
|
||||
);
|
||||
}
|
||||
|
||||
public function testValue()
|
||||
{
|
||||
$bindingLoader = new class() implements BindingLoader
|
||||
{
|
||||
public function load(): BindingData
|
||||
{
|
||||
$data = new BindingData();
|
||||
|
||||
$binder = new Binder($data);
|
||||
|
||||
$binder->bindImplementation(
|
||||
CacheItemPoolInterface::class,
|
||||
FileCacheItemPool::class
|
||||
);
|
||||
|
||||
$data->addContext(
|
||||
SomeClassRequiringValue::class,
|
||||
'$value',
|
||||
Binding::createFromValue('TEST_VALUE')
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
};
|
||||
|
||||
$container = (new ContainerBuilder())
|
||||
->withBindingLoader($bindingLoader)
|
||||
->withParams(new ApplicationParams(noErrorHandler: true))
|
||||
->build();
|
||||
|
||||
$injectableFactory = $container->get('injectableFactory');
|
||||
|
||||
$this->assertInstanceOf(InjectableFactory::class, $injectableFactory);
|
||||
|
||||
$obj = $injectableFactory->create(SomeClassRequiringValue::class);
|
||||
|
||||
$this->assertNotNull($obj);
|
||||
|
||||
$this->assertSame(
|
||||
'TEST_VALUE',
|
||||
$obj->getValue()
|
||||
);
|
||||
}
|
||||
|
||||
public function testQualifier(): void
|
||||
{
|
||||
$bindingLoader = new class() implements BindingLoader
|
||||
{
|
||||
public function load(): BindingData
|
||||
{
|
||||
$data = new BindingData();
|
||||
$binder = new Binder($data);
|
||||
|
||||
$binder->bindImplementation(
|
||||
CacheItemPoolInterface::class,
|
||||
FileCacheItemPool::class
|
||||
);
|
||||
|
||||
$binder->bindService(SomeService::class, 'testService');
|
||||
$binder->bindService(QualifiedClassKey::create(SomeService::class, 'alt'), 'testServiceAlt');
|
||||
|
||||
return $data;
|
||||
}
|
||||
};
|
||||
|
||||
$testService = new SomeService();
|
||||
$testServiceAlt = new SomeService('alt');
|
||||
|
||||
$container = (new ContainerBuilder())
|
||||
->withBindingLoader($bindingLoader)
|
||||
->withParams(new ApplicationParams(noErrorHandler: true))
|
||||
->withServices([
|
||||
'testService' => $testService,
|
||||
'testServiceAlt' => $testServiceAlt,
|
||||
])
|
||||
->build();
|
||||
|
||||
$injectableFactory = $container->get('injectableFactory');
|
||||
|
||||
$this->assertInstanceOf(InjectableFactory::class, $injectableFactory);
|
||||
|
||||
$obj = $injectableFactory->create(SomeClassRequiringService::class);
|
||||
$objAlt = $injectableFactory->create(SomeClassRequiringServiceAlt::class);
|
||||
|
||||
$this->assertInstanceOf(SomeService::class, $obj->getService());
|
||||
$this->assertEquals('default', $obj->getService()->name);
|
||||
|
||||
$this->assertInstanceOf(SomeService::class, $objAlt->getService());
|
||||
$this->assertEquals('alt', $objAlt->getService()->name);
|
||||
}
|
||||
}
|
||||
42
tests/integration/Espo/Core/ContainerTest.php
Normal file
42
tests/integration/Espo/Core/ContainerTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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\integration\Espo\Core;
|
||||
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
class ContainerTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
public function testGetByClass1(): void
|
||||
{
|
||||
$em = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$this->assertInstanceOf(EntityManager::class, $em);
|
||||
}
|
||||
}
|
||||
385
tests/integration/Espo/Core/EntryPoint/EntryPointTest.php
Normal file
385
tests/integration/Espo/Core/EntryPoint/EntryPointTest.php
Normal file
@@ -0,0 +1,385 @@
|
||||
<?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 integration\Espo\Core\EntryPoint;
|
||||
|
||||
use Espo\Core\Api\ErrorOutput;
|
||||
use Espo\Core\Api\Method;
|
||||
use Espo\Core\Api\RequestWrapper;
|
||||
use Espo\Core\Api\ResponseWrapper;
|
||||
use Espo\Core\ApplicationState;
|
||||
use Espo\Core\Binding\BindingContainerBuilder;
|
||||
use Espo\Core\EntryPoint\OutputEmitter;
|
||||
use Espo\Core\EntryPoint\RequestFactory;
|
||||
use Espo\Core\EntryPoint\ResponseFactory;
|
||||
use Espo\Core\EntryPoint\Starter;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class EntryPointTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testNoAuth(): void
|
||||
{
|
||||
$this->reCreateApplication(reuse: true, noUser: true);
|
||||
|
||||
$outputEmitter = $this->createMock(OutputEmitter::class);
|
||||
$errorOutput = $this->createMock(ErrorOutput::class);
|
||||
|
||||
$request = $this->createRequest(
|
||||
method: Method::GET,
|
||||
queryParams: [
|
||||
'entryPoint' => 'oauthCallback',
|
||||
],
|
||||
);
|
||||
|
||||
$response = $this->createMock(ResponseWrapper::class);
|
||||
|
||||
$starter = $this->createStarter(
|
||||
request: $request,
|
||||
response: $response,
|
||||
outputEmitter: $outputEmitter,
|
||||
errorOutput: $errorOutput,
|
||||
);
|
||||
|
||||
$errorOutput
|
||||
->expects(self::never())
|
||||
->method('processWithBodyPrinting');
|
||||
|
||||
$response
|
||||
->expects(self::once())
|
||||
->method('writeBody')
|
||||
->with(
|
||||
$this->callback(function (string $body) {
|
||||
return str_contains($body, "Site URL");
|
||||
})
|
||||
);
|
||||
|
||||
$starter->start();
|
||||
|
||||
$applicationState = $this->getContainer()->getByClass(ApplicationState::class);
|
||||
|
||||
$this->assertTrue($applicationState->hasUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testNoPostMethod(): void
|
||||
{
|
||||
$this->reCreateApplication(reuse: true, noUser: true);
|
||||
|
||||
$outputEmitter = $this->createMock(OutputEmitter::class);
|
||||
$errorOutput = $this->createMock(ErrorOutput::class);
|
||||
|
||||
$request = $this->createRequest(
|
||||
method: Method::POST,
|
||||
queryParams: [
|
||||
'entryPoint' => 'oauthCallback',
|
||||
],
|
||||
);
|
||||
|
||||
$response = $this->createMock(ResponseWrapper::class);
|
||||
|
||||
$starter = $this->createStarter(
|
||||
request: $request,
|
||||
response: $response,
|
||||
outputEmitter: $outputEmitter,
|
||||
errorOutput: $errorOutput,
|
||||
);
|
||||
|
||||
$errorOutput
|
||||
->expects(self::once())
|
||||
->method('processWithBodyPrinting');
|
||||
|
||||
$starter->start();
|
||||
|
||||
$applicationState = $this->getContainer()->getByClass(ApplicationState::class);
|
||||
|
||||
$this->assertFalse($applicationState->hasUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testNotExposed(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
$metadata->set('app', 'entryPoints', [
|
||||
'oauthCallback' => [
|
||||
'notExposed' => true,
|
||||
],
|
||||
]);
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication(reuse: true, noUser: true);
|
||||
|
||||
$outputEmitter = $this->createMock(OutputEmitter::class);
|
||||
$errorOutput = $this->createMock(ErrorOutput::class);
|
||||
|
||||
$request = $this->createRequest(
|
||||
method: Method::GET,
|
||||
queryParams: [
|
||||
'entryPoint' => 'oauthCallback',
|
||||
],
|
||||
);
|
||||
|
||||
$response = $this->createMock(ResponseWrapper::class);
|
||||
|
||||
$starter = $this->createStarter(
|
||||
request: $request,
|
||||
response: $response,
|
||||
outputEmitter: $outputEmitter,
|
||||
errorOutput: $errorOutput,
|
||||
);
|
||||
|
||||
$errorOutput
|
||||
->expects(self::once())
|
||||
->method('processWithBodyPrinting');
|
||||
|
||||
$starter->start();
|
||||
|
||||
$applicationState = $this->getContainer()->getByClass(ApplicationState::class);
|
||||
|
||||
$this->assertFalse($applicationState->hasUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testAllowedMethods(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
$metadata->set('app', 'entryPoints', [
|
||||
'oauthCallback' => [
|
||||
'allowedMethods' => ['get', 'post'],
|
||||
],
|
||||
]);
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication(reuse: true, noUser: true);
|
||||
|
||||
$outputEmitter = $this->createMock(OutputEmitter::class);
|
||||
$errorOutput = $this->createMock(ErrorOutput::class);
|
||||
|
||||
$request = $this->createRequest(
|
||||
method: Method::POST,
|
||||
queryParams: [
|
||||
'entryPoint' => 'oauthCallback',
|
||||
],
|
||||
);
|
||||
|
||||
$response = $this->createMock(ResponseWrapper::class);
|
||||
|
||||
$starter = $this->createStarter(
|
||||
request: $request,
|
||||
response: $response,
|
||||
outputEmitter: $outputEmitter,
|
||||
errorOutput: $errorOutput,
|
||||
);
|
||||
|
||||
$errorOutput
|
||||
->expects(self::never())
|
||||
->method('processWithBodyPrinting');
|
||||
|
||||
$starter->start();
|
||||
|
||||
$applicationState = $this->getContainer()->getByClass(ApplicationState::class);
|
||||
|
||||
$this->assertTrue($applicationState->hasUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testAuthRequired(): void
|
||||
{
|
||||
$this->reCreateApplication(reuse: true, noUser: true);
|
||||
|
||||
$outputEmitter = $this->createMock(OutputEmitter::class);
|
||||
$errorOutput = $this->createMock(ErrorOutput::class);
|
||||
|
||||
$request = $this->createRequest(
|
||||
method: Method::GET,
|
||||
queryParams: [
|
||||
'entryPoint' => 'avatar',
|
||||
],
|
||||
);
|
||||
|
||||
$response = $this->createMock(ResponseWrapper::class);
|
||||
|
||||
$starter = $this->createStarter(
|
||||
request: $request,
|
||||
response: $response,
|
||||
outputEmitter: $outputEmitter,
|
||||
errorOutput: $errorOutput,
|
||||
);
|
||||
|
||||
$errorOutput
|
||||
->expects(self::never())
|
||||
->method('processWithBodyPrinting');
|
||||
|
||||
$response
|
||||
->expects(self::never())
|
||||
->method('writeBody');
|
||||
|
||||
$starter->start();
|
||||
|
||||
$applicationState = $this->getContainer()->getByClass(ApplicationState::class);
|
||||
|
||||
$this->assertFalse($applicationState->hasUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testConsumesFail(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
$metadata->set('app', 'entryPoints', [
|
||||
'oauthCallback' => [
|
||||
'consumes' => ['application/json'],
|
||||
],
|
||||
]);
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication(reuse: true, noUser: true);
|
||||
|
||||
$outputEmitter = $this->createMock(OutputEmitter::class);
|
||||
$errorOutput = $this->createMock(ErrorOutput::class);
|
||||
|
||||
$request = $this->createRequest(
|
||||
method: Method::GET,
|
||||
queryParams: [
|
||||
'entryPoint' => 'oauthCallback',
|
||||
],
|
||||
headers: [
|
||||
'Content-Type' => 'text/plain',
|
||||
],
|
||||
);
|
||||
|
||||
$response = $this->createMock(ResponseWrapper::class);
|
||||
|
||||
$starter = $this->createStarter(
|
||||
request: $request,
|
||||
response: $response,
|
||||
outputEmitter: $outputEmitter,
|
||||
errorOutput: $errorOutput,
|
||||
);
|
||||
|
||||
$errorOutput
|
||||
->expects(self::once())
|
||||
->method('processWithBodyPrinting');
|
||||
|
||||
$starter->start();
|
||||
|
||||
$applicationState = $this->getContainer()->getByClass(ApplicationState::class);
|
||||
|
||||
$this->assertFalse($applicationState->hasUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testConsumesSuccess(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
$metadata->set('app', 'entryPoints', [
|
||||
'oauthCallback' => [
|
||||
'consumes' => ['application/json'],
|
||||
],
|
||||
]);
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication(reuse: true, noUser: true);
|
||||
|
||||
$outputEmitter = $this->createMock(OutputEmitter::class);
|
||||
$errorOutput = $this->createMock(ErrorOutput::class);
|
||||
|
||||
$request = $this->createRequest(
|
||||
method: Method::GET,
|
||||
queryParams: [
|
||||
'entryPoint' => 'oauthCallback',
|
||||
],
|
||||
headers: [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
);
|
||||
|
||||
$response = $this->createMock(ResponseWrapper::class);
|
||||
|
||||
$starter = $this->createStarter(
|
||||
request: $request,
|
||||
response: $response,
|
||||
outputEmitter: $outputEmitter,
|
||||
errorOutput: $errorOutput,
|
||||
);
|
||||
|
||||
$errorOutput
|
||||
->expects(self::never())
|
||||
->method('processWithBodyPrinting');
|
||||
|
||||
$starter->start();
|
||||
|
||||
$applicationState = $this->getContainer()->getByClass(ApplicationState::class);
|
||||
|
||||
$this->assertTrue($applicationState->hasUser());
|
||||
}
|
||||
|
||||
private function createStarter(
|
||||
RequestWrapper $request,
|
||||
ResponseWrapper $response,
|
||||
OutputEmitter $outputEmitter,
|
||||
ErrorOutput $errorOutput,
|
||||
): Starter {
|
||||
|
||||
$requestFactory = $this->createMock(RequestFactory::class);
|
||||
$responseFactory = $this->createMock(ResponseFactory::class);
|
||||
|
||||
$requestFactory
|
||||
->expects(self::once())
|
||||
->method('create')
|
||||
->willReturn($request);
|
||||
|
||||
$responseFactory
|
||||
->expects(self::once())
|
||||
->method('create')
|
||||
->willReturn($response);
|
||||
|
||||
$binding = BindingContainerBuilder::create()
|
||||
->bindInstance(RequestFactory::class, $requestFactory)
|
||||
->bindInstance(ResponseFactory::class, $responseFactory)
|
||||
->bindInstance(OutputEmitter::class, $outputEmitter)
|
||||
->bindInstance(ErrorOutput::class, $errorOutput)
|
||||
->build();
|
||||
|
||||
return $this->getInjectableFactory()->createWithBinding(Starter::class, $binding);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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\integration\Espo\Core\Field\Address;
|
||||
|
||||
use Espo\Core\Field\{
|
||||
Address\AddressFormatterFactory,
|
||||
Address,
|
||||
};
|
||||
|
||||
class AddressFormatterTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
public function testFormatter1()
|
||||
{
|
||||
$formatterFactory = $this->getContainer()->get('injectableFactory')->create(AddressFormatterFactory::class);
|
||||
|
||||
$formatter = $formatterFactory->create(1);
|
||||
|
||||
$address = Address::createBuilder()
|
||||
->setStreet('street')
|
||||
->setCity('city')
|
||||
->setCountry('country')
|
||||
->setState('state')
|
||||
->setPostalCode('postalCode')
|
||||
->build();
|
||||
|
||||
$expected =
|
||||
"street\n" .
|
||||
"city, state postalCode\n" .
|
||||
"country";
|
||||
|
||||
$result = $formatter->format($address);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
359
tests/integration/Espo/Core/Field/ValueObjectTest.php
Normal file
359
tests/integration/Espo/Core/Field/ValueObjectTest.php
Normal file
@@ -0,0 +1,359 @@
|
||||
<?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\integration\Espo\Core\Field;
|
||||
|
||||
use Espo\Core\Field\Address;
|
||||
use Espo\Core\Field\Currency;
|
||||
use Espo\Core\Field\Date;
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Core\Field\DateTimeOptional;
|
||||
use Espo\Core\Field\EmailAddress;
|
||||
use Espo\Core\Field\EmailAddressGroup;
|
||||
use Espo\Core\Field\Link;
|
||||
use Espo\Core\Field\LinkMultiple;
|
||||
use Espo\Core\Field\LinkMultipleItem;
|
||||
use Espo\Core\Field\LinkParent;
|
||||
use Espo\Core\Field\PhoneNumber;
|
||||
use Espo\Core\Field\PhoneNumberGroup;
|
||||
use Espo\Modules\Crm\Entities\Meeting;
|
||||
use Espo\ORM\EntityManager;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class ValueObjectTest extends BaseTestCase
|
||||
{
|
||||
public function testAddress()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$entity = $entityManager->getNewEntity('Account');
|
||||
|
||||
$address = Address
|
||||
::create()
|
||||
->withCity('Test')
|
||||
->withCountry('United States');
|
||||
|
||||
$entity->setBillingAddress($address);
|
||||
|
||||
$entityManager->saveEntity($entity);
|
||||
|
||||
$entity = $entityManager->getEntityById('Account', $entity->getId());
|
||||
|
||||
$address = $entity->getBillingAddress();
|
||||
|
||||
$this->assertNotNull($address);
|
||||
|
||||
$this->assertEquals('Test', $address->getCity());
|
||||
|
||||
$entity->setValueObject('billingAddress', null);
|
||||
|
||||
$address = $entity->getValueObject('billingAddress');
|
||||
|
||||
$this->assertNotNull($address);
|
||||
|
||||
$this->assertEquals(null, $address->getCity());
|
||||
}
|
||||
|
||||
public function testCurrency()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$opportunity = $entityManager->getNewEntity('Opportunity');
|
||||
|
||||
$opportunity->set('name', 'opp-1');
|
||||
|
||||
$opportunity->setAmount(new Currency(1000.0, 'USD'));
|
||||
|
||||
$entityManager->saveEntity($opportunity);
|
||||
|
||||
$opportunity = $entityManager->getEntityById('Opportunity', $opportunity->getId());
|
||||
|
||||
$currency = $opportunity->getAmount();
|
||||
|
||||
$this->assertNotNull($currency);
|
||||
|
||||
$this->assertEquals(1000.0, $currency->getAmount());
|
||||
$this->assertEquals('USD', $currency->getCode());
|
||||
}
|
||||
|
||||
public function testDate()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$opportunity = $entityManager->getNewEntity('Opportunity');
|
||||
|
||||
$opportunity->set('name', 'opp-1');
|
||||
|
||||
$opportunity->setCloseDate(Date::fromString('2021-05-01'));
|
||||
|
||||
$entityManager->saveEntity($opportunity);
|
||||
|
||||
$opportunity = $entityManager->getEntityById('Opportunity', $opportunity->getId());
|
||||
|
||||
$closeDate = $opportunity->getCloseDate();
|
||||
|
||||
$this->assertNotNull($closeDate);
|
||||
|
||||
$this->assertEquals('2021-05-01', $closeDate->getString());
|
||||
|
||||
$opportunity->setValueObject('closeDate', null);
|
||||
|
||||
$entityManager->saveEntity($opportunity);
|
||||
|
||||
$opportunity = $entityManager->getEntityById('Opportunity', $opportunity->getId());
|
||||
|
||||
$closeDate = $opportunity->getValueObject('closeDate');
|
||||
|
||||
$this->assertNull($closeDate);
|
||||
}
|
||||
|
||||
public function testDateTime()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$call = $entityManager->getNewEntity('Call');
|
||||
|
||||
$call->set('name', 'call-1');
|
||||
|
||||
$call->setValueObject('dateStart', DateTime::fromString('2021-05-01 10:00:00'));
|
||||
|
||||
$entityManager->saveEntity($call);
|
||||
|
||||
$call = $entityManager->getEntityById('Call', $call->getId());
|
||||
|
||||
$dateStart = $call->getValueObject('dateStart');
|
||||
|
||||
$this->assertNotNull($dateStart);
|
||||
|
||||
$this->assertEquals('2021-05-01 10:00:00', $dateStart->getString());
|
||||
|
||||
$call->setValueObject('dateStart', null);
|
||||
|
||||
$entityManager->saveEntity($call);
|
||||
|
||||
$call = $entityManager->getEntityById('Call', $call->getId());
|
||||
|
||||
$dateStart = $call->getValueObject('dateStart');
|
||||
|
||||
$this->assertNull($dateStart);
|
||||
}
|
||||
|
||||
public function testDateTimeOptional()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$meeting = $entityManager->getRepositoryByClass(Meeting::class)->getNew();
|
||||
|
||||
$meeting->set('name', 'meeting-1');
|
||||
|
||||
$meeting->setDateStart(DateTimeOptional::fromString('2021-05-01 10:00:00'));
|
||||
|
||||
$entityManager->saveEntity($meeting);
|
||||
|
||||
$entityManager->refreshEntity($meeting);
|
||||
|
||||
$dateStart = $meeting->getDateStart();
|
||||
|
||||
$this->assertNotNull($dateStart);
|
||||
|
||||
$this->assertEquals('2021-05-01 10:00:00', $dateStart->getString());
|
||||
|
||||
$meeting->setValueObject('dateStart', null);
|
||||
|
||||
$entityManager->saveEntity($meeting);
|
||||
|
||||
$entityManager->refreshEntity($meeting);
|
||||
|
||||
$dateStart = $meeting->getValueObject('dateStart');
|
||||
|
||||
$this->assertNull($dateStart);
|
||||
|
||||
$meeting->setIsAllDay(true);
|
||||
$meeting->setValueObject('dateStart', DateTimeOptional::fromString('2021-05-01'));
|
||||
|
||||
$entityManager->saveEntity($meeting);
|
||||
|
||||
$entityManager->refreshEntity($meeting);
|
||||
|
||||
$dateStart = $meeting->getValueObject('dateStart');
|
||||
|
||||
$this->assertNotNull($dateStart);
|
||||
|
||||
$this->assertEquals('2021-05-01', $dateStart->getString());
|
||||
}
|
||||
|
||||
public function testEmailAddress()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$entity = $entityManager->getNewEntity('Account');
|
||||
|
||||
$group = EmailAddressGroup::create([
|
||||
EmailAddress::create('one@test.com'),
|
||||
EmailAddress::create('two@test.com')->optedOut(),
|
||||
EmailAddress::create('three@test.com')->invalid(),
|
||||
]);
|
||||
|
||||
$entity->setEmailAddressGroup($group);
|
||||
|
||||
$entityManager->saveEntity($entity);
|
||||
|
||||
$entity = $entityManager->getEntityById('Account', $entity->getId());
|
||||
|
||||
$group = $entity->getEmailAddressGroup();
|
||||
|
||||
$this->assertEquals('one@test.com', $group->getPrimary()->getAddress());
|
||||
|
||||
$this->assertTrue($group->getList()[1]->isOptedOut() || $group->getList()[2]->isOptedOut());
|
||||
|
||||
$this->assertTrue($group->getList()[1]->isInvalid() || $group->getList()[2]->isInvalid());
|
||||
}
|
||||
|
||||
public function testPhoneNumber()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$entity = $entityManager->getNewEntity('Account');
|
||||
|
||||
$group = PhoneNumberGroup::create([
|
||||
PhoneNumber::create('1')->withType('Office'),
|
||||
PhoneNumber::create('2')->optedOut(),
|
||||
PhoneNumber::create('3')->invalid(),
|
||||
]);
|
||||
|
||||
$entity->setPhoneNumberGroup($group);
|
||||
|
||||
$entityManager->saveEntity($entity);
|
||||
|
||||
$entity = $entityManager->getEntityById('Account', $entity->getId());
|
||||
|
||||
$group = $entity->getPhoneNumberGroup();
|
||||
|
||||
$this->assertEquals('1', $group->getPrimary()->getNumber());
|
||||
$this->assertEquals('Office', $group->getPrimary()->getType());
|
||||
|
||||
$this->assertTrue($group->getList()[1]->isOptedOut() || $group->getList()[2]->isOptedOut());
|
||||
|
||||
$this->assertTrue($group->getList()[1]->isInvalid() || $group->getList()[2]->isInvalid());
|
||||
}
|
||||
|
||||
public function testLink()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$entity = $entityManager->getNewEntity('Account');
|
||||
|
||||
$entity->setValueObject('assignedUser', Link::create('1'));
|
||||
|
||||
$link = $entity->getValueObject('assignedUser');
|
||||
|
||||
$this->assertEquals('1', $link->getId());
|
||||
|
||||
$entity->setValueObject('assignedUser', null);
|
||||
|
||||
$this->assertNull($entity->getValueObject('assignedUser'));
|
||||
}
|
||||
|
||||
public function testLinkParent()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$entity = $entityManager->getNewEntity('Task');
|
||||
|
||||
$entity->setValueObject('parent', LinkParent::create('Account', 'test-id'));
|
||||
|
||||
$link = $entity->getValueObject('parent');
|
||||
|
||||
$this->assertEquals('test-id', $link->getId());
|
||||
$this->assertEquals('Account', $link->getEntityType());
|
||||
|
||||
$entity->setValueObject('parent', null);
|
||||
|
||||
$this->assertNull($entity->getValueObject('parent'));
|
||||
}
|
||||
|
||||
public function testLinkMultiple1(): void
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$c1 = $entityManager->createEntity('Contact', []);
|
||||
$c2 = $entityManager->createEntity('Contact', []);
|
||||
|
||||
$entity = $entityManager->getNewEntity('Opportunity');
|
||||
|
||||
$link = LinkMultiple::create([
|
||||
LinkMultipleItem::create($c1->getId())->withColumnValue('role', 'Decision Maker'),
|
||||
LinkMultipleItem::create($c2->getId()),
|
||||
]);
|
||||
|
||||
$entity->setValueObject('contacts', $link);
|
||||
|
||||
$entityManager->saveEntity($entity);
|
||||
|
||||
$entity = $entityManager->getEntityById('Opportunity', $entity->getId());
|
||||
|
||||
/** @var LinkMultiple */
|
||||
$link = $entity->getValueObject('contacts');
|
||||
|
||||
$this->assertEquals(2, $link->getCount());
|
||||
|
||||
$this->assertEquals('Decision Maker', $link->getById($c1->getId())->getColumnValue('role'));
|
||||
$this->assertEquals(null, $link->getById($c2->getId())->getColumnValue('role'));
|
||||
}
|
||||
|
||||
public function testLinkMultiple2()
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$c1 = $entityManager->createEntity('Contact', []);
|
||||
$c2 = $entityManager->createEntity('Contact', []);
|
||||
|
||||
$entity = $entityManager->getNewEntity('Opportunity');
|
||||
|
||||
$link = LinkMultiple::create([
|
||||
LinkMultipleItem::create($c1->getId())->withColumnValue('role', 'Decision Maker'),
|
||||
LinkMultipleItem::create($c2->getId()),
|
||||
]);
|
||||
|
||||
$entity->setValueObject('contacts', $link);
|
||||
|
||||
$entityManager->saveEntity($entity);
|
||||
|
||||
$entity = $entityManager->getEntityById('Opportunity', $entity->getId());
|
||||
|
||||
$entity->loadLinkMultipleField('contacts');
|
||||
|
||||
/** @var LinkMultiple */
|
||||
$link = $entity->getValueObject('contacts');
|
||||
|
||||
$this->assertEquals(2, $link->getCount());
|
||||
|
||||
$this->assertEquals('Decision Maker', $link->getById($c1->getId())->getColumnValue('role'));
|
||||
}
|
||||
}
|
||||
161
tests/integration/Espo/Core/FieldProcessing/EmailAddressTest.php
Normal file
161
tests/integration/Espo/Core/FieldProcessing/EmailAddressTest.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?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\integration\Espo\Core\FieldProcessing;
|
||||
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use Espo\Core\Field\EmailAddress;
|
||||
use Espo\Core\Field\EmailAddressGroup;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class EmailAddressTest extends BaseTestCase
|
||||
{
|
||||
public function testEmailAddress1(): void
|
||||
{
|
||||
/* @var $entityManager EntityManager */
|
||||
$entityManager = $this->getContainer()->get('entityManager');
|
||||
|
||||
$contact = $entityManager->createEntity('Contact', [
|
||||
'emailAddress' => 'test@test.com',
|
||||
]);
|
||||
|
||||
$contact = $entityManager->getEntityById('Contact', $contact->getId());
|
||||
|
||||
/* @var $group1 EmailAddressGroup */
|
||||
$group1 = $contact->getEmailAddressGroup();
|
||||
|
||||
$this->assertEquals(1, $group1->getCount());
|
||||
|
||||
$this->assertEquals('test@test.com', $group1->getPrimary()->getAddress());
|
||||
|
||||
$group2 = EmailAddressGroup::create()
|
||||
->withAdded(
|
||||
EmailAddress::create('test-a@test.com')->invalid()
|
||||
)
|
||||
->withAdded(
|
||||
EmailAddress::create('test@test.com')->optedOut()
|
||||
);
|
||||
|
||||
$contact->setValueObject('emailAddress', $group2);
|
||||
|
||||
$entityManager->saveEntity($contact);
|
||||
|
||||
$contact = $entityManager->getEntityById('Contact', $contact->getId());
|
||||
|
||||
/* @var $group3 EmailAddressGroup */
|
||||
$group3 = $contact->getEmailAddressGroup();
|
||||
|
||||
$this->assertEquals(2, $group3->getCount());
|
||||
$this->assertEquals('test-a@test.com', $group3->getPrimary()->getAddress());
|
||||
$this->assertTrue($group3->getPrimary()->isInvalid());
|
||||
$this->assertTrue($group3->getList()[1]->isOptedOut());
|
||||
|
||||
$group4 = EmailAddressGroup::create()
|
||||
->withAdded(
|
||||
EmailAddress::create('test-a@test.com')->invalid()
|
||||
);
|
||||
|
||||
$contact->setValueObject('emailAddress', $group4);
|
||||
|
||||
$entityManager->saveEntity($contact);
|
||||
|
||||
$contact = $entityManager->getEntityById('Contact', $contact->getId());
|
||||
|
||||
/* @var $group5 EmailAddressGroup */
|
||||
$group5 = $contact->getEmailAddressGroup();
|
||||
|
||||
$this->assertEquals(1, $group5->getCount());
|
||||
}
|
||||
|
||||
public function testEmailAddress2(): void
|
||||
{
|
||||
/* @var $entityManager EntityManager */
|
||||
$entityManager = $this->getContainer()->get('entityManager');
|
||||
|
||||
$lead = $entityManager->createEntity('Lead', [
|
||||
'emailAddress' => 'test@test.com',
|
||||
]);
|
||||
|
||||
$contact = $entityManager->createEntity('Contact', [
|
||||
'emailAddress' => 'test@test.com',
|
||||
]);
|
||||
|
||||
$contactFetched = $entityManager->getEntityById('Contact', $contact->getId());
|
||||
|
||||
/* @var $group EmailAddressGroup */
|
||||
$group = $contactFetched->getEmailAddressGroup();
|
||||
|
||||
$this->assertEquals(1, $group->getCount());
|
||||
|
||||
$this->assertEquals('test@test.com', $group->getPrimary()->getAddress());
|
||||
}
|
||||
|
||||
public function testPrimaryFirst(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$lead = $em->getRDBRepositoryByClass(Lead::class)
|
||||
->getNew();
|
||||
|
||||
$lead->set('emailAddressData', [
|
||||
(object) ['emailAddress' => 'test-1@test.com'],
|
||||
(object) ['emailAddress' => 'test-2@test.com'],
|
||||
(object) ['emailAddress' => 'test-3@test.com'],
|
||||
(object) ['emailAddress' => 'test-4@test.com'],
|
||||
]);
|
||||
|
||||
$em->saveEntity($lead);
|
||||
$em->refreshEntity($lead);
|
||||
|
||||
$this->assertEquals('test-1@test.com', $lead->getEmailAddress());
|
||||
}
|
||||
|
||||
public function testEmailAddress3(): void
|
||||
{
|
||||
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Contact::class);
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
/** @var Contact $contact */
|
||||
$contact = $em->createEntity(Contact::ENTITY_TYPE);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->update($contact->getId(), (object) [
|
||||
'emailAddress' => 'test@test.com',
|
||||
], UpdateParams::create());
|
||||
|
||||
$em->refreshEntity($contact);
|
||||
|
||||
$this->assertEquals('test@test.com', $contact->getEmailAddress());
|
||||
}
|
||||
}
|
||||
73
tests/integration/Espo/Core/FieldProcessing/FileTest.php
Normal file
73
tests/integration/Espo/Core/FieldProcessing/FileTest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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\integration\Espo\Core\FieldProcessing;
|
||||
|
||||
use Espo\Core\{
|
||||
ORM\EntityManager,
|
||||
};
|
||||
|
||||
class FileTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
public function testFile1(): void
|
||||
{
|
||||
/* @var $entityManager EntityManager */
|
||||
$entityManager = $this->getContainer()->get('entityManager');
|
||||
|
||||
$attachment1 = $entityManager->createEntity('Attachment', [
|
||||
'contents' => 'test-1',
|
||||
'relatedType' => 'Document',
|
||||
]);
|
||||
|
||||
$document = $entityManager->createEntity('Document', [
|
||||
'fileId' => $attachment1->getId(),
|
||||
]);
|
||||
|
||||
$attachment1 = $entityManager->getEntityById('Attachment', $attachment1->getId());
|
||||
|
||||
$this->assertEquals($document->getId(), $attachment1->get('relatedId'));
|
||||
|
||||
$attachment2 = $entityManager->createEntity('Attachment', [
|
||||
'contents' => 'test-2',
|
||||
'relatedType' => 'Document',
|
||||
]);
|
||||
|
||||
$document->set('fileId', $attachment2->getId());
|
||||
|
||||
$entityManager->saveEntity($document);
|
||||
|
||||
$attachment2 = $entityManager->getEntityById('Attachment', $attachment2->getId());
|
||||
|
||||
$this->assertEquals($document->getId(), $attachment2->get('relatedId'));
|
||||
|
||||
$attachment1 = $entityManager->getEntityById('Attachment', $attachment1->getId());
|
||||
|
||||
$this->assertNull($attachment1);
|
||||
}
|
||||
}
|
||||
141
tests/integration/Espo/Core/FieldProcessing/PhoneNumberTest.php
Normal file
141
tests/integration/Espo/Core/FieldProcessing/PhoneNumberTest.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?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\integration\Espo\Core\FieldProcessing;
|
||||
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
use Espo\Core\Field\PhoneNumber;
|
||||
use Espo\Core\Field\PhoneNumberGroup;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class PhoneNumberTest extends BaseTestCase
|
||||
{
|
||||
public function testPhoneNumber1(): void
|
||||
{
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$contact = $entityManager->getNewEntity(Contact::ENTITY_TYPE);
|
||||
$contact->set('phoneNumber', '+1');
|
||||
$entityManager->saveEntity($contact);
|
||||
|
||||
$this->assertEquals('+1', $contact->get('phoneNumber'));
|
||||
|
||||
$contact = $entityManager->getEntityById('Contact', $contact->getId());
|
||||
|
||||
/* @var $group1 PhoneNumberGroup */
|
||||
$group1 = $contact->getPhoneNumberGroup();
|
||||
|
||||
$this->assertEquals(1, $group1->getCount());
|
||||
|
||||
$this->assertEquals('+1', $group1->getPrimary()->getNumber());
|
||||
|
||||
$group2 = PhoneNumberGroup
|
||||
::create()
|
||||
->withAdded(
|
||||
PhoneNumber::create('+2')->invalid()
|
||||
)
|
||||
->withAdded(
|
||||
PhoneNumber::create('+1')->optedOut()
|
||||
);
|
||||
|
||||
$contact->setValueObject('phoneNumber', $group2);
|
||||
|
||||
$entityManager->saveEntity($contact);
|
||||
|
||||
$contact = $entityManager->getEntityById('Contact', $contact->getId());
|
||||
|
||||
/* @var $group3 PhoneNumberGroup */
|
||||
$group3 = $contact->getPhoneNumberGroup();
|
||||
|
||||
$this->assertEquals(2, $group3->getCount());
|
||||
$this->assertEquals('+2', $group3->getPrimary()->getNumber());
|
||||
$this->assertTrue($group3->getPrimary()->isInvalid());
|
||||
$this->assertTrue($group3->getList()[1]->isOptedOut());
|
||||
|
||||
$group4 = PhoneNumberGroup
|
||||
::create()
|
||||
->withAdded(
|
||||
PhoneNumber::create('+2')->invalid()
|
||||
);
|
||||
|
||||
$contact->setValueObject('phoneNumber', $group4);
|
||||
|
||||
$entityManager->saveEntity($contact);
|
||||
|
||||
$contact = $entityManager->getEntityById('Contact', $contact->getId());
|
||||
|
||||
/* @var $group5 PhoneNumberGroup */
|
||||
$group5 = $contact->getPhoneNumberGroup();
|
||||
|
||||
$this->assertEquals(1, $group5->getCount());
|
||||
}
|
||||
|
||||
public function testPrimaryFirst(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$lead = $em->getRDBRepositoryByClass(Lead::class)
|
||||
->getNew();
|
||||
|
||||
$lead->set('phoneNumberData', [
|
||||
(object) ['phoneNumber' => '+0000000001'],
|
||||
(object) ['phoneNumber' => '+0000000002'],
|
||||
(object) ['phoneNumber' => '+0000000003'],
|
||||
(object) ['phoneNumber' => '+0000000004'],
|
||||
]);
|
||||
|
||||
$em->saveEntity($lead);
|
||||
$em->refreshEntity($lead);
|
||||
|
||||
$this->assertEquals('+0000000001', $lead->getPhoneNumber());
|
||||
}
|
||||
|
||||
public function testPhoneNumber2(): void
|
||||
{
|
||||
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Contact::class);
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
/** @var Contact $contact */
|
||||
$contact = $em->createEntity(Contact::ENTITY_TYPE);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->update($contact->getId(), (object) [
|
||||
'phoneNumber' => '+11111111111',
|
||||
], UpdateParams::create());
|
||||
|
||||
$em->refreshEntity($contact);
|
||||
|
||||
$this->assertEquals('+11111111111', $contact->getPhoneNumber());
|
||||
}
|
||||
}
|
||||
228
tests/integration/Espo/Core/FieldProcessing/RelationTest.php
Normal file
228
tests/integration/Espo/Core/FieldProcessing/RelationTest.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?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\integration\Espo\Core\FieldProcessing;
|
||||
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
use Espo\Modules\Crm\Entities\Opportunity;
|
||||
|
||||
class RelationTest extends BaseTestCase
|
||||
{
|
||||
public function testLinkMultiple1(): void
|
||||
{
|
||||
/* @var $entityManager EntityManager */
|
||||
$entityManager = $this->getContainer()->get('entityManager');
|
||||
|
||||
$contact1 = $entityManager->createEntity('Contact', []);
|
||||
$contact2 = $entityManager->createEntity('Contact', []);
|
||||
$contact3 = $entityManager->createEntity('Contact', []);
|
||||
|
||||
$opportunity = $entityManager->createEntity('Opportunity', [
|
||||
'contactsIds' => [
|
||||
$contact1->getId(),
|
||||
$contact2->getId(),
|
||||
],
|
||||
'contactsColumns' => (object) [
|
||||
$contact1->getId() => (object) [
|
||||
'role' => 'Decision Maker',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$opportunity = $entityManager->getEntityById('Opportunity', $opportunity->getId());
|
||||
|
||||
$this->assertEquals(
|
||||
self::sortArray([
|
||||
$contact1->getId(),
|
||||
$contact2->getId(),
|
||||
]),
|
||||
self::sortArray($opportunity->getLinkMultipleIdList('contacts'))
|
||||
);
|
||||
|
||||
$column1 = $entityManager
|
||||
->getRDBRepository('Opportunity')
|
||||
->getRelation($opportunity, 'contacts')
|
||||
->getColumn($contact1, 'role');
|
||||
|
||||
$this->assertEquals('Decision Maker', $column1);
|
||||
|
||||
$opportunity->set([
|
||||
'contactsIds' => [
|
||||
$contact2->getId(),
|
||||
$contact3->getId(),
|
||||
],
|
||||
'contactsColumns' => (object) [
|
||||
$contact2->getId() => (object) [
|
||||
'role' => null,
|
||||
],
|
||||
$contact3->getId() => (object) [
|
||||
'role' => 'Evaluator',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($opportunity);
|
||||
|
||||
$opportunity = $entityManager->getEntityById('Opportunity', $opportunity->getId());
|
||||
|
||||
$this->assertEquals(
|
||||
self::sortArray([
|
||||
$contact2->getId(),
|
||||
$contact3->getId(),
|
||||
]),
|
||||
self::sortArray($opportunity->getLinkMultipleIdList('contacts'))
|
||||
);
|
||||
|
||||
$column3 = $entityManager
|
||||
->getRDBRepository('Opportunity')
|
||||
->getRelation($opportunity, 'contacts')
|
||||
->getColumn($contact3, 'role');
|
||||
|
||||
$this->assertEquals('Evaluator', $column3);
|
||||
|
||||
$opportunity = $entityManager->getEntityById('Opportunity', $opportunity->getId());
|
||||
|
||||
$opportunity->set([
|
||||
'contactsColumns' => (object) [
|
||||
$contact3->getId() => (object) [
|
||||
'role' => 'Decision Maker',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($opportunity);
|
||||
|
||||
$column3 = $entityManager
|
||||
->getRDBRepository('Opportunity')
|
||||
->getRelation($opportunity, 'contacts')
|
||||
->getColumn($contact3, 'role');
|
||||
|
||||
$this->assertEquals('Decision Maker', $column3);
|
||||
|
||||
// W/o link-multiple.
|
||||
|
||||
$opp1 = $entityManager->getRDBRepositoryByClass(Opportunity::class)->getNew();
|
||||
$entityManager->saveEntity($opp1);
|
||||
|
||||
$opp2 = $entityManager->getRDBRepositoryByClass(Opportunity::class)->getNew();
|
||||
$entityManager->saveEntity($opp2);
|
||||
|
||||
$contact = $entityManager->getRDBRepositoryByClass(Contact::class)->getNew();
|
||||
$contact->setMultiple([
|
||||
'opportunitiesIds' => [$opp1->getId()]
|
||||
]);
|
||||
$entityManager->saveEntity($contact);
|
||||
|
||||
$this->assertTrue(
|
||||
$entityManager->getRelation($contact, 'opportunities')->isRelatedById($opp1->getId())
|
||||
);
|
||||
|
||||
// Do not allow update IDs if no link-multiple field.
|
||||
|
||||
$contact->setMultiple([
|
||||
'opportunitiesIds' => [$opp2->getId()]
|
||||
]);
|
||||
$entityManager->saveEntity($contact);
|
||||
|
||||
$this->assertTrue(
|
||||
$entityManager->getRelation($contact, 'opportunities')->isRelatedById($opp1->getId())
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$entityManager->getRelation($contact, 'opportunities')->isRelatedById($opp2->getId())
|
||||
);
|
||||
}
|
||||
|
||||
public function testHasOne(): void
|
||||
{
|
||||
/* @var $entityManager EntityManager */
|
||||
$entityManager = $this->getContainer()->get('entityManager');
|
||||
|
||||
$lead1 = $entityManager->createEntity('Lead', []);
|
||||
$lead2 = $entityManager->createEntity('Lead', []);
|
||||
|
||||
$account = $entityManager->createEntity('Account', []);
|
||||
|
||||
$lead1->set('createdAccountId', $account->getId());
|
||||
|
||||
$entityManager->saveEntity($lead1);
|
||||
|
||||
$lead2->set('createdAccountId', $account->getId());
|
||||
|
||||
$entityManager->saveEntity($lead2);
|
||||
|
||||
$lead1 = $entityManager->getEntityById('Lead', $lead1->getId());
|
||||
|
||||
$this->assertNull($lead1->get('createdAccountId'));
|
||||
|
||||
$lead2 = $entityManager->getEntityById('Lead', $lead2->getId());
|
||||
|
||||
$this->assertEquals($account->getId(), $lead2->get('createdAccountId'));
|
||||
}
|
||||
|
||||
public function testBelongsToHasOne(): void
|
||||
{
|
||||
/* @var $entityManager EntityManager */
|
||||
$entityManager = $this->getContainer()->get('entityManager');
|
||||
|
||||
$lead1 = $entityManager->createEntity('Lead', []);
|
||||
$lead2 = $entityManager->createEntity('Lead', []);
|
||||
|
||||
$account = $entityManager->createEntity('Account', [
|
||||
'originalLeadId' => $lead1->getId(),
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($account);
|
||||
|
||||
$account = $entityManager->getEntityById('Account', $account->getId());
|
||||
|
||||
$account->set([
|
||||
'originalLeadId' => $lead2->getId(),
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($account);
|
||||
|
||||
$lead2 = $entityManager->getEntityById('Lead', $lead2->getId());
|
||||
|
||||
$this->assertEquals($account->getId(), $lead2->get('createdAccountId'));
|
||||
|
||||
$lead1 = $entityManager->getEntityById('Lead', $lead1->getId());
|
||||
|
||||
$this->assertEquals(null, $lead1->get('createdAccountId'));
|
||||
}
|
||||
|
||||
private static function sortArray(array $array): array
|
||||
{
|
||||
sort($array);
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
139
tests/integration/Espo/Core/FieldProcessing/ReminderTest.php
Normal file
139
tests/integration/Espo/Core/FieldProcessing/ReminderTest.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?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\integration\Espo\Core\FieldProcessing;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Espo\Core\Authentication\Util\DelayUtil;
|
||||
use Espo\Core\Binding\Binder;
|
||||
use Espo\Core\Binding\BindingProcessor;
|
||||
use Espo\Core\Field\DateTime;
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
use Espo\Core\Utils\DateTime\Clock;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\Meeting;
|
||||
use Espo\Modules\Crm\Entities\Reminder;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class ReminderTest extends BaseTestCase
|
||||
{
|
||||
public function testOne(): void
|
||||
{
|
||||
/* @var $entityManager EntityManager */
|
||||
$entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$user = $this->getContainer()->getByClass(User::class);
|
||||
|
||||
$meeting = $entityManager->createEntity('Meeting', [
|
||||
'dateStart' => DateTime::createNow()->modify('+1 day')->toString(),
|
||||
'usersIds' => [$user->getId()],
|
||||
'reminders' => [
|
||||
(object) [
|
||||
'type' => 'Popup',
|
||||
'seconds' => 0,
|
||||
],
|
||||
(object) [
|
||||
'type' => 'Popup',
|
||||
'seconds' => 60,
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$reminderList = $entityManager
|
||||
->getRDBRepository(Reminder::ENTITY_TYPE)
|
||||
->where([
|
||||
'entityId' => $meeting->getId(),
|
||||
'entityType' => $meeting->getEntityType(),
|
||||
])
|
||||
->order('remindAt')
|
||||
->find();
|
||||
|
||||
$this->assertEquals(2, count($reminderList));
|
||||
}
|
||||
|
||||
public function testFallsInPast(): void
|
||||
{
|
||||
$clock = $this->createMock(Clock::class);
|
||||
$clock->method('now')
|
||||
->willReturn(new DateTimeImmutable('2030-01-01 00:00'));
|
||||
|
||||
|
||||
$app = $this->createApplication(
|
||||
binding: new class ($clock) implements BindingProcessor {
|
||||
|
||||
public function __construct(private Clock $clock) {}
|
||||
|
||||
public function process(Binder $binder): void
|
||||
{
|
||||
$binder->bindInstance(Clock::class, $this->clock);
|
||||
}
|
||||
},
|
||||
// @todo Need to reset loaded hooks in the HookManager?
|
||||
//reuse: true,
|
||||
);
|
||||
$this->setApplication($app);
|
||||
|
||||
$entityManager = $this->getEntityManager();
|
||||
|
||||
$user = $this->getContainer()->getByClass(User::class);
|
||||
|
||||
$meeting = $entityManager->createEntity(Meeting::ENTITY_TYPE, [
|
||||
'dateStart' => DateTime::fromDateTime($clock->now())->modify('+10 minutes')->toString(),
|
||||
'usersIds' => [$user->getId()],
|
||||
'reminders' => [
|
||||
(object) [
|
||||
'type' => Reminder::TYPE_POPUP,
|
||||
'seconds' => 60 * 60,
|
||||
],
|
||||
(object) [
|
||||
'type' => Reminder::TYPE_POPUP,
|
||||
'seconds' => 120 * 60,
|
||||
],
|
||||
(object) [
|
||||
'type' => Reminder::TYPE_EMAIL,
|
||||
'seconds' => 60 * 60,
|
||||
],
|
||||
(object) [
|
||||
'type' => Reminder::TYPE_EMAIL,
|
||||
'seconds' => 120 * 60,
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
$reminderList = $entityManager
|
||||
->getRDBRepositoryByClass(Reminder::class)
|
||||
->where([
|
||||
'entityId' => $meeting->getId(),
|
||||
'entityType' => $meeting->getEntityType(),
|
||||
])
|
||||
->find();
|
||||
|
||||
$this->assertCount(2, $reminderList);
|
||||
}
|
||||
}
|
||||
1660
tests/integration/Espo/Core/Formula/FormulaTest.php
Normal file
1660
tests/integration/Espo/Core/Formula/FormulaTest.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,81 @@
|
||||
<?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\integration\Espo\Core\FulltextIndex;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class CheckCreatedIndexTest extends BaseTestCase
|
||||
{
|
||||
protected ?string $dataFile = 'InitData.php';
|
||||
protected ?string $pathToFiles = 'Core/FulltextIndex/customFiles';
|
||||
|
||||
static public function entityList()
|
||||
{
|
||||
return [
|
||||
['Email'],
|
||||
['Account'],
|
||||
['Contact'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('entityList')]
|
||||
public function testCreatedIndexes($entityName)
|
||||
{
|
||||
$entityManager = $this->getContainer()->get('entityManager');
|
||||
$pdo = $entityManager->getPDO();
|
||||
|
||||
$fulltextFieldList = $entityManager->getMetadata()->get($entityName, 'fullTextSearchColumnList');
|
||||
|
||||
if (!$fulltextFieldList) {
|
||||
$this->assertNull($fulltextFieldList);
|
||||
return;
|
||||
}
|
||||
|
||||
$query = "SHOW INDEX FROM `". Util::toCamelCase($entityName) ."` WHERE Index_type = 'FULLTEXT'";
|
||||
$sth = $pdo->prepare($query);
|
||||
$sth->execute();
|
||||
|
||||
$rowList = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$this->assertNotEmpty($rowList);
|
||||
|
||||
$result = [];
|
||||
foreach ($rowList as $row) {
|
||||
$result[] = Util::toCamelCase($row['Column_name']);
|
||||
}
|
||||
|
||||
asort($fulltextFieldList);
|
||||
asort($result);
|
||||
|
||||
$this->assertEquals($fulltextFieldList, $result);
|
||||
}
|
||||
}
|
||||
219
tests/integration/Espo/Core/Job/JobTest.php
Normal file
219
tests/integration/Espo/Core/Job/JobTest.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?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\integration\Espo\Core\Job;
|
||||
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\Job\Job\Status;
|
||||
use Espo\Core\Job\JobManager;
|
||||
use Espo\Core\Job\JobSchedulerFactory;
|
||||
use Espo\Core\Job\PrepareProcessor;
|
||||
use Espo\Core\Job\QueueName;
|
||||
|
||||
use Espo\Entities\Job as JobEntity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
use tests\integration\testClasses\Job\Job as TestJob;
|
||||
|
||||
class JobTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var JobManager
|
||||
*/
|
||||
private $jobManager;
|
||||
|
||||
|
||||
/** @var EntityManager */
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var JobSchedulerFactory
|
||||
*/
|
||||
private $schedulerFactory;
|
||||
|
||||
private ?PrepareProcessor $prepareProcessor = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->jobManager = $this->getContainer()->getByClass(JobManager::class);
|
||||
$this->prepareProcessor = $this->getInjectableFactory()->create(PrepareProcessor::class);
|
||||
|
||||
$this->entityManager = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$this->schedulerFactory = $this->getContainer()
|
||||
->getByClass(InjectableFactory::class)
|
||||
->create(JobSchedulerFactory::class);
|
||||
}
|
||||
|
||||
public function testScheduler(): void
|
||||
{
|
||||
$this->schedulerFactory
|
||||
->create()
|
||||
->setClassName(TestJob::class)
|
||||
->setQueue(QueueName::Q0)
|
||||
->schedule();
|
||||
|
||||
$this->jobManager->processQueue(QueueName::Q0, 10);
|
||||
|
||||
$job = $this->entityManager
|
||||
->getRDBRepositoryByClass(JobEntity::class)
|
||||
->where(['className' => TestJob::class])
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($job);
|
||||
|
||||
$this->assertEquals(Status::SUCCESS, $job->getStatus());
|
||||
}
|
||||
|
||||
public function testProcessQueueNoGroup(): void
|
||||
{
|
||||
$job = $this->entityManager->createEntity('Job', [
|
||||
'job' => 'Dummy',
|
||||
'queue' => 'q0',
|
||||
]);
|
||||
|
||||
$this->jobManager->processQueue('q0', 10);
|
||||
|
||||
$jobReloaded = $this->entityManager->getEntityById('Job', $job->getId());
|
||||
|
||||
$this->assertEquals(Status::SUCCESS, $jobReloaded->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testProcessQueueGroupAll(): void
|
||||
{
|
||||
$job1 = $this->entityManager->createEntity('Job', [
|
||||
'job' => 'Dummy',
|
||||
'group' => 'group-0',
|
||||
]);
|
||||
|
||||
$job2 = $this->entityManager->createEntity('Job', [
|
||||
'job' => 'Dummy',
|
||||
'group' => 'group-1',
|
||||
]);
|
||||
|
||||
$job3 = $this->entityManager->createEntity('Job', [
|
||||
'job' => 'Dummy',
|
||||
'group' => 'group-1',
|
||||
]);
|
||||
|
||||
|
||||
$this->prepareProcessor->process();
|
||||
$this->jobManager->processMainQueue();
|
||||
|
||||
$job1Reloaded = $this->entityManager->getEntityById('Job', $job1->getId());
|
||||
$job2Reloaded = $this->entityManager->getEntityById('Job', $job2->getId());
|
||||
$job3Reloaded = $this->entityManager->getEntityById('Job', $job3->getId());
|
||||
|
||||
$this->assertEquals(Status::SUCCESS, $job1Reloaded->getStatus());
|
||||
$this->assertEquals(Status::SUCCESS, $job2Reloaded->getStatus());
|
||||
$this->assertEquals(Status::SUCCESS, $job3Reloaded->getStatus());
|
||||
}
|
||||
|
||||
public function testProcessQueueGroupSeparate(): void
|
||||
{
|
||||
$job1 = $this->entityManager->createEntity('Job', [
|
||||
'job' => 'Dummy',
|
||||
'group' => 'group-0',
|
||||
]);
|
||||
|
||||
$job2 = $this->entityManager->createEntity('Job', [
|
||||
'job' => 'Dummy',
|
||||
'group' => 'group-1',
|
||||
]);
|
||||
|
||||
$job3 = $this->entityManager->createEntity('Job', [
|
||||
'job' => 'Dummy',
|
||||
'group' => 'group-1',
|
||||
]);
|
||||
|
||||
$this->jobManager->processGroup('group-1', 100);
|
||||
|
||||
$job1Reloaded = $this->entityManager->getEntityById('Job', $job1->getId());
|
||||
$job2Reloaded = $this->entityManager->getEntityById('Job', $job2->getId());
|
||||
$job3Reloaded = $this->entityManager->getEntityById('Job', $job3->getId());
|
||||
|
||||
$this->assertEquals(Status::PENDING, $job1Reloaded->getStatus());
|
||||
$this->assertEquals(Status::SUCCESS, $job2Reloaded->getStatus());
|
||||
$this->assertEquals(Status::SUCCESS, $job3Reloaded->getStatus());
|
||||
|
||||
$this->jobManager->processGroup('group-0', 100);
|
||||
|
||||
$job1Reloaded2 = $this->entityManager->getEntityById('Job', $job1->getId());
|
||||
|
||||
$this->assertEquals(Status::SUCCESS, $job1Reloaded2->getStatus());
|
||||
}
|
||||
|
||||
public function testRunJobById(): void
|
||||
{
|
||||
$job = $this->entityManager->createEntity('Job', [
|
||||
'job' => 'Dummy',
|
||||
'status' => Status::READY,
|
||||
]);
|
||||
|
||||
$this->jobManager->runJobById($job->getId());
|
||||
|
||||
$jobReloaded = $this->entityManager->getEntityById('Job', $job->getId());
|
||||
|
||||
$this->assertEquals(Status::SUCCESS, $jobReloaded->getStatus());
|
||||
}
|
||||
|
||||
public function testRunJobByEntity(): void
|
||||
{
|
||||
$job = $this->entityManager->createEntity('Job', [
|
||||
'job' => 'Dummy',
|
||||
]);
|
||||
|
||||
$this->jobManager->runJob($job);
|
||||
|
||||
$jobReloaded = $this->entityManager->getEntityById('Job', $job->getId());
|
||||
|
||||
$this->assertEquals(Status::SUCCESS, $jobReloaded->getStatus());
|
||||
}
|
||||
|
||||
public function testRunJobWithClassName(): void
|
||||
{
|
||||
$job = $this->entityManager->createEntity('Job', [
|
||||
'className' => TestJob::class,
|
||||
'data' => (object) [
|
||||
'test' => '1',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->jobManager->runJob($job);
|
||||
|
||||
$jobReloaded = $this->entityManager->getEntityById('Job', $job->getId());
|
||||
|
||||
$this->assertEquals(Status::SUCCESS, $jobReloaded->getStatus());
|
||||
}
|
||||
}
|
||||
221
tests/integration/Espo/Core/Mail/ParentFinderTest.php
Normal file
221
tests/integration/Espo/Core/Mail/ParentFinderTest.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?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\integration\Espo\Core\Mail;
|
||||
|
||||
use Espo\Core\Mail\Importer\DefaultParentFinder;
|
||||
use Espo\Core\Mail\Message;
|
||||
use Espo\Entities\Email;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class ParentFinderTest extends BaseTestCase
|
||||
{
|
||||
public function testReplied(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$account = $em->createEntity(Account::ENTITY_TYPE, [
|
||||
'name' => 'Test'
|
||||
]);
|
||||
|
||||
$emailOne = $em->createEntity(Email::ENTITY_TYPE, [
|
||||
'parentId' => $account->getId(),
|
||||
'parentType' => $account->getEntityType(),
|
||||
'status' => Email::STATUS_ARCHIVED,
|
||||
]);
|
||||
|
||||
/** @var Email $email */
|
||||
$email = $em->getNewEntity(Email::ENTITY_TYPE);
|
||||
|
||||
$email->set([
|
||||
'repliedId' => $emailOne->getId(),
|
||||
]);
|
||||
|
||||
$finder = $this->getInjectableFactory()->create(DefaultParentFinder::class);
|
||||
|
||||
$message = $this->createMock(Message::class);
|
||||
|
||||
$parent = $finder->find($email, $message);
|
||||
|
||||
$this->assertInstanceOf(Account::class, $parent);
|
||||
$this->assertEquals($account->getId(), $parent->getId());
|
||||
}
|
||||
|
||||
public function testReferences(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$account = $em->createEntity(Account::ENTITY_TYPE, [
|
||||
'name' => 'Test'
|
||||
]);
|
||||
|
||||
/** @var Email $email */
|
||||
$email = $em->getNewEntity(Email::ENTITY_TYPE);
|
||||
|
||||
$finder = $this->getInjectableFactory()->create(DefaultParentFinder::class);
|
||||
|
||||
$message = $this->createMock(Message::class);
|
||||
|
||||
$message
|
||||
->expects($this->once())
|
||||
->method('getHeader')
|
||||
->with('References')
|
||||
->willReturn('Account/' . $account->getId(). '/1667915635/6605@espo');
|
||||
|
||||
$parent = $finder->find($email, $message);
|
||||
|
||||
$this->assertInstanceOf(Account::class, $parent);
|
||||
$this->assertEquals($account->getId(), $parent->getId());
|
||||
}
|
||||
|
||||
public function testFromAddressAccount(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
/** @var Account $subject */
|
||||
$subject = $em->createEntity(Account::ENTITY_TYPE, [
|
||||
'emailAddress' => 'subject@test.com',
|
||||
]);
|
||||
|
||||
/** @var Email $email */
|
||||
$email = $em->getNewEntity(Email::ENTITY_TYPE);
|
||||
|
||||
$email->setFromAddress($subject->getEmailAddress());
|
||||
|
||||
$finder = $this->getInjectableFactory()->create(DefaultParentFinder::class);
|
||||
|
||||
$message = $this->createMock(Message::class);
|
||||
|
||||
$parent = $finder->find($email, $message);
|
||||
|
||||
$this->assertInstanceOf(Account::class, $parent);
|
||||
$this->assertEquals($subject->getId(), $parent->getId());
|
||||
}
|
||||
|
||||
public function testFromAddressContact(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
/** @var Contact $subject */
|
||||
$subject = $em->createEntity(Contact::ENTITY_TYPE, [
|
||||
'emailAddress' => 'subject@test.com',
|
||||
]);
|
||||
|
||||
/** @var Email $email */
|
||||
$email = $em->getNewEntity(Email::ENTITY_TYPE);
|
||||
|
||||
$email->setFromAddress($subject->getEmailAddress());
|
||||
|
||||
$finder = $this->getInjectableFactory()->create(DefaultParentFinder::class);
|
||||
|
||||
$message = $this->createMock(Message::class);
|
||||
|
||||
$parent = $finder->find($email, $message);
|
||||
|
||||
$this->assertInstanceOf(Contact::class, $parent);
|
||||
$this->assertEquals($subject->getId(), $parent->getId());
|
||||
}
|
||||
|
||||
public function testFromAddressLead(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
/** @var Lead $subject */
|
||||
$subject = $em->createEntity(Lead::ENTITY_TYPE, [
|
||||
'emailAddress' => 'subject@test.com',
|
||||
]);
|
||||
|
||||
/** @var Email $email */
|
||||
$email = $em->getNewEntity(Email::ENTITY_TYPE);
|
||||
|
||||
$email->setFromAddress($subject->getEmailAddress());
|
||||
|
||||
$finder = $this->getInjectableFactory()->create(DefaultParentFinder::class);
|
||||
|
||||
$message = $this->createMock(Message::class);
|
||||
|
||||
$parent = $finder->find($email, $message);
|
||||
|
||||
$this->assertInstanceOf(Lead::class, $parent);
|
||||
$this->assertEquals($subject->getId(), $parent->getId());
|
||||
}
|
||||
|
||||
public function testReplyToAddress(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
/** @var Lead $subject */
|
||||
$subject = $em->createEntity(Lead::ENTITY_TYPE, [
|
||||
'emailAddress' => 'subject@test.com',
|
||||
]);
|
||||
|
||||
/** @var Email $email */
|
||||
$email = $em->getNewEntity(Email::ENTITY_TYPE);
|
||||
|
||||
$email->setFromAddress('any@address.com');
|
||||
$email->addReplyToAddress($subject->getEmailAddress());
|
||||
|
||||
$finder = $this->getInjectableFactory()->create(DefaultParentFinder::class);
|
||||
|
||||
$message = $this->createMock(Message::class);
|
||||
|
||||
$parent = $finder->find($email, $message);
|
||||
|
||||
$this->assertInstanceOf(Lead::class, $parent);
|
||||
$this->assertEquals($subject->getId(), $parent->getId());
|
||||
}
|
||||
|
||||
public function testToAddress(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
/** @var Lead $subject */
|
||||
$subject = $em->createEntity(Lead::ENTITY_TYPE, [
|
||||
'emailAddress' => 'subject@test.com',
|
||||
]);
|
||||
|
||||
/** @var Email $email */
|
||||
$email = $em->getNewEntity(Email::ENTITY_TYPE);
|
||||
|
||||
$email->setFromAddress('any@address.com');
|
||||
$email->addToAddress($subject->getEmailAddress());
|
||||
|
||||
$finder = $this->getInjectableFactory()->create(DefaultParentFinder::class);
|
||||
|
||||
$message = $this->createMock(Message::class);
|
||||
|
||||
$parent = $finder->find($email, $message);
|
||||
|
||||
$this->assertInstanceOf(Lead::class, $parent);
|
||||
$this->assertEquals($subject->getId(), $parent->getId());
|
||||
}
|
||||
}
|
||||
@@ -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\integration\Espo\Core\Notification;
|
||||
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Entities\User;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class AssignmentNotificatorTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
private $user1;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
private $user2;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->initTestData();
|
||||
|
||||
$this->entityManager = $this->getEntityManager();
|
||||
}
|
||||
|
||||
private function initTestData() : void
|
||||
{
|
||||
$configWriter = $this->getContainer()->getByClass(InjectableFactory::class)->create(ConfigWriter::class);
|
||||
|
||||
$this->getMetadata()->set('scopes', 'Meeting', [
|
||||
'stream' => false,
|
||||
]);
|
||||
|
||||
$this->getMetadata()->save();
|
||||
|
||||
$configWriter->set('assignmentNotificationsEntityList', [
|
||||
'Email',
|
||||
'Meeting',
|
||||
]);
|
||||
|
||||
$configWriter->save();
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$role = $em->createEntity('Role', [
|
||||
'name' => 'test',
|
||||
'data' => [
|
||||
'Meeting' => [
|
||||
'read' => 'own',
|
||||
],
|
||||
'Email' => [
|
||||
'read' => 'own',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->user1 = $em->createEntity('User', [
|
||||
'userName' => 'test-1',
|
||||
'lastName' => 'Test 1',
|
||||
'rolesIds' => [$role->getId()],
|
||||
'emailAddress' => 'test1@test.com',
|
||||
]);
|
||||
|
||||
$this->user2 = $em->createEntity('User', [
|
||||
'userName' => 'test-2',
|
||||
'lastName' => 'Test 2',
|
||||
'rolesIds' => [$role->getId()],
|
||||
'emailAddress' => 'test2@test.com',
|
||||
]);
|
||||
|
||||
$em->createEntity('User', [
|
||||
'userName' => 'test-3',
|
||||
'lastName' => 'Test 3',
|
||||
'rolesIds' => [],
|
||||
'emailAddress' => 'test3@test.com',
|
||||
]);
|
||||
|
||||
$preferences2 = $em->getEntityById('Preferences', $this->user2->getId());
|
||||
|
||||
$preferences2->set([
|
||||
'assignmentNotificationsIgnoreEntityTypeList' => ['Meeting'],
|
||||
]);
|
||||
|
||||
$em->saveEntity($preferences2);
|
||||
}
|
||||
|
||||
public function testAssignmentSelf() : void
|
||||
{
|
||||
$meeting = $this->entityManager->createEntity('Meeting', [
|
||||
'name' => 'test',
|
||||
'assignedUserId' => $this->user1->getId(),
|
||||
'createdById' => $this->user1->getId(),
|
||||
]);
|
||||
|
||||
$notification = $this->entityManager
|
||||
->getRDBRepository('Notification')
|
||||
->where([
|
||||
'userId' => '1',
|
||||
'type' => 'Assign',
|
||||
'relatedType' => 'Meeting',
|
||||
'relatedId' => $meeting->getId(),
|
||||
])
|
||||
->findOne();
|
||||
|
||||
$this->assertNull($notification, 'notification');
|
||||
}
|
||||
|
||||
public function testAssignmentEnabled() : void
|
||||
{
|
||||
$meeting = $this->entityManager->createEntity('Meeting', [
|
||||
'name' => 'test',
|
||||
'assignedUserId' => $this->user1->getId(),
|
||||
]);
|
||||
|
||||
$notification = $this->entityManager
|
||||
->getRDBRepository('Notification')
|
||||
->where([
|
||||
'userId' => $this->user1->getId(),
|
||||
'type' => 'Assign',
|
||||
'relatedType' => 'Meeting',
|
||||
'relatedId' => $meeting->getId(),
|
||||
])
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($notification);
|
||||
}
|
||||
|
||||
public function testAssignmentDisabled() : void
|
||||
{
|
||||
$call = $this->entityManager->createEntity('Call', [
|
||||
'name' => 'test',
|
||||
'assignedUserId' => $this->user1->getId(),
|
||||
]);
|
||||
|
||||
$notification = $this->entityManager
|
||||
->getRDBRepository('Notification')
|
||||
->where([
|
||||
'userId' => $this->user1->getId(),
|
||||
'type' => 'Assign',
|
||||
'relatedType' => 'Call',
|
||||
'relatedId' => $call->getId(),
|
||||
])
|
||||
->findOne();
|
||||
|
||||
$this->assertNull($notification);
|
||||
}
|
||||
|
||||
public function testAssignmentIgnored() : void
|
||||
{
|
||||
$meeting = $this->entityManager->createEntity('Meeting', [
|
||||
'name' => 'test',
|
||||
'assignedUserId' => $this->user2->getId(),
|
||||
]);
|
||||
|
||||
$notification = $this->entityManager
|
||||
->getRDBRepository('Notification')
|
||||
->where([
|
||||
'userId' => $this->user1->getId(),
|
||||
'type' => 'Assign',
|
||||
'relatedType' => 'Meeting',
|
||||
'relatedId' => $meeting->getId(),
|
||||
])
|
||||
->findOne();
|
||||
|
||||
$this->assertNull($notification, 'notification');
|
||||
}
|
||||
|
||||
public function testAssignmentEmailYes() : void
|
||||
{
|
||||
$email = $this->entityManager->createEntity('Email', [
|
||||
'name' => 'test',
|
||||
'status' => 'Archived',
|
||||
'from' => $this->user2->get('emailAddress'),
|
||||
'to' => $this->user1->get('emailAddress'),
|
||||
'dateSent' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
$notification = $this->entityManager
|
||||
->getRDBRepository('Notification')
|
||||
->where([
|
||||
'userId' => $this->user1->getId(),
|
||||
'type' => 'EmailReceived',
|
||||
'relatedType' => 'Email',
|
||||
'relatedId' => $email->getId(),
|
||||
])
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($notification);
|
||||
}
|
||||
}
|
||||
77
tests/integration/Espo/Core/ORM/CoreEntityTest.php
Normal file
77
tests/integration/Espo/Core/ORM/CoreEntityTest.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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\integration\Espo\Core\ORM;
|
||||
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\Modules\Crm\Entities\Opportunity;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class CoreEntityTest extends BaseTestCase
|
||||
{
|
||||
public function testLinkMultiple(): void
|
||||
{
|
||||
$contact1 = $this->getEntityManager()->createEntity(Contact::ENTITY_TYPE, [
|
||||
'lastName' => 'Test 1',
|
||||
]);
|
||||
|
||||
$contact2 = $this->getEntityManager()->createEntity(Contact::ENTITY_TYPE, [
|
||||
'lastName' => 'Test 2',
|
||||
]);
|
||||
|
||||
$opp = $this->getEntityManager()->createEntity(Opportunity::ENTITY_TYPE, [
|
||||
'name' => 'Test',
|
||||
'contactsIds' => [$contact1->getId()],
|
||||
'contactsColumns' => [
|
||||
$contact1->getId() => ['role' => 'Evaluator']
|
||||
],
|
||||
]);
|
||||
|
||||
$opp = $this->getEntityManager()
|
||||
->getRDBRepositoryByClass(Opportunity::class)
|
||||
->getById($opp->getId());
|
||||
|
||||
$this->assertTrue(in_array($contact1->getId(), $opp->getLinkMultipleIdList('contacts')));
|
||||
$this->assertEquals('Evaluator', $opp->getLinkMultipleColumn('contacts', 'role', $contact1->getId()));
|
||||
|
||||
$opp->addLinkMultipleId('contacts', $contact2->getId());
|
||||
$opp->setLinkMultipleColumn('contacts', 'role', $contact2->getId(), 'Decision Maker');
|
||||
|
||||
$this->assertTrue($opp->hasLinkMultipleId('contacts', $contact2->getId()));
|
||||
$this->assertEquals('Decision Maker', $opp->getLinkMultipleColumn('contacts', 'role', $contact2->getId()));
|
||||
|
||||
// Rewrites set values.
|
||||
$opp->loadLinkMultipleField('contacts');
|
||||
|
||||
$this->assertFalse($opp->hasLinkMultipleId('contacts', $contact2->getId()));
|
||||
|
||||
$this->assertTrue(in_array($contact1->getId(), $opp->getFetched('contactsIds')));
|
||||
$this->assertFalse(in_array($contact2->getId(), $opp->getFetched('contactsIds')));
|
||||
}
|
||||
}
|
||||
1026
tests/integration/Espo/Core/Select/SelectBuilderTest.php
Normal file
1026
tests/integration/Espo/Core/Select/SelectBuilderTest.php
Normal file
File diff suppressed because it is too large
Load Diff
50
tests/integration/Espo/Core/Utils/ClassFinderTest.php
Normal file
50
tests/integration/Espo/Core/Utils/ClassFinderTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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\integration\Espo\Core\Utils;
|
||||
|
||||
class ClassFinderTest extends \tests\integration\Core\BaseTestCase
|
||||
{
|
||||
public function testFind1()
|
||||
{
|
||||
$classFinder = $this->getContainer()->get('classFinder');
|
||||
|
||||
$this->assertEquals(
|
||||
'Espo\\Modules\\Crm\\Entities\\Account',
|
||||
$classFinder->find('Entities', 'Account')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'Espo\\Entities\\Email',
|
||||
$classFinder->find('Entities', 'Email')
|
||||
);
|
||||
|
||||
$this->assertTrue(file_exists('data/cache/application/classmapEntities.php'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
|
||||
#[NoTransaction]
|
||||
class AddressFieldTest extends Base
|
||||
{
|
||||
static public function fieldList()
|
||||
{
|
||||
return [
|
||||
['testAddressStreet', 255],
|
||||
['testAddressCity', 100],
|
||||
['testAddressState', 100],
|
||||
['testAddressCountry', 100],
|
||||
['testAddressPostalCode', 40],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('fieldList')]
|
||||
public function testColumn($fieldName, $length)
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', $fieldName);
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals($length, $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class ArrayFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testArray');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('mediumtext', $column['COLUMN_TYPE']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class AutoIncrementFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Case', 'number');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('int', $column['DATA_TYPE']);
|
||||
$this->assertEquals('NO', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('10', $column['NUMERIC_PRECISION']);
|
||||
$this->assertEquals('auto_increment', $column['EXTRA']);
|
||||
$this->assertEquals('UNI', $column['COLUMN_KEY']);
|
||||
}
|
||||
|
||||
public function testColumnOnExistingTable(): void
|
||||
{
|
||||
$this->updateDefs('Test', 'testAutoIncrement', [
|
||||
'type' => 'autoincrement',
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testAutoIncrement');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('int', $column['DATA_TYPE']);
|
||||
$this->assertEquals('NO', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('10', $column['NUMERIC_PRECISION']);
|
||||
$this->assertEquals('auto_increment', $column['EXTRA']);
|
||||
$this->assertEquals('UNI', $column['COLUMN_KEY']);
|
||||
}
|
||||
|
||||
public function testDeleteColumnOnExistingTable(): void
|
||||
{
|
||||
// 1. Create "testAutoIncrement" field
|
||||
$this->testColumnOnExistingTable();
|
||||
|
||||
// 2. Delete "testAutoIncrement" field
|
||||
$this->getMetadata()->delete('entityDefs', 'Test', ['fields.testAutoIncrement']);
|
||||
$this->getMetadata()->save();
|
||||
|
||||
// Issue that it requires rebuilding between removing and adding a new indexes.
|
||||
$this->getDataManager()->rebuild();
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testAutoIncrement');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('int', $column['DATA_TYPE']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('10', $column['NUMERIC_PRECISION']);
|
||||
$this->assertEmpty($column['EXTRA']);
|
||||
$this->assertEmpty($column['COLUMN_KEY']);
|
||||
}
|
||||
|
||||
public function testDeleteCreateColumnOnExistingTable(): void
|
||||
{
|
||||
// 1. Create "testAutoIncrement" field
|
||||
$this->testColumnOnExistingTable();
|
||||
|
||||
// 2. Delete "testAutoIncrement" field
|
||||
$metadata = $this->getMetadata();
|
||||
$metadata->delete('entityDefs', 'Test', ['fields.testAutoIncrement']);
|
||||
$metadata->save();
|
||||
|
||||
$this->getDataManager()->rebuild();
|
||||
|
||||
// 3. Create "testAutoIncrement2" field
|
||||
$this->updateDefs('Test', 'testAutoIncrement2', [
|
||||
'type' => 'autoincrement',
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testAutoIncrement');
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('int', $column['DATA_TYPE']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('10', $column['NUMERIC_PRECISION']);
|
||||
$this->assertEmpty($column['EXTRA']);
|
||||
$this->assertEmpty($column['COLUMN_KEY']);
|
||||
|
||||
$column2 = $this->getColumnInfo('Test', 'testAutoIncrement2');
|
||||
$this->assertNotEmpty($column2);
|
||||
$this->assertEquals('int', $column2['DATA_TYPE']);
|
||||
$this->assertEquals('NO', $column2['IS_NULLABLE']);
|
||||
$this->assertEquals('10', $column2['NUMERIC_PRECISION']);
|
||||
$this->assertEquals('auto_increment', $column2['EXTRA']);
|
||||
$this->assertEquals('UNI', $column2['COLUMN_KEY']);
|
||||
}
|
||||
}
|
||||
110
tests/integration/Espo/Core/Utils/Database/Base.php
Normal file
110
tests/integration/Espo/Core/Utils/Database/Base.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Database\Helper;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Utils\Util;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
abstract class Base extends BaseTestCase
|
||||
{
|
||||
protected ?string $dataFile = 'InitData.php';
|
||||
protected ?string $pathToFiles = 'Core/Database/customFiles';
|
||||
|
||||
protected function beforeSetUp(): void
|
||||
{}
|
||||
|
||||
protected function getColumnInfo($entityName, $fieldName)
|
||||
{
|
||||
$pdo = $this->getInjectableFactory()
|
||||
->create(Helper::class)
|
||||
->getPDO();
|
||||
|
||||
$dbName = $this->getContainer()
|
||||
->getByClass(Config::class)
|
||||
->get('database.dbname');
|
||||
|
||||
$query = "
|
||||
SELECT * FROM information_schema.columns
|
||||
WHERE table_name = '" . Util::toUnderScore($entityName) . "'
|
||||
AND column_name = '" . Util::toUnderScore($fieldName) . "'
|
||||
AND table_schema = '" . $dbName . "'
|
||||
";
|
||||
|
||||
$sth = $pdo->prepare($query);
|
||||
$sth->execute();
|
||||
|
||||
return $sth->fetch(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
protected function updateDefs($entityName, $fieldName, array $fieldDefs = [], ?array $linkDefs = null)
|
||||
{
|
||||
$metadata = $this->getContainer()->getByClass(Metadata::class);
|
||||
|
||||
$entityDefs = $metadata->get(['entityDefs', $entityName]);
|
||||
|
||||
if (empty($entityDefs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$save = false;
|
||||
|
||||
if (!empty($fieldDefs)) {
|
||||
$currentFieldDefs = $entityDefs['fields'][$fieldName] ?? [];
|
||||
$entityDefs['fields'][$fieldName] = array_merge($currentFieldDefs, $fieldDefs);
|
||||
$save = true;
|
||||
}
|
||||
|
||||
if (!empty($linkDefs)) {
|
||||
$currentLinkDefs = $entityDefs['links'][$fieldName] ?? [];
|
||||
$entityDefs['links'][$fieldName] = array_merge($currentLinkDefs, $linkDefs);
|
||||
$save = true;
|
||||
}
|
||||
|
||||
if ($save) {
|
||||
$metadata->set('entityDefs', 'Test', $entityDefs);
|
||||
$metadata->save();
|
||||
|
||||
$this->getDataManager()->rebuild([$entityName]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function executeQuery($query)
|
||||
{
|
||||
$pdo = $this->getInjectableFactory()
|
||||
->create(Helper::class)
|
||||
->getPDO();
|
||||
|
||||
$sth = $pdo->prepare($query);
|
||||
$sth->execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class BooleanFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testBoolean');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('tinyint', $column['DATA_TYPE']);
|
||||
$this->assertEquals('0', $column['COLUMN_DEFAULT']);
|
||||
$this->assertEquals('NO', $column['IS_NULLABLE']);
|
||||
}
|
||||
|
||||
public function testDefaultValue()
|
||||
{
|
||||
$this->updateDefs('Test', 'testBoolean', [
|
||||
'default' => true,
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testBoolean');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('tinyint', $column['DATA_TYPE']);
|
||||
$this->assertEquals('1', $column['COLUMN_DEFAULT']);
|
||||
$this->assertEquals('NO', $column['IS_NULLABLE']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
|
||||
#[NoTransaction]
|
||||
class CurrencyFieldTest extends Base
|
||||
{
|
||||
static public function fieldList(): array
|
||||
{
|
||||
return [
|
||||
['testCurrency', 'double', null, null],
|
||||
['testCurrencyCurrency', 'varchar', 3, 'utf8mb4_unicode_ci'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('fieldList')]
|
||||
public function testColumns($fieldName, $type, $length, $collation): void
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', $fieldName);
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals($type, $column['DATA_TYPE']);
|
||||
$this->assertEquals($length, $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals($collation, $column['COLLATION_NAME']);
|
||||
}
|
||||
}
|
||||
45
tests/integration/Espo/Core/Utils/Database/DateFieldTest.php
Normal file
45
tests/integration/Espo/Core/Utils/Database/DateFieldTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class DateFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testDate');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('date', $column['DATA_TYPE']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class DateTimeFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testDateTime');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('datetime', $column['DATA_TYPE']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
}
|
||||
}
|
||||
47
tests/integration/Espo/Core/Utils/Database/FileFieldTest.php
Normal file
47
tests/integration/Espo/Core/Utils/Database/FileFieldTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class FileFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testFileId');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals(17, $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class FloatFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testFloat');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('double', $column['DATA_TYPE']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
}
|
||||
}
|
||||
117
tests/integration/Espo/Core/Utils/Database/HelperTest.php
Normal file
117
tests/integration/Espo/Core/Utils/Database/HelperTest.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use Espo\Core\Utils\Database\Helper;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use PDO;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class HelperTest extends BaseTestCase
|
||||
{
|
||||
/** @var ?Helper */
|
||||
protected $helper;
|
||||
|
||||
protected function initTest()
|
||||
{
|
||||
$this->helper = $this->getInjectableFactory()->create(Helper::class);
|
||||
}
|
||||
|
||||
private function getDatabaseInfo()
|
||||
{
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$sth = $pdo->prepare("select version()");
|
||||
$sth->execute();
|
||||
|
||||
$version = $sth->fetchColumn();
|
||||
|
||||
$type = 'mysql';
|
||||
if (preg_match('/mariadb/i', $version)) {
|
||||
$type = 'mariadb';
|
||||
}
|
||||
|
||||
if (preg_match('/[0-9]+\.[0-9]+\.[0-9]+/', $version, $match)) {
|
||||
$version = $match[0];
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => $type,
|
||||
'version' => $version,
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetDbalConnectionWithConfig()
|
||||
{
|
||||
$this->initTest();
|
||||
|
||||
$this->assertInstanceOf(Connection::class, $this->helper->getDbalConnection());
|
||||
}
|
||||
|
||||
public function testGetPdoConnectionWithConfig()
|
||||
{
|
||||
$this->initTest();
|
||||
|
||||
$this->assertInstanceOf(PDO::class, $this->helper->getPDO());
|
||||
}
|
||||
|
||||
public function testGetDatabaseInfo()
|
||||
{
|
||||
$this->initTest();
|
||||
|
||||
$databaseInfo = $this->getDatabaseInfo();
|
||||
if (empty($databaseInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertEquals($databaseInfo['type'], strtolower($this->helper->getType()));
|
||||
$this->assertEquals($databaseInfo['version'], $this->helper->getVersion());
|
||||
}
|
||||
|
||||
public function testGetDatabaseType()
|
||||
{
|
||||
$this->initTest();
|
||||
|
||||
$databaseInfo = $this->getDatabaseInfo();
|
||||
if (empty($databaseInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($databaseInfo['type']) {
|
||||
case 'mysql':
|
||||
$this->assertEquals('MySQL', $this->helper->getType());
|
||||
break;
|
||||
|
||||
case 'mariadb':
|
||||
$this->assertEquals('MariaDB', $this->helper->getType());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class IntegerFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testInteger');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('int', $column['DATA_TYPE']);
|
||||
$this->assertEquals(10, $column['NUMERIC_PRECISION']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
}
|
||||
}
|
||||
83
tests/integration/Espo/Core/Utils/Database/TextFieldTest.php
Normal file
83
tests/integration/Espo/Core/Utils/Database/TextFieldTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class TextFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testText');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('mediumtext', $column['COLUMN_TYPE']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
|
||||
public function testIncreaseColumnLength()
|
||||
{
|
||||
$this->updateDefs('Test', 'testText', [
|
||||
'type' => 'text',
|
||||
'dbType' => 'longtext',
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testText');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('longtext', $column['COLUMN_TYPE']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
|
||||
public function testReduceColumnLength()
|
||||
{
|
||||
$this->updateDefs('Test', 'testText', [
|
||||
'type' => 'text',
|
||||
'dbType' => 'longtext',
|
||||
]);
|
||||
|
||||
$this->getContainer()->get('metadata')->delete('entityDefs', 'Test', [
|
||||
'fields.testText.dbType',
|
||||
]);
|
||||
$this->getContainer()->get('metadata')->save();
|
||||
|
||||
$this->getDataManager()->rebuildDatabase();
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testText');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('longtext', $column['COLUMN_TYPE']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
}
|
||||
229
tests/integration/Espo/Core/Utils/Database/VarcharFieldTest.php
Normal file
229
tests/integration/Espo/Core/Utils/Database/VarcharFieldTest.php
Normal file
@@ -0,0 +1,229 @@
|
||||
<?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\integration\Espo\Core\Utils\Database;
|
||||
|
||||
use Espo\Core\Utils\Database\Helper as DatabaseHelper;
|
||||
use integration\Core\NoTransaction;
|
||||
|
||||
#[NoTransaction]
|
||||
class VarcharFieldTest extends Base
|
||||
{
|
||||
public function testColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals(100, $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
|
||||
public function testIncreaseColumnLength()
|
||||
{
|
||||
$this->updateDefs('Test', 'testVarchar', [
|
||||
'maxLength' => 150,
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals('150', $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
|
||||
public function testReduceColumnLength()
|
||||
{
|
||||
$this->updateDefs('Test', 'testVarchar', [
|
||||
'maxLength' => 50,
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals('100', $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
|
||||
public function testReduceColumnLength2()
|
||||
{
|
||||
$this->updateDefs('Test', 'testVarchar', [
|
||||
'maxLength' => 50,
|
||||
'default' => 'test-default',
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals('100', $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
|
||||
public function testReduceColumnLength3()
|
||||
{
|
||||
$this->executeQuery(
|
||||
"ALTER TABLE test MODIFY COLUMN test_varchar VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL;"
|
||||
);
|
||||
|
||||
$this->updateDefs('Test', 'testVarchar', [
|
||||
'maxLength' => 50,
|
||||
'default' => 'test-default',
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertNotEmpty($column);
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals('100', $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
$this->assertEquals('YES', $column['IS_NULLABLE']);
|
||||
|
||||
$this->assertContains($column['COLLATION_NAME'], [
|
||||
'utf8_unicode_ci',
|
||||
'utf8mb3_unicode_ci'
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCollationForExistingColumn()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
|
||||
$this->executeQuery(
|
||||
"ALTER TABLE test MODIFY COLUMN test_varchar VARCHAR(". $column['CHARACTER_MAXIMUM_LENGTH'] .") CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL;"
|
||||
);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertContains($column['COLLATION_NAME'], [
|
||||
'utf8_unicode_ci',
|
||||
'utf8mb3_unicode_ci'
|
||||
]);
|
||||
|
||||
$this->updateDefs('Test', 'testVarchar', [
|
||||
'maxLength' => 150,
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals('150', $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
|
||||
$this->assertContains($column['COLLATION_NAME'], [
|
||||
'utf8_unicode_ci',
|
||||
'utf8mb3_unicode_ci'
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCollationForExistingColumn2()
|
||||
{
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
|
||||
$this->executeQuery(
|
||||
"ALTER TABLE test MODIFY COLUMN test_varchar VARCHAR(". $column['CHARACTER_MAXIMUM_LENGTH'] .") CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL;"
|
||||
);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertContains($column['COLLATION_NAME'], [
|
||||
'utf8_unicode_ci',
|
||||
'utf8mb3_unicode_ci'
|
||||
]);
|
||||
|
||||
$this->updateDefs('Test', 'testVarchar', [
|
||||
'default' => 'test-default',
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
|
||||
$this->assertContains($column['COLLATION_NAME'], [
|
||||
'utf8_unicode_ci',
|
||||
'utf8mb3_unicode_ci'
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCollationForNewColumn()
|
||||
{
|
||||
$this->updateDefs('Test', 'newTestVarchar', [
|
||||
'type' => 'varchar',
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'newTestVarchar');
|
||||
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
}
|
||||
|
||||
public function testDefaultValue()
|
||||
{
|
||||
$this->updateDefs('Test', 'testVarchar', [
|
||||
'default' => 'test-default',
|
||||
]);
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertEquals('varchar', $column['DATA_TYPE']);
|
||||
$this->assertEquals('100', $column['CHARACTER_MAXIMUM_LENGTH']);
|
||||
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
|
||||
|
||||
$dbHelper = $this->getInjectableFactory()->create(DatabaseHelper::class);
|
||||
|
||||
if (
|
||||
$dbHelper->getType() == 'MariaDB'
|
||||
&& version_compare($dbHelper->getVersion(), '10.2.7', '>=')
|
||||
) {
|
||||
$this->assertEquals("'test-default'", $column['COLUMN_DEFAULT']);
|
||||
} else {
|
||||
$this->assertEquals('test-default', $column['COLUMN_DEFAULT']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure columns not removed.
|
||||
*/
|
||||
public function testRemoveField(): void
|
||||
{
|
||||
$this->getMetadata()->delete('entityDefs', 'Test', ['fields.testVarchar']);
|
||||
$this->getMetadata()->save();
|
||||
$this->getDataManager()->rebuildDatabase();
|
||||
|
||||
$column = $this->getColumnInfo('Test', 'testVarchar');
|
||||
|
||||
$this->assertTrue((bool) $column);
|
||||
}
|
||||
}
|
||||
133
tests/integration/Espo/Core/Utils/FieldManager/ArrayTypeTest.php
Normal file
133
tests/integration/Espo/Core/Utils/FieldManager/ArrayTypeTest.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?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\integration\Espo\Core\Utils\FieldManager;
|
||||
|
||||
use Espo\ORM\EntityManager;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class ArrayTypeTest extends BaseTestCase
|
||||
{
|
||||
private $jsonFieldDefs = '{
|
||||
"name":"testArray",
|
||||
"label":"TestArray",
|
||||
"type":"array",
|
||||
"required":false,
|
||||
"noEmptyString":false,
|
||||
"dynamicLogicVisible":null,
|
||||
"dynamicLogicRequired":null,
|
||||
"dynamicLogicReadOnly":null,
|
||||
"dynamicLogicOptions":null,
|
||||
"options":["option1","option2","option3"],
|
||||
"translatedOptions":{"option1":"option1","option2":"option2","option3":"option3"},
|
||||
"tooltipText":null,
|
||||
"isPersonalData":false,
|
||||
"inlineEditDisabled":false,
|
||||
"audited":false,
|
||||
"readOnly":false,
|
||||
"tooltip":false
|
||||
}';
|
||||
|
||||
protected function createFieldManager($app = null)
|
||||
{
|
||||
if (!$app) {
|
||||
$app = $this;
|
||||
}
|
||||
|
||||
return $app->getContainer()->get('injectableFactory')->create(
|
||||
'Espo\\Tools\\FieldManager\\FieldManager'
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$fieldManager = $this->createFieldManager();
|
||||
|
||||
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
|
||||
|
||||
$fieldManager->create('Account', 'testArray', $fieldDefs);
|
||||
|
||||
$this->getContainer()->get('dataManager')->rebuild(['Account']);
|
||||
|
||||
$app = $this->createApplication();
|
||||
|
||||
$metadata = $app->getContainer()->get('metadata');
|
||||
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestArray');
|
||||
|
||||
$this->assertArrayHasKey('type', $savedFieldDefs);
|
||||
$this->assertArrayHasKey('isCustom', $savedFieldDefs);
|
||||
$this->assertArrayHasKey('options', $savedFieldDefs);
|
||||
$this->assertEquals('array', $savedFieldDefs['type']);
|
||||
$this->assertTrue($savedFieldDefs['isCustom']);
|
||||
|
||||
$entityManager = $app->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$account = $entityManager->getNewEntity('Account');
|
||||
$account->set([
|
||||
'name' => 'Test',
|
||||
'cTestArray' => ['option1', 'option3']
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($account);
|
||||
|
||||
$account = $entityManager->getEntityById('Account', $account->getId());
|
||||
$this->assertEquals(['option1', 'option3'], $account->get('cTestArray'));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$this->testCreate();
|
||||
|
||||
$app = $this->createApplication();
|
||||
|
||||
$fieldManager = $this->createFieldManager($app);
|
||||
|
||||
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
|
||||
$fieldDefs['required'] = true;
|
||||
|
||||
$fieldManager->update('Account', 'cTestArray', $fieldDefs);
|
||||
|
||||
$this->getContainer()->get('dataManager')->rebuild(['Account']);
|
||||
|
||||
$app = $this->createApplication();
|
||||
|
||||
$metadata = $app->getContainer()->get('metadata');
|
||||
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestArray');
|
||||
|
||||
$this->assertTrue($savedFieldDefs['required']);
|
||||
|
||||
$entityManager = $app->getContainer()->getByClass(EntityManager::class);
|
||||
$account = $entityManager->getNewEntity('Account');
|
||||
$account->set([
|
||||
'name' => 'Test',
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($account);
|
||||
}
|
||||
}
|
||||
141
tests/integration/Espo/Core/Utils/FieldManager/EnumTypeTest.php
Normal file
141
tests/integration/Espo/Core/Utils/FieldManager/EnumTypeTest.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?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\integration\Espo\Core\Utils\FieldManager;
|
||||
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\ORM\EntityManager;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class EnumTypeTest extends BaseTestCase
|
||||
{
|
||||
private $jsonFieldDefs = '{
|
||||
"type":"enum",
|
||||
"required":true,
|
||||
"dynamicLogicVisible":null,
|
||||
"dynamicLogicRequired":null,
|
||||
"dynamicLogicReadOnly":null,
|
||||
"dynamicLogicOptions":null,
|
||||
"name":"testEnum",
|
||||
"label":"TestEnum",
|
||||
"audited":true,
|
||||
"options":["option1","option2","option3"],
|
||||
"translatedOptions":{"option1":"option1","option2":"option2","option3":"option3"},
|
||||
"default":"option2",
|
||||
"tooltipText":"",
|
||||
"isPersonalData":false,
|
||||
"isSorted":false,
|
||||
"readOnly":false,
|
||||
"tooltip":false
|
||||
}';
|
||||
|
||||
protected function createFieldManager($app = null)
|
||||
{
|
||||
if (!$app) {
|
||||
$app = $this;
|
||||
}
|
||||
|
||||
return $app->getContainer()->get('injectableFactory')->create(
|
||||
'Espo\\Tools\\FieldManager\\FieldManager'
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$fieldManager = $this->createFieldManager();
|
||||
|
||||
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
|
||||
|
||||
$fieldManager->create('Account', 'testEnum', $fieldDefs);
|
||||
$this->getDataManager()->rebuild(['Account']);
|
||||
|
||||
$app = $this->createApplication();
|
||||
|
||||
$metadata = $app->getContainer()->getByClass(Metadata::class);
|
||||
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestEnum');
|
||||
|
||||
$this->assertEquals('enum', $savedFieldDefs['type']);
|
||||
$this->assertEquals('option2', $savedFieldDefs['default']);
|
||||
$this->assertTrue($savedFieldDefs['required']);
|
||||
$this->assertTrue($savedFieldDefs['isCustom']);
|
||||
$this->assertTrue($savedFieldDefs['audited']);
|
||||
|
||||
$entityManager = $app->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$account = $entityManager->getNewEntity('Account');
|
||||
$account->set([
|
||||
'name' => 'Test',
|
||||
'cTestEnum' => 'option1',
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($account);
|
||||
|
||||
$account = $entityManager->getEntityById('Account', $account->getId());
|
||||
$this->assertEquals('option1', $account->get('cTestEnum'));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$this->testCreate();
|
||||
|
||||
$app = $this->createApplication();
|
||||
|
||||
$fieldManager = $this->createFieldManager($app);
|
||||
|
||||
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
|
||||
$fieldDefs['required'] = false;
|
||||
$fieldDefs['default'] = 'option3';
|
||||
$fieldDefs['readOnly'] = true;
|
||||
|
||||
$fieldManager->update('Account', 'cTestEnum', $fieldDefs);
|
||||
$this->getDataManager()->rebuild(['Account']);
|
||||
|
||||
$app = $this->createApplication();
|
||||
|
||||
$metadata = $app->getContainer()->get('metadata');
|
||||
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestEnum');
|
||||
|
||||
$this->assertFalse($savedFieldDefs['required']);
|
||||
$this->assertEquals('option3', $savedFieldDefs['default']);
|
||||
$this->assertTrue($savedFieldDefs['audited']);
|
||||
$this->assertTrue($savedFieldDefs['readOnly']);
|
||||
|
||||
$entityManager = $app->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$account = $entityManager->getNewEntity('Account');
|
||||
$account->set([
|
||||
'name' => 'New Test',
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($account);
|
||||
|
||||
$account = $entityManager->getEntityById('Account', $account->getId());
|
||||
$this->assertEquals('option3', $account->get('cTestEnum'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?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\integration\Espo\Core\Utils\FieldManager;
|
||||
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class VarcharTypeTest extends BaseTestCase
|
||||
{
|
||||
private $jsonFieldDefs = '{
|
||||
"type":"varchar",
|
||||
"required":true,
|
||||
"trim":true,
|
||||
"dynamicLogicVisible":null,
|
||||
"dynamicLogicRequired":null,
|
||||
"dynamicLogicReadOnly":null,
|
||||
"name":"testVarchar",
|
||||
"label":"TestVarchar",
|
||||
"tooltipText":"",
|
||||
"isPersonalData":false,
|
||||
"default":"",
|
||||
"maxLength":null,
|
||||
"audited":false,
|
||||
"readOnly":false,
|
||||
"tooltip":false
|
||||
}';
|
||||
|
||||
protected function createFieldManager($app = null)
|
||||
{
|
||||
if (!$app) {
|
||||
$app = $this;
|
||||
}
|
||||
|
||||
return $app->getContainer()->get('injectableFactory')->create(
|
||||
'Espo\\Tools\\FieldManager\\FieldManager'
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$fieldManager = $this->createFieldManager();
|
||||
|
||||
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
|
||||
|
||||
$fieldManager->create('Account', 'testVarchar', $fieldDefs);
|
||||
$this->getContainer()->get('dataManager')->rebuild(['Account']);
|
||||
|
||||
$app = $this->createApplication();
|
||||
|
||||
$metadata = $app->getContainer()->get('metadata');
|
||||
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestVarchar');
|
||||
|
||||
$this->assertArrayHasKey('type', $savedFieldDefs);
|
||||
$this->assertArrayHasKey('isCustom', $savedFieldDefs);
|
||||
$this->assertEquals('varchar', $savedFieldDefs['type']);
|
||||
$this->assertTrue($savedFieldDefs['required']);
|
||||
$this->assertTrue($savedFieldDefs['isCustom']);
|
||||
|
||||
$entityManager = $app->getContainer()->get('entityManager');
|
||||
$account = $entityManager->getEntity('Account');
|
||||
$account->set([
|
||||
'name' => 'Test',
|
||||
'cTestVarchar' => 'test-value'
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($account);
|
||||
|
||||
$account = $entityManager->getEntity('Account', $account->getId());
|
||||
$this->assertEquals('test-value', $account->get('cTestVarchar'));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$this->testCreate();
|
||||
|
||||
$app = $this->createApplication();
|
||||
|
||||
$fieldManager = $this->createFieldManager($app);
|
||||
|
||||
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
|
||||
$fieldDefs['required'] = false;
|
||||
$fieldDefs['default'] = 'default-value';
|
||||
|
||||
$fieldManager->update('Account', 'cTestVarchar', $fieldDefs);
|
||||
$this->getContainer()->get('dataManager')->rebuild(['Account']);
|
||||
|
||||
$app = $this->createApplication();
|
||||
|
||||
$metadata = $app->getContainer()->get('metadata');
|
||||
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestVarchar');
|
||||
|
||||
$this->assertFalse($savedFieldDefs['required']);
|
||||
$this->assertEquals('default-value', $savedFieldDefs['default']);
|
||||
|
||||
$entityManager = $app->getContainer()->get('entityManager');
|
||||
|
||||
$account = $entityManager->getEntity('Account');
|
||||
$account->set([
|
||||
'name' => 'New Test',
|
||||
]);
|
||||
|
||||
$entityManager->saveEntity($account);
|
||||
|
||||
$account = $entityManager->getEntity('Account', $account->getId());
|
||||
$this->assertEquals('default-value', $account->get('cTestVarchar'));
|
||||
}
|
||||
}
|
||||
110
tests/integration/Espo/Core/Utils/MetadataTest.php
Normal file
110
tests/integration/Espo/Core/Utils/MetadataTest.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?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\integration\Espo\Core\Utils;
|
||||
|
||||
use Espo\Core\Utils\Json;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class MetadataTest extends BaseTestCase
|
||||
{
|
||||
private $filePath1 = 'custom/Espo/Custom/Resources/metadata/app/rebuild.json';
|
||||
private $filePath2 = 'custom/Espo/Custom/Resources/metadata/recordDefs/Note.json';
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->getFileManager()->removeFile($this->filePath1);
|
||||
$this->getFileManager()->removeFile($this->filePath2);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testAppend1(): void
|
||||
{
|
||||
$initial = $this->getMetadata()->get(['app', 'rebuild', 'actionClassNameList']);
|
||||
|
||||
$contents1 = Json::encode(
|
||||
(object) [
|
||||
'actionClassNameList' => [
|
||||
"\\Espo\\Core\\Rebuild\\Actions\\ScheduledJobs",
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$contents2 = Json::encode(
|
||||
(object) [
|
||||
'readLoaderClassNameList' => [
|
||||
"\\Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader",
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$this->createDirForFile($this->filePath1);
|
||||
$this->getFileManager()->putContents($this->filePath1, $contents1);
|
||||
$this->getFileManager()->putContents($this->filePath2, $contents2);
|
||||
$this->getDataManager()->clearCache();
|
||||
$this->getDataManager()->rebuildMetadata();
|
||||
|
||||
$this->reCreateApplication(reuse: true);
|
||||
|
||||
$metadata = $this->getContainer()->getByClass(Metadata::class);
|
||||
|
||||
$this->assertSame(
|
||||
array_merge(
|
||||
$initial,
|
||||
["\\Espo\\Core\\Rebuild\\Actions\\ScheduledJobs"]
|
||||
),
|
||||
$metadata->get(['app', 'rebuild', 'actionClassNameList'])
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
[
|
||||
"Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader",
|
||||
"\\Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader",
|
||||
],
|
||||
$metadata->get(['recordDefs', 'Note', 'readLoaderClassNameList'])
|
||||
);
|
||||
|
||||
$this->getFileManager()->removeFile($this->filePath1);
|
||||
$this->getFileManager()->removeFile($this->filePath2);
|
||||
$this->getDataManager()->clearCache();
|
||||
}
|
||||
|
||||
private function createDirForFile(string $filePath): void
|
||||
{
|
||||
$prevFolder = '';
|
||||
|
||||
foreach (array_slice(explode('/', $filePath), 0, -1) as $folder) {
|
||||
$prevFolder .= $folder . '/';
|
||||
|
||||
$this->getFileManager()->mkdir(substr($prevFolder, 0, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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\integration\Espo\Core\Utils\ScheduledJob;
|
||||
|
||||
use Espo\Core\Utils\ScheduledJob\Populator;
|
||||
use Espo\Entities\ScheduledJob;
|
||||
use Espo\ORM\Query\DeleteBuilder;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class PopulatorTest extends BaseTestCase
|
||||
{
|
||||
public function testPopulate(): void
|
||||
{
|
||||
$deleteQuery = DeleteBuilder::create()
|
||||
->from(ScheduledJob::ENTITY_TYPE)
|
||||
->where([
|
||||
ScheduledJob::FIELD_JOB => 'Cleanup',
|
||||
])
|
||||
->build();
|
||||
|
||||
$this->getEntityManager()->getQueryExecutor()->execute($deleteQuery);
|
||||
|
||||
|
||||
$this->assertEquals(0, $this->getJobCount());
|
||||
|
||||
$populator = $this->getInjectableFactory()->create(Populator::class);
|
||||
|
||||
$populator->populate();
|
||||
|
||||
$this->assertEquals(1, $this->getJobCount());
|
||||
}
|
||||
|
||||
private function getJobCount(): int
|
||||
{
|
||||
return $this->getEntityManager()
|
||||
->getRDBRepositoryByClass(ScheduledJob::class)
|
||||
->where([
|
||||
ScheduledJob::FIELD_JOB => 'Cleanup',
|
||||
])
|
||||
->count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user