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,176 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Field\Currency;
use Espo\Core\Currency\ConfigDataProvider as CurrencyConfigDataProvider;
use Espo\Core\Currency\InternalRatesProvider;
use Espo\Core\Utils\Config;
use PHPUnit\Framework\TestCase;
use RuntimeException;
class CurrencyConfigDataProviderTest extends TestCase
{
private $config;
private $provider;
private $ratesProvider;
protected function setUp() : void
{
$this->config = $this->createMock(Config::class);
$this->ratesProvider = $this->createMock(InternalRatesProvider::class);
$this->provider = new CurrencyConfigDataProvider(
$this->config,
$this->ratesProvider,
);
}
public function testDefaultCurrency()
{
$this->config
->expects($this->once())
->method('get')
->with('defaultCurrency')
->willReturn('USD');
$currency = $this->provider->getDefaultCurrency();
$this->assertEquals('USD', $currency);
}
public function testBaseCurrency()
{
$this->config
->expects($this->once())
->method('get')
->with('baseCurrency')
->willReturn('USD');
$currency = $this->provider->getBaseCurrency();
$this->assertEquals('USD', $currency);
}
public function testCurrencyList()
{
$this->config
->expects($this->once())
->method('get')
->with('currencyList')
->willReturn(['USD', 'EUR']);
$result = $this->provider->getCurrencyList();
$this->assertEquals(['USD', 'EUR'], $result);
}
public function testHasCurrency()
{
$this->config
->expects($this->once())
->method('get')
->with('currencyList')
->willReturn(['USD', 'EUR']);
$result = $this->provider->hasCurrency('EUR');
$this->assertTrue($result);
}
public function testCurrencyRate1()
{
$this->ratesProvider
->expects($this->any())
->method('get')
->willReturn([
'EUR' => 1.2,
]);
$invokedCount = $this->exactly(2);
$this->config
->expects($invokedCount)
->method('get')
->willReturnCallback(function ($param) use ($invokedCount) {
if ($invokedCount->numberOfInvocations() === 1) {
$this->assertEquals('baseCurrency', $param);
return 'USD';
}
if ($invokedCount->numberOfInvocations() === 2) {
$this->assertEquals('currencyList', $param);
return ['USD', 'EUR'];
}
throw new RuntimeException();
});
$result = $this->provider->getCurrencyRate('EUR');
$this->assertEquals(1.2, $result);
}
public function testCurrencyRate2()
{
$this->ratesProvider
->expects($this->any())
->method('get')
->willReturn([
'EUR' => 1.2,
]);
$invokedCount = $this->exactly(2);
$this->config
->expects($invokedCount)
->method('get')
->willReturnCallback(function ($param) use ($invokedCount) {
if ($invokedCount->numberOfInvocations() === 1) {
$this->assertEquals('baseCurrency', $param);
return 'USD';
}
if ($invokedCount->numberOfInvocations() === 2) {
$this->assertEquals('currencyList', $param);
return ['USD', 'EUR'];
}
throw new RuntimeException();
});
$result = $this->provider->getCurrencyRate('USD');
$this->assertEquals(1.0, $result);
}
}

View File

