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

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\PhoneNumber;
use Espo\Core\Field\PhoneNumber;
use Espo\Core\Field\PhoneNumber\PhoneNumberGroupAttributeExtractor;
use Espo\Core\Field\PhoneNumberGroup;
use PHPUnit\Framework\TestCase;
class PhoneNumberGroupAttributeExtractorTest extends TestCase
{
public function testExtract()
{
$group = PhoneNumberGroup
::create([
PhoneNumber::create('+1')->withType('Test-1'),
PhoneNumber::create('+2')->withType('Test-2')->optedOut(),
]);
$valueMap = (new PhoneNumberGroupAttributeExtractor())->extract($group, 'phoneNumber');
$this->assertEquals(
(object) [
'phoneNumber' => '+1',
'phoneNumberData' => [
(object) [
'phoneNumber' => '+1',
'type' => 'Test-1',
'primary' => true,
'optOut' => false,
'invalid' => false,
],
(object) [
'phoneNumber' => '+2',
'type' => 'Test-2',
'primary' => false,
'optOut' => true,
'invalid' => false,
],
]
],
$valueMap
);
}
public function testEmpty()
{
$group = PhoneNumberGroup
::create([]);
$valueMap = (new PhoneNumberGroupAttributeExtractor())->extract($group, 'phoneNumber');
$this->assertEquals(
(object) [
'phoneNumber' => null,
'phoneNumberData' => [],
],
$valueMap
);
}
}

View File

