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:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user