-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |