@@ -3064,6 +3064,65 @@ public function testNoChangeUpdateDocumentWithoutPermission(Document $document):
30643064 return $ document ;
30653065 }
30663066
3067+ public function testNoChangeUpdateDocumentWithRelationWithoutPermission (): void
3068+ {
3069+ if (!static ::getDatabase ()->getAdapter ()->getSupportForRelationships ()) {
3070+ $ this ->expectNotToPerformAssertions ();
3071+ return ;
3072+ }
3073+
3074+ Authorization::cleanRoles ();
3075+ Authorization::setRole (Role::user ('a ' )->toString ());
3076+
3077+ static ::getDatabase ()->createCollection ('parentRelationTest ' , [], [], [
3078+ Permission::read (Role::user ('a ' )),
3079+ Permission::create (Role::user ('a ' )),
3080+ ]);
3081+ static ::getDatabase ()->createCollection ('childRelationTest ' , [], [], [
3082+ Permission::read (Role::user ('a ' )),
3083+ Permission::create (Role::user ('a ' )),
3084+ ]);
3085+ static ::getDatabase ()->createAttribute ('parentRelationTest ' , 'name ' , Database::VAR_STRING , 255 , false );
3086+ static ::getDatabase ()->createAttribute ('childRelationTest ' , 'name ' , Database::VAR_STRING , 255 , false );
3087+
3088+ static ::getDatabase ()->createRelationship (
3089+ collection: 'parentRelationTest ' ,
3090+ relatedCollection: 'childRelationTest ' ,
3091+ type: Database::RELATION_ONE_TO_MANY ,
3092+ id: 'childs '
3093+ );
3094+
3095+ // Create document with relationship with nested data
3096+ $ parent = static ::getDatabase ()->createDocument ('parentRelationTest ' , new Document ([
3097+ '$id ' => 'parent1 ' ,
3098+ 'name ' => 'Parent 1 ' ,
3099+ 'childs ' => [
3100+ [
3101+ '$id ' => 'child1 ' ,
3102+ 'name ' => 'Child 1 ' ,
3103+ ],
3104+ ],
3105+ ]));
3106+ $ this ->assertEquals (1 , \count ($ parent ['childs ' ]));
3107+ $ updatedParent = static ::getDatabase ()->updateDocument ('parentRelationTest ' , 'parent1 ' , new Document ([
3108+ '$id ' => 'parent1 ' ,
3109+ 'name ' =>'Parent 1 ' ,
3110+ '$collection ' => 'parentRelationTest ' ,
3111+ 'childs ' => [
3112+ new Document ([
3113+ '$id ' => 'child1 ' ,
3114+ '$collection ' => 'childRelationTest '
3115+ ]),
3116+ ]
3117+ ]));
3118+
3119+ $ this ->assertEquals ($ updatedParent ->getUpdatedAt (), $ parent ->getUpdatedAt ());
3120+ $ this ->assertEquals ($ updatedParent ->getAttribute ('childs ' )[0 ]->getUpdatedAt (), $ parent ->getAttribute ('childs ' )[0 ]->getUpdatedAt ());
3121+
3122+ static ::getDatabase ()->deleteCollection ('parentRelationTest ' );
3123+ static ::getDatabase ()->deleteCollection ('childRelationTest ' );
3124+ }
3125+
30673126 public function testExceptionAttributeLimit (): void
30683127 {
30693128 if ($ this ->getDatabase ()->getLimitForAttributes () > 0 ) {
@@ -11216,7 +11275,7 @@ public function testCollectionPermissionsRelationshipsUpdateThrowsException(arra
1121611275 $ document = static ::getDatabase ()->updateDocument (
1121711276 $ collection ->getId (),
1121811277 $ document ->getId (),
11219- $ document ->setAttribute ('test ' , ' ipsum ' )
11278+ $ document ->setAttribute ('test ' , $ document -> getAttribute ( ' test ' ). ' new_value ' )
1122011279 );
1122111280 }
1122211281
0 commit comments