aboutsummaryrefslogtreecommitdiffstats
path: root/apps/webhook_listeners/tests/Service/PHPMongoQueryTest.php
blob: 337b876dfef1516ef8a4a1a8671d9b55ad9ea6c2 (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
<?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],
		];
	}

	#[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteQuery')]
	public function testExecuteQuery(array $query, array $document, bool $matches): void {
		$this->assertEquals($matches, PHPMongoQuery::executeQuery($query, $document));
	}
}