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:
Côme Chilliet 2024-06-03 15:32:26 +02:00 committed by Côme Chilliet
parent 7fe3f1cc70
commit 75b2ed4c79

View 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));
}
}