mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 00:32:29 -04:00
chore: Add tests for the PHPMongoQuery class
It appears that it does not match Mongo current documentation exactly so we should look into adapting it. Having equality autodetect regex is a bit weird. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
7fe3f1cc70
commit
75b2ed4c79
1 changed files with 47 additions and 0 deletions
47
apps/webhooks/tests/Service/PHPMongoQueryTest.php
Normal file
47
apps/webhooks/tests/Service/PHPMongoQueryTest.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Webhooks\Tests\Db;
|
||||
|
||||
use OCA\Webhooks\Service\PHPMongoQuery;
|
||||
use OCP\Files\Events\Node\NodeWrittenEvent;
|
||||
use Test\TestCase;
|
||||
|
||||
class PHPMongoQueryTest extends TestCase {
|
||||
private function dataExecuteQuery() {
|
||||
$event = [
|
||||
'event' => [
|
||||
'class' => NodeWrittenEvent::class,
|
||||
'node' => [
|
||||
'id' => 23,
|
||||
'path' => '/tmp/file.txt',
|
||||
],
|
||||
],
|
||||
'user' => [
|
||||
'uid' => 'bob',
|
||||
],
|
||||
];
|
||||
return [
|
||||
[[], [], true],
|
||||
[[], $event, true],
|
||||
[['event.class' => NodeWrittenEvent::class], $event, true],
|
||||
[['event.class' => NodeWrittenEvent::class, 'user.uid' => 'bob'], $event, true],
|
||||
[['event.node.path' => '/.txt$/'], $event, true],
|
||||
[['event.node.id' => ['$gte' => 22]], $event, true],
|
||||
[['event.class' => 'SomethingElse'], $event, false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataExecuteQuery
|
||||
*/
|
||||
public function testExecuteQuery(array $query, array $document, bool $matches) {
|
||||
$this->assertEquals($matches, PHPMongoQuery::executeQuery($query, $document));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue