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,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);
}
}