@@ -0,0 +1,154 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Field\Currency;
use Espo\Core\{
Field\Currency,
Currency\Converter as CurrencyConverter,
Currency\ConfigDataProvider as CurrencyConfigDataProvider,
Currency\Rates as CurrencyRates,
};
class CurrencyConverterTest extends \PHPUnit\Framework\TestCase
{
public function testConvert1()
{
$currencyConfigDataProvider = $this->createMock(CurrencyConfigDataProvider::class);
$currencyConfigDataProvider
->expects($this->any())
->method('hasCurrency')
->with('EUR')
->willReturn(true);
$currencyConfigDataProvider
->expects($this->any())
->method('getCurrencyRate')
->willReturnMap([
['USD', 1.0],
['EUR', 1.2],
]);
$value = new Currency(2.0, 'USD');
$converter = new CurrencyConverter($currencyConfigDataProvider);
$convertedValue = $converter->convert($value, 'EUR');
$this->assertEquals('EUR', $convertedValue->getCode());
$this->assertEquals(round(2.0 / 1.2, 10), round($convertedValue->getAmount(), 10));
}
public function testConvert2()
{
$currencyConfigDataProvider = $this->createMock(CurrencyConfigDataProvider::class);
$currencyConfigDataProvider
->expects($this->any())
->method('hasCurrency')
->with('EUR')
->willReturn(true);
$currencyConfigDataProvider
->expects($this->any())
->method('getCurrencyRate')
->willReturnMap([
['USD', 1.0],
['EUR', 1.2],
['UAH', 0.035],
]);
$value = new Currency(2.0, 'UAH');
$converter = new CurrencyConverter($currencyConfigDataProvider);
$convertedValue = $converter->convert($value, 'EUR');
$this->assertEquals('EUR', $convertedValue->getCode());
$this->assertEquals(round(2.0 * 0.035 / 1.2, 10), round($convertedValue->getAmount(), 10));
}
public function testConvertToDefault()
{
$currencyConfigDataProvider = $this->createMock(CurrencyConfigDataProvider::class);
$currencyConfigDataProvider
->expects($this->any())
->method('getDefaultCurrency')
->willReturn('USD');
$currencyConfigDataProvider
->expects($this->any())
->method('hasCurrency')
->with('USD')
->willReturn(true);
$currencyConfigDataProvider
->expects($this->any())
->method('getCurrencyRate')
->willReturnMap([
['USD', 1.0],
['EUR', 1.2],
]);
$value = new Currency(2.0, 'EUR');
$converter = new CurrencyConverter($currencyConfigDataProvider);
$convertedValue = $converter->convertToDefault($value);
$this->assertEquals('USD', $convertedValue->getCode());
$this->assertEquals(round(2.0 * 1.2, 10), round($convertedValue->getAmount(), 10));
}
public function testConvertWithRates()
{
$currencyConfigDataProvider = $this->createMock(CurrencyConfigDataProvider::class);
$rates = CurrencyRates::fromAssoc([
'USD' => 1.0,
'EUR' => 1.2,
'UAH' => 0.035,
]);
$value = new Currency(2.0, 'UAH');
$converter = new CurrencyConverter($currencyConfigDataProvider);
$convertedValue = $converter->convertWithRates($value, 'EUR', $rates);
$this->assertEquals('EUR', $convertedValue->getCode());
$this->assertEquals(round(2.0 * 0.035 / 1.2, 10), round($convertedValue->getAmount(), 10));
}
}

View File

