@@ -739,4 +739,175 @@ public function testValidateIdentifySignersIntegration(): void {
739739
740740 $ this ->assertNull ($ result );
741741 }
742+
743+ #[DataProvider('providerValidateIdentifySigners ' )]
744+ public function testValidateIdentifySigners (array $ data , bool $ shouldThrow = false , string $ expectedMessage = '' ): void {
745+ // Mock signature method for valid cases
746+ $ signatureMethod = $ this ->createMock (ISignatureMethod::class);
747+ $ identifyMethod = $ this ->createMock (IIdentifyMethod::class);
748+ $ identifyMethod ->method ('getSignatureMethods ' )->willReturn ([$ signatureMethod ]);
749+ $ identifyMethod ->method ('validateToRequest ' );
750+
751+ $ this ->identifyMethodService
752+ ->method ('getInstanceOfIdentifyMethod ' )
753+ ->willReturn ($ identifyMethod );
754+
755+ $ validateHelper = $ this ->getValidateHelper ();
756+
757+ if ($ shouldThrow ) {
758+ $ this ->expectException (LibresignException::class);
759+ if ($ expectedMessage ) {
760+ $ this ->expectExceptionMessage ($ expectedMessage );
761+ }
762+ }
763+
764+ $ validateHelper ->validateIdentifySigners ($ data );
765+
766+ if (!$ shouldThrow ) {
767+ $ this ->assertTrue (true ); // If we get here without exception, test passed
768+ }
769+ }
770+
771+ public static function providerValidateIdentifySigners (): array {
772+ return [
773+ 'valid data with identify structure single method ' => [
774+ [
775+ 'users ' => [
776+ [
777+ 'identify ' => [
778+ 'account ' => 'user@example.com '
779+ ]
780+ ]
781+ ]
782+ ],
783+ false , // should not throw
784+ ],
785+ 'valid data with identify structure multiple methods ' => [
786+ [
787+ 'users ' => [
788+ [
789+ 'identify ' => [
790+ 'account ' => 'user@example.com ' ,
791+ 'email ' => 'user@example.com '
792+ ]
793+ ]
794+ ]
795+ ],
796+ false , // should not throw
797+ ],
798+ 'valid data with identifyMethods structure single method ' => [
799+ [
800+ 'users ' => [
801+ [
802+ 'identifyMethods ' => [
803+ ['method ' => 'account ' , 'value ' => 'user@example.com ' ]
804+ ]
805+ ]
806+ ]
807+ ],
808+ false , // should not throw
809+ ],
810+ 'valid data with identifyMethods structure multiple methods ' => [
811+ [
812+ 'users ' => [
813+ [
814+ 'identifyMethods ' => [
815+ ['method ' => 'account ' , 'value ' => 'user@example.com ' ],
816+ ['method ' => 'email ' , 'value ' => 'user@example.com ' ]
817+ ]
818+ ]
819+ ]
820+ ],
821+ false , // should not throw
822+ ],
823+ 'mixed structures in same data ' => [
824+ [
825+ 'users ' => [
826+ [
827+ 'identify ' => [
828+ 'account ' => 'user1@example.com '
829+ ]
830+ ],
831+ [
832+ 'identifyMethods ' => [
833+ ['method ' => 'email ' , 'value ' => 'user2@example.com ' ]
834+ ]
835+ ]
836+ ]
837+ ],
838+ false , // should not throw
839+ ],
840+ 'empty data structure ' => [
841+ [],
842+ true , // should throw
843+ 'No signers '
844+ ],
845+ 'missing users key ' => [
846+ ['someOtherKey ' => 'value ' ],
847+ true , // should throw
848+ 'No signers '
849+ ],
850+ 'empty users array ' => [
851+ ['users ' => []],
852+ true , // should throw
853+ 'No signers '
854+ ],
855+ 'users not array ' => [
856+ ['users ' => 'not-an-array ' ],
857+ true , // should throw
858+ 'No signers '
859+ ],
860+ 'empty signer ' => [
861+ ['users ' => [[]]],
862+ true , // should throw
863+ 'No signers '
864+ ],
865+ 'signer not array ' => [
866+ ['users ' => ['not-an-array ' ]],
867+ true , // should throw
868+ 'No signers '
869+ ],
870+ 'signer without identify methods ' => [
871+ ['users ' => [['someKey ' => 'value ' ]]],
872+ true , // should throw
873+ 'No identify methods for signer '
874+ ],
875+ 'signer with empty identify ' => [
876+ ['users ' => [['identify ' => []]]],
877+ true , // should throw
878+ 'No identify methods for signer '
879+ ],
880+ 'signer with empty identifyMethods ' => [
881+ ['users ' => [['identifyMethods ' => []]]],
882+ true , // should throw
883+ 'No identify methods for signer '
884+ ],
885+ 'invalid identifyMethods structure - missing method ' => [
886+ [
887+ 'users ' => [
888+ [
889+ 'identifyMethods ' => [
890+ ['value ' => 'user@example.com ' ] // missing 'method'
891+ ]
892+ ]
893+ ]
894+ ],
895+ true , // should throw
896+ 'Invalid identify method structure '
897+ ],
898+ 'invalid identifyMethods structure - missing value ' => [
899+ [
900+ 'users ' => [
901+ [
902+ 'identifyMethods ' => [
903+ ['method ' => 'email ' ] // missing 'value'
904+ ]
905+ ]
906+ ]
907+ ],
908+ true , // should throw
909+ 'Invalid identify method structure '
910+ ],
911+ ];
912+ }
742913}
0 commit comments