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,50 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils;
class ClassFinderTest extends \tests\integration\Core\BaseTestCase
{
public function testFind1()
{
$classFinder = $this->getContainer()->get('classFinder');
$this->assertEquals(
'Espo\\Modules\\Crm\\Entities\\Account',
$classFinder->find('Entities', 'Account')
);
$this->assertEquals(
'Espo\\Entities\\Email',
$classFinder->find('Entities', 'Email')
);
$this->assertTrue(file_exists('data/cache/application/classmapEntities.php'));
}
}

View File

@@ -0,0 +1,60 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
use PHPUnit\Framework\Attributes\DataProvider;
#[NoTransaction]
class AddressFieldTest extends Base
{
static public function fieldList()
{
return [
['testAddressStreet', 255],
['testAddressCity', 100],
['testAddressState', 100],
['testAddressCountry', 100],
['testAddressPostalCode', 40],
];
}
#[DataProvider('fieldList')]
public function testColumn($fieldName, $length)
{
$column = $this->getColumnInfo('Test', $fieldName);
$this->assertNotEmpty($column);
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals($length, $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
}

View File

@@ -0,0 +1,46 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
#[NoTransaction]
class ArrayFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Test', 'testArray');
$this->assertNotEmpty($column);
$this->assertEquals('mediumtext', $column['COLUMN_TYPE']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
}

View File

@@ -0,0 +1,120 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
#[NoTransaction]
class AutoIncrementFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Case', 'number');
$this->assertNotEmpty($column);
$this->assertEquals('int', $column['DATA_TYPE']);
$this->assertEquals('NO', $column['IS_NULLABLE']);
$this->assertEquals('10', $column['NUMERIC_PRECISION']);
$this->assertEquals('auto_increment', $column['EXTRA']);
$this->assertEquals('UNI', $column['COLUMN_KEY']);
}
public function testColumnOnExistingTable(): void
{
$this->updateDefs('Test', 'testAutoIncrement', [
'type' => 'autoincrement',
]);
$column = $this->getColumnInfo('Test', 'testAutoIncrement');
$this->assertNotEmpty($column);
$this->assertEquals('int', $column['DATA_TYPE']);
$this->assertEquals('NO', $column['IS_NULLABLE']);
$this->assertEquals('10', $column['NUMERIC_PRECISION']);
$this->assertEquals('auto_increment', $column['EXTRA']);
$this->assertEquals('UNI', $column['COLUMN_KEY']);
}
public function testDeleteColumnOnExistingTable(): void
{
// 1. Create "testAutoIncrement" field
$this->testColumnOnExistingTable();
// 2. Delete "testAutoIncrement" field
$this->getMetadata()->delete('entityDefs', 'Test', ['fields.testAutoIncrement']);
$this->getMetadata()->save();
// Issue that it requires rebuilding between removing and adding a new indexes.
$this->getDataManager()->rebuild();
$column = $this->getColumnInfo('Test', 'testAutoIncrement');
$this->assertNotEmpty($column);
$this->assertEquals('int', $column['DATA_TYPE']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('10', $column['NUMERIC_PRECISION']);
$this->assertEmpty($column['EXTRA']);
$this->assertEmpty($column['COLUMN_KEY']);
}
public function testDeleteCreateColumnOnExistingTable(): void
{
// 1. Create "testAutoIncrement" field
$this->testColumnOnExistingTable();
// 2. Delete "testAutoIncrement" field
$metadata = $this->getMetadata();
$metadata->delete('entityDefs', 'Test', ['fields.testAutoIncrement']);
$metadata->save();
$this->getDataManager()->rebuild();
// 3. Create "testAutoIncrement2" field
$this->updateDefs('Test', 'testAutoIncrement2', [
'type' => 'autoincrement',
]);
$column = $this->getColumnInfo('Test', 'testAutoIncrement');
$this->assertNotEmpty($column);
$this->assertEquals('int', $column['DATA_TYPE']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('10', $column['NUMERIC_PRECISION']);
$this->assertEmpty($column['EXTRA']);
$this->assertEmpty($column['COLUMN_KEY']);
$column2 = $this->getColumnInfo('Test', 'testAutoIncrement2');
$this->assertNotEmpty($column2);
$this->assertEquals('int', $column2['DATA_TYPE']);
$this->assertEquals('NO', $column2['IS_NULLABLE']);
$this->assertEquals('10', $column2['NUMERIC_PRECISION']);
$this->assertEquals('auto_increment', $column2['EXTRA']);
$this->assertEquals('UNI', $column2['COLUMN_KEY']);
}
}

View File

@@ -0,0 +1,110 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Database\Helper;
use Espo\Core\Utils\Metadata;
use Espo\Core\Utils\Util;
use tests\integration\Core\BaseTestCase;
abstract class Base extends BaseTestCase
{
protected ?string $dataFile = 'InitData.php';
protected ?string $pathToFiles = 'Core/Database/customFiles';
protected function beforeSetUp(): void
{}
protected function getColumnInfo($entityName, $fieldName)
{
$pdo = $this->getInjectableFactory()
->create(Helper::class)
->getPDO();
$dbName = $this->getContainer()
->getByClass(Config::class)
->get('database.dbname');
$query = "
SELECT * FROM information_schema.columns
WHERE table_name = '" . Util::toUnderScore($entityName) . "'
AND column_name = '" . Util::toUnderScore($fieldName) . "'
AND table_schema = '" . $dbName . "'
";
$sth = $pdo->prepare($query);
$sth->execute();
return $sth->fetch(\PDO::FETCH_ASSOC);
}
protected function updateDefs($entityName, $fieldName, array $fieldDefs = [], ?array $linkDefs = null)
{
$metadata = $this->getContainer()->getByClass(Metadata::class);
$entityDefs = $metadata->get(['entityDefs', $entityName]);
if (empty($entityDefs)) {
return;
}
$save = false;
if (!empty($fieldDefs)) {
$currentFieldDefs = $entityDefs['fields'][$fieldName] ?? [];
$entityDefs['fields'][$fieldName] = array_merge($currentFieldDefs, $fieldDefs);
$save = true;
}
if (!empty($linkDefs)) {
$currentLinkDefs = $entityDefs['links'][$fieldName] ?? [];
$entityDefs['links'][$fieldName] = array_merge($currentLinkDefs, $linkDefs);
$save = true;
}
if ($save) {
$metadata->set('entityDefs', 'Test', $entityDefs);
$metadata->save();
$this->getDataManager()->rebuild([$entityName]);
}
}
protected function executeQuery($query)
{
$pdo = $this->getInjectableFactory()
->create(Helper::class)
->getPDO();
$sth = $pdo->prepare($query);
$sth->execute();
}
}

View File

@@ -0,0 +1,60 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
#[NoTransaction]
class BooleanFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Test', 'testBoolean');
$this->assertNotEmpty($column);
$this->assertEquals('tinyint', $column['DATA_TYPE']);
$this->assertEquals('0', $column['COLUMN_DEFAULT']);
$this->assertEquals('NO', $column['IS_NULLABLE']);
}
public function testDefaultValue()
{
$this->updateDefs('Test', 'testBoolean', [
'default' => true,
]);
$column = $this->getColumnInfo('Test', 'testBoolean');
$this->assertNotEmpty($column);
$this->assertEquals('tinyint', $column['DATA_TYPE']);
$this->assertEquals('1', $column['COLUMN_DEFAULT']);
$this->assertEquals('NO', $column['IS_NULLABLE']);
}
}