@@ -0,0 +1,317 @@
<?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\PhoneNumber;
use Espo\Core\Field\PhoneNumber\PhoneNumberGroupFactory;
use Espo\Core\Utils\Metadata;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\Repositories\PhoneNumber as PhoneNumberRepository;
use PHPUnit\Framework\TestCase;
use InvalidArgumentException;
use RuntimeException;
class PhoneNumberGroupFactoryTest extends TestCase
{
/**
* @var Metadata
*/
private $metadata;
/**
* @var EntityManager
*/
private $entityManager;
/**
* @var PhoneNumberRepository
*/
private $phoneNumberRepository;
/**
* @var PhoneNumberGroupFactory
*/
private $factory;
public function setUp() : void
{
$this->metadata = $this->createMock(Metadata::class);
$this->entityManager = $this->createMock(EntityManager::class);
$this->phoneNumberRepository = $this->createMock(PhoneNumberRepository::class);
$this->factory = new PhoneNumberGroupFactory($this->metadata, $this->entityManager);
$this->entityManager
->expects($this->any())
->method('getRepository')
->with('PhoneNumber')
->willReturn($this->phoneNumberRepository);
}
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 initPhoneNumberRepository(Entity $entity, array $dataList) : void
{
$this->phoneNumberRepository
->expects($this->once())
->method('getPhoneNumberData')
->with($entity)
->willReturn($dataList);
}
public function testIsCreatableFromEntityTrue() : void
{
$this->initField('Test', 'test', 'phone');
$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 testCreateFromPhoneNumberRepository() : void
{
$this->initField('Test', 'test', 'phone');
$entity = $this->createEntityMock('Test');
$dataList = [
(object) [
'phoneNumber' => '+1',
'type' => 'Test-1',
'primary' => true,
'optOut' => false,
'invalid' => false,
],
(object) [
'phoneNumber' => '+2',
'type' => 'Test-2',
'primary' => false,
'optOut' => false,
'invalid' => true,
],
(object) [
'phoneNumber' => '+3',
'type' => 'Test-3',
'primary' => false,
'optOut' => true,
'invalid' => false,
],
];
$this->initPhoneNumberRepository($entity, $dataList);
$entity
->method('has')
->willReturnMap(
[
['testData', false],
['test', true],
]
);
$entity
->method('get')
->willReturnMap(
[
['testData', null],
['test', '+1'],
]
);
$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('+1', $one->getNumber());
$this->assertTrue($two->isInvalid());
$this->assertTrue($three->isOptedOut());
$this->assertEquals('Test-1', $one->getType());
$this->assertEquals('+1', $group->getPrimary()->getNumber());
}
public function testCreateFromDataAttribute() : void
{
$this->initField('Test', 'test', 'phone');
$entity = $this->createEntityMock('Test');
$dataList = [
(object) [
'phoneNumber' => '+1',
'type' => '1',
'primary' => true,
'optOut' => false,
'invalid' => false,
],
(object) [
'phoneNumber' => '+2',
'type' => '2',
'primary' => false,
'optOut' => false,
'invalid' => true,
],
(object) [
'phoneNumber' => '+3',
'type' => '3',
'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('+1', $one->getNumber());
$this->assertTrue($two->isInvalid());
$this->assertTrue($three->isOptedOut());
$this->assertEquals('+1', $group->getPrimary()->getNumber());
}
public function testCreateEmpty1() : void
{
$this->initField('Test', 'test', 'phone');
$entity = $this->createEntityMock('Test');
$dataList = [];
$this->initPhoneNumberRepository($entity, $dataList);
$group = $this->factory->createFromEntity($entity, 'test');
$this->assertEquals(0, $group->getCount());
}
public function testCreateEmpty2() : void
{
$this->initField('Test', 'test', 'phone');
$entity = $this->createEntityMock('Test');
$dataList = [];
$this->initPhoneNumberRepository($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,237 @@
<?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\PhoneNumber;
use Espo\Core\Field\PhoneNumber;
use Espo\Core\Field\PhoneNumberGroup;
use PHPUnit\Framework\TestCase;
use InvalidArgumentException;
class PhoneNumberGroupTest extends TestCase
{
public function testEmpty()
{
$group = PhoneNumberGroup::create();
$this->assertEquals(0, count($group->getNumberList()));
$this->assertEquals(0, count($group->getSecondaryList()));
$this->assertNull($group->getPrimary());
$this->assertNull($group->getPrimaryNumber());
$this->assertEquals(0, $group->getCount());
}
public function testDuplicate()
{
$this->expectException(InvalidArgumentException::class);
PhoneNumberGroup
::create([
PhoneNumber::create('+100'),
PhoneNumber::create('+100'),
]);
}
public function testWithPrimary1()
{
$primary = PhoneNumber::create('+000')->invalid();
$group = PhoneNumberGroup
::create()
->withPrimary($primary);
$this->assertEquals(1, count($group->getList()));
$this->assertEquals(0, count($group->getSecondaryList()));
$this->assertNotNull($group->getPrimary());
$this->assertEquals('+000', $group->getPrimary()->getNumber());
$this->assertEquals('+000', $group->getPrimaryNumber());
$primaryAnother = PhoneNumber::create('+001');
$groupAnother = $group->withPrimary($primaryAnother);
$this->assertEquals(2, count($groupAnother->getList()));
$this->assertEquals(1, count($groupAnother->getSecondaryList()));
$this->assertEquals('+001', $groupAnother->getPrimary()->getNumber());
$this->assertEquals('+000', $groupAnother->getList()[1]->getNumber());
$this->assertTrue($groupAnother->getList()[1]->isInvalid());
$this->assertTrue($groupAnother->hasNumber('+000'));
$this->assertTrue($groupAnother->hasNumber('+001'));
}
public function testWithPrimary2()
{
$number = PhoneNumber::create('+100')->invalid();
$group = PhoneNumberGroup
::create([$number])
->withAdded(
PhoneNumber::create('+200')
)
->withPrimary(
PhoneNumber::create('+200')
);
$this->assertEquals('+200', $group->getPrimary()->getNumber());
$this->assertEquals(2, count($group->getList()));
}
public function testWithAdded1()
{
$number = PhoneNumber::create('+100')->invalid();
$group = PhoneNumberGroup
::create([$number])
->withAdded(
PhoneNumber::create('+200')
);
$this->assertEquals('+100', $group->getPrimary()->getNumber());
$this->assertEquals(2, count($group->getList()));
$this->assertEquals(2, $group->getCount());
}
public function testWithAddedList()
{
$group = PhoneNumberGroup
::create()
->withAddedList([
PhoneNumber::create('+100'),
PhoneNumber::create('+200'),
]);
$this->assertEquals('+100', $group->getPrimary()->getNumber());
$this->assertEquals(2, count($group->getList()));
}
public function testWithRemoved1()
{
$group = PhoneNumberGroup
::create([
PhoneNumber::create('+100'),
PhoneNumber::create('+200'),
PhoneNumber::create('+300'),
])
->withRemoved(PhoneNumber::create('+200'));
$this->assertEquals('+100', $group->getPrimary()->getNumber());
$this->assertEquals(2, count($group->getList()));
}
public function testWithRemoved2()
{
$group = PhoneNumberGroup
::create([
PhoneNumber::create('+100'),
PhoneNumber::create('+200'),
PhoneNumber::create('+300'),
])
->withRemoved(PhoneNumber::create('+100'));
$this->assertEquals('+200', $group->getPrimary()->getNumber());
$this->assertEquals(2, count($group->getList()));
}
public function testWithRemoved3()
{
$group = PhoneNumberGroup
::create([
PhoneNumber::create('+100'),
])
->withRemoved(PhoneNumber::create('+100'));
$this->assertNull($group->getPrimary());
$this->assertEquals(0, count($group->getList()));
$this->assertEquals(0, $group->getCount());
}
public function testHasNumber()
{
$group = PhoneNumberGroup
::create([
PhoneNumber::create('+100'),
PhoneNumber::create('+200'),
]);
$this->assertTrue($group->hasNumber('+100'));
$this->assertTrue($group->hasNumber('+200'));
$this->assertFalse($group->hasNumber('+400'));
}
public function testGetByNumber()
{
$group = PhoneNumberGroup
::create([
PhoneNumber::create('+100'),
PhoneNumber::create('+200'),
PhoneNumber::create('+300'),
]);
$this->assertEquals('+100', $group->getByNumber('+100')->getNumber());
$this->assertNull($group->getByNumber('+400'));
}
public function testClone()
{
$group = PhoneNumberGroup
::create([
PhoneNumber::create('+100'),
PhoneNumber::create('+200'),
PhoneNumber::create('+300'),
]);
$cloned = clone $group;
$this->assertEquals('+100', $cloned->getByNumber('+100')->getNumber());
$this->assertEquals($cloned->getPrimary()->getNumber(), $group->getPrimary()->getNumber());
$this->assertNotSame($cloned->getPrimary(), $group->getPrimary());
$this->assertNotSame($cloned->getList()[1], $group->getList()[1]);
}
}

View File

@@ -0,0 +1,85 @@
<?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\PhoneNumber;
use Espo\Core\Field\PhoneNumber;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
class PhoneNumberTest extends TestCase
{
public function testInvalidEmpty()
{
$this->expectException(InvalidArgumentException::class);
PhoneNumber::create('');
}
public function testCloneInvalid()
{
$number = PhoneNumber::create('+100')->invalid();
$this->assertEquals('+100', $number->getNumber());
$this->assertTrue($number->isInvalid());
$this->assertFalse($number->isOptedOut());
$this->assertNull($number->getType());
}
public function testCloneOptedOut()
{
$number = PhoneNumber::create('+100')->optedOut();
$this->assertFalse($number->isInvalid());
$this->assertTrue($number->isOptedOut());
}
public function testCloneWithType()
{
$number = PhoneNumber::createWithType('+100', 'Office');
$this->assertEquals('+100', $number->getNumber());
$this->assertEquals('Office', $number->getType());
}
public function testCloneNotOptedOut()
{
$number = PhoneNumber::create('+100')
->optedOut()
->notOptedOut()
->invalid()
->notInvalid();
$this->assertFalse($number->isInvalid());
$this->assertFalse($number->isOptedOut());
}
}