FlattenNestedBoolTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\Files\Search\QueryOptimizer;
  7. use OC\Files\Search\QueryOptimizer\FlattenNestedBool;
  8. use OC\Files\Search\QueryOptimizer\FlattenSingleArgumentBinaryOperation;
  9. use OC\Files\Search\SearchBinaryOperator;
  10. use OC\Files\Search\SearchComparison;
  11. use OCP\Files\Search\ISearchBinaryOperator;
  12. use OCP\Files\Search\ISearchComparison;
  13. use Test\TestCase;
  14. class FlattenNestedBoolTest extends TestCase {
  15. private $optimizer;
  16. private $simplifier;
  17. protected function setUp(): void {
  18. parent::setUp();
  19. $this->optimizer = new FlattenNestedBool();
  20. $this->simplifier = new FlattenSingleArgumentBinaryOperation();
  21. }
  22. public function testOrs(): void {
  23. $operator = new SearchBinaryOperator(
  24. ISearchBinaryOperator::OPERATOR_OR,
  25. [
  26. new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', 'foo'),
  27. new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, [
  28. new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', 'bar'),
  29. new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', 'asd'),
  30. ])
  31. ]
  32. );
  33. $this->assertEquals('(path eq "foo" or (path eq "bar" or path eq "asd"))', $operator->__toString());
  34. $this->optimizer->processOperator($operator);
  35. $this->simplifier->processOperator($operator);
  36. $this->assertEquals('(path eq "foo" or path eq "bar" or path eq "asd")', $operator->__toString());
  37. }
  38. }