View File

@@ -0,0 +1,57 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
use PHPUnit\Framework\Attributes\DataProvider;
#[NoTransaction]
class CurrencyFieldTest extends Base
{
static public function fieldList(): array
{
return [
['testCurrency', 'double', null, null],
['testCurrencyCurrency', 'varchar', 3, 'utf8mb4_unicode_ci'],
];
}
#[DataProvider('fieldList')]
public function testColumns($fieldName, $type, $length, $collation): void
{
$column = $this->getColumnInfo('Test', $fieldName);
$this->assertNotEmpty($column);
$this->assertEquals($type, $column['DATA_TYPE']);
$this->assertEquals($length, $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals($collation, $column['COLLATION_NAME']);
}
}

View File

@@ -0,0 +1,45 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
#[NoTransaction]
class DateFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Test', 'testDate');
$this->assertNotEmpty($column);
$this->assertEquals('date', $column['DATA_TYPE']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
}
}

View File

@@ -0,0 +1,45 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
#[NoTransaction]
class DateTimeFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Test', 'testDateTime');
$this->assertNotEmpty($column);
$this->assertEquals('datetime', $column['DATA_TYPE']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
}
}

View File

@@ -0,0 +1,47 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
#[NoTransaction]
class FileFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Test', 'testFileId');
$this->assertNotEmpty($column);
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals(17, $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
}

