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,131 @@
<?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\Tools\MassUpdate;
use Espo\Core\MassAction\Data as MassActionData;
use Espo\Tools\MassUpdate\Data;
use Espo\Tools\MassUpdate\Action;
class DataTest extends \PHPUnit\Framework\TestCase
{
public function testData1(): void
{
$massActionData = MassActionData::fromRaw(
(object) [
'values' => (object) [
'a1' => '1',
'a2' => '2',
'a3' => '3',
],
'actions' => (object) [
'a1' => 'update',
'a2' => 'add',
'a3' => 'remove',
],
],
);
$data = Data::fromMassActionData($massActionData);
$this->assertEquals('1', $data->getValue('a1'));
$this->assertEquals(null, $data->getValue('a0'));
$this->assertEquals(true, $data->has('a1'));
$this->assertEquals(false, $data->has('a0'));
$this->assertEquals(['a1', 'a2', 'a3'], $data->getAttributeList());
$this->assertEquals(
(object) [
'a1' => '1',
'a2' => '2',
'a3' => '3',
],
$data->getValues()
);
$this->assertEquals(Action::UPDATE, $data->getAction('a1'));
$this->assertEquals(Action::ADD, $data->getAction('a2'));
$this->assertEquals(Action::REMOVE, $data->getAction('a3'));
$this->assertEquals('1m', $data->with('a1', '1m')->getValue('a1'));
$this->assertEquals(false, $data->without('a1')->has('a1'));
$massActionDataModified = $data
->with('a1', '1m', Action::ADD)
->without('a2')
->toMassActionData();
$values = $massActionDataModified->get('values');
$actions = $massActionDataModified->get('actions');
$this->assertEquals('1m', $values->a1);
$this->assertFalse(property_exists($values, 'a2'));
$this->assertEquals(Action::ADD, $actions->a1);
$this->assertFalse(property_exists($actions, 'a2'));
}
public function testCreate(): void
{
$data = Data::create()
->with('a1', null, Action::UPDATE)
->with('a2', ['1'], Action::ADD);
$this->assertEquals(null, $data->getValue('a1'));
$this->assertEquals(['1'], $data->getValue('a2'));
$this->assertEquals(Action::ADD, $data->getAction('a2'));
}
public function testWith(): void
{
$data = Data::create()
->with('a1', '1', Action::ADD)
->with('a1', '2')
->with('a2', '2');
$this->assertEquals(Action::ADD, $data->getAction('a1'));
$this->assertEquals(Action::UPDATE, $data->getAction('a2'));
}
public function testBc(): void
{
$massActionData = MassActionData::fromRaw(
(object) [
'a1' => '1',
'a2' => '2',
'a3' => '3',
],
);
$data = Data::fromMassActionData($massActionData);
$this->assertEquals('1', $data->getValue('a1'));
$this->assertEquals(Action::UPDATE, $data->getAction('a1'));
}
}

View File

@@ -0,0 +1,109 @@
<?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\Tools\MassUpdate;
use Espo\Tools\MassUpdate\Data;
use Espo\Tools\MassUpdate\ValueMapPreparator;
use Espo\Tools\MassUpdate\Action;
use Espo\ORM\Entity;
use Espo\ORM\Defs as OrmDefs;
use PHPUnit\Framework\TestCase;
class ValueMapPreparatorTest extends TestCase
{
public function testPrepare1(): void
{
$preparator = new ValueMapPreparator(
$this->createMock(OrmDefs::class)
);
$data = Data::create()
->with('a1', ['1', '2'], Action::ADD)
->with('a2', ['1', '2', '3'], Action::REMOVE)
->with('a3', ['1', '2'], Action::UPDATE)
->with('a4', ['1'], Action::REMOVE)
->with('a5', [], Action::ADD)
->with('a6', [], Action::REMOVE)
->with('a7', ['1'], Action::ADD)
->with('a8', ['1'], Action::REMOVE)
->with('a9', null, Action::REMOVE)
->with('a10', null, Action::ADD)
->with('a11', null, Action::UPDATE)
->with('a12', (object) ['k2' => 'v2'], Action::ADD)
->with('a13', (object) ['k2' => 'v2'], Action::REMOVE);
$entity = $this->createMock(Entity::class);
$entity
->expects($this->any())
->method('has')
->willReturn(true);
$entity
->expects($this->any())
->method('get')
->willReturnCallback(
function ($attribute) {
$map = [
'a1' => ['0'],
'a2' => ['0', '1', '2'],
'a3' => ['0'],
'a4' => ['1'],
'a5' => ['1'],
'a6' => ['1'],
'a7' => null,
'a8' => null,
'a12' => (object) ['k1' => 'v1'],
'a13' => (object) ['k1' => 'v1', 'k2' => 'v2'],
];
return $map[$attribute] ?? null;
}
);
$values = $preparator->prepare($entity, $data);
$this->assertEquals(['0', '1', '2'], $values->a1);
$this->assertEquals(['0'], $values->a2);
$this->assertEquals(['1', '2'], $values->a3);
$this->assertEquals([], $values->a4);
$this->assertEquals(['1'], $values->a5);
$this->assertEquals(['1'], $values->a6);
$this->assertEquals(['1'], $values->a7);
$this->assertEquals([], $values->a8);
$this->assertFalse(property_exists($values, 'a9'));
$this->assertFalse(property_exists($values, 'a10'));
$this->assertEquals(null, $values->a11);
$this->assertEquals((object) ['k1' => 'v1', 'k2' => 'v2'], $values->a12);
$this->assertEquals((object) ['k1' => 'v1'], $values->a13);
}
}