0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-05-16 19:25:29 +00:00
nextcloud_server/apps/webhook_listeners/tests/Service/PHPMongoQueryTest.php
Joas Schilling 4ccf62a224
chore: Cleanup and prepare some app tests for PHPUnit 10
Signed-off-by: Joas Schilling <coding@schilljs.com>
2024-09-19 18:19:32 +02:00

47 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\WebhookListeners\Tests\Service;
use OCA\WebhookListeners\Service\PHPMongoQuery;
use OCP\Files\Events\Node\NodeWrittenEvent;
use Test\TestCase;
class PHPMongoQueryTest extends TestCase {
public static function dataExecuteQuery(): array {
$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): void {
$this->assertEquals($matches, PHPMongoQuery::executeQuery($query, $document));
}
}