@@ -704,13 +704,13 @@ public function deleteObjectProvider(): array
704704 /**
705705 * Test `deleteObject`.
706706 *
707- * @param mixed $input Input data for delete
708- * @param mixed $expected Expected result
707+ * @param array $input Input data for delete
708+ * @param array $expected Expected result
709709 * @return void
710710 * @dataProvider deleteObjectProvider
711711 * @covers ::deleteObject()
712712 */
713- public function testDeleteObject ($ input , $ expected ): void
713+ public function testDeleteObject (array $ input , array $ expected ): void
714714 {
715715 $ this ->authenticate ();
716716
@@ -720,6 +720,92 @@ public function testDeleteObject($input, $expected): void
720720 static ::assertEmpty ($ response );
721721 }
722722
723+ /**
724+ * Test `deleteObjects`, `removeObjects` and `restoreObjects.
725+ * Skip on be4 (delete multiple available from BEdita v5.28.0).
726+ *
727+ * @return void
728+ * @covers ::deleteObjects()
729+ * @covers ::restoreObjects()
730+ * @covers ::getObject()
731+ */
732+ public function testDeleteRemoveRestore (): void
733+ {
734+ $ this ->authenticate ();
735+ $ type = 'documents ' ;
736+ $ docId = $ this ->newObject ([
737+ 'type ' => $ type ,
738+ 'data ' => [
739+ 'title ' => 'this is a test document ' ,
740+ ],
741+ ]);
742+ $ ids = [$ docId ];
743+ $ response = $ this ->client ->deleteObjects ($ ids , $ type );
744+ static ::assertEquals (204 , $ this ->client ->getStatusCode ());
745+ static ::assertEquals ('No Content ' , $ this ->client ->getStatusMessage ());
746+ static ::assertEmpty ($ response );
747+ $ response = $ this ->client ->getObjects ($ type , ['filter ' => ['id ' => $ ids [0 ]]]);
748+ static ::assertEmpty ($ response ['data ' ]);
749+ $ response = $ this ->client ->restoreObjects ($ ids , $ type );
750+ static ::assertEquals (204 , $ this ->client ->getStatusCode ());
751+ static ::assertEquals ('No Content ' , $ this ->client ->getStatusMessage ());
752+ static ::assertEmpty ($ response );
753+ $ response = $ this ->client ->getObjects ($ type , ['filter ' => ['id ' => $ ids [0 ]]]);
754+ static ::assertNotEmpty ($ response ['data ' ]);
755+ $ response = $ this ->client ->deleteObjects ($ ids , $ type );
756+ static ::assertEquals (204 , $ this ->client ->getStatusCode ());
757+ static ::assertEquals ('No Content ' , $ this ->client ->getStatusMessage ());
758+ static ::assertEmpty ($ response );
759+ $ response = $ this ->client ->removeObjects ($ ids , $ type );
760+ static ::assertEquals (204 , $ this ->client ->getStatusCode ());
761+ static ::assertEquals ('No Content ' , $ this ->client ->getStatusMessage ());
762+ static ::assertEmpty ($ response );
763+ }
764+
765+ /**
766+ * Test `deleteObjects` on exception.
767+ *
768+ * @return void
769+ * @covers ::deleteObjects()
770+ */
771+ public function testDeleteObjects (): void
772+ {
773+ $ client = new class ($ this ->apiBaseUrl , $ this ->apiKey ) extends BEditaClient {
774+ public function deleteObject ($ id , string $ type ): ?array
775+ {
776+ return [];
777+ }
778+ };
779+ $ response = $ client ->authenticate ($ this ->adminUser , $ this ->adminPassword );
780+ $ client ->setupTokens ($ response ['meta ' ]);
781+ $ type = 'documents ' ;
782+ $ response = $ client ->save ($ type , ['title ' => 'this is a test document ' ]);
783+ $ docId = $ response ['data ' ]['id ' ];
784+ $ ids = [$ docId , 'abc ' ];
785+ $ actual = $ client ->deleteObjects ($ ids , $ type );
786+ static ::assertEmpty ($ actual );
787+ }
788+
789+ /**
790+ * Test `deleteObjects` on exception.
791+ *
792+ * @return void
793+ */
794+ public function testDeleteObjectsOnException (): void
795+ {
796+ $ this ->authenticate ();
797+ $ type = 'documents ' ;
798+ $ docId = $ this ->newObject ([
799+ 'type ' => $ type ,
800+ 'data ' => [
801+ 'title ' => 'this is a test document ' ,
802+ ],
803+ ]);
804+ $ ids = [$ docId , 'abc ' ];
805+ $ this ->expectException (BEditaClientException::class);
806+ $ this ->client ->deleteObjects ($ ids , $ type );
807+ }
808+
723809 /**
724810 * Data provider for `testRestoreObject`
725811 */
@@ -763,6 +849,31 @@ public function testRestoreObject($input, $expected): void
763849 static ::assertEmpty ($ response );
764850 }
765851
852+ /**
853+ * Test `restoreObjects`.
854+ * Skip on be4 (delete multiple available from BEdita v5.28.0).
855+ *
856+ * @return void
857+ * @covers ::restoreObjects()
858+ */
859+ public function testRestoreObjects (): void
860+ {
861+ $ this ->authenticate ();
862+ $ type = 'documents ' ;
863+ $ docId = $ this ->newObject ([
864+ 'type ' => $ type ,
865+ 'data ' => [
866+ 'title ' => 'this is a test document ' ,
867+ ],
868+ ]);
869+ $ ids = [$ docId ];
870+ $ this ->client ->deleteObjects ($ ids , $ type );
871+ $ response = $ this ->client ->restoreObjects ($ ids , $ type );
872+ static ::assertEquals (204 , $ this ->client ->getStatusCode ());
873+ static ::assertEquals ('No Content ' , $ this ->client ->getStatusMessage ());
874+ static ::assertEmpty ($ response );
875+ }
876+
766877 /**
767878 * Data provider for `testRemove`
768879 */
@@ -806,6 +917,55 @@ public function testRemove($input, $expected): void
806917 static ::assertEmpty ($ response );
807918 }
808919
920+ /**
921+ * Test `removeObjects` on exception.
922+ *
923+ * @return void
924+ * @covers ::removeObjects()
925+ */
926+ public function testRemoveObjects (): void
927+ {
928+ $ client = new class ($ this ->apiBaseUrl , $ this ->apiKey ) extends BEditaClient {
929+ public function remove ($ id ): ?array
930+ {
931+ if ($ id === 'abc ' ) {
932+ return [];
933+ }
934+
935+ return $ this ->delete (sprintf ('/trash/%s ' , $ id ));
936+ }
937+ };
938+ $ response = $ client ->authenticate ($ this ->adminUser , $ this ->adminPassword );
939+ $ client ->setupTokens ($ response ['meta ' ]);
940+ $ type = 'documents ' ;
941+ $ response = $ client ->save ($ type , ['title ' => 'this is a test document ' ]);
942+ $ docId = $ response ['data ' ]['id ' ];
943+ $ client ->deleteObject ($ docId , $ type );
944+ $ ids = [$ docId , 'abc ' ];
945+ $ actual = $ client ->removeObjects ($ ids , $ type );
946+ static ::assertEmpty ($ actual );
947+ }
948+
949+ /**
950+ * Test `removeObjects` on exception.
951+ *
952+ * @return void
953+ */
954+ public function testRemoveObjectsOnException (): void
955+ {
956+ $ this ->authenticate ();
957+ $ type = 'documents ' ;
958+ $ docId = $ this ->newObject ([
959+ 'type ' => $ type ,
960+ 'data ' => [
961+ 'title ' => 'this is a test document ' ,
962+ ],
963+ ]);
964+ $ ids = [$ docId , 'abc ' ];
965+ $ this ->expectException (BEditaClientException::class);
966+ $ this ->client ->removeObjects ($ ids , $ type );
967+ }
968+
809969 /**
810970 * Test `schema`.
811971 *
@@ -991,13 +1151,13 @@ public function testSendRequest($input, $expected): void
9911151 * Create new object for test purposes.
9921152 *
9931153 * @param array $input The input data.
994- * @return int|string the Id.
1154+ * @return int the Id.
9951155 */
996- private function newObject ($ input )
1156+ private function newObject ($ input ): int
9971157 {
9981158 $ response = $ this ->client ->save ($ input ['type ' ], $ input ['data ' ]);
9991159
1000- return $ response ['data ' ]['id ' ];
1160+ return ( int ) $ response ['data ' ]['id ' ];
10011161 }
10021162
10031163 /**
0 commit comments