@@ -0,0 +1,285 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace tests\unit\Espo\Core\Field\Currency;
use Espo\Core\Field\Currency;
use Espo\Core\Field\Currency\CurrencyFactory;
use Espo\ORM\Entity;
use PHPUnit\Framework\TestCase;
use InvalidArgumentException;
class CurrencyTest extends TestCase
{
public function testValue1()
{
$value = Currency::create(2.0, 'USD');
$this->assertEquals(2.0, $value->getAmount());
$this->assertEquals('USD', $value->getCode());
}
public function testValue()
{
$value = Currency::create(0.5, 'USD');
$this->assertEquals('0.5', $value->getAmountAsString());
$this->assertEquals('USD', $value->getCode());
}
public function testAdd()
{
$value = (new Currency(2.0, 'USD'))->add(
new Currency(1.0, 'USD')
);
$this->assertEquals(3.0, $value->getAmount());
$this->assertEquals('USD', $value->getCode());
}
public function testSubtract()
{
$value = (new Currency(2.0, 'USD'))->subtract(
new Currency(3.0, 'USD')
);
$this->assertEquals(-1.0, $value->getAmount());
$this->assertEquals('USD', $value->getCode());
}
public function testMultiply1()
{
$value = (new Currency(2.0, 'USD'))->multiply(3.0);
$this->assertEquals(6.0, $value->getAmount());
$this->assertEquals('USD', $value->getCode());
}
public function testMultiply2()
{
$value = (new Currency(2.0, 'USD'))->multiply(0.5);
$this->assertEquals('1.00000000000000', $value->getAmountAsString());
$this->assertEquals('USD', $value->getCode());
}
public function testDivide1()
{
$value = (new Currency(6.0, 'USD'))->divide(3.0);
$this->assertEquals(2.0, $value->getAmount());
$this->assertEquals('USD', $value->getCode());
}
public function testDivide2()
{
$value = (new Currency(6.0, 'USD'))->divide(0.5);
$this->assertEquals('12.00000000000000', $value->getAmount());
$this->assertEquals('USD', $value->getCode());
}
public function testRound1()
{
$value = (new Currency(2.306, 'USD'))->round(2);
$this->assertEquals(2.31, $value->getAmount());
$this->assertEquals('USD', $value->getCode());
}
public function testRound2()
{
$value = (new Currency(2.306, 'USD'))->round(4);
$this->assertEquals(2.306, $value->getAmount());
}
public function testRound3()
{
$value = (new Currency(2.306, 'USD'))->round(0);
$this->assertEquals(2, $value->getAmount());
}
public function testRound4()
{
$value = (new Currency(-2.306, 'USD'))->round(2);
$this->assertEquals(-2.31, $value->getAmount());
}
public function testRound5()
{
$value = (new Currency(-2.5, 'USD'))->round(0);
$this->assertEquals(-3, $value->getAmount());
}
public function testBadAdd()
{
$this->expectException(InvalidArgumentException::class);
(new Currency(2.0, 'USD'))->add(
new Currency(1.0, 'EUR')
);
}
public function testGetBadCode()
{
$this->expectException(InvalidArgumentException::class);
new Currency(2.0, '');
}
public function testCreateFromEntity()
{
$entity = $this->createMock(Entity::class);
$entity
->expects($this->any())
->method('get')
->willReturnMap([
['test', 10.0],
['testCurrency', 'USD'],
]);
$entity
->expects($this->any())
->method('has')
->willReturnMap([
['test', true],
['testCurrency', true],
]);
$factory = new CurrencyFactory();
$value = $factory->createFromEntity($entity, 'test');
$this->assertEquals(10.0, $value->getAmount());
$this->assertEquals('USD', $value->getCode());
}
public function testCreatableFromEntityTrue()
{
$entity = $this->createMock(Entity::class);
$entity
->expects($this->any())
->method('get')
->willReturnMap([
['test', 5],
['testCurrency', 'USD'],
]);
$factory = new CurrencyFactory();
$this->assertTrue(
$factory->isCreatableFromEntity($entity, 'test')
);
}
public function testCreatableFromEntityFalse()
{
$entity = $this->createMock(Entity::class);
$entity
->expects($this->any())
->method('get')
->willReturnMap([
['test', 5.0],
['testCurrency', null],
]);
$factory = new CurrencyFactory();
$this->assertFalse(
$factory->isCreatableFromEntity($entity, 'test')
);
}
public function testCompare1(): void
{
$this->assertEquals(
1,
Currency::create(2.0, 'USD')
->compare(
Currency::create(1.0, 'USD')
)
);
}
public function testCompare2(): void
{
$this->assertEquals(
0,
Currency::create(2.1, 'USD')
->compare(
Currency::create(2.1, 'USD')
)
);
}
public function testCompare3(): void
{
$this->assertEquals(
-1,
Currency::create(2.1, 'USD')
->compare(
Currency::create(3.1, 'USD')
)
);
}
public function testCompare4(): void
{
$this->expectException(InvalidArgumentException::class);
Currency::create(2.1, 'EUR')
->compare(
Currency::create(2.1, 'USD')
);
}
public function testIsNegative1(): void
{
$this->assertTrue(Currency::create(-1.0, 'USD')->isNegative());
}
public function testIsNegative2(): void
{
$this->assertFalse(Currency::create(1.0, 'USD')->isNegative());
}
public function testIsNegative3(): void
{
$this->assertFalse(Currency::create(0.0, 'USD')->isNegative());
}
}