Skip to content

Commit 5f6c1fb

Browse files
committed
Add test
1 parent 957a496 commit 5f6c1fb

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

src/Database/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4108,7 +4108,7 @@ public function updateDocument(string $collection, string $id, Document $documen
41084108
fn () => $this->getDocument($collection->getId(), $id, forUpdate: true)
41094109
));
41104110

4111-
$skipPermissionsUpdate = true;
4111+
$skipPermissionsUpdate = false;
41124112

41134113
if ($document->offsetExists('$permissions')) {
41144114
$originalPermissions = $old->getPermissions();

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,70 @@ public function testCreateDocumentsWithDifferentAttributes(): void
388388
$database->deleteCollection($collection);
389389
}
390390

391-
public function testUpsertDocuments(): void
391+
public function testSkipPermissions(): void
392+
{
393+
/** @var Database $database */
394+
$database = static::getDatabase();
395+
396+
if (!$database->getAdapter()->getSupportForUpserts()) {
397+
$this->expectNotToPerformAssertions();
398+
return;
399+
}
400+
401+
$database->createCollection(__FUNCTION__);
402+
$database->createAttribute(__FUNCTION__, 'number', Database::VAR_INTEGER, 0, false);
403+
404+
$data = [];
405+
for ($i = 1; $i <= 10; $i++) {
406+
$data[] = [
407+
'$id' => "$i",
408+
'number' => $i,
409+
];
410+
}
411+
412+
$documents = array_map(fn($d) => new Document($d), $data);
413+
414+
$results = [];
415+
$count = $database->createDocuments(__FUNCTION__, $documents, onNext: function ($doc) use (&$results) {
416+
$results[] = $doc;
417+
});
418+
419+
$this->assertEquals($count, \count($results));
420+
$this->assertEquals(10, \count($results));
421+
422+
/**
423+
* Update 1 row
424+
*/
425+
$data[\array_key_last($data)]['number'] = 100;
426+
427+
/**
428+
* Add 1 row
429+
*/
430+
$data[] = [
431+
'$id' => "101",
432+
'number' => 101,
433+
];
434+
435+
$documents = array_map(fn($d) => new Document($d), $data);
436+
437+
Authorization::disable();
438+
439+
$results = [];
440+
$count = $database->createOrUpdateDocuments(
441+
__FUNCTION__,
442+
$documents,
443+
onNext: function ($doc) use (&$results) {
444+
$results[] = $doc;
445+
}
446+
);
447+
448+
Authorization::reset();
449+
450+
$this->assertEquals(2, \count($results));
451+
$this->assertEquals(2, $count);
452+
}
453+
454+
public function testUpsertDocuments(): void
392455
{
393456
/** @var Database $database */
394457
$database = static::getDatabase();

0 commit comments

Comments
 (0)