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,173 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Upgrades;
use Espo\Core\Container;
use Espo\Core\Upgrades\ActionManager;
use Espo\Core\Upgrades\Base;
use PHPUnit\Framework\TestCase;
use tests\unit\ReflectionHelper;
use Espo\Core\Utils\File\Manager as FileManager;
class ActionManagerTest extends TestCase
{
protected $object;
protected $objects;
private $reflection;
protected $params = [
'name' => 'Extension',
'params' => [
'packagePath' => 'tests/unit/testData/Upgrades/data/upload/extensions',
'backupPath' => 'tests/unit/testData/Upgrades/data/.backup/extensions',
'scriptNames' => [
'before' => 'BeforeInstall',
'after' => 'AfterInstall',
'beforeUninstall' => 'BeforeUninstall',
'afterUninstall' => 'AfterUninstall',
]
],
];
protected function setUp(): void
{
$this->objects['container'] = $container = $this->createMock(Container::class);
$fileManager = $this->createMock(FileManager::class);
$container
->expects($this->any())
->method('getByClass')
->willReturnMap(
[
[FileManager::class, $fileManager],
]
);
$this->object = new ActionManager(
$this->params['name'],
$container,
$this->params['params']
);
$this->reflection = new ReflectionHelper($this->object);
}
protected function tearDown() : void
{
$this->object = NULL;
}
public function testGetObjectExtensionUpload()
{
$this->object->setAction(Base::UPLOAD);
$class = $this->reflection->invokeMethod('getObject');
$this->assertInstanceOf('Espo\Core\Upgrades\Actions\Extension\Upload', $class);
}
public function testGetObjectExtensionInstall()
{
$this->object->setAction(Base::INSTALL);
$class = $this->reflection->invokeMethod('getObject');
$this->assertInstanceOf('Espo\Core\Upgrades\Actions\Extension\Install', $class);
}
public function testGetObjectExtensionUninstall()
{
$this->object->setAction(Base::UNINSTALL);
$class = $this->reflection->invokeMethod('getObject');
$this->assertInstanceOf('Espo\Core\Upgrades\Actions\Extension\Uninstall', $class);
}
public function testGetObjectExtensionDelete()
{
$this->object->setAction(Base::DELETE);
$class = $this->reflection->invokeMethod('getObject');
$this->assertInstanceOf('Espo\Core\Upgrades\Actions\Extension\Delete', $class);
}
public function testGetObjectExtensionNotExists()
{
$this->expectException('Espo\Core\Exceptions\Error');
$this->object->setAction('CustomClass');
$class = $this->reflection->invokeMethod('getObject');
}
public function testGetObjectUpgradeUpload()
{
$this->reflection->setProperty('managerName', 'Upgrade');
$this->object->setAction(Base::UPLOAD);
$class = $this->reflection->invokeMethod('getObject');
$this->assertInstanceOf('Espo\Core\Upgrades\Actions\Upgrade\Upload', $class);
}
public function testGetObjectUpgradeInstall()
{
$this->reflection->setProperty('managerName', 'Upgrade');
$this->object->setAction(Base::INSTALL);
$class = $this->reflection->invokeMethod('getObject');
$this->assertInstanceOf('Espo\Core\Upgrades\Actions\Upgrade\Install', $class);
}
public function testGetObjectUpgradeUninstall()
{
$this->expectException('Espo\Core\Exceptions\Error');
$this->reflection->setProperty('managerName', 'Upgrade');
$this->object->setAction(Base::UNINSTALL);
$class = $this->reflection->invokeMethod('getObject');
$this->assertInstanceOf('Espo\Core\Upgrades\Actions\Upgrade\Uninstall', $class);
$class->run([]);
}
public function testGetObjectUpgradeDelete()
{
$this->expectException('Espo\Core\Exceptions\Error');
$this->reflection->setProperty('managerName', 'Upgrade');
$this->object->setAction(Base::DELETE);
$class = $this->reflection->invokeMethod('getObject');
$this->assertInstanceOf('Espo\Core\Upgrades\Actions\Upgrade\Delete', $class);
$class->run([]);
}
}

View File

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

View File