View File

@@ -0,0 +1,45 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
#[NoTransaction]
class FloatFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Test', 'testFloat');
$this->assertNotEmpty($column);
$this->assertEquals('double', $column['DATA_TYPE']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
}
}

View File

@@ -0,0 +1,117 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use Espo\Core\Utils\Database\Helper;
use Doctrine\DBAL\Connection;
use PDO;
use tests\integration\Core\BaseTestCase;
class HelperTest extends BaseTestCase
{
/** @var ?Helper */
protected $helper;
protected function initTest()
{
$this->helper = $this->getInjectableFactory()->create(Helper::class);
}
private function getDatabaseInfo()
{
$pdo = $this->getEntityManager()->getPDO();
$sth = $pdo->prepare("select version()");
$sth->execute();
$version = $sth->fetchColumn();
$type = 'mysql';
if (preg_match('/mariadb/i', $version)) {
$type = 'mariadb';
}
if (preg_match('/[0-9]+\.[0-9]+\.[0-9]+/', $version, $match)) {
$version = $match[0];
}
return [
'type' => $type,
'version' => $version,
];
}
public function testGetDbalConnectionWithConfig()
{
$this->initTest();
$this->assertInstanceOf(Connection::class, $this->helper->getDbalConnection());
}
public function testGetPdoConnectionWithConfig()
{
$this->initTest();
$this->assertInstanceOf(PDO::class, $this->helper->getPDO());
}
public function testGetDatabaseInfo()
{
$this->initTest();
$databaseInfo = $this->getDatabaseInfo();
if (empty($databaseInfo)) {
return;
}
$this->assertEquals($databaseInfo['type'], strtolower($this->helper->getType()));
$this->assertEquals($databaseInfo['version'], $this->helper->getVersion());
}
public function testGetDatabaseType()
{
$this->initTest();
$databaseInfo = $this->getDatabaseInfo();
if (empty($databaseInfo)) {
return;
}
switch ($databaseInfo['type']) {
case 'mysql':
$this->assertEquals('MySQL', $this->helper->getType());
break;
case 'mariadb':
$this->assertEquals('MariaDB', $this->helper->getType());
break;
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
#[NoTransaction]
class IntegerFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Test', 'testInteger');
$this->assertNotEmpty($column);
$this->assertEquals('int', $column['DATA_TYPE']);
$this->assertEquals(10, $column['NUMERIC_PRECISION']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use integration\Core\NoTransaction;
#[NoTransaction]
class TextFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Test', 'testText');
$this->assertNotEmpty($column);
$this->assertEquals('mediumtext', $column['COLUMN_TYPE']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
public function testIncreaseColumnLength()
{
$this->updateDefs('Test', 'testText', [
'type' => 'text',
'dbType' => 'longtext',
]);
$column = $this->getColumnInfo('Test', 'testText');
$this->assertNotEmpty($column);
$this->assertEquals('longtext', $column['COLUMN_TYPE']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
public function testReduceColumnLength()
{
$this->updateDefs('Test', 'testText', [
'type' => 'text',
'dbType' => 'longtext',
]);
$this->getContainer()->get('metadata')->delete('entityDefs', 'Test', [
'fields.testText.dbType',
]);
$this->getContainer()->get('metadata')->save();
$this->getDataManager()->rebuildDatabase();
$column = $this->getColumnInfo('Test', 'testText');
$this->assertNotEmpty($column);
$this->assertEquals('longtext', $column['COLUMN_TYPE']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
}

View File

@@ -0,0 +1,229 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\Database;
use Espo\Core\Utils\Database\Helper as DatabaseHelper;
use integration\Core\NoTransaction;
#[NoTransaction]
class VarcharFieldTest extends Base
{
public function testColumn()
{
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertNotEmpty($column);
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals(100, $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
public function testIncreaseColumnLength()
{
$this->updateDefs('Test', 'testVarchar', [
'maxLength' => 150,
]);
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertNotEmpty($column);
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals('150', $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
public function testReduceColumnLength()
{
$this->updateDefs('Test', 'testVarchar', [
'maxLength' => 50,
]);
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertNotEmpty($column);
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals('100', $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
public function testReduceColumnLength2()
{
$this->updateDefs('Test', 'testVarchar', [
'maxLength' => 50,
'default' => 'test-default',
]);
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertNotEmpty($column);
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals('100', $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
public function testReduceColumnLength3()
{
$this->executeQuery(
"ALTER TABLE test MODIFY COLUMN test_varchar VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL;"
);
$this->updateDefs('Test', 'testVarchar', [
'maxLength' => 50,
'default' => 'test-default',
]);
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertNotEmpty($column);
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals('100', $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertEquals('YES', $column['IS_NULLABLE']);
$this->assertContains($column['COLLATION_NAME'], [
'utf8_unicode_ci',
'utf8mb3_unicode_ci'
]);
}
public function testCollationForExistingColumn()
{
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
$this->executeQuery(
"ALTER TABLE test MODIFY COLUMN test_varchar VARCHAR(". $column['CHARACTER_MAXIMUM_LENGTH'] .") CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL;"
);
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertContains($column['COLLATION_NAME'], [
'utf8_unicode_ci',
'utf8mb3_unicode_ci'
]);
$this->updateDefs('Test', 'testVarchar', [
'maxLength' => 150,
]);
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals('150', $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertContains($column['COLLATION_NAME'], [
'utf8_unicode_ci',
'utf8mb3_unicode_ci'
]);
}
public function testCollationForExistingColumn2()
{
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
$this->executeQuery(
"ALTER TABLE test MODIFY COLUMN test_varchar VARCHAR(". $column['CHARACTER_MAXIMUM_LENGTH'] .") CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL;"
);
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertContains($column['COLLATION_NAME'], [
'utf8_unicode_ci',
'utf8mb3_unicode_ci'
]);
$this->updateDefs('Test', 'testVarchar', [
'default' => 'test-default',
]);
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertContains($column['COLLATION_NAME'], [
'utf8_unicode_ci',
'utf8mb3_unicode_ci'
]);
}
public function testCollationForNewColumn()
{
$this->updateDefs('Test', 'newTestVarchar', [
'type' => 'varchar',
]);
$column = $this->getColumnInfo('Test', 'newTestVarchar');
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
}
public function testDefaultValue()
{
$this->updateDefs('Test', 'testVarchar', [
'default' => 'test-default',
]);
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertEquals('varchar', $column['DATA_TYPE']);
$this->assertEquals('100', $column['CHARACTER_MAXIMUM_LENGTH']);
$this->assertEquals('utf8mb4_unicode_ci', $column['COLLATION_NAME']);
$dbHelper = $this->getInjectableFactory()->create(DatabaseHelper::class);
if (
$dbHelper->getType() == 'MariaDB'
&& version_compare($dbHelper->getVersion(), '10.2.7', '>=')
) {
$this->assertEquals("'test-default'", $column['COLUMN_DEFAULT']);
} else {
$this->assertEquals('test-default', $column['COLUMN_DEFAULT']);
}
}
/**
* Make sure columns not removed.
*/
public function testRemoveField(): void
{
$this->getMetadata()->delete('entityDefs', 'Test', ['fields.testVarchar']);
$this->getMetadata()->save();
$this->getDataManager()->rebuildDatabase();
$column = $this->getColumnInfo('Test', 'testVarchar');
$this->assertTrue((bool) $column);
}
}

View File

@@ -0,0 +1,133 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\FieldManager;
use Espo\ORM\EntityManager;
use tests\integration\Core\BaseTestCase;
class ArrayTypeTest extends BaseTestCase
{
private $jsonFieldDefs = '{
"name":"testArray",
"label":"TestArray",
"type":"array",
"required":false,
"noEmptyString":false,
"dynamicLogicVisible":null,
"dynamicLogicRequired":null,
"dynamicLogicReadOnly":null,
"dynamicLogicOptions":null,
"options":["option1","option2","option3"],
"translatedOptions":{"option1":"option1","option2":"option2","option3":"option3"},
"tooltipText":null,
"isPersonalData":false,
"inlineEditDisabled":false,
"audited":false,
"readOnly":false,
"tooltip":false
}';
protected function createFieldManager($app = null)
{
if (!$app) {
$app = $this;
}
return $app->getContainer()->get('injectableFactory')->create(
'Espo\\Tools\\FieldManager\\FieldManager'
);
}
public function testCreate()
{
$fieldManager = $this->createFieldManager();
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
$fieldManager->create('Account', 'testArray', $fieldDefs);
$this->getContainer()->get('dataManager')->rebuild(['Account']);
$app = $this->createApplication();
$metadata = $app->getContainer()->get('metadata');
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestArray');
$this->assertArrayHasKey('type', $savedFieldDefs);
$this->assertArrayHasKey('isCustom', $savedFieldDefs);
$this->assertArrayHasKey('options', $savedFieldDefs);
$this->assertEquals('array', $savedFieldDefs['type']);
$this->assertTrue($savedFieldDefs['isCustom']);
$entityManager = $app->getContainer()->getByClass(EntityManager::class);
$account = $entityManager->getNewEntity('Account');
$account->set([
'name' => 'Test',
'cTestArray' => ['option1', 'option3']
]);
$entityManager->saveEntity($account);
$account = $entityManager->getEntityById('Account', $account->getId());
$this->assertEquals(['option1', 'option3'], $account->get('cTestArray'));
}
public function testUpdate()
{
$this->testCreate();
$app = $this->createApplication();
$fieldManager = $this->createFieldManager($app);
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
$fieldDefs['required'] = true;
$fieldManager->update('Account', 'cTestArray', $fieldDefs);
$this->getContainer()->get('dataManager')->rebuild(['Account']);
$app = $this->createApplication();
$metadata = $app->getContainer()->get('metadata');
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestArray');
$this->assertTrue($savedFieldDefs['required']);
$entityManager = $app->getContainer()->getByClass(EntityManager::class);
$account = $entityManager->getNewEntity('Account');
$account->set([
'name' => 'Test',
]);
$entityManager->saveEntity($account);
}
}

View File

@@ -0,0 +1,141 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\FieldManager;
use Espo\Core\Utils\Metadata;
use Espo\ORM\EntityManager;
use tests\integration\Core\BaseTestCase;
class EnumTypeTest extends BaseTestCase
{
private $jsonFieldDefs = '{
"type":"enum",
"required":true,
"dynamicLogicVisible":null,
"dynamicLogicRequired":null,
"dynamicLogicReadOnly":null,
"dynamicLogicOptions":null,
"name":"testEnum",
"label":"TestEnum",
"audited":true,
"options":["option1","option2","option3"],
"translatedOptions":{"option1":"option1","option2":"option2","option3":"option3"},
"default":"option2",
"tooltipText":"",
"isPersonalData":false,
"isSorted":false,
"readOnly":false,
"tooltip":false
}';
protected function createFieldManager($app = null)
{
if (!$app) {
$app = $this;
}
return $app->getContainer()->get('injectableFactory')->create(
'Espo\\Tools\\FieldManager\\FieldManager'
);
}
public function testCreate()
{
$fieldManager = $this->createFieldManager();
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
$fieldManager->create('Account', 'testEnum', $fieldDefs);
$this->getDataManager()->rebuild(['Account']);
$app = $this->createApplication();
$metadata = $app->getContainer()->getByClass(Metadata::class);
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestEnum');
$this->assertEquals('enum', $savedFieldDefs['type']);
$this->assertEquals('option2', $savedFieldDefs['default']);
$this->assertTrue($savedFieldDefs['required']);
$this->assertTrue($savedFieldDefs['isCustom']);
$this->assertTrue($savedFieldDefs['audited']);
$entityManager = $app->getContainer()->getByClass(EntityManager::class);
$account = $entityManager->getNewEntity('Account');
$account->set([
'name' => 'Test',
'cTestEnum' => 'option1',
]);
$entityManager->saveEntity($account);
$account = $entityManager->getEntityById('Account', $account->getId());
$this->assertEquals('option1', $account->get('cTestEnum'));
}
public function testUpdate()
{
$this->testCreate();
$app = $this->createApplication();
$fieldManager = $this->createFieldManager($app);
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
$fieldDefs['required'] = false;
$fieldDefs['default'] = 'option3';
$fieldDefs['readOnly'] = true;
$fieldManager->update('Account', 'cTestEnum', $fieldDefs);
$this->getDataManager()->rebuild(['Account']);
$app = $this->createApplication();
$metadata = $app->getContainer()->get('metadata');
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestEnum');
$this->assertFalse($savedFieldDefs['required']);
$this->assertEquals('option3', $savedFieldDefs['default']);
$this->assertTrue($savedFieldDefs['audited']);
$this->assertTrue($savedFieldDefs['readOnly']);
$entityManager = $app->getContainer()->getByClass(EntityManager::class);
$account = $entityManager->getNewEntity('Account');
$account->set([
'name' => 'New Test',
]);
$entityManager->saveEntity($account);
$account = $entityManager->getEntityById('Account', $account->getId());
$this->assertEquals('option3', $account->get('cTestEnum'));
}
}

View File

@@ -0,0 +1,133 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\FieldManager;
use tests\integration\Core\BaseTestCase;
class VarcharTypeTest extends BaseTestCase
{
private $jsonFieldDefs = '{
"type":"varchar",
"required":true,
"trim":true,
"dynamicLogicVisible":null,
"dynamicLogicRequired":null,
"dynamicLogicReadOnly":null,
"name":"testVarchar",
"label":"TestVarchar",
"tooltipText":"",
"isPersonalData":false,
"default":"",
"maxLength":null,
"audited":false,
"readOnly":false,
"tooltip":false
}';
protected function createFieldManager($app = null)
{
if (!$app) {
$app = $this;
}
return $app->getContainer()->get('injectableFactory')->create(
'Espo\\Tools\\FieldManager\\FieldManager'
);
}
public function testCreate()
{
$fieldManager = $this->createFieldManager();
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
$fieldManager->create('Account', 'testVarchar', $fieldDefs);
$this->getContainer()->get('dataManager')->rebuild(['Account']);
$app = $this->createApplication();
$metadata = $app->getContainer()->get('metadata');
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestVarchar');
$this->assertArrayHasKey('type', $savedFieldDefs);
$this->assertArrayHasKey('isCustom', $savedFieldDefs);
$this->assertEquals('varchar', $savedFieldDefs['type']);
$this->assertTrue($savedFieldDefs['required']);
$this->assertTrue($savedFieldDefs['isCustom']);
$entityManager = $app->getContainer()->get('entityManager');
$account = $entityManager->getEntity('Account');
$account->set([
'name' => 'Test',
'cTestVarchar' => 'test-value'
]);
$entityManager->saveEntity($account);
$account = $entityManager->getEntity('Account', $account->getId());
$this->assertEquals('test-value', $account->get('cTestVarchar'));
}
public function testUpdate()
{
$this->testCreate();
$app = $this->createApplication();
$fieldManager = $this->createFieldManager($app);
$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));
$fieldDefs['required'] = false;
$fieldDefs['default'] = 'default-value';
$fieldManager->update('Account', 'cTestVarchar', $fieldDefs);
$this->getContainer()->get('dataManager')->rebuild(['Account']);
$app = $this->createApplication();
$metadata = $app->getContainer()->get('metadata');
$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestVarchar');
$this->assertFalse($savedFieldDefs['required']);
$this->assertEquals('default-value', $savedFieldDefs['default']);
$entityManager = $app->getContainer()->get('entityManager');
$account = $entityManager->getEntity('Account');
$account->set([
'name' => 'New Test',
]);
$entityManager->saveEntity($account);
$account = $entityManager->getEntity('Account', $account->getId());
$this->assertEquals('default-value', $account->get('cTestVarchar'));
}
}

View File

@@ -0,0 +1,110 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils;
use Espo\Core\Utils\Json;
use Espo\Core\Utils\Metadata;
use tests\integration\Core\BaseTestCase;
class MetadataTest extends BaseTestCase
{
private $filePath1 = 'custom/Espo/Custom/Resources/metadata/app/rebuild.json';
private $filePath2 = 'custom/Espo/Custom/Resources/metadata/recordDefs/Note.json';
protected function tearDown(): void
{
$this->getFileManager()->removeFile($this->filePath1);
$this->getFileManager()->removeFile($this->filePath2);
parent::tearDown();
}
public function testAppend1(): void
{
$initial = $this->getMetadata()->get(['app', 'rebuild', 'actionClassNameList']);
$contents1 = Json::encode(
(object) [
'actionClassNameList' => [
"\\Espo\\Core\\Rebuild\\Actions\\ScheduledJobs",
]
]
);
$contents2 = Json::encode(
(object) [
'readLoaderClassNameList' => [
"\\Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader",
]
]
);
$this->createDirForFile($this->filePath1);
$this->getFileManager()->putContents($this->filePath1, $contents1);
$this->getFileManager()->putContents($this->filePath2, $contents2);
$this->getDataManager()->clearCache();
$this->getDataManager()->rebuildMetadata();
$this->reCreateApplication(reuse: true);
$metadata = $this->getContainer()->getByClass(Metadata::class);
$this->assertSame(
array_merge(
$initial,
["\\Espo\\Core\\Rebuild\\Actions\\ScheduledJobs"]
),
$metadata->get(['app', 'rebuild', 'actionClassNameList'])
);
$this->assertSame(
[
"Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader",
"\\Espo\\Classes\\FieldProcessing\\Note\\AdditionalFieldsLoader",
],
$metadata->get(['recordDefs', 'Note', 'readLoaderClassNameList'])
);
$this->getFileManager()->removeFile($this->filePath1);
$this->getFileManager()->removeFile($this->filePath2);
$this->getDataManager()->clearCache();
}
private function createDirForFile(string $filePath): void
{
$prevFolder = '';
foreach (array_slice(explode('/', $filePath), 0, -1) as $folder) {
$prevFolder .= $folder . '/';
$this->getFileManager()->mkdir(substr($prevFolder, 0, -1));
}
}
}

View File

@@ -0,0 +1,69 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\integration\Espo\Core\Utils\ScheduledJob;
use Espo\Core\Utils\ScheduledJob\Populator;
use Espo\Entities\ScheduledJob;
use Espo\ORM\Query\DeleteBuilder;
use tests\integration\Core\BaseTestCase;
class PopulatorTest extends BaseTestCase
{
public function testPopulate(): void
{
$deleteQuery = DeleteBuilder::create()
->from(ScheduledJob::ENTITY_TYPE)
->where([
ScheduledJob::FIELD_JOB => 'Cleanup',
])
->build();
$this->getEntityManager()->getQueryExecutor()->execute($deleteQuery);
$this->assertEquals(0, $this->getJobCount());
$populator = $this->getInjectableFactory()->create(Populator::class);
$populator->populate();
$this->assertEquals(1, $this->getJobCount());
}
private function getJobCount(): int
{
return $this->getEntityManager()
->getRDBRepositoryByClass(ScheduledJob::class)
->where([
ScheduledJob::FIELD_JOB => 'Cleanup',
])
->count();
}
}