aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Search/SearchIntegrationTest.php
blob: 141eaca238cb85c0b5385c2e5c5492f1ffb52435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace Test\Files\Search;

use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OC\Files\Storage\Temporary;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use Test\TestCase;

/**
 * @group DB
 */
class SearchIntegrationTest extends TestCase {
	private $cache;
	private $storage;

	protected function setUp(): void {
		parent::setUp();

		$this->storage = new Temporary([]);
		$this->cache = $this->storage->getCache();
		$this->storage->getScanner()->scan('');
	}


	public function testThousandAndOneFilters() {
		$id = $this->cache->put('file10', ['size' => 1, 'mtime' => 50, 'mimetype' => 'foo/folder']);

		$comparisons = [];
		for($i = 1; $i <= 1001; $i++) {
			$comparisons[] = new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', "file$i");
		}
		$operator = new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, $comparisons);
		$query = new SearchQuery($operator, 10, 0, []);

		$results = $this->cache->searchQuery($query);

		$this->assertCount(1, $results);
		$this->assertEquals($id, $results[0]->getId());
	}
}