@@ -704,13 +704,13 @@ public function deleteObjectProvider(): array
704
704
/**
705
705
* Test `deleteObject`.
706
706
*
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
709
709
* @return void
710
710
* @dataProvider deleteObjectProvider
711
711
* @covers ::deleteObject()
712
712
*/
713
- public function testDeleteObject ($ input , $ expected ): void
713
+ public function testDeleteObject (array $ input , array $ expected ): void
714
714
{
715
715
$ this ->authenticate ();
716
716
@@ -720,6 +720,92 @@ public function testDeleteObject($input, $expected): void
720
720
static ::assertEmpty ($ response );
721
721
}
722
722
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
+
723
809
/**
724
810
* Data provider for `testRestoreObject`
725
811
*/
@@ -763,6 +849,31 @@ public function testRestoreObject($input, $expected): void
763
849
static ::assertEmpty ($ response );
764
850
}
765
851
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
+
766
877
/**
767
878
* Data provider for `testRemove`
768
879
*/
@@ -806,6 +917,55 @@ public function testRemove($input, $expected): void
806
917
static ::assertEmpty ($ response );
807
918
}
808
919
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
+
809
969
/**
810
970
* Test `schema`.
811
971
*
@@ -991,13 +1151,13 @@ public function testSendRequest($input, $expected): void
991
1151
* Create new object for test purposes.
992
1152
*
993
1153
* @param array $input The input data.
994
- * @return int|string the Id.
1154
+ * @return int the Id.
995
1155
*/
996
- private function newObject ($ input )
1156
+ private function newObject ($ input ): int
997
1157
{
998
1158
$ response = $ this ->client ->save ($ input ['type ' ], $ input ['data ' ]);
999
1159
1000
- return $ response ['data ' ]['id ' ];
1160
+ return ( int ) $ response ['data ' ]['id ' ];
1001
1161
}
1002
1162
1003
1163
/**
0 commit comments