Skip to content

Commit 17b92df

Browse files
committed
add test bsack
1 parent 84ed291 commit 17b92df

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/e2e/Adapter/Scopes/Relationships/OneToOneTests.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,44 @@ public function testOneToOneOneWayRelationship(): void
435435
$this->assertEquals(null, $library);
436436
}
437437

438+
public function testOneToOneOneWayRelationshipRejectsChildSideWrites(): void
439+
{
440+
/** @var Database $database */
441+
$database = $this->getDatabase();
442+
443+
if (!$database->getAdapter()->getSupportForRelationships()) {
444+
$this->expectNotToPerformAssertions();
445+
return;
446+
}
447+
448+
$database->createCollection('parent');
449+
$database->createCollection('child');
450+
451+
$database->createRelationship(
452+
collection: 'parent',
453+
relatedCollection: 'child',
454+
type: Database::RELATION_ONE_TO_ONE,
455+
id: 'child1'
456+
);
457+
458+
try {
459+
$database->createDocument('parent', new Document([
460+
'$permissions' => [
461+
Permission::read(Role::any()),
462+
Permission::update(Role::any()),
463+
Permission::delete(Role::any()),
464+
],
465+
'child1' => [
466+
'$id' => 'foo',
467+
'$permissions' => [Permission::read(Role::any())],
468+
],
469+
]));
470+
$this->fail('Failed to throw Exception');
471+
} catch (Exception $e) {
472+
$this->assertEquals('Invalid relationship value. Cannot set a value from the child side of a oneToOne relationship when twoWay is false.', $e->getMessage());
473+
}
474+
}
475+
438476
/**
439477
* @throws AuthorizationException
440478
* @throws LimitException

0 commit comments

Comments
 (0)