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:
130
tests/integration/Espo/Record/AssignmentTest.php
Normal file
130
tests/integration/Espo/Record/AssignmentTest.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Acl\Table;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Entities\Team;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class AssignmentTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testAssignmentSelf(): void
|
||||
{
|
||||
$team1 = $this->getEntityManager()->createEntity(Team::ENTITY_TYPE);
|
||||
|
||||
$user1 = $this->createUser([
|
||||
'userName' => 'test1',
|
||||
'defaultTeamId' => $team1->getId(),
|
||||
'teamsIds' => [$team1->getId()],
|
||||
], [
|
||||
'data' => [
|
||||
Lead::ENTITY_TYPE => [
|
||||
'create' => Table::LEVEL_YES,
|
||||
'read' => Table::LEVEL_OWN,
|
||||
'edit' => Table::LEVEL_OWN,
|
||||
'delete' => Table::LEVEL_OWN,
|
||||
],
|
||||
],
|
||||
'assignmentPermission' => Table::LEVEL_NO,
|
||||
]);
|
||||
|
||||
$this->authenticate('test1');
|
||||
|
||||
$lead1 = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Lead::class)
|
||||
->create((object) [
|
||||
'lastName' => 'Test 1',
|
||||
])->getEntity();
|
||||
|
||||
$this->assertEquals($user1->getId(), $lead1->getAssignedUser()?->getId());
|
||||
$this->assertEquals([$team1->getId()], $lead1->getLinkMultipleIdList('teams'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testAssignment1(): void
|
||||
{
|
||||
$team = $this->getEntityManager()->createEntity(Team::ENTITY_TYPE);
|
||||
|
||||
$this->createUser([
|
||||
'userName' => 'test1',
|
||||
'defaultTeamId' => $team->getId(),
|
||||
'teamsIds' => [$team->getId()],
|
||||
], [
|
||||
'data' => [
|
||||
Lead::ENTITY_TYPE => [
|
||||
'create' => Table::LEVEL_YES,
|
||||
'read' => Table::LEVEL_OWN,
|
||||
'edit' => Table::LEVEL_OWN,
|
||||
'delete' => Table::LEVEL_OWN,
|
||||
],
|
||||
User::ENTITY_TYPE => [
|
||||
'read' => Table::LEVEL_TEAM,
|
||||
],
|
||||
],
|
||||
'assignmentPermission' => Table::LEVEL_TEAM,
|
||||
]);
|
||||
|
||||
$user2 = $this->createUser([
|
||||
'userName' => 'test2',
|
||||
'defaultTeamId' => $team->getId(),
|
||||
'teamsIds' => [$team->getId()],
|
||||
], [
|
||||
'data' => [
|
||||
Lead::ENTITY_TYPE => [
|
||||
'create' => Table::LEVEL_YES,
|
||||
'read' => Table::LEVEL_OWN,
|
||||
'edit' => Table::LEVEL_OWN,
|
||||
'delete' => Table::LEVEL_OWN,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->authenticate('test1');
|
||||
|
||||
$lead = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Lead::class)
|
||||
->create((object) [
|
||||
'lastName' => 'Test 1',
|
||||
'assignedUserId' => $user2->getId(),
|
||||
])->getEntity();
|
||||
|
||||
$this->assertEquals($user2->getId(), $lead->getAssignedUser()?->getId());
|
||||
}
|
||||
}
|
||||
200
tests/integration/Espo/Record/CascadeRemovalTest.php
Normal file
200
tests/integration/Espo/Record/CascadeRemovalTest.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\Modules\Crm\Entities\Opportunity;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\ORM\Query\SelectBuilder;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class CascadeRemovalTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testRemovalAndRestoral(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
$metadata->set('entityDefs', 'Account', [
|
||||
'links' => [
|
||||
'opportunities' => [
|
||||
RelationParam::CASCADE_REMOVAL => true,
|
||||
]
|
||||
]
|
||||
]);
|
||||
$metadata->set('entityDefs', 'Opportunity', [
|
||||
'links' => [
|
||||
'tasks' => [
|
||||
RelationParam::CASCADE_REMOVAL => true,
|
||||
]
|
||||
]
|
||||
]);
|
||||
$metadata->save();
|
||||
$this->getDataManager()->clearCache();
|
||||
$this->getDataManager()->rebuildMetadata();
|
||||
|
||||
$this->reCreateApplication(reuse: true);
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$account = $em->createEntity('Account', ['name' => 'a1']);
|
||||
$contact = $em->createEntity('Contact', ['lastName' => 'c1', 'accountId' => $account->getId()]);
|
||||
$opp1 = $em->createEntity('Opportunity', ['name' => 'o1', 'accountId' => $account->getId()]);
|
||||
$opp2 = $em->createEntity('Opportunity', ['name' => 'o2', 'accountId' => $account->getId()]);
|
||||
$opp3 = $em->createEntity('Opportunity', ['name' => 'o3']);
|
||||
|
||||
$task1 = $em->createEntity('Task', [
|
||||
'name' => 't1',
|
||||
'parentType' => 'Opportunity',
|
||||
'parentId' => $opp1->getId(),
|
||||
]);
|
||||
|
||||
$em->removeEntity($account);
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Account::ENTITY_TYPE)
|
||||
->clone(
|
||||
SelectBuilder::create()
|
||||
->from(Account::ENTITY_TYPE)
|
||||
->withDeleted()
|
||||
->build()
|
||||
)
|
||||
->where([
|
||||
Attribute::ID => $account->getId(),
|
||||
Attribute::DELETED => true,
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Contact::ENTITY_TYPE)
|
||||
->where([
|
||||
Attribute::ID => $contact->getId(),
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Opportunity::ENTITY_TYPE)
|
||||
->clone(
|
||||
SelectBuilder::create()
|
||||
->from(Opportunity::ENTITY_TYPE)
|
||||
->withDeleted()
|
||||
->build()
|
||||
)
|
||||
->where([
|
||||
Attribute::ID => $opp1->getId(),
|
||||
Attribute::DELETED => true,
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Opportunity::ENTITY_TYPE)
|
||||
->clone(
|
||||
SelectBuilder::create()
|
||||
->from(Opportunity::ENTITY_TYPE)
|
||||
->withDeleted()
|
||||
->build()
|
||||
)
|
||||
->where([
|
||||
Attribute::ID => $opp2->getId(),
|
||||
Attribute::DELETED => true,
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Task::ENTITY_TYPE)
|
||||
->clone(
|
||||
SelectBuilder::create()
|
||||
->from(Task::ENTITY_TYPE)
|
||||
->withDeleted()
|
||||
->build()
|
||||
)
|
||||
->where([
|
||||
Attribute::ID => $task1->getId(),
|
||||
Attribute::DELETED => true,
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Opportunity::ENTITY_TYPE)
|
||||
->where([
|
||||
Attribute::ID => $opp3->getId(),
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
|
||||
//
|
||||
|
||||
$service = $this->getContainer()->getByClass(ServiceContainer::class)->get(Account::ENTITY_TYPE);
|
||||
|
||||
$service->restoreDeleted($account->getId());
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Account::ENTITY_TYPE)
|
||||
->where([
|
||||
Attribute::ID => $account->getId(),
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Opportunity::ENTITY_TYPE)
|
||||
->where([
|
||||
Attribute::ID => $opp1->getId(),
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Opportunity::ENTITY_TYPE)
|
||||
->where([
|
||||
Attribute::ID => $opp2->getId(),
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
|
||||
$this->assertNotNull(
|
||||
$em->getRDBRepository(Task::ENTITY_TYPE)
|
||||
->where([
|
||||
Attribute::ID => $task1->getId(),
|
||||
])
|
||||
->findOne()
|
||||
);
|
||||
}
|
||||
}
|
||||
91
tests/integration/Espo/Record/DefaultsPopulatorTest.php
Normal file
91
tests/integration/Espo/Record/DefaultsPopulatorTest.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Acl\Table;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Conflict;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Entities\Portal;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\CaseObj;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class DefaultsPopulatorTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws Forbidden
|
||||
* @throws Conflict
|
||||
*/
|
||||
public function testPortal(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$account = $em->getRDBRepositoryByClass(Account::class)->getNew();
|
||||
$em->saveEntity($account);
|
||||
|
||||
$contact = $em->getRDBRepositoryByClass(Contact::class)->getNew();
|
||||
$contact->setAccount($account);
|
||||
$em->saveEntity($contact);
|
||||
|
||||
$portal = $em->getRDBRepositoryByClass(Portal::class)->getNew();
|
||||
$em->saveEntity($portal);
|
||||
|
||||
$this->createUser([
|
||||
'userName' => 'tester',
|
||||
'portalsIds' => [$portal->getId()],
|
||||
'contactId' => $contact->getId(),
|
||||
'accountsIds' => [$account->getId()],
|
||||
], [
|
||||
'data' => [
|
||||
'Case' => [
|
||||
'create' => Table::LEVEL_YES,
|
||||
'read' => 'contact',
|
||||
],
|
||||
],
|
||||
], true);
|
||||
|
||||
$this->auth(userName: 'tester', portalId: $portal->getId());
|
||||
$this->reCreateApplication(reuse: true);
|
||||
|
||||
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(CaseObj::class);
|
||||
|
||||
$result = $service->create((object) [
|
||||
'name' => 'Test',
|
||||
], CreateParams::create());
|
||||
|
||||
$this->assertEquals($contact->getId(), $result->getEntity()->getContact()?->getId());
|
||||
$this->assertEquals($account->getId(), $result->getEntity()->getAccount()?->getId());
|
||||
}
|
||||
}
|
||||
129
tests/integration/Espo/Record/DuplicateFindTest.php
Normal file
129
tests/integration/Espo/Record/DuplicateFindTest.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Exceptions\ConflictSilent;
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class DuplicateFindTest extends BaseTestCase
|
||||
{
|
||||
public function testAccount1()
|
||||
{
|
||||
$service = $this->getContainer()
|
||||
->get('recordServiceContainer')
|
||||
->get('Account');
|
||||
|
||||
$data1 = (object) [
|
||||
'name' => 'test1',
|
||||
'emailAddress' => 'test@test.com',
|
||||
];
|
||||
|
||||
$service->create($data1, CreateParams::create());
|
||||
|
||||
$this->expectException(ConflictSilent::class);
|
||||
|
||||
$data2 = (object) [
|
||||
'name' => 'test2',
|
||||
'emailAddress' => 'test@test.com',
|
||||
];
|
||||
|
||||
$service->create($data2, CreateParams::create());
|
||||
}
|
||||
|
||||
public function testAccountSkip()
|
||||
{
|
||||
$service = $this->getContainer()
|
||||
->get('recordServiceContainer')
|
||||
->get('Account');
|
||||
|
||||
$data1 = (object) [
|
||||
'name' => 'test1',
|
||||
'emailAddress' => 'test@test.com',
|
||||
];
|
||||
|
||||
$service->create($data1, CreateParams::create());
|
||||
|
||||
$data2 = (object) [
|
||||
'name' => 'test2',
|
||||
'emailAddress' => 'test@test.com',
|
||||
];
|
||||
|
||||
$service->create($data2, CreateParams::create()->withSkipDuplicateCheck());
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testLead1()
|
||||
{
|
||||
$service = $this->getContainer()
|
||||
->get('recordServiceContainer')
|
||||
->get('Lead');
|
||||
|
||||
$data1 = (object) [
|
||||
'lastName' => 'test1',
|
||||
'emailAddress' => 'test@test.com',
|
||||
];
|
||||
|
||||
$service->create($data1, CreateParams::create());
|
||||
|
||||
$this->expectException(ConflictSilent::class);
|
||||
|
||||
$data2 = (object) [
|
||||
'lastName' => 'test2',
|
||||
'emailAddress' => 'test@test.com',
|
||||
];
|
||||
|
||||
$service->create($data2, CreateParams::create());
|
||||
}
|
||||
|
||||
public function testLeadSkip()
|
||||
{
|
||||
$service = $this->getContainer()
|
||||
->get('recordServiceContainer')
|
||||
->get('Lead');
|
||||
|
||||
$data1 = (object) [
|
||||
'lastName' => 'test1',
|
||||
'emailAddress' => 'test@test.com',
|
||||
];
|
||||
|
||||
$service->create($data1, CreateParams::create());
|
||||
|
||||
$data2 = (object) [
|
||||
'lastName' => 'test2',
|
||||
'emailAddress' => 'test@test.com',
|
||||
];
|
||||
|
||||
$service->create($data2, CreateParams::create()->withSkipDuplicateCheck());
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
87
tests/integration/Espo/Record/EntityDuplicatorTest.php
Normal file
87
tests/integration/Espo/Record/EntityDuplicatorTest.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use Espo\Core\Record\Duplicator\EntityDuplicator;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Entities\Email;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class EntityDuplicatorTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testDuplicate(): void
|
||||
{
|
||||
$user = $this->createUser([
|
||||
'userName' => 'test',
|
||||
'type' => User::TYPE_ADMIN,
|
||||
]);
|
||||
|
||||
$this->authenticate('test');
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$account = $em->getRDBRepositoryByClass(Account::class)->getNew();
|
||||
$account->setName('Account');
|
||||
$em->saveEntity($account);
|
||||
|
||||
$email = $em->getRDBRepositoryByClass(Email::class)->getNew();
|
||||
$email->setSubject('Test');
|
||||
$email->setParent($account);
|
||||
$em->saveEntity($email);
|
||||
|
||||
$taskService = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Task::class);
|
||||
|
||||
$task = $taskService->create((object) [
|
||||
'name' => 'Task',
|
||||
'originalEmailId' => $email->getId(),
|
||||
'parentId' => $account->getId(),
|
||||
'parentType' => $account->getEntityType(),
|
||||
'assignedUserId' => $user->getId(),
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals($email->getId(), $task->get('emailId'));
|
||||
|
||||
$duplicator = $this->getInjectableFactory()->create(EntityDuplicator::class);
|
||||
|
||||
$values = $duplicator->duplicate($task);
|
||||
|
||||
$this->assertEquals($account->getId(), $values->accountId ?? null);
|
||||
$this->assertFalse(isset($values->emailId));
|
||||
}
|
||||
}
|
||||
50
tests/integration/Espo/Record/EntityProviderTest.php
Normal file
50
tests/integration/Espo/Record/EntityProviderTest.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\Record;
|
||||
|
||||
use Espo\Core\Record\EntityProvider;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class EntityProviderTest extends BaseTestCase
|
||||
{
|
||||
public function testGet(): void
|
||||
{
|
||||
$account = $this->getEntityManager()->createEntity(Account::ENTITY_TYPE);
|
||||
$id = $account->getId();
|
||||
|
||||
$provider = $this->getInjectableFactory()->create(EntityProvider::class);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$account = $provider->getByClass(Account::class, $account->getId());
|
||||
|
||||
$this->assertEquals($id, $account->getId());
|
||||
}
|
||||
}
|
||||
727
tests/integration/Espo/Record/FieldValidationTest.php
Normal file
727
tests/integration/Espo/Record/FieldValidationTest.php
Normal file
@@ -0,0 +1,727 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Application;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\FieldValidation\Type;
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Tools\App\SettingsService as SettingsService;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class FieldValidationTest extends BaseTestCase
|
||||
{
|
||||
private function setFieldsDefs(Application $app, string $entityType, array $data)
|
||||
{
|
||||
$metadata = $app->getContainer()->getByClass(Metadata::class);
|
||||
|
||||
$metadata->set('entityDefs', $entityType, [
|
||||
'fields' => $data,
|
||||
]);
|
||||
|
||||
$metadata->save();
|
||||
}
|
||||
|
||||
public function testRequiredVarchar1()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'name' => [
|
||||
'required' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->create((object) [
|
||||
'name' => null,
|
||||
], CreateParams::create());
|
||||
}
|
||||
|
||||
public function testUpdateRequiredVarchar1()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'name' => [
|
||||
'required' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$entity = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->create(
|
||||
(object) [
|
||||
'name' => 'test'
|
||||
],
|
||||
CreateParams::create()
|
||||
)
|
||||
->getEntity();
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->update(
|
||||
$entity->getId(),
|
||||
(object) [
|
||||
'name' => '',
|
||||
],
|
||||
UpdateParams::create()
|
||||
);
|
||||
}
|
||||
|
||||
public function testRequiredVarchar2()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'name' => [
|
||||
'required' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->create(
|
||||
(object) [
|
||||
|
||||
],
|
||||
CreateParams::create()
|
||||
);
|
||||
}
|
||||
|
||||
public function testRequiredVarchar3()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'name' => [
|
||||
'required' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->create((object) [
|
||||
'name' => 'test',
|
||||
], CreateParams::create());
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testMaxLength1()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'name' => [
|
||||
'required' => true,
|
||||
'maxLength' => 5,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->create((object) [
|
||||
'name' => '123456',
|
||||
], CreateParams::create());
|
||||
}
|
||||
|
||||
public function testMaxLength2()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'name' => [
|
||||
'required' => true,
|
||||
'maxLength' => 5,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->create((object) [
|
||||
'name' => '12345',
|
||||
], CreateParams::create());
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testRequiredLink1()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'assignedUser' => [
|
||||
'required' => true,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->create((object) [
|
||||
'name' => 'test',
|
||||
'assignedUserId' => null,
|
||||
], CreateParams::create());
|
||||
}
|
||||
|
||||
private function getAdminUser(): User
|
||||
{
|
||||
$repository = $this->getContainer()
|
||||
->getByClass(EntityManager::class)
|
||||
->getRDBRepositoryByClass(User::class);
|
||||
|
||||
$user = $repository
|
||||
->where(['type' => User::TYPE_ADMIN])
|
||||
->findOne();
|
||||
|
||||
if (!$user) {
|
||||
$user = $repository->getNew();
|
||||
$user->set('userName', 'test-admin');
|
||||
$user->set('type', User::TYPE_ADMIN);
|
||||
|
||||
$repository->save($user);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function testRequiredLink2()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'assignedUser' => [
|
||||
'required' => true,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->create((object) [
|
||||
'name' => 'test',
|
||||
'assignedUserId' => $this->getAdminUser()->getId(),
|
||||
], CreateParams::create());
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testRequiredLinkMultiple1()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'teams' => [
|
||||
'required' => true,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->create((object) [
|
||||
'name' => 'test',
|
||||
'teamsIds' => [],
|
||||
], CreateParams::create());
|
||||
}
|
||||
|
||||
public function testRequiredCurrency1()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Lead', [
|
||||
'opportunityAmount' => [
|
||||
'required' => true,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Lead')
|
||||
->create((object) [
|
||||
'lastName' => 'test',
|
||||
'opportunityAmount' => null,
|
||||
], CreateParams::create());
|
||||
}
|
||||
|
||||
public function testRequiredCurrency2()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Lead', [
|
||||
'opportunityAmount' => [
|
||||
'required' => true,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Lead')
|
||||
->create((object) [
|
||||
'lastName' => 'test',
|
||||
'opportunityAmount' => 100,
|
||||
'opportunityAmountCurrency' => null,
|
||||
], CreateParams::create());
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testRequiredCurrency3()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Lead', [
|
||||
'opportunityAmount' => [
|
||||
'required' => true,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Lead')
|
||||
->create((object) [
|
||||
'lastName' => 'test',
|
||||
'opportunityAmount' => 100,
|
||||
'opportunityAmountCurrency' => 'USD',
|
||||
], CreateParams::create());
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testRequiredEnum1()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Lead', [
|
||||
'status' => [
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->getDataManager()->clearCache();
|
||||
$this->getDataManager()->rebuildMetadata();
|
||||
|
||||
$this->authenticate(null);
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Lead')
|
||||
->create((object) [
|
||||
'lastName' => 'test',
|
||||
], CreateParams::create());
|
||||
}
|
||||
|
||||
public function testRequiredEnum2()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Lead', [
|
||||
'status' => [
|
||||
'required' => true,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Lead')
|
||||
->create((object) [
|
||||
'lastName' => 'test',
|
||||
'status' => null,
|
||||
], CreateParams::create());
|
||||
}
|
||||
|
||||
public function testRequiredEnum3()
|
||||
{
|
||||
$this->setFieldsDefs($this->getApplication(), 'Lead', [
|
||||
'status' => [
|
||||
'required' => true,
|
||||
]
|
||||
]);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Lead')
|
||||
->create((object) [
|
||||
'lastName' => 'test',
|
||||
'status' => 'New',
|
||||
], CreateParams::create());
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testSkipRequired()
|
||||
{
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Meeting')
|
||||
->create((object) [
|
||||
'name' => 'test',
|
||||
'dateStart' => '2021-01-01 00:00:00',
|
||||
'duration' => 1000,
|
||||
'assignedUserId' => $this->getAdminUser()->getId(),
|
||||
], CreateParams::create());
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testSettings()
|
||||
{
|
||||
$service = $this->getInjectableFactory()->create(SettingsService::class);
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$service->setConfigData((object) [
|
||||
'activitiesEntityList' => 'should-be-array',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCurrencyValid(): void
|
||||
{
|
||||
$service = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Lead::class);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->create((object) [
|
||||
'lastName' => 'Test 1',
|
||||
'opportunityAmount' => '100.10',
|
||||
], CreateParams::create());
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->create((object) [
|
||||
'lastName' => 'Test 2',
|
||||
'opportunityAmount' => '100',
|
||||
], CreateParams::create());
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->create((object) [
|
||||
'lastName' => 'Test 3',
|
||||
'opportunityAmount' => '',
|
||||
], CreateParams::create());
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->create((object) [
|
||||
'lastName' => 'Test 4',
|
||||
'opportunityAmount' => null,
|
||||
], CreateParams::create());
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->create((object) [
|
||||
'lastName' => 'Test Bad 1',
|
||||
'opportunityAmount' => 'bad-value',
|
||||
], CreateParams::create());
|
||||
}
|
||||
|
||||
public function testPhoneNumber(): void
|
||||
{
|
||||
$service = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Account::class);
|
||||
|
||||
$configWriter = $this->getInjectableFactory()->create(ConfigWriter::class);
|
||||
$configWriter->set('phoneNumberExtensions', true);
|
||||
$configWriter->save();
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->create((object)[
|
||||
'name' => 'Test 1',
|
||||
'phoneNumberData' => [
|
||||
(object)[
|
||||
'phoneNumber' => '+38 09 044 433 22 ext. 001',
|
||||
],
|
||||
],
|
||||
], CreateParams::create());
|
||||
|
||||
$thrown = false;
|
||||
|
||||
try {
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->create((object)[
|
||||
'name' => 'Test 2',
|
||||
'phoneNumberData' => [
|
||||
(object)[
|
||||
'phoneNumber' => '+38 09 044 433 22 ext. ABC',
|
||||
],
|
||||
(object)[
|
||||
'phoneNumber' => '+38 09 044 433 33 ext. 1234567',
|
||||
],
|
||||
],
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$thrown = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($thrown);
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testDynamicLogicRequired(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
|
||||
$metadata->set('logicDefs', Account::ENTITY_TYPE, [
|
||||
'fields' => [
|
||||
'description' => [
|
||||
Type::REQUIRED => [
|
||||
'conditionGroup' => [
|
||||
[
|
||||
'type' => 'equals',
|
||||
'attribute' => 'type',
|
||||
'value' => 'Customer',
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$metadata->save();
|
||||
|
||||
$this->getDataManager()->clearCache();
|
||||
$this->getDataManager()->rebuildMetadata();
|
||||
|
||||
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Account::class);
|
||||
|
||||
$account = $service->create((object) [
|
||||
'name' => 'Test',
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$isThrown = false;
|
||||
|
||||
try {
|
||||
$service->update($account->getId(), (object) [
|
||||
'type' => 'Customer',
|
||||
], UpdateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
$isThrown = false;
|
||||
|
||||
try {
|
||||
$service->update($account->getId(), (object) [
|
||||
'type' => 'Customer',
|
||||
'description' => 'Test.',
|
||||
], UpdateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
|
||||
$this->assertFalse($isThrown);
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testDecimal(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
$metadata->set('entityDefs', 'Account', [
|
||||
'fields' => [
|
||||
'test' => [
|
||||
'type' => FieldType::DECIMAL,
|
||||
'min' => '-1.0',
|
||||
'max' => '100.0',
|
||||
]
|
||||
],
|
||||
]);
|
||||
$metadata->save();
|
||||
|
||||
$this->getDataManager()->rebuild();
|
||||
|
||||
$this->reCreateApplication();
|
||||
|
||||
$service = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Account::class);
|
||||
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-0',
|
||||
'test' => null,
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertFalse($isThrown);
|
||||
|
||||
/** @noinspection PhpConditionAlreadyCheckedInspection */
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-1',
|
||||
'test' => '10.0',
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertFalse($isThrown);
|
||||
|
||||
/** @noinspection PhpConditionAlreadyCheckedInspection */
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-2',
|
||||
'test' => '-1.0',
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertFalse($isThrown);
|
||||
|
||||
/** @noinspection PhpConditionAlreadyCheckedInspection */
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-3',
|
||||
'test' => '100.0',
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertFalse($isThrown);
|
||||
|
||||
/** @noinspection PhpConditionAlreadyCheckedInspection */
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-4',
|
||||
'test' => '-10.0',
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-5',
|
||||
'test' => '100.1',
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-6',
|
||||
'test' => 'abc',
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-7',
|
||||
'test' => ['test'],
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-8',
|
||||
'test' => 10.0,
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertFalse($isThrown);
|
||||
|
||||
/** @noinspection PhpConditionAlreadyCheckedInspection */
|
||||
$isThrown = false;
|
||||
try {
|
||||
$service->create((object) [
|
||||
'name' => 'Test-9',
|
||||
'test' => 10,
|
||||
], CreateParams::create());
|
||||
} catch (BadRequest) {
|
||||
$isThrown = true;
|
||||
}
|
||||
$this->assertFalse($isThrown);
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testDependsOn(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$account = $em->createEntity('Account', [
|
||||
'name' => 'Test',
|
||||
]);
|
||||
|
||||
$this->setFieldsDefs($this->getApplication(), 'Account', [
|
||||
'description' => [
|
||||
'required' => true,
|
||||
'validationDependsOnFieldList' => ['name'],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->getDataManager()->clearCache();
|
||||
$this->getDataManager()->rebuildMetadata();
|
||||
|
||||
$this->expectException(BadRequest::class);
|
||||
|
||||
$this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account')
|
||||
->update($account->getId(), (object) [
|
||||
'name' => 'Test 1',
|
||||
], UpdateParams::create());
|
||||
}
|
||||
}
|
||||
653
tests/integration/Espo/Record/LinkTest.php
Normal file
653
tests/integration/Espo/Record/LinkTest.php
Normal file
@@ -0,0 +1,653 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Field\Date;
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\Attachment;
|
||||
use Espo\Entities\Email;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\CaseObj;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\Modules\Crm\Entities\Document;
|
||||
use Espo\Modules\Crm\Entities\Lead;
|
||||
use Espo\Modules\Crm\Entities\Opportunity;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class LinkTest extends BaseTestCase
|
||||
{
|
||||
public function testUnlinkRequired1(): void
|
||||
{
|
||||
$metadata = $this->getContainer()->getByClass(Metadata::class);
|
||||
|
||||
$metadata->set('entityDefs', CaseObj::ENTITY_TYPE, [
|
||||
'fields' => [
|
||||
'account' => ['required' => true]
|
||||
]
|
||||
]);
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication(reuse: true);
|
||||
|
||||
$em = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$account = $em->createEntity(Account::ENTITY_TYPE, [
|
||||
'name' => 'Test',
|
||||
]);
|
||||
|
||||
$case = $em->createEntity(CaseObj::ENTITY_TYPE, [
|
||||
'name' => 'Test',
|
||||
'accountId' => $account->getId(),
|
||||
]);
|
||||
|
||||
$accountService = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Account::class);
|
||||
|
||||
$this->expectException(Forbidden::class);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$accountService->unlink($account->getId(), 'cases', $case->getId());
|
||||
}
|
||||
|
||||
public function testLinkCheck1(): void
|
||||
{
|
||||
$user = $this->createUser('test', [
|
||||
'data' => [
|
||||
'Account' => [
|
||||
'create' => 'no',
|
||||
'read' => 'own',
|
||||
'edit' => 'no',
|
||||
'delete' => 'no',
|
||||
],
|
||||
'Opportunity' => [
|
||||
'create' => 'yes',
|
||||
'read' => 'own',
|
||||
'edit' => 'own',
|
||||
'delete' => 'no',
|
||||
],
|
||||
'Task' => [
|
||||
'create' => 'yes',
|
||||
'read' => 'own',
|
||||
'edit' => 'own',
|
||||
'delete' => 'no',
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
$em = $this->getContainer()->getByClass(EntityManager::class);
|
||||
|
||||
$account1 = $em->createEntity(Account::ENTITY_TYPE, [
|
||||
'name' => '1',
|
||||
'assignedUserId' => $user->getId(),
|
||||
]);
|
||||
|
||||
$account2 = $em->createEntity(Account::ENTITY_TYPE, [
|
||||
'name' => '2',
|
||||
]);
|
||||
|
||||
$this->authenticate('test');
|
||||
|
||||
$oppService = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Opportunity::class);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$oppService->create((object) [
|
||||
'name' => '1',
|
||||
'accountId' => $account1->getId(),
|
||||
'assignedUserId' => $user->getId(),
|
||||
'amount' => 1.0,
|
||||
'amountCurrency' => 'USD',
|
||||
'probability' => 10,
|
||||
'closeDate' => Date::createToday()->toString(),
|
||||
], CreateParams::create());
|
||||
|
||||
$isThrown = false;
|
||||
|
||||
try {
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$oppService->create((object) [
|
||||
'name' => '2',
|
||||
'accountId' => $account2->getId(),
|
||||
'assignedUserId' => $user->getId(),
|
||||
'amount' => 1.0,
|
||||
'amountCurrency' => 'USD',
|
||||
'probability' => 10,
|
||||
'closeDate' => Date::createToday()->toString(),
|
||||
], CreateParams::create());
|
||||
}
|
||||
catch (Forbidden) {
|
||||
$isThrown = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
//
|
||||
|
||||
$taskService = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Task::class);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$task1 = $taskService->create((object) [
|
||||
'name' => '1',
|
||||
'accountId' => $account1->getId(),
|
||||
'parentType' => $account1->getEntityType(),
|
||||
'assignedUserId' => $user->getId(),
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$isThrown = false;
|
||||
|
||||
try {
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$taskService->create((object) [
|
||||
'name' => '2',
|
||||
'parentId' => $account2->getId(),
|
||||
'parentType' => $account2->getEntityType(),
|
||||
'assignedUserId' => $user->getId(),
|
||||
], CreateParams::create());
|
||||
}
|
||||
catch (Forbidden) {
|
||||
$isThrown = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
//
|
||||
|
||||
$isThrown = false;
|
||||
|
||||
try {
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$taskService->update($task1->getId(), (object) [
|
||||
'parentId' => $account2->getId(),
|
||||
'parentType' => $account2->getEntityType(),
|
||||
], UpdateParams::create())->getEntity();
|
||||
}
|
||||
catch (Forbidden) {
|
||||
$isThrown = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
//
|
||||
|
||||
$metadata = $this->getContainer()->getByClass(Metadata::class);
|
||||
|
||||
$metadata->set('entityDefs', Opportunity::ENTITY_TYPE, [
|
||||
'fields' => [
|
||||
'account' => [
|
||||
'defaultAttributes' => [
|
||||
'accountId' => $account2->getId(),
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication();
|
||||
|
||||
$oppService = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Opportunity::class);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$oppService->create((object) [
|
||||
'name' => '2',
|
||||
'accountId' => $account2->getId(),
|
||||
'assignedUserId' => $user->getId(),
|
||||
'amount' => 1.0,
|
||||
'amountCurrency' => 'USD',
|
||||
'probability' => 10,
|
||||
'closeDate' => Date::createToday()->toString(),
|
||||
], CreateParams::create());
|
||||
}
|
||||
|
||||
public function testLinkCheckEmailToCase(): void
|
||||
{
|
||||
$user = $this->createUser('test', [
|
||||
'data' => [
|
||||
'Account' => [
|
||||
'create' => 'no',
|
||||
'read' => 'own',
|
||||
'edit' => 'no',
|
||||
'delete' => 'no',
|
||||
],
|
||||
'Case' => [
|
||||
'create' => 'yes',
|
||||
'read' => 'own',
|
||||
'edit' => 'own',
|
||||
'delete' => 'no',
|
||||
],
|
||||
'Contact' => [
|
||||
'create' => 'yes',
|
||||
'read' => 'own',
|
||||
'edit' => 'own',
|
||||
'delete' => 'no',
|
||||
],
|
||||
'Lead' => [
|
||||
'create' => 'yes',
|
||||
'read' => 'own',
|
||||
'edit' => 'own',
|
||||
'delete' => 'no',
|
||||
],
|
||||
'Email' => [
|
||||
'create' => 'yes',
|
||||
'read' => 'own',
|
||||
'edit' => 'own',
|
||||
'delete' => 'no',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$account = $em->createEntity(Account::ENTITY_TYPE, ['assignedUserId' => $user->getId()]);
|
||||
$lead = $em->createEntity(Lead::ENTITY_TYPE);
|
||||
$contact = $em->createEntity(Contact::ENTITY_TYPE, ['lastName' => 'contact']);
|
||||
$email = $em->createEntity(Email::ENTITY_TYPE, [
|
||||
'assignedUserId' => $user->getId(),
|
||||
'parentId' => $lead->getId(),
|
||||
'parentType' => Lead::ENTITY_TYPE,
|
||||
]);
|
||||
|
||||
$this->authenticate('test');
|
||||
|
||||
$caseService = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(CaseObj::class);
|
||||
|
||||
// Should not create if no access to the Lead.
|
||||
|
||||
$isThrown = false;
|
||||
|
||||
try {
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$caseService->create((object) [
|
||||
'name' => '1',
|
||||
'assignedUserId' => $user->getId(),
|
||||
'leadId' => $lead->getId(),
|
||||
'accountId' => $account->getId(),
|
||||
], CreateParams::create());
|
||||
}
|
||||
catch (Forbidden) {
|
||||
$isThrown = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
// Should create if an email with a Lead parent is passed.
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$caseService->create((object) [
|
||||
'name' => '1',
|
||||
'assignedUserId' => $user->getId(),
|
||||
'leadId' => $lead->getId(),
|
||||
'accountId' => $account->getId(),
|
||||
'originalEmailId' => $email->getId(),
|
||||
], CreateParams::create());
|
||||
|
||||
//
|
||||
|
||||
$account = $em->createEntity(Account::ENTITY_TYPE);
|
||||
$email = $em->createEntity(Email::ENTITY_TYPE, [
|
||||
'assignedUserId' => $user->getId(),
|
||||
'parentId' => $account->getId(),
|
||||
'parentType' => Account::ENTITY_TYPE,
|
||||
]);
|
||||
|
||||
// Should not create if no access to the Account.
|
||||
|
||||
$isThrown = false;
|
||||
|
||||
try {
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$caseService->create((object) [
|
||||
'name' => '1',
|
||||
'assignedUserId' => $user->getId(),
|
||||
'accountId' => $account->getId(),
|
||||
], CreateParams::create());
|
||||
}
|
||||
catch (Forbidden) {
|
||||
$isThrown = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
// Should create if an email with an Account parent is passed.
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$caseService->create((object) [
|
||||
'name' => '1',
|
||||
'assignedUserId' => $user->getId(),
|
||||
'accountId' => $account->getId(),
|
||||
'originalEmailId' => $email->getId(),
|
||||
], CreateParams::create());
|
||||
|
||||
//
|
||||
|
||||
$account = $em->createEntity(Account::ENTITY_TYPE, ['assignedUserId' => $user->getId()]);
|
||||
|
||||
$email = $em->createEntity(Email::ENTITY_TYPE, [
|
||||
'assignedUserId' => $user->getId(),
|
||||
'parentId' => $contact->getId(),
|
||||
'parentType' => Contact::ENTITY_TYPE,
|
||||
]);
|
||||
|
||||
// Should not create if no access to the Contact.
|
||||
|
||||
$isThrown = false;
|
||||
|
||||
try {
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$caseService->create((object) [
|
||||
'name' => '1',
|
||||
'assignedUserId' => $user->getId(),
|
||||
'accountId' => $account->getId(),
|
||||
'contactId' => $contact->getId(),
|
||||
'contactsIds' => [$contact->getId()],
|
||||
], CreateParams::create());
|
||||
}
|
||||
catch (Forbidden) {
|
||||
$isThrown = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($isThrown);
|
||||
|
||||
// Should create if an email with a Contact parent is passed.
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$caseService->create((object) [
|
||||
'name' => '1',
|
||||
'assignedUserId' => $user->getId(),
|
||||
'accountId' => $account->getId(),
|
||||
'contactId' => $contact->getId(),
|
||||
'contactsIds' => [$contact->getId()],
|
||||
'originalEmailId' => $email->getId(),
|
||||
], CreateParams::create());
|
||||
|
||||
// Should not allow more than 1 ID.
|
||||
|
||||
$contactAnother = $this->getEntityManager()->createEntity(Contact::ENTITY_TYPE);
|
||||
|
||||
$isThrown = false;
|
||||
|
||||
try {
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$caseService->create((object) [
|
||||
'name' => '1',
|
||||
'assignedUserId' => $user->getId(),
|
||||
'contactId' => $contact->getId(),
|
||||
'contactsIds' => [$contact->getId(), $contactAnother->getId()],
|
||||
'originalEmailId' => $email->getId(),
|
||||
], CreateParams::create());
|
||||
}
|
||||
catch (Forbidden) {
|
||||
$isThrown = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($isThrown);
|
||||
}
|
||||
|
||||
public function testLoadNames(): void
|
||||
{
|
||||
$caseService = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(CaseObj::class);
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$contact = $em->createEntity(Contact::ENTITY_TYPE, ['lastName' => 'contact']);
|
||||
$contact1 = $em->createEntity(Contact::ENTITY_TYPE, ['lastName' => 'contact1']);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$case = $caseService->create((object) [
|
||||
'name' => '1',
|
||||
'contactId' => $contact->getId(),
|
||||
'contactsIds' => [$contact->getId()],
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals(
|
||||
(object) [
|
||||
$contact->getId() => $contact->get('lastName'),
|
||||
],
|
||||
$case->get('contactsNames')
|
||||
);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$case = $caseService->update($case->getId(), (object) [
|
||||
'contactsIds' => [$contact->getId(), $contact1->getId()],
|
||||
], UpdateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals(
|
||||
(object) [
|
||||
$contact->getId() => $contact->get('lastName'),
|
||||
$contact1->getId() => $contact1->get('lastName'),
|
||||
],
|
||||
$case->get('contactsNames')
|
||||
);
|
||||
}
|
||||
|
||||
public function testOneToOne(): void
|
||||
{
|
||||
$metadata = $this->getContainer()->getByClass(Metadata::class);
|
||||
|
||||
$metadata->set('entityDefs', CaseObj::ENTITY_TYPE, [
|
||||
'links' => [
|
||||
'task' => [
|
||||
'foreign' => 'case',
|
||||
'type' => RelationType::BELONGS_TO,
|
||||
'entity' => Task::ENTITY_TYPE,
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
$metadata->set('entityDefs', Task::ENTITY_TYPE, [
|
||||
'fields' => [
|
||||
'case' => [
|
||||
'type' => FieldType::LINK_ONE,
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
'case' => [
|
||||
'foreign' => 'task',
|
||||
'type' => RelationType::HAS_ONE,
|
||||
'entity' => CaseObj::ENTITY_TYPE,
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
$metadata->save();
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$this->getDataManager()->rebuild();
|
||||
$this->reCreateApplication();
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$task = $em->getRDBRepositoryByClass(Task::class)->getNew();
|
||||
$task->setMultiple(['name' => 'Task']);
|
||||
$em->saveEntity($task);
|
||||
|
||||
$case = $em->getRDBRepositoryByClass(CaseObj::class)->getNew();
|
||||
$case->setMultiple(['name' => 'Case']);
|
||||
$em->saveEntity($case);
|
||||
|
||||
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Task::class);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$service->update($task->getId(), (object) [
|
||||
'caseId' => $case->getId(),
|
||||
], UpdateParams::create());
|
||||
|
||||
$this->assertTrue(
|
||||
$em->getRDBRepositoryByClass(Task::class)
|
||||
->getRelation($task, 'case')
|
||||
->isRelatedById($case->getId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testAttachmentsOne(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$attachment1 = $em->getRDBRepositoryByClass(Attachment::class)->getNew();
|
||||
$em->saveEntity($attachment1);
|
||||
|
||||
$attachment2 = $em->getRDBRepositoryByClass(Attachment::class)->getNew();
|
||||
$em->saveEntity($attachment2);
|
||||
|
||||
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Document::class);
|
||||
|
||||
$document1 = $service->create((object) [
|
||||
Field::NAME => 'Good',
|
||||
Document::FIELD_FILE . 'Id' => $attachment1->getId(),
|
||||
Document::FIELD_PUBLISH_DATE => Date::createToday()->toString(),
|
||||
])->getEntity();
|
||||
|
||||
//
|
||||
|
||||
$throw = false;
|
||||
|
||||
try {
|
||||
$service->create((object) [
|
||||
Field::NAME => 'Bad',
|
||||
Document::FIELD_FILE . 'Id' => $attachment1->getId(),
|
||||
Document::FIELD_PUBLISH_DATE => Date::createToday()->toString(),
|
||||
]);
|
||||
} catch (Forbidden) {
|
||||
$throw = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($throw, 'Should not allow to link already linked attachments.');
|
||||
|
||||
//
|
||||
|
||||
$service->create((object) [
|
||||
Field::NAME => 'Good 2',
|
||||
Document::FIELD_FILE . 'Id' => $attachment2->getId(),
|
||||
Document::FIELD_PUBLISH_DATE => Date::createToday()->toString(),
|
||||
]);
|
||||
|
||||
//
|
||||
|
||||
$throw = false;
|
||||
|
||||
try {
|
||||
$service->update($document1->getId(), (object) [
|
||||
Document::FIELD_FILE . 'Id' => $attachment2->getId(),
|
||||
]);
|
||||
} catch (Forbidden) {
|
||||
$throw = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($throw, 'Should not allow to link already linked attachments.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testAttachmentsMany(): void
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$attachment1 = $em->getRDBRepositoryByClass(Attachment::class)->getNew();
|
||||
$em->saveEntity($attachment1);
|
||||
|
||||
$attachment2 = $em->getRDBRepositoryByClass(Attachment::class)->getNew();
|
||||
$em->saveEntity($attachment2);
|
||||
|
||||
$attachment3 = $em->getRDBRepositoryByClass(Attachment::class)->getNew();
|
||||
$em->saveEntity($attachment3);
|
||||
|
||||
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(CaseObj::class);
|
||||
|
||||
$case1 = $service->create((object) [
|
||||
Field::NAME => 'Good',
|
||||
CaseObj::FIELD_ATTACHMENTS . 'Ids' => [$attachment1->getId()],
|
||||
])->getEntity();
|
||||
|
||||
//
|
||||
|
||||
$throw = false;
|
||||
|
||||
try {
|
||||
$service->create((object) [
|
||||
Field::NAME => 'Bad',
|
||||
CaseObj::FIELD_ATTACHMENTS . 'Ids' => [$attachment1->getId()],
|
||||
]);
|
||||
} catch (Forbidden) {
|
||||
$throw = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($throw, 'Should not allow to link already linked attachments.');
|
||||
|
||||
//
|
||||
|
||||
$case2 = $service->create((object) [
|
||||
Field::NAME => 'Good 2',
|
||||
CaseObj::FIELD_ATTACHMENTS . 'Ids' => [$attachment3->getId()],
|
||||
])->getEntity();
|
||||
|
||||
//
|
||||
|
||||
$service->update($case1->getId(), (object) [
|
||||
CaseObj::FIELD_ATTACHMENTS . 'Ids' => [$attachment1->getId(), $attachment2->getId()],
|
||||
]);
|
||||
|
||||
//
|
||||
|
||||
$throw = false;
|
||||
|
||||
try {
|
||||
$service->update($case2->getId(), (object) [
|
||||
CaseObj::FIELD_ATTACHMENTS . 'Ids' => [$attachment2->getId()],
|
||||
]);
|
||||
} catch (Forbidden) {
|
||||
$throw = true;
|
||||
}
|
||||
|
||||
$this->assertTrue($throw, 'Should not allow to link already linked attachments.');
|
||||
}
|
||||
}
|
||||
123
tests/integration/Espo/Record/ReadOnlyTest.php
Normal file
123
tests/integration/Espo/Record/ReadOnlyTest.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class ReadOnlyTest extends BaseTestCase
|
||||
{
|
||||
public function testReadOnly(): void
|
||||
{
|
||||
$metadata = $this->getContainer()->getByClass(Metadata::class);
|
||||
$metadata->set('entityDefs', Account::ENTITY_TYPE, [
|
||||
'fields' => [
|
||||
'name' => [
|
||||
'readOnlyAfterCreate' => true,
|
||||
],
|
||||
'type' => [
|
||||
'readOnly' => true,
|
||||
],
|
||||
]
|
||||
]);
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication(reuse: true);
|
||||
|
||||
$service = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Account::class);
|
||||
|
||||
$account = $service->create((object) [
|
||||
'name' => 'Test',
|
||||
'type' => 'Customer',
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals('Test', $account->get('name'));
|
||||
$this->assertNull($account->get('type'));
|
||||
|
||||
$account = $service->update($account->getId(), (object) [
|
||||
'name' => 'Test 1',
|
||||
'billingAddressCity' => 'Hello',
|
||||
], UpdateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals('Test', $account->get('name'));
|
||||
$this->assertEquals('Hello', $account->get('billingAddressCity'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnhandledExceptionInspection
|
||||
*/
|
||||
public function testReadOnlyDynamicLogic(): void
|
||||
{
|
||||
$metadata = $this->getMetadata();
|
||||
|
||||
$metadata->set('logicDefs', Account::ENTITY_TYPE, [
|
||||
'fields' => [
|
||||
'description' => [
|
||||
'readOnlySaved' => [
|
||||
'conditionGroup' => [
|
||||
[
|
||||
'type' => 'equals',
|
||||
'attribute' => 'type',
|
||||
'value' => 'Customer',
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$metadata->save();
|
||||
|
||||
$this->reCreateApplication(reuse: true);
|
||||
|
||||
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Account::class);
|
||||
|
||||
$account = $service->create((object) [
|
||||
'name' => 'Test',
|
||||
'description' => '1',
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$service->update($account->getId(), (object) [
|
||||
'type' => 'Customer',
|
||||
], UpdateParams::create());
|
||||
|
||||
$account = $service->update($account->getId(), (object) [
|
||||
'description' => '2',
|
||||
], UpdateParams::create());
|
||||
|
||||
$this->assertEquals('1', $account->getValueMap()->description);
|
||||
}
|
||||
}
|
||||
79
tests/integration/Espo/Record/RestoreDeletedTest.php
Normal file
79
tests/integration/Espo/Record/RestoreDeletedTest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use Espo\Core\Record\ReadParams;
|
||||
use Espo\Core\Record\DeleteParams;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class RestoreDeletedTest extends BaseTestCase
|
||||
{
|
||||
public function testDeleted(): void
|
||||
{
|
||||
$service = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account');
|
||||
|
||||
$account = $service->create((object) [
|
||||
'name' => 'Test'
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$service->delete($account->getId(), DeleteParams::create());
|
||||
|
||||
$account = $service->read($account->getId(), ReadParams::create());
|
||||
|
||||
$this->assertNotNull($account);
|
||||
|
||||
$this->assertTrue($account->get('deleted'));
|
||||
}
|
||||
|
||||
public function testRestoreDeleted()
|
||||
{
|
||||
$service = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->get('Account');
|
||||
|
||||
$account = $service->create((object) [
|
||||
'name' => 'Test'
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$service->delete($account->getId(), DeleteParams::create());
|
||||
|
||||
$service->restoreDeleted($account->getId());
|
||||
|
||||
$account = $service->read($account->getId(), ReadParams::create())->getEntity();
|
||||
|
||||
$this->assertNotNull($account);
|
||||
|
||||
$this->assertFalse($account->get('deleted'));
|
||||
}
|
||||
}
|
||||
255
tests/integration/Espo/Record/SanitizeTest.php
Normal file
255
tests/integration/Espo/Record/SanitizeTest.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Record\CreateParams;
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use Espo\Modules\Crm\Entities\Meeting;
|
||||
use Espo\Modules\Crm\Entities\Opportunity;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use Espo\Tools\FieldManager\FieldManager;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class SanitizeTest extends BaseTestCase
|
||||
{
|
||||
public function testSanitize(): void
|
||||
{
|
||||
// phone
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$this->getInjectableFactory()
|
||||
->create(FieldManager::class)
|
||||
->create(Account::ENTITY_TYPE, 'array', ['type' => 'array']);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$this->getDataManager()->rebuild();
|
||||
|
||||
$this->reCreateApplication();
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$user = $em->getRDBRepositoryByClass(User::class)->getNew();
|
||||
$user->setUserName('test');
|
||||
$em->saveEntity($user);
|
||||
|
||||
$service = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Account::class);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
/** @var Account $account */
|
||||
$account = $service->create((object) [
|
||||
'name' => ' Test 1 ',
|
||||
'sicCode' => ' ',
|
||||
'phoneNumber' => '+380 9044 433 11',
|
||||
'description' => '',
|
||||
'cArray' => [
|
||||
' test ',
|
||||
'hello',
|
||||
],
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$numbers = $account->getPhoneNumberGroup()->getNumberList();
|
||||
$this->assertCount(1, $numbers);
|
||||
$this->assertEquals('+380904443311', $numbers[0]);
|
||||
|
||||
$this->assertEquals('Test 1', $account->getName());
|
||||
$this->assertEquals(null, $account->get('sicCode'));
|
||||
$this->assertEquals(null, $account->get('description'));
|
||||
$this->assertEquals(['test', 'hello'], $account->get('cArray'));
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
/** @var Account $account */
|
||||
$account = $service->create((object) [
|
||||
'name' => 'Test 2',
|
||||
'phoneNumberData' => [
|
||||
(object) [
|
||||
'phoneNumber' => '+38 09 044 433 22',
|
||||
],
|
||||
(object) [
|
||||
'phoneNumber' => '+38 09 044 433 33',
|
||||
],
|
||||
],
|
||||
'description' => 'Test',
|
||||
'cArray' => null,
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals('Test', $account->get('description'));
|
||||
$this->assertEquals([], $account->get('cArray'));
|
||||
|
||||
$numbers = $account->getPhoneNumberGroup()->getNumberList();
|
||||
$this->assertCount(2, $numbers);
|
||||
|
||||
sort($numbers);
|
||||
|
||||
$this->assertEquals('+380904443322', $numbers[0]);
|
||||
$this->assertEquals('+380904443333', $numbers[1]);
|
||||
|
||||
$configWriter = $this->getInjectableFactory()->create(ConfigWriter::class);
|
||||
$configWriter->set('phoneNumberExtensions', true);
|
||||
$configWriter->save();
|
||||
|
||||
/** @var Account $account */
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$account = $service->create((object) [
|
||||
'name' => 'Test 3',
|
||||
'phoneNumberData' => [
|
||||
(object) [
|
||||
'phoneNumber' => '+38 09 044 433 22 ext. 0001',
|
||||
],
|
||||
(object) [
|
||||
'phoneNumber' => '+38 09 044 433 33 x. 1001',
|
||||
],
|
||||
(object) [
|
||||
'phoneNumber' => '+380904443344x.1000',
|
||||
],
|
||||
(object) [
|
||||
'phoneNumber' => '+380904443355#1000',
|
||||
],
|
||||
(object) [
|
||||
'phoneNumber' => '+380904443366 # 1000',
|
||||
],
|
||||
],
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$numbers = $account->getPhoneNumberGroup()->getNumberList();
|
||||
$this->assertCount(5, $numbers);
|
||||
|
||||
sort($numbers);
|
||||
|
||||
$this->assertEquals('+380904443322 ext. 0001', $numbers[0]);
|
||||
$this->assertEquals('+380904443333 ext. 1001', $numbers[1]);
|
||||
$this->assertEquals('+380904443344 ext. 1000', $numbers[2]);
|
||||
$this->assertEquals('+380904443355 ext. 1000', $numbers[3]);
|
||||
$this->assertEquals('+380904443366 ext. 1000', $numbers[4]);
|
||||
|
||||
// datetime
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$meeting = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Meeting::class)
|
||||
->create((object) [
|
||||
'name' => 'Test',
|
||||
'dateStart' => '2030-12-10 10:11:12',
|
||||
'dateEnd' => '2030-12-10T10:11:12-01:00',
|
||||
'assignedUserId' => $user->getId(),
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals('2030-12-10 10:11:12', $meeting->get('dateStart'));
|
||||
$this->assertEquals('2030-12-10 11:11:12', $meeting->get('dateEnd'));
|
||||
|
||||
// datetimeOptional
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$task = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Task::class)
|
||||
->create((object) [
|
||||
'name' => 'Test',
|
||||
'dateStartDate' => '2030-12-10T10:11:12-01:00',
|
||||
'dateEnd' => '2030-12-10T10:11:12-01:00',
|
||||
'assignedUserId' => $user->getId(),
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals('2030-12-10', $task->get('dateStartDate'));
|
||||
$this->assertEquals('2030-12-10 11:11:12', $task->get('dateEnd'));
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$task = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Task::class)
|
||||
->create((object) [
|
||||
'name' => 'Test',
|
||||
'dateStartDate' => '2030-12-10',
|
||||
'assignedUserId' => $user->getId(),
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals('2030-12-10', $task->get('dateStartDate'));
|
||||
|
||||
// date
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$meeting = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Opportunity::class)
|
||||
->create((object) [
|
||||
'name' => 'Test',
|
||||
'closeDate' => '2030-12-10T10:11:12-01:00',
|
||||
'assignedUserId' => $user->getId(),
|
||||
'probability' => 10,
|
||||
'amount' => 1.0,
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals('2030-12-10', $meeting->get('closeDate'));
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$meeting = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Opportunity::class)
|
||||
->create((object) [
|
||||
'name' => 'Test',
|
||||
'closeDate' => '2030-12-10',
|
||||
'assignedUserId' => $user->getId(),
|
||||
'probability' => 10,
|
||||
'amount' => 1.0,
|
||||
], CreateParams::create())->getEntity();
|
||||
|
||||
$this->assertEquals('2030-12-10', $meeting->get('closeDate'));
|
||||
}
|
||||
|
||||
public function testForeign(): void
|
||||
{
|
||||
$account = $this->getEntityManager()->createEntity(Account::ENTITY_TYPE, [
|
||||
'type' => Account::TYPE_CUSTOMER,
|
||||
]);
|
||||
|
||||
$serviceContainer = $this->getContainer()->getByClass(ServiceContainer::class);
|
||||
|
||||
$contactService = $serviceContainer->getByClass(Contact::class);
|
||||
|
||||
$data = (object) [
|
||||
'lastName' => 'C-1',
|
||||
'accountId' => $account->getId(),
|
||||
];
|
||||
$contactService->sanitizeInput($data);
|
||||
$this->assertEquals(Account::TYPE_CUSTOMER, $data->accountType ?? null);
|
||||
|
||||
$data = (object) [
|
||||
'lastName' => 'C-2',
|
||||
];
|
||||
$contactService->sanitizeInput($data);
|
||||
$this->assertEquals(null, $data->accountType ?? null);
|
||||
}
|
||||
}
|
||||
61
tests/integration/Espo/Record/UpdateTest.php
Normal file
61
tests/integration/Espo/Record/UpdateTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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\Record;
|
||||
|
||||
use Espo\Core\Record\ServiceContainer;
|
||||
use Espo\Core\Record\UpdateParams;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\Modules\Crm\Entities\Contact;
|
||||
use tests\integration\Core\BaseTestCase;
|
||||
|
||||
class UpdateTest extends BaseTestCase
|
||||
{
|
||||
public function testUpdateForeign(): void
|
||||
{
|
||||
$service = $this->getContainer()
|
||||
->getByClass(ServiceContainer::class)
|
||||
->getByClass(Contact::class);
|
||||
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$account1 = $em->createEntity(Account::ENTITY_TYPE, ['type' => Account::TYPE_CUSTOMER]);
|
||||
$account2 = $em->createEntity(Account::ENTITY_TYPE, ['type' => Account::TYPE_PARTNER]);
|
||||
$contact = $em->createEntity(Contact::ENTITY_TYPE, ['accountId' => $account1->getId()]);
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$contact = $service->update(
|
||||
$contact->getId(),
|
||||
(object) ['accountId' => $account2->getId()],
|
||||
UpdateParams::create()
|
||||
);
|
||||
|
||||
$this->assertEquals(Account::TYPE_PARTNER, $contact->get('accountType'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user