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
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:
450
tests/unit/Espo/ORM/Query/Part/ExpressionTest.php
Normal file
450
tests/unit/Espo/ORM/Query/Part/ExpressionTest.php
Normal file
@@ -0,0 +1,450 @@
|
||||
<?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\ORM\Query\Part;
|
||||
|
||||
use Espo\ORM\Query\Part\Expression as Expr;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class ExpressionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function testAlias1(): void
|
||||
{
|
||||
$actual = Expr::alias('test')->getValue();
|
||||
|
||||
$expected = '#test';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testAlias2(): void
|
||||
{
|
||||
$actual = Expr::alias('test.someAlias')->getValue();
|
||||
|
||||
$expected = 'test.#someAlias';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testColumn1(): void
|
||||
{
|
||||
$actual = Expr::column('test')->getValue();
|
||||
|
||||
$expected = 'test';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testColumn2(): void
|
||||
{
|
||||
$actual = Expr::column('alias.test')->getValue();
|
||||
|
||||
$expected = 'alias.test';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testColumn3(): void
|
||||
{
|
||||
$actual = Expr::column('@alias1.test')->getValue();
|
||||
|
||||
$expected = '@alias1.test';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testColumn4(): void
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
||||
Expr::column('@alias@test');
|
||||
}
|
||||
|
||||
public function testColumn5(): void
|
||||
{
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
||||
Expr::column('^test');
|
||||
}
|
||||
|
||||
public function testValue1(): void
|
||||
{
|
||||
$actual = Expr::value('"test"')->getValue();
|
||||
|
||||
$expected = "'" . '"test"' . "'";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testValue2(): void
|
||||
{
|
||||
$actual = Expr::value("'test'")->getValue();
|
||||
|
||||
$expected = "'" . "\\'test\\'" . "'";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testValue3(): void
|
||||
{
|
||||
$actual = Expr::value(10)->getValue();
|
||||
|
||||
$expected = '10';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testValue4(): void
|
||||
{
|
||||
$actual = Expr::value(10.5)->getValue();
|
||||
|
||||
$expected = '10.5';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testValue6(): void
|
||||
{
|
||||
$actual = Expr::value(true)->getValue();
|
||||
|
||||
$expected = 'TRUE';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testValue7(): void
|
||||
{
|
||||
$actual = Expr::value(false)->getValue();
|
||||
|
||||
$expected = 'FALSE';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testValue8(): void
|
||||
{
|
||||
$actual = Expr::value(null)->getValue();
|
||||
|
||||
$expected = 'NULL';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testFuncIf1(): void
|
||||
{
|
||||
$actual = Expr::if(
|
||||
Expr::column('test'),
|
||||
'1',
|
||||
2
|
||||
)->getValue();
|
||||
|
||||
$expected = "IF:(test, '1', 2)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testFuncIf2(): void
|
||||
{
|
||||
$actual = Expr::if(
|
||||
Expr::column('test'),
|
||||
Expr::column('hello.man'),
|
||||
true
|
||||
)->getValue();
|
||||
|
||||
$expected = "IF:(test, hello.man, TRUE)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testFuncLike(): void
|
||||
{
|
||||
$actual = Expr::like(
|
||||
Expr::column('test'),
|
||||
'test%'
|
||||
)->getValue();
|
||||
|
||||
$expected = "LIKE:(test, 'test%')";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testFuncEqual(): void
|
||||
{
|
||||
$actual = Expr::equal(
|
||||
Expr::column('test'),
|
||||
1
|
||||
)->getValue();
|
||||
|
||||
$expected = "EQUAL:(test, 1)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testFuncNotEqual(): void
|
||||
{
|
||||
$actual = Expr::notEqual(
|
||||
Expr::column('test'),
|
||||
1
|
||||
)->getValue();
|
||||
|
||||
$expected = "NOT_EQUAL:(test, 1)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testIn(): void
|
||||
{
|
||||
$actual = Expr::in(
|
||||
Expr::column('test'),
|
||||
[
|
||||
Expr::value(1),
|
||||
2
|
||||
]
|
||||
)->getValue();
|
||||
|
||||
$expected = "IN:(test, 1, 2)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testCoalesce(): void
|
||||
{
|
||||
$actual = Expr::coalesce(
|
||||
Expr::column('test1'),
|
||||
Expr::column('test2')
|
||||
)->getValue();
|
||||
|
||||
$expected = "COALESCE:(test1, test2)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testIfNull(): void
|
||||
{
|
||||
$actual = Expr::ifNull(
|
||||
Expr::column('test1'),
|
||||
''
|
||||
)->getValue();
|
||||
|
||||
$expected = "IFNULL:(test1, '')";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testMonth(): void
|
||||
{
|
||||
$actual = Expr::month(
|
||||
Expr::column('test')
|
||||
)->getValue();
|
||||
|
||||
$expected = "MONTH_NUMBER:(test)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWeek0(): void
|
||||
{
|
||||
$actual = Expr::week(
|
||||
Expr::column('test')
|
||||
)->getValue();
|
||||
|
||||
$expected = "WEEK_NUMBER:(test)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWeek1(): void
|
||||
{
|
||||
$actual = Expr::week(
|
||||
Expr::column('test'),
|
||||
1
|
||||
)->getValue();
|
||||
|
||||
$expected = "WEEK_NUMBER_1:(test)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testDayOfWeek(): void
|
||||
{
|
||||
$actual = Expr::dayOfWeek(
|
||||
Expr::column('test')
|
||||
)->getValue();
|
||||
|
||||
$expected = "DAYOFWEEK:(test)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testDayOfMonth(): void
|
||||
{
|
||||
$actual = Expr::dayOfMonth(
|
||||
Expr::column('test')
|
||||
)->getValue();
|
||||
|
||||
$expected = "DAYOFMONTH:(test)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testYear(): void
|
||||
{
|
||||
$actual = Expr::year(
|
||||
Expr::column('test')
|
||||
)->getValue();
|
||||
|
||||
$expected = "YEAR:(test)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testYearFiscsal(): void
|
||||
{
|
||||
$actual = Expr::yearFiscal(
|
||||
Expr::column('test'),
|
||||
10
|
||||
)->getValue();
|
||||
|
||||
$expected = "YEAR_10:(test)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testNow(): void
|
||||
{
|
||||
$actual = Expr::now(
|
||||
)->getValue();
|
||||
|
||||
$expected = "NOW:()";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testConvertTimezone(): void
|
||||
{
|
||||
$actual = Expr::convertTimezone(
|
||||
Expr::column('test'),
|
||||
-10.5
|
||||
)->getValue();
|
||||
|
||||
$expected = "TZ:(test, -10.5)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testConcat(): void
|
||||
{
|
||||
$actual = Expr::concat(
|
||||
Expr::column('test'),
|
||||
' ',
|
||||
'test'
|
||||
)->getValue();
|
||||
|
||||
$expected = "CONCAT:(test, ' ', 'test')";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testReplace(): void
|
||||
{
|
||||
$actual = Expr::replace(
|
||||
Expr::column('test'),
|
||||
'test',
|
||||
'hello'
|
||||
)->getValue();
|
||||
|
||||
$expected = "REPLACE:(test, 'test', 'hello')";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testAdd(): void
|
||||
{
|
||||
$actual = Expr::add(
|
||||
Expr::column('test'),
|
||||
1
|
||||
)->getValue();
|
||||
|
||||
$expected = "ADD:(test, 1)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testRound(): void
|
||||
{
|
||||
$actual = Expr::round(
|
||||
Expr::column('test'),
|
||||
1
|
||||
)->getValue();
|
||||
|
||||
$expected = "ROUND:(test, 1)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testAnd(): void
|
||||
{
|
||||
$actual = Expr::and(
|
||||
Expr::column('test1'),
|
||||
Expr::column('test2')
|
||||
)->getValue();
|
||||
|
||||
$expected = "AND:(test1, test2)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testOr(): void
|
||||
{
|
||||
$actual = Expr::or(
|
||||
Expr::column('test1'),
|
||||
Expr::column('test2')
|
||||
)->getValue();
|
||||
|
||||
$expected = "OR:(test1, test2)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testNot(): void
|
||||
{
|
||||
$actual = Expr::not(
|
||||
Expr::column('test')
|
||||
)->getValue();
|
||||
|
||||
$expected = "NOT:(test)";
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
||||
100
tests/unit/Espo/ORM/Query/Part/JoinTest.php
Normal file
100
tests/unit/Espo/ORM/Query/Part/JoinTest.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?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\ORM\Query\Part;
|
||||
|
||||
use Espo\ORM\Query\Part\Expression;
|
||||
use Espo\ORM\Query\Part\Join;
|
||||
use Espo\ORM\Query\Part\Expression as Expr;
|
||||
use Espo\ORM\Query\SelectBuilder;
|
||||
|
||||
class JoinTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testCreate1(): void
|
||||
{
|
||||
$conditions = Expr::isNull(
|
||||
Expr::column('test')
|
||||
);
|
||||
|
||||
$join = Join::createWithRelationTarget('test')
|
||||
->withAlias('testAlias')
|
||||
->withConditions($conditions);
|
||||
|
||||
$this->assertEquals('test', $join->getTarget());
|
||||
$this->assertEquals('testAlias', $join->getAlias());
|
||||
$this->assertEquals($conditions, $join->getConditions());
|
||||
|
||||
$this->assertTrue($join->isRelation());
|
||||
$this->assertFalse($join->isTable());
|
||||
|
||||
$this->assertEquals(Join::MODE_RELATION, $join->getMode());
|
||||
}
|
||||
|
||||
public function testCreate2(): void
|
||||
{
|
||||
$conditions = Expr::isNull(
|
||||
Expr::column('test')
|
||||
);
|
||||
|
||||
$join = Join::createWithTableTarget('Test')
|
||||
->withAlias('testAlias')
|
||||
->withConditions($conditions);
|
||||
|
||||
$this->assertEquals('Test', $join->getTarget());
|
||||
$this->assertEquals('testAlias', $join->getAlias());
|
||||
$this->assertEquals($conditions, $join->getConditions());
|
||||
|
||||
$this->assertTrue($join->isTable());
|
||||
$this->assertFalse($join->isRelation());
|
||||
|
||||
$this->assertEquals(Join::MODE_TABLE, $join->getMode());
|
||||
}
|
||||
|
||||
public function testCreate3(): void
|
||||
{
|
||||
$join = Join::create('Test', 'testAlias');
|
||||
|
||||
$this->assertEquals('Test', $join->getTarget());
|
||||
$this->assertEquals('testAlias', $join->getAlias());
|
||||
}
|
||||
|
||||
public function testCreate4(): void
|
||||
{
|
||||
$join = Join::createWithSubQuery(
|
||||
SelectBuilder::create()
|
||||
->select(Expression::value(true))
|
||||
->build()
|
||||
,
|
||||
'a'
|
||||
);
|
||||
|
||||
$this->assertTrue($join->isSubQuery());
|
||||
$this->assertEquals(Join::MODE_SUB_QUERY, $join->getMode());
|
||||
}
|
||||
}
|
||||
78
tests/unit/Espo/ORM/Query/Part/OrderExpressionTest.php
Normal file
78
tests/unit/Espo/ORM/Query/Part/OrderExpressionTest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?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\ORM\Query\Part;
|
||||
|
||||
use Espo\ORM\Query\Part\Order as OrderExpr;
|
||||
use Espo\ORM\Query\Part\Expression as Expr;
|
||||
|
||||
class OrderExpressionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testCreate1(): void
|
||||
{
|
||||
$order = OrderExpr::fromString('test')->withDesc();
|
||||
|
||||
$this->assertEquals(Expr::create('test'), $order->getExpression());
|
||||
$this->assertEquals(OrderExpr::DESC, $order->getDirection());
|
||||
$this->assertEquals(true, $order->isDesc());
|
||||
}
|
||||
|
||||
public function testCreate2(): void
|
||||
{
|
||||
$order = OrderExpr::fromString('test');
|
||||
|
||||
$this->assertEquals(OrderExpr::ASC, $order->getDirection());
|
||||
$this->assertEquals(false, $order->isDesc());
|
||||
}
|
||||
|
||||
public function testCreate3(): void
|
||||
{
|
||||
$order = OrderExpr::fromString('test')->withAsc();
|
||||
|
||||
$this->assertEquals(Expr::create('test'), $order->getExpression());
|
||||
$this->assertEquals(OrderExpr::ASC, $order->getDirection());
|
||||
$this->assertEquals(false, $order->isDesc());
|
||||
}
|
||||
|
||||
public function testCreate4(): void
|
||||
{
|
||||
$order = OrderExpr::fromString('test')->withDirection(OrderExpr::DESC);
|
||||
|
||||
$this->assertEquals(OrderExpr::DESC, $order->getDirection());
|
||||
}
|
||||
|
||||
public function testReverseOrder(): void
|
||||
{
|
||||
$order = OrderExpr::fromString('test')
|
||||
->withDirection(OrderExpr::DESC)
|
||||
->withReverseDirection();
|
||||
|
||||
$this->assertEquals(OrderExpr::ASC, $order->getDirection());
|
||||
}
|
||||
}
|
||||
489
tests/unit/Espo/ORM/Query/Part/WhereTest.php
Normal file
489
tests/unit/Espo/ORM/Query/Part/WhereTest.php
Normal file
@@ -0,0 +1,489 @@
|
||||
<?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\ORM\Query\Part;
|
||||
|
||||
use Espo\ORM\{
|
||||
Query\Part\Where\AndGroup,
|
||||
Query\Part\Where\OrGroup,
|
||||
Query\Part\WhereClause,
|
||||
Query\Part\Where\Comparison as Comp,
|
||||
Query\Part\Expression as Expr,
|
||||
Query\Part\Condition as Cond,
|
||||
Query\SelectBuilder,
|
||||
};
|
||||
|
||||
class WhereTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function testAndGroup1(): void
|
||||
{
|
||||
$raw =
|
||||
AndGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test1' => '1',
|
||||
])
|
||||
)
|
||||
->build()
|
||||
->getRaw();
|
||||
|
||||
|
||||
$expextedRaw = [
|
||||
'AND' => [
|
||||
'test1' => '1',
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testAndGroup2(): void
|
||||
{
|
||||
$raw =
|
||||
AndGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test1' => '1',
|
||||
'test1a' => '1a',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test2' => '2',
|
||||
])
|
||||
)
|
||||
->build()
|
||||
->getRaw();
|
||||
|
||||
|
||||
$expextedRaw = [
|
||||
'AND' => [
|
||||
['test1' => '1', 'test1a' => '1a'],
|
||||
['test2' => '2'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testAndGroup3(): void
|
||||
{
|
||||
$raw =
|
||||
AndGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test1' => '1',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
OrGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'o1' => '1',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'o2' => '2',
|
||||
])
|
||||
)
|
||||
->build()
|
||||
)
|
||||
->build()
|
||||
->getRaw();
|
||||
|
||||
|
||||
$expextedRaw = [
|
||||
'AND' => [
|
||||
['test1' => '1'],
|
||||
[
|
||||
'OR' => [
|
||||
['o1' => '1'],
|
||||
['o2' => '2'],
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testOrGroup1(): void
|
||||
{
|
||||
$raw =
|
||||
OrGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test1' => '1',
|
||||
])
|
||||
)
|
||||
->build()
|
||||
->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'OR' => [
|
||||
['test1' => '1'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testOrGroup2(): void
|
||||
{
|
||||
$raw =
|
||||
OrGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test1' => '1',
|
||||
'test2' => '2',
|
||||
])
|
||||
)
|
||||
->build()
|
||||
->getRaw();
|
||||
|
||||
|
||||
$expextedRaw = [
|
||||
'OR' => [
|
||||
[
|
||||
'test1' => '1',
|
||||
'test2' => '2',
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testAndGroupMerge1(): void
|
||||
{
|
||||
$group1 =
|
||||
AndGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test1' => '1',
|
||||
])
|
||||
)
|
||||
->build();
|
||||
|
||||
$group =
|
||||
AndGroup::createBuilder()
|
||||
->merge($group1)
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test2' => '2',
|
||||
])
|
||||
)
|
||||
->build();
|
||||
|
||||
$raw = $group->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'AND' => [
|
||||
['test1' => '1'],
|
||||
['test2' => '2'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testOrGroupMerge1(): void
|
||||
{
|
||||
$orGroup1 =
|
||||
OrGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test1' => '1',
|
||||
])
|
||||
)
|
||||
->build();
|
||||
|
||||
$orGroup =
|
||||
OrGroup::createBuilder()
|
||||
->merge($orGroup1)
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test2' => '2',
|
||||
])
|
||||
)
|
||||
->build();
|
||||
|
||||
$raw = $orGroup->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'OR' => [
|
||||
['test1' => '1'],
|
||||
['test2' => '2'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testOrGroupMerge2(): void
|
||||
{
|
||||
$orGroup1 =
|
||||
OrGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test1' => '1',
|
||||
])
|
||||
)
|
||||
->build();
|
||||
|
||||
$orGroup =
|
||||
OrGroup::createBuilder()
|
||||
->add(
|
||||
WhereClause::fromRaw([
|
||||
'test2' => '2',
|
||||
])
|
||||
)
|
||||
->merge($orGroup1)
|
||||
->build();
|
||||
|
||||
$raw = $orGroup->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'OR' => [
|
||||
['test2' => '2'],
|
||||
['test1' => '1'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testAndGroupCreate1(): void
|
||||
{
|
||||
$raw = AndGroup
|
||||
::create(
|
||||
WhereClause::fromRaw(['test1' => '1']),
|
||||
WhereClause::fromRaw(['test2' => '2'])
|
||||
)
|
||||
->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'AND' => [
|
||||
['test1' => '1'],
|
||||
['test2' => '2'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testOrGroupCreate1(): void
|
||||
{
|
||||
$raw = OrGroup
|
||||
::create(
|
||||
WhereClause::fromRaw(['test1' => '1']),
|
||||
WhereClause::fromRaw(['test2' => '2'])
|
||||
)
|
||||
->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'OR' => [
|
||||
['test1' => '1'],
|
||||
['test2' => '2'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testAndGroupCreateWithCmp(): void
|
||||
{
|
||||
$raw = AndGroup
|
||||
::create(
|
||||
Comp::equal(Expr::column('test1'), '1'),
|
||||
Comp::equal(Expr::column('test2'), '2')
|
||||
)
|
||||
->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'AND' => [
|
||||
['test1=' => '1'],
|
||||
['test2=' => '2'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testAll(): void
|
||||
{
|
||||
$raw =
|
||||
Cond::and(
|
||||
Cond::equal(Cond::column('test1'), '1'),
|
||||
Cond::notEqual(Expr::column('test2'), '2'),
|
||||
Cond::greater(Expr::column('test3'), 3),
|
||||
Expr::greater(Expr::column('test4'), 4),
|
||||
Cond::equal(Expr::column('test5'), Expr::column('hello5')),
|
||||
Comp::equal(Expr::column('test6'), Expr::column('hello6')),
|
||||
Cond::equal(Expr::column('test9'), Expr::column('hello9')),
|
||||
Comp::greaterOrEqual(Expr::column('test10'), Expr::column('hello10'))
|
||||
)
|
||||
->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'AND' => [
|
||||
['test1=' => '1'],
|
||||
['test2!=' => '2'],
|
||||
['test3>' => 3],
|
||||
['GREATER_THAN:(test4, 4):' => null],
|
||||
['test5=:' => 'hello5'],
|
||||
['test6=:' => 'hello6'],
|
||||
['test9=:' => 'hello9'],
|
||||
['test10>=:' => 'hello10'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testAny(): void
|
||||
{
|
||||
$raw =
|
||||
Cond::or(
|
||||
Cond::equal(Expr::column('test1'), '1'),
|
||||
Cond::equal(Expr::column('test2'), '2')
|
||||
)
|
||||
->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'OR' => [
|
||||
['test1=' => '1'],
|
||||
['test2=' => '2'],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testNot1(): void
|
||||
{
|
||||
$raw =
|
||||
Cond::not(
|
||||
Cond::or(
|
||||
Cond::equal(Expr::column('test1'), '1'),
|
||||
Cond::equal(Expr::column('test2'), '2')
|
||||
)
|
||||
)
|
||||
->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'NOT' => [
|
||||
'OR' => [
|
||||
['test1=' => '1'],
|
||||
['test2=' => '2'],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testNot2(): void
|
||||
{
|
||||
$raw =
|
||||
Cond::not(
|
||||
Cond::equal(Expr::column('test1'), '1')
|
||||
)
|
||||
->getRaw();
|
||||
|
||||
$expextedRaw = [
|
||||
'NOT' => [
|
||||
'test1=' => '1',
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expextedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testInQuery(): void
|
||||
{
|
||||
$query = (new SelectBuilder)->from('Test')->build();
|
||||
|
||||
$raw =
|
||||
Cond::in(Expr::column('id'), $query)
|
||||
->getRaw();
|
||||
|
||||
$expectedRaw = [
|
||||
'id=s' => $query
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testNotInQuery(): void
|
||||
{
|
||||
$query = (new SelectBuilder)->from('Test')->build();
|
||||
|
||||
$raw =
|
||||
Cond::notIn(Expr::column('id'), $query)
|
||||
->getRaw();
|
||||
|
||||
$expectedRaw = [
|
||||
'id!=s' => $query
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testInList(): void
|
||||
{
|
||||
$raw =
|
||||
Cond::in(Expr::column('status'), ['1', '2'])
|
||||
->getRaw();
|
||||
|
||||
$expectedRaw = [
|
||||
'status=' => ['1', '2']
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedRaw, $raw);
|
||||
}
|
||||
|
||||
public function testNotInList(): void
|
||||
{
|
||||
$raw =
|
||||
Cond::notIn(Expr::column('status'), ['1', '2'])
|
||||
->getRaw();
|
||||
|
||||
$expectedRaw = [
|
||||
'status!=' => ['1', '2']
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedRaw, $raw);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user