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 1s
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:
upstream-mirror
2026-09-18 04:19:15 +05:00
commit 7cc7e6b4f3
10077 changed files with 900756 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Field\EmailAddress;
use Espo\Core\Field\EmailAddress;
use Espo\Core\Field\EmailAddress\EmailAddressGroupAttributeExtractor;
use Espo\Core\Field\EmailAddressGroup;
use PHPUnit\Framework\TestCase;
class EmailAddressGroupAttributeExtractorTest extends TestCase
{
public function testExtract()
{
$group = EmailAddressGroup
::create([
EmailAddress::create('ONE@test.com'),
EmailAddress::create('two@test.com')->optedOut(),
]);
$valueMap = (new EmailAddressGroupAttributeExtractor())->extract($group, 'emailAddress');
$this->assertEquals(
(object) [
'emailAddress' => 'ONE@test.com',
'emailAddressData' => [
(object) [
'emailAddress' => 'ONE@test.com',
'lower' => 'one@test.com',
'primary' => true,
'optOut' => false,
'invalid' => false,
],
(object) [
'emailAddress' => 'two@test.com',
'lower' => 'two@test.com',
'primary' => false,
'optOut' => true,
'invalid' => false,
],
]
],
$valueMap
);
}
public function testEmpty()
{
$group = EmailAddressGroup
::create([]);
$valueMap = (new EmailAddressGroupAttributeExtractor())->extract($group, 'emailAddress');
$this->assertEquals(
(object) [
'emailAddress' => null,
'emailAddressData' => [],
],
$valueMap
);
}
}

View File

@@ -0,0 +1,309 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Field\EmailAddress;
use Espo\Core\Field\EmailAddress\EmailAddressGroupFactory;
use Espo\Core\Utils\Metadata;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use PHPUnit\Framework\TestCase;
use RuntimeException;
class EmailAddressGroupFactoryTest extends TestCase
{
/**
* @var Metadata
*/
private $metadata;
/**
* @var EmailAddressRepository
*/
private $emailAddressRepository;
/**
* @var EmailAddressGroupFactory
*/
private $factory;
public function setUp() : void
{
$this->metadata = $this->createMock(Metadata::class);
$entityManager = $this->createMock(EntityManager::class);
$this->emailAddressRepository = $this->createMock(EmailAddressRepository::class);
$this->factory = new EmailAddressGroupFactory($this->metadata, $entityManager);
$entityManager
->expects($this->any())
->method('getRepository')
->with('EmailAddress')
->willReturn($this->emailAddressRepository);
}
private function initField(string $entityType, string $field, string $type) : void
{
$this->metadata
->expects($this->any())
->method('get')
->with(['entityDefs', $entityType, 'fields', $field, 'type'])
->willReturn($type);
}
private function createEntityMock(string $entityType) : Entity
{
$entity = $this->createMock(Entity::class);
$entity
->expects($this->any())
->method('getEntityType')
->willReturn($entityType);
return $entity;
}
private function initEmailAddressRepository(Entity $entity, array $dataList) : void
{
$this->emailAddressRepository
->expects($this->once())
->method('getEmailAddressData')
->with($entity)
->willReturn($dataList);
}
public function testIsCreatableFromEntityTrue() : void
{
$this->initField('Test', 'test', 'email');
$entity = $this->createEntityMock('Test');
$this->assertTrue($this->factory->isCreatableFromEntity($entity, 'test'));
}
public function testIsCreatableFromEntityBad() : void
{
$this->initField('Test', 'test', 'varchar');
$entity = $this->createEntityMock('Test');
$this->assertFalse($this->factory->isCreatableFromEntity($entity, 'test'));
}
public function testCreateException() : void
{
$this->initField('Test', 'test', 'varchar');
$entity = $this->createEntityMock('Test');
$this->expectException(RuntimeException::class);
$this->factory->createFromEntity($entity, 'test');
}
public function testCreateFromEmailAddressRepository() : void
{
$this->initField('Test', 'test', 'email');
$entity = $this->createEntityMock('Test');
$dataList = [
(object) [
'emailAddress' => 'ONE@test.com',
'lower' => 'one@test.com',
'primary' => true,
'optOut' => false,
'invalid' => false,
],
(object) [
'emailAddress' => 'TWO@test.com',
'lower' => 'two@test.com',
'primary' => false,
'optOut' => false,
'invalid' => true,
],
(object) [
'emailAddress' => 'THREE@test.com',
'lower' => 'three@test.com',
'primary' => false,
'optOut' => true,
'invalid' => false,
],
];
$this->initEmailAddressRepository($entity, $dataList);
$entity
->method('has')
->willReturnMap(
[
['testData', false],
['test', true],
]
);
$entity
->method('get')
->willReturnMap(
[
['testData', null],
['test', 'ONE@test.com'],
]
);
$group = $this->factory->createFromEntity($entity, 'test');
$this->assertEquals(3, $group->getCount());
$one = $group->getList()[0];
$two = $group->getList()[1];
$three = $group->getList()[2];
$this->assertEquals('ONE@test.com', $one->getAddress());
$this->assertTrue($two->isInvalid());
$this->assertTrue($three->isOptedOut());
$this->assertEquals('ONE@test.com', $group->getPrimary()->getAddress());
}
public function testCreateFromDataAttribute() : void
{
$this->initField('Test', 'test', 'email');
$entity = $this->createEntityMock('Test');
$dataList = [
(object) [
'emailAddress' => 'ONE@test.com',
'lower' => 'one@test.com',
'primary' => true,
'optOut' => false,
'invalid' => false,
],
(object) [
'emailAddress' => 'TWO@test.com',
'lower' => 'two@test.com',
'primary' => false,
'optOut' => false,
'invalid' => true,
],
(object) [
'emailAddress' => 'THREE@test.com',
'lower' => 'three@test.com',
'primary' => false,
'optOut' => true,
'invalid' => false,
],
];
$entity
->expects($this->once())
->method('has')
->with('testData')
->willReturn(true);
$entity
->expects($this->once())
->method('get')
->with('testData')
->willReturn($dataList);
$group = $this->factory->createFromEntity($entity, 'test');
$this->assertEquals(3, $group->getCount());
$one = $group->getList()[0];
$two = $group->getList()[1];
$three = $group->getList()[2];
$this->assertEquals('ONE@test.com', $one->getAddress());
$this->assertTrue($two->isInvalid());
$this->assertTrue($three->isOptedOut());
$this->assertEquals('ONE@test.com', $group->getPrimary()->getAddress());
}
public function testCreateEmpty1() : void
{
$this->initField('Test', 'test', 'email');
$entity = $this->createEntityMock('Test');
$dataList = [];
$this->initEmailAddressRepository($entity, $dataList);
$group = $this->factory->createFromEntity($entity, 'test');
$this->assertEquals(0, $group->getCount());
}
public function testCreateEmpty2() : void
{
$this->initField('Test', 'test', 'email');
$entity = $this->createEntityMock('Test');
$dataList = [];
$this->initEmailAddressRepository($entity, $dataList);
$entity
->method('has')
->willReturnMap(
[
['testData', false],
['test', true],
]
);
$entity
->method('get')
->willReturnMap(
[
['testData', null],
['test', null],
]
);
$group = $this->factory->createFromEntity($entity, 'test');
$this->assertEquals(0, $group->getCount());
}
}