@@ -0,0 +1,322 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Upgrades\Actions;
use Espo\Core\Utils\Id\RecordIdGenerator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use tests\unit\ReflectionHelper;
use Espo\Core\Utils\Util;
use Espo\Core\Container;
use Espo\Core\Upgrades\ActionManager;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\File\Manager as FileManager;
use Espo\Core\Utils\Log;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\Config\ConfigWriter;
class BaseTest extends TestCase
{
protected $object;
protected $objects;
protected $fileManager;
protected $reflection;
private $fileManagerOriginal;
private $config;
protected $actionManagerParams = [
'name' => 'Extension',
'packagePath' => 'tests/unit/testData/Upgrades/data/upload/extensions',
'backupPath' => 'tests/unit/testData/Upgrades/data/.backup/extensions',
'scriptNames' => [
'before' => 'BeforeInstall',
'after' => 'AfterInstall',
'beforeUninstall' => 'BeforeUninstall',
'afterUninstall' => 'AfterUninstall',
]
];
protected $currentVersion = '11.5.2';
protected function setUp(): void
{
$container = $this->createMock(Container::class);
$actionManager = $this->createMock(ActionManager::class);
$this->config = $this->createMock(Config::class);
$this->fileManager = $this->createMock(FileManager::class);
$injectableFactory = $this->createMock(InjectableFactory::class);
$configWriter = $this->createMock(ConfigWriter::class);
$log = $this->createMock(Log::class);
$systemConfig = $this->createMock(Config\SystemConfig::class);
$map = [
[Config::class, $this->config],
[FileManager::class, $this->fileManager],
[InjectableFactory::class, $injectableFactory],
[Log::class, $log],
[Config\SystemConfig::class, $systemConfig]
];
$idGenerator = $this->createMock(RecordIdGenerator::class);
$idGenerator
->expects($this->any())
->method('generate')
->willReturn(Util::generateId());
$injectableFactory
->expects($this->any())
->method('createResolved')
->willReturnMap([
[RecordIdGenerator::class, null, $idGenerator]
]);
$injectableFactory
->expects($this->any())
->method('create')
->with(ConfigWriter::class)
->willReturn($configWriter);
$container
->expects($this->any())
->method('getByClass')
->willReturnMap($map);
$actionManagerParams = $this->actionManagerParams;
$actionManager
->expects($this->once())
->method('getParams')
->willReturn($actionManagerParams);
$this->object = new Base($container, $actionManager);
$this->reflection = new ReflectionHelper($this->object);
/** @noinspection PhpArgumentWithoutNamedIdentifierInspection */
/** @noinspection SpellCheckingInspection */
$this->reflection->setProperty('processId', 'ngkdf54n566n45');
/* create a package directory with manifest.json file */
$packagePath = $this->reflection->invokeMethod('getPath', ['packagePath']);
$manifestName = $this->reflection->getProperty('manifestName');
$filename = $packagePath . '/' .$manifestName;
$this->fileManagerOriginal = new FileManager();
$this->fileManagerOriginal->putContents($filename, '');
/* END */
}
protected function tearDown() : void
{
$this->object = NULL;
$processId = $this->reflection->getProperty('processId');
if (isset($processId)) {
$packagePath = $this->reflection->invokeMethod('getPath', ['packagePath']);
$this->fileManagerOriginal->removeInDir($packagePath, true);
}
}
public function testCreateProcessIdWithExists()
{
$this->expectException('Espo\Core\Exceptions\Error');
$this->reflection->invokeMethod('createProcessId');
}
public function testCreateProcessId()
{
$this->reflection->setProperty('processId', null);
$processId = $this->reflection->invokeMethod('createProcessId');
$this->assertEquals( $processId, $this->reflection->invokeMethod('getProcessId') );
}
public function testGetProcessId()
{
$this->expectException('Espo\Core\Exceptions\Error');
$this->reflection->setProperty('processId', null);
$this->reflection->invokeMethod('getProcessId');
}
public function testGetManifestIncorrect()
{
$this->expectException('Espo\Core\Exceptions\Error');
$manifest = '{
"name": "Upgrade 1.0-b3 to 1.0-b4"
}';
$this->fileManager
->expects($this->once())
->method('getContents')
->willReturn($manifest);
$this->config
->expects($this->once())
->method('has')
->willReturn(false);
$this->reflection->invokeMethod('getManifest');
}
public function testGetManifest()
{
$manifest = '{
"name": "Extension Test",
"version": "1.2.0",
"acceptableVersions": [
],
"releaseDate": "2014-09-25",
"author": "EspoCRM",
"description": "My Description"
}';
$this->fileManager
->expects($this->once())
->method('getContents')
->willReturn($manifest);
$this->assertEquals( json_decode($manifest,true), $this->reflection->invokeMethod('getManifest') );
}
static public function acceptableVersions()
{
return [
['11.5.2'],
[['11.5.2']],
[['1.4', '11.5.2']],
['11.*',],
['11.5.*',],
['~11.5',],
['~11',],
['^11.1',],
['^11',],
['11.1 - 11.9',],
['>=11.1',],
['<=12',],
['>=11 <=12',],
];
}
#[DataProvider('acceptableVersions')]
public function testCheckVersions($versions, $currentVersion = null)
{
if (!isset($currentVersion)) {
$currentVersion = $this->currentVersion;
}
$this->assertTrue(
$this->reflection->invokeMethod('checkVersions', [$versions, $currentVersion, 'error'])
);
}
static public function unacceptableVersions()
{
return [
['1.*',],
['11\.*',],
['11\.5\.2',],
['11.5*',],
['11.1-11.9',],
['.0.1'],
];
}
#[DataProvider('unacceptableVersions')]
public function testCheckVersionsException($versions, $currentVersion = null)
{
if (!isset($currentVersion)) {
$currentVersion = $this->currentVersion;
}
$this->expectException('Espo\Core\Exceptions\Error');
$this->config
->expects($this->once())
->method('has')
->willReturn(false);
$this->reflection->invokeMethod('checkVersions', [$versions, $currentVersion, 'error']);
}
public function testIsAcceptableEmpty()
{
$version = [];
$this->reflection->setProperty('data', ['manifest' => ['acceptableVersions' => $version]]);
$this->assertTrue($this->reflection->invokeMethod('isAcceptable') );
}
public function testGetPath(): void
{
$packageId = $this->reflection->invokeMethod('getProcessId');
$packagePath = Util::fixPath($this->actionManagerParams['packagePath'] . '/' . $packageId);
$this->assertEquals($packagePath, $this->reflection->invokeMethod('getPath', ['packagePath']));
$this->assertEquals($packagePath, $this->reflection->invokeMethod('getPath', ['packagePath']));
$postfix = 'z';
$this->assertEquals($packagePath.$postfix, $this->reflection->invokeMethod('getPath', ['packagePath', true]));
$backupPath = Util::fixPath($this->actionManagerParams['backupPath'] . '/' . $packageId);
$this->assertEquals( $backupPath, $this->reflection->invokeMethod('getPath', ['backupPath']) );
}
public function testCheckPackageType()
{
$this->reflection->setProperty('data', ['manifest' => []]);
$this->assertTrue( $this->reflection->invokeMethod('checkPackageType') );
$this->reflection->setProperty('data', ['manifest' => ['type' => 'extension']]);
$this->assertTrue( $this->reflection->invokeMethod('checkPackageType') );
}
public function testCheckPackageTypeUpgrade()
{
$this->expectException('Espo\Core\Exceptions\Error');
$this->config
->expects($this->once())
->method('has')
->willReturn(false);
$this->reflection->setProperty('data', ['manifest' => ['type' => 'upgrade']]);
$this->assertTrue( $this->reflection->invokeMethod('checkPackageType') );
}
}

