aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Cache/SearchBuilderTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Cache/SearchBuilderTest.php')
-rw-r--r--tests/lib/Files/Cache/SearchBuilderTest.php44
1 files changed, 19 insertions, 25 deletions
diff --git a/tests/lib/Files/Cache/SearchBuilderTest.php b/tests/lib/Files/Cache/SearchBuilderTest.php
index 5eb1a0252f0..ee097044e3b 100644
--- a/tests/lib/Files/Cache/SearchBuilderTest.php
+++ b/tests/lib/Files/Cache/SearchBuilderTest.php
@@ -1,22 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * 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 <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\Cache;
@@ -30,6 +16,9 @@ use OCP\Files\IMimeTypeLoader;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOperator;
+use OCP\FilesMetadata\IFilesMetadataManager;
+use OCP\IDBConnection;
+use OCP\Server;
use Test\TestCase;
/**
@@ -39,9 +28,12 @@ class SearchBuilderTest extends TestCase {
/** @var IQueryBuilder */
private $builder;
- /** @var IMimeTypeLoader|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IMimeTypeLoader&\PHPUnit\Framework\MockObject\MockObject */
private $mimetypeLoader;
+ /** @var IFilesMetadataManager&\PHPUnit\Framework\MockObject\MockObject */
+ private $filesMetadataManager;
+
/** @var SearchBuilder */
private $searchBuilder;
@@ -50,8 +42,9 @@ class SearchBuilderTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $this->builder = Server::get(IDBConnection::class)->getQueryBuilder();
$this->mimetypeLoader = $this->createMock(IMimeTypeLoader::class);
+ $this->filesMetadataManager = $this->createMock(IFilesMetadataManager::class);
$this->mimetypeLoader->expects($this->any())
->method('getId')
@@ -75,7 +68,7 @@ class SearchBuilderTest extends TestCase {
[6, 'image']
]);
- $this->searchBuilder = new SearchBuilder($this->mimetypeLoader);
+ $this->searchBuilder = new SearchBuilder($this->mimetypeLoader, $this->filesMetadataManager);
$this->numericStorageId = 10000;
$this->builder->select(['fileid'])
@@ -86,7 +79,7 @@ class SearchBuilderTest extends TestCase {
protected function tearDown(): void {
parent::tearDown();
- $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $builder = Server::get(IDBConnection::class)->getQueryBuilder();
$builder->delete('filecache')
->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->numericStorageId, IQueryBuilder::PARAM_INT)));
@@ -119,7 +112,7 @@ class SearchBuilderTest extends TestCase {
$data['mimetype'] = 1;
}
- $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $builder = Server::get(IDBConnection::class)->getQueryBuilder();
$values = [];
foreach ($data as $key => $value) {
@@ -144,7 +137,7 @@ class SearchBuilderTest extends TestCase {
return $rows;
}
- public function comparisonProvider() {
+ public static function comparisonProvider(): array {
return [
[new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'mtime', 125), [1]],
[new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), [0]],
@@ -154,6 +147,7 @@ class SearchBuilderTest extends TestCase {
[new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', 'foo%'), [0, 1]],
[new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'image/jpg'), [0]],
[new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', 'image/%'), [0, 1]],
+ [new SearchComparison(ISearchComparison::COMPARE_IN, 'mimetype', ['image/jpg', 'image/png']), [0, 1]],
[new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'size', 50),
new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125)
@@ -184,12 +178,12 @@ class SearchBuilderTest extends TestCase {
}
/**
- * @dataProvider comparisonProvider
*
* @param ISearchOperator $operator
* @param array $fileIds
*/
- public function testComparison(ISearchOperator $operator, array $fileIds) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('comparisonProvider')]
+ public function testComparison(ISearchOperator $operator, array $fileIds): void {
$fileId = [];
$fileId[] = $this->addCacheEntry([
'path' => 'foobar',