0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-25 01:16:50 +00:00
nextcloud_server/tests/lib/Files/Search/QueryOptimizer/FlattenNestedBoolTest.php
Robin Appelman 2e14a7a4a6
optimize query pattern used by storage filter
Signed-off-by: Robin Appelman <robin@icewind.nl>
2024-02-15 17:55:40 +01:00

42 lines
1.3 KiB
PHP

<?php
namespace Test\Files\Search\QueryOptimizer;
use OC\Files\Search\QueryOptimizer\FlattenNestedBool;
use OC\Files\Search\QueryOptimizer\FlattenSingleArgumentBinaryOperation;
use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use Test\TestCase;
class FlattenNestedBoolTest extends TestCase {
private $optimizer;
private $simplifier;
protected function setUp(): void {
parent::setUp();
$this->optimizer = new FlattenNestedBool();
$this->simplifier = new FlattenSingleArgumentBinaryOperation();
}
public function testOrs() {
$operator = new SearchBinaryOperator(
ISearchBinaryOperator::OPERATOR_OR,
[
new SearchComparison(ISearchComparison::COMPARE_EQUAL, "path", "foo"),
new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, [
new SearchComparison(ISearchComparison::COMPARE_EQUAL, "path", "bar"),
new SearchComparison(ISearchComparison::COMPARE_EQUAL, "path", "asd"),
])
]
);
$this->assertEquals('(path eq "foo" or (path eq "bar" or path eq "asd"))', $operator->__toString());
$this->optimizer->processOperator($operator);
$this->simplifier->processOperator($operator);
$this->assertEquals('(path eq "foo" or path eq "bar" or path eq "asd")', $operator->__toString());
}
}