View File

@@ -0,0 +1,191 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Upgrades\Migration;
use Espo\Core\Console\IO;
use Espo\Core\DataManager;
use Espo\Core\Upgrades\Migration\ExtractedStepsProvider;
use Espo\Core\Upgrades\Migration\Runner;
use Espo\Core\Upgrades\Migration\StepRunner;
use Espo\Core\Upgrades\Migration\VersionDataProvider;
use Espo\Core\Utils\Config\ConfigWriter;
use PHPUnit\Framework\TestCase;
class RunnerTest extends TestCase
{
protected ?IO $io = null;
protected ?ExtractedStepsProvider $stepsProvider = null;
protected ?VersionDataProvider $versionDataProvider;
protected ?StepRunner $stepsRunner = null;
protected ?DataManager $dataManager = null;
protected ?ConfigWriter $configWriter = null;
protected function setUp(): void
{
$this->io = $this->createMock(IO::class);
$this->stepsProvider = $this->createMock(ExtractedStepsProvider::class);
$this->versionDataProvider = $this->createMock(VersionDataProvider::class);
$this->stepsRunner = $this->createMock(StepRunner::class);
$this->dataManager = $this->createMock(DataManager::class);
$this->configWriter = $this->createMock(ConfigWriter::class);
}
public function testRunMigration(): void
{
$this->versionDataProvider
->expects($this->once())
->method('getTargetVersion')
->willReturn('8.3.5');
$this->versionDataProvider
->expects($this->once())
->method('getPreviousVersion')
->willReturn('8.0.4');
$this->stepsProvider
->expects($this->once())
->method('getPrepare')
->willReturn([
'8.2',
'8.3',
]);
$this->stepsProvider
->expects($this->once())
->method('getAfterUpgrade')
->willReturn([
'8.1',
'8.3',
]);
$this->stepsRunner
->expects($this->any())
->method('runPrepare')
->willReturnMap([
['8.2', true],
['8.3', true],
]);
$this->stepsRunner
->expects($this->any())
->method('runAfterUpgrade')
->willReturnMap([
['8.1', true],
['8.3', true],
]);
$runner = new Runner(
$this->stepsProvider,
$this->versionDataProvider,
$this->stepsRunner,
$this->dataManager,
$this->configWriter
);
/** @noinspection PhpUnhandledExceptionInspection */
$runner->run($this->io);
}
public function testRunNoMigration(): void
{
$this->versionDataProvider
->expects($this->once())
->method('getTargetVersion')
->willReturn('9.3.4');
$this->versionDataProvider
->expects($this->once())
->method('getPreviousVersion')
->willReturn('9.2.7');
$this->stepsRunner
->expects($this->never())
->method('runPrepare');
$this->stepsRunner
->expects($this->never())
->method('runAfterUpgrade');
$this->configWriter
->expects($this->once())
->method('set')
->with('version', '9.3.4');
$runner = new Runner(
$this->stepsProvider,
$this->versionDataProvider,
$this->stepsRunner,
$this->dataManager,
$this->configWriter
);
/** @noinspection PhpUnhandledExceptionInspection */
$runner->run($this->io);
}
public function testRunSameVersion(): void
{
$this->versionDataProvider
->expects($this->once())
->method('getTargetVersion')
->willReturn('9.3.4');
$this->versionDataProvider
->expects($this->once())
->method('getPreviousVersion')
->willReturn('9.3.4');
$this->stepsRunner
->expects($this->never())
->method('runPrepare');
$this->stepsRunner
->expects($this->never())
->method('runAfterUpgrade');
$this->configWriter
->expects($this->never())
->method('set');
$runner = new Runner(
$this->stepsProvider,
$this->versionDataProvider,
$this->stepsRunner,
$this->dataManager,
$this->configWriter
);
/** @noinspection PhpUnhandledExceptionInspection */
$runner->run($this->io);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Upgrades\Migration;
use Espo\Core\Upgrades\Migration\StepsProvider;
use Espo\Core\Utils\File\Manager;
use PHPUnit\Framework\TestCase;
class StepsProviderTest extends TestCase
{
public function testGet1(): void
{
$fileManager = $this->createMock(Manager::class);
$fileManager
->expects($this->once())
->method('getDirList')
->willReturn(['V7_5_1', 'V8_0', 'V8_1', 'V8_2', 'V8_2_2']);
$fileManager
->expects($this->any())
->method('isFile')
->willReturn(true);
$provider = new StepsProvider($fileManager);
$this->assertEquals([
'7.5.1',
'8.0',
'8.1',
'8.2',
'8.2.2',
], $provider->getAfterUpgrade());
}
}

View File

@@ -0,0 +1,271 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Upgrades\Migration;
use Espo\Core\Upgrades\Migration\VersionUtil;
use PHPUnit\Framework\TestCase;
class VersionUtilTest extends TestCase
{
public function testStepToVersion(): void
{
$this->assertEquals('8.0.0', VersionUtil::stepToVersion('8.0'));
$this->assertEquals('8.0.1', VersionUtil::stepToVersion('8.0.1'));
$this->assertEquals('8.1.0', VersionUtil::stepToVersion('8.1.0'));
}
public function testGet1(): void
{
$list = VersionUtil::extractSteps('8.0.0', '8.3.0', [
'7.0',
'7.5',
'8.0',
'8.0.1',
'8.0.3',
'8.1',
'8.1.4',
'8.3',
'8.3.1',
]);
$this->assertEquals([
'8.0.1',
'8.0.3',
'8.1',
'8.3',
], $list);
}
public function testGet2(): void
{
$list = VersionUtil::extractSteps('8.0.0', '8.3.1', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.1',
]);
$this->assertEquals([
'8.1',
'8.3',
], $list);
}
public function testGet3(): void
{
$list = VersionUtil::extractSteps('8.0.0', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
]);
$this->assertEquals([
'8.1',
'8.3',
], $list);
}
public function testGet4(): void
{
$list = VersionUtil::extractSteps('8.2.0', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
]);
$this->assertEquals([
'8.3',
], $list);
}
public function testGet5(): void
{
$list = VersionUtil::extractSteps('8.0.4', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
]);
$this->assertEquals([
'8.1',
'8.3',
], $list);
}
public function testGetMajor1(): void
{
$list = VersionUtil::extractSteps('7.5.4', '8.3.5', array_reverse([
'7.0',
'7.5',
'7.5.1',
'7.6',
'7.6.1',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
]));
$this->assertEquals([
'7.6',
'8.0',
'8.1',
'8.3',
], $list);
}
public function testGetPatch1(): void
{
$list = VersionUtil::extractSteps('8.3.0', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
'8.3.4',
]);
$this->assertEquals([
'8.3.2',
'8.3.4',
], $list);
}
public function testGetPatch2(): void
{
$list = VersionUtil::extractSteps('8.3.0', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
'8.3.4',
'8.3.5',
'8.6.1',
]);
$this->assertEquals([
'8.3.2',
'8.3.4',
'8.3.5',
], $list);
}
public function testGetPatch3(): void
{
$list = VersionUtil::extractSteps('8.3.0', '8.3.5', [
'8.3',
'8.3.0-beta',
'8.3.0-beta.1',
'8.3.0-beta.2',
'8.3.2',
'8.3.4',
'8.3.5',
'8.6.1',
]);
$this->assertEquals([
'8.3.2',
'8.3.4',
'8.3.5',
], $list);
}
public function testGetPatch4(): void
{
$list = VersionUtil::extractSteps('8.3.0-beta.1', '8.3.0', [
'8.3',
'8.3.0-beta.1',
'8.3.0-beta.2',
'8.3.0',
]);
$this->assertEquals([
'8.3.0-beta.2',
'8.3.0',
], $list);
}
public function testGetSame1(): void
{
$list = VersionUtil::extractSteps('8.3.5', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
'8.3.4',
'8.3.5',
'8.6.1',
]);
$this->assertEquals([], $list);
}
public function testGetSame2(): void
{
$list = VersionUtil::extractSteps('8.6.1', '8.6.1', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
'8.3.4',
'8.3.5',
'8.6.1',
]);
$this->assertEquals([], $list);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace tests\unit\Espo\Core\Upgrades\Migrations\V10_1;
use Espo\Core\Upgrades\Migrations\V10_1\AfterUpgrade;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;
class AfterUpgradeTest extends TestCase
{
public function testThemeParamsDefaultToTopNavbarAndRtl(): void
{
$this->assertEquals(
(object) [
'navbar' => 'top',
'direction' => 'rtl',
],
$this->prepareThemeParams(null),
);
}
public function testThemeParamsPreserveNavbarAndCustomValues(): void
{
$this->assertEquals(
(object) [
'navbar' => 'side',
'custom' => 'value',
'direction' => 'rtl',
],
$this->prepareThemeParams((object) [
'navbar' => 'side',
'custom' => 'value',
'direction' => 'ltr',
]),
);
}
private function prepareThemeParams(mixed $value): object
{
$reflection = new ReflectionClass(AfterUpgrade::class);
$migration = $reflection->newInstanceWithoutConstructor();
$method = new ReflectionMethod(AfterUpgrade::class, 'prepareThemeParams');
/** @var object */
return $method->invoke($migration, $value);
}
}