View File

@@ -0,0 +1,249 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Field\EmailAddress;
use Espo\Core\Field\EmailAddress;
use Espo\Core\Field\EmailAddressGroup;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
class EmailAddressGroupTest extends TestCase
{
public function testEmpty()
{
$group = EmailAddressGroup::create();
$this->assertEquals(0, count($group->getAddressList()));
$this->assertEquals(0, count($group->getSecondaryList()));
$this->assertNull($group->getPrimary());
$this->assertNull($group->getPrimaryAddress());
$this->assertEquals(0, $group->getCount());
}
public function testDuplicate1()
{
$this->expectException(InvalidArgumentException::class);
EmailAddressGroup
::create([
EmailAddress::create('one@test.com'),
EmailAddress::create('one@test.com'),
]);
}
public function testDuplicate2()
{
$this->expectException(InvalidArgumentException::class);
EmailAddressGroup
::create([
EmailAddress::create('one@test.com'),
EmailAddress::create('ONE@test.com'),
]);
}
public function testWithPrimary1()
{
$primary = EmailAddress::create('primary@test.com')->invalid();
$group = EmailAddressGroup
::create()
->withPrimary($primary);
$this->assertEquals(1, count($group->getList()));
$this->assertEquals(0, count($group->getSecondaryList()));
$this->assertNotNull($group->getPrimary());
$this->assertEquals('primary@test.com', $group->getPrimary()->getAddress());
$this->assertEquals('primary@test.com', $group->getPrimaryAddress());
$primaryAnother = EmailAddress::create('primaryAnother@test.com');
$groupAnother = $group->withPrimary($primaryAnother);
$this->assertEquals(2, count($groupAnother->getList()));
$this->assertEquals(1, count($groupAnother->getSecondaryList()));
$this->assertEquals('primaryAnother@test.com', $groupAnother->getPrimary()->getAddress());
$this->assertEquals('primary@test.com', $groupAnother->getList()[1]->getAddress());
$this->assertTrue($groupAnother->getList()[1]->isInvalid());
$this->assertTrue($groupAnother->hasAddress('primary@test.com'));
$this->assertTrue($groupAnother->hasAddress('primaryAnother@test.com'));
}
public function testWithPrimary2()
{
$address = EmailAddress::create('one@test.com')->invalid();
$group = EmailAddressGroup
::create([$address])
->withAdded(
EmailAddress::create('two@test.com')
)
->withPrimary(
EmailAddress::create('two@test.com')
);
$this->assertEquals('two@test.com', $group->getPrimary()->getAddress());
$this->assertEquals(2, count($group->getList()));
}
public function testWithAdded1()
{
$address = EmailAddress::create('one@test.com')->invalid();
$group = EmailAddressGroup
::create([$address])
->withAdded(
EmailAddress::create('two@test.com')
);
$this->assertEquals('one@test.com', $group->getPrimary()->getAddress());
$this->assertEquals(2, count($group->getList()));
$this->assertEquals(2, $group->getCount());
}
public function testWithAddedList()
{
$group = EmailAddressGroup
::create()
->withAddedList([
EmailAddress::create('one@test.com'),
EmailAddress::create('two@test.com'),
]);
$this->assertEquals('one@test.com', $group->getPrimary()->getAddress());
$this->assertEquals(2, count($group->getList()));
}
public function testWithRemoved1()
{
$group = EmailAddressGroup
::create([
EmailAddress::create('one@test.com'),
EmailAddress::create('two@test.com'),
EmailAddress::create('three@test.com'),
])
->withRemoved(EmailAddress::create('two@test.com'));
$this->assertEquals('one@test.com', $group->getPrimary()->getAddress());
$this->assertEquals(2, count($group->getList()));
}
public function testWithRemoved2()
{
$group = EmailAddressGroup
::create([
EmailAddress::create('one@test.com'),
EmailAddress::create('two@test.com'),
EmailAddress::create('three@test.com'),
])
->withRemoved(EmailAddress::create('one@test.com'));
$this->assertEquals('two@test.com', $group->getPrimary()->getAddress());
$this->assertEquals(2, count($group->getList()));
}
public function testWithRemoved3()
{
$group = EmailAddressGroup
::create([
EmailAddress::create('one@test.com'),
])
->withRemoved(EmailAddress::create('one@test.com'));
$this->assertNull($group->getPrimary());
$this->assertEquals(0, count($group->getList()));
$this->assertEquals(0, $group->getCount());
}
public function testHasAddress()
{
$group = EmailAddressGroup
::create([
EmailAddress::create('one@test.com'),
EmailAddress::create('two@test.com'),
]);
$this->assertTrue($group->hasAddress('one@test.com'));
$this->assertTrue($group->hasAddress('two@test.com'));
$this->assertFalse($group->hasAddress('four@test.com'));
}
public function testGetByAddress()
{
$group = EmailAddressGroup
::create([
EmailAddress::create('one@test.com'),
EmailAddress::create('two@test.com'),
EmailAddress::create('three@test.com'),
]);
$this->assertEquals('one@test.com', $group->getByAddress('one@test.com')->getAddress());
$this->assertNull($group->getByAddress('four@test.com'));
}
public function testClone()
{
$group = EmailAddressGroup
::create([
EmailAddress::create('one@test.com'),
EmailAddress::create('two@test.com'),
EmailAddress::create('three@test.com'),
]);
$cloned = clone $group;
$this->assertEquals('one@test.com', $cloned->getByAddress('one@test.com')->getAddress());
$this->assertEquals($cloned->getPrimary()->getAddress(), $group->getPrimary()->getAddress());
$this->assertNotSame($cloned->getPrimary(), $group->getPrimary());
$this->assertNotSame($cloned->getList()[1], $group->getList()[1]);
}
}

View File

@@ -0,0 +1,82 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Field\EmailAddress;
use Espo\Core\Field\EmailAddress;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
class EmailAddressTest extends TestCase
{
public function testInvalidAddress()
{
$this->expectException(InvalidArgumentException::class);
EmailAddress::create('one');
}
public function testInvalidEmpty()
{
$this->expectException(InvalidArgumentException::class);
EmailAddress::create('');
}
public function testCloneInvalid()
{
$address = EmailAddress::create('test@test.com')->invalid();
$this->assertEquals('test@test.com', $address->getAddress());
$this->assertTrue($address->isInvalid());
$this->assertFalse($address->isOptedOut());
}
public function testCloneOptedOut()
{
$address = EmailAddress::create('test@test.com')->optedOut();
$this->assertFalse($address->isInvalid());
$this->assertTrue($address->isOptedOut());
}
public function testCloneNotOptedOut()
{
$address = EmailAddress::create('test@test.com')
->optedOut()
->notOptedOut()
->invalid()
->notInvalid();
$this->assertFalse($address->isInvalid());
$this->assertFalse($address->isOptedOut());
}
}