2525use OpenConext \EngineBlock \Metadata \Coins ;
2626use OpenConext \EngineBlock \Metadata \ContactPerson ;
2727use OpenConext \EngineBlock \Metadata \Entity \ServiceProvider ;
28+ use OpenConext \EngineBlock \Metadata \Organization ;
2829use OpenConext \EngineBlock \Metadata \Utils ;
2930use PHPUnit \Framework \TestCase ;
3031use SAML2 \Constants ;
3132
3233class ConsentTest extends TestCase
3334{
34- private function createServiceProvider ()
35+ private function createServiceProvider (array $ organizations = [] )
3536 {
3637 $ supportContact = new ContactPerson ('support ' );
3738 $ supportContact ->givenName = 'givenName ' ;
3839 $ supportContact ->surName = 'surName ' ;
3940 $ supportContact ->telephoneNumber = '+31612345678 ' ;
4041 $ supportContact ->emailAddress = 'mail@example.org ' ;
4142
43+ $ enOrg = new Organization ('Organization name EN ' , 'Organization display name EN ' , 'https://org.example.com ' );
44+ $ nlOrg = new Organization ('Organization name NL ' , 'Organization display name NL ' , 'https://org.example.nl ' );
45+ $ ptOrg = new Organization ('Organization name PT ' , 'Organization display name PT ' , 'https://org.example.pt ' );
46+ if (!empty ($ organizations )) {
47+ $ enOrg = $ organizations ['en ' ];
48+ $ nlOrg = $ organizations ['nl ' ];
49+ $ ptOrg = $ organizations ['pt ' ];
50+ }
51+
4252 $ serviceProvider = Utils::instantiate (
4353 ServiceProvider::class,
4454 [
@@ -52,6 +62,9 @@ private function createServiceProvider()
5262 'displayNameNl ' => 'Display Name NL ' ,
5363 'termsOfServiceUrl ' => 'https://example.org/eula ' ,
5464 'nameIdFormat ' => Constants::NAMEID_TRANSIENT ,
65+ 'organizationEn ' => $ enOrg ,
66+ 'organizationNl ' => $ nlOrg ,
67+ 'organizationPt ' => $ ptOrg ,
5568 ]
5669 );
5770
@@ -99,6 +112,37 @@ public function all_values_are_serialized_to_json()
99112 $ this ->assertEquals ($ serviceProvider ->getCoins ()->termsOfServiceUrl (), $ json ['eula_url ' ]);
100113 $ this ->assertEquals ($ serviceProvider ->contactPersons [0 ]->emailAddress , $ json ['support_email ' ]);
101114 $ this ->assertEquals ($ serviceProvider ->nameIdFormat , $ json ['name_id_format ' ]);
115+ $ this ->assertEquals ($ serviceProvider ->organizationEn ->displayName , $ json ['organization_display_name ' ]['en ' ]);
116+ $ this ->assertEquals ($ serviceProvider ->organizationNl ->displayName , $ json ['organization_display_name ' ]['nl ' ]);
117+ $ this ->assertEquals ($ serviceProvider ->organizationPt ->displayName , $ json ['organization_display_name ' ]['pt ' ]);
118+ }
119+
120+ /**
121+ * @dataProvider provideOrganizations
122+ */
123+ public function test_display_name_of_organizations_works_as_intended (
124+ array $ organizations ,
125+ array $ expectations ,
126+ string $ errorMessage
127+ ) {
128+ $ serviceProvider = $ this ->createServiceProvider ($ organizations );
129+ $ consentGivenOn = new DateTime ('20080624 10:00:00 ' );
130+ $ consentType = ConsentType::explicit ();
131+
132+ $ consent = new Consent (
133+ new ConsentModel (
134+ 'user-id ' ,
135+ 'entity-id ' ,
136+ $ consentGivenOn ,
137+ $ consentType
138+ ),
139+ $ serviceProvider
140+ );
141+
142+ $ json = $ consent ->jsonSerialize ()['service_provider ' ]['organization_display_name ' ];
143+ $ this ->assertEquals ($ expectations ['en ' ], $ json ['en ' ], $ errorMessage );
144+ $ this ->assertEquals ($ expectations ['nl ' ], $ json ['nl ' ], $ errorMessage );
145+ $ this ->assertEquals ($ expectations ['pt ' ], $ json ['pt ' ], $ errorMessage );
102146 }
103147
104148 /**
@@ -171,6 +215,73 @@ public function display_name_falls_back_to_entity_id_if_name_is_empty()
171215 $ this ->assertEquals ($ serviceProvider ->entityId , $ json ['service_provider ' ]['display_name ' ]['nl ' ]);
172216 }
173217
218+ public function provideOrganizations ()
219+ {
220+ $ displayNameEn = 'Organization display name EN ' ;
221+ $ nameEn = 'Organization name EN ' ;
222+ $ unknownEn = 'unknown ' ;
223+ $ displayNameNl = 'Organization display name NL ' ;
224+ $ nameNl = 'Organization name NL ' ;
225+ $ displayNamePt = 'Organization display name PT ' ;
226+ $ namePt = 'Organization name PT ' ;
227+
228+ $ enOrg = new Organization ($ nameEn , $ displayNameEn , 'https://org.example.com ' );
229+ $ nlOrg = new Organization ($ nameNl , $ displayNameNl , 'https://org.example.com ' );
230+ $ ptOrg = new Organization ($ namePt , $ displayNamePt , 'https://org.example.com ' );
231+ $ organizations = ['en ' => $ enOrg , 'nl ' => $ nlOrg , 'pt ' => $ ptOrg ];
232+ $ expectation = ['en ' => $ displayNameEn , 'nl ' => $ displayNameNl , 'pt ' => $ displayNamePt ];
233+ $ exceptionMessage = 'Failed asserting rule: If OrganizationDisplayName:L is set, return OrganizationDisplayName:L ' ;
234+ yield [$ organizations , $ expectation , $ exceptionMessage ];
235+
236+ $ enOrg = new Organization ($ nameEn , '' , 'https://org.example.com ' );
237+ $ nlOrg = new Organization ($ nameNl , '' , 'https://org.example.com ' );
238+ $ ptOrg = new Organization ($ namePt , '' , 'https://org.example.com ' );
239+ $ organizations = ['en ' => $ enOrg , 'nl ' => $ nlOrg , 'pt ' => $ ptOrg ];
240+ $ expectation = ['en ' => $ nameEn , 'nl ' => $ nameNl , 'pt ' => $ namePt ];
241+ $ exceptionMessage = 'Failed asserting rule: else if OrganizationName:L is set, returnOrganizationName:L ' ;
242+ yield [$ organizations , $ expectation , $ exceptionMessage ];
243+
244+ $ enOrg = new Organization ($ nameEn , $ displayNameEn , 'https://org.example.com ' );
245+ $ nlOrg = new Organization ('' , '' , 'https://org.example.com ' );
246+ $ ptOrg = new Organization ('' , '' , 'https://org.example.com ' );
247+ $ organizations = ['en ' => $ enOrg , 'nl ' => $ nlOrg , 'pt ' => $ ptOrg ];
248+ $ expectation = ['en ' => $ displayNameEn , 'nl ' => $ displayNameEn , 'pt ' => $ displayNameEn ];
249+ $ exceptionMessage = 'Failed asserting rule: else if OrganizationDisplayName:"en" is set, return OrganizationDisplayName:"en" ' ;
250+ yield [$ organizations , $ expectation , $ exceptionMessage ];
251+
252+ $ enOrg = new Organization ($ nameEn , '' , 'https://org.example.com ' );
253+ $ nlOrg = new Organization ('' , '' , 'https://org.example.com ' );
254+ $ ptOrg = new Organization ('' , '' , 'https://org.example.com ' );
255+ $ organizations = ['en ' => $ enOrg , 'nl ' => $ nlOrg , 'pt ' => $ ptOrg ];
256+ $ expectation = ['en ' => $ nameEn , 'nl ' => $ nameEn , 'pt ' => $ nameEn ];
257+ $ exceptionMessage = 'Failed asserting rule: else if OrganizationName:"en" is set, returnOrganizationName:"en" ' ;
258+ yield [$ organizations , $ expectation , $ exceptionMessage ];
259+
260+ $ enOrg = new Organization ('' , '' , 'https://org.example.com ' );
261+ $ nlOrg = new Organization ('' , '' , 'https://org.example.com ' );
262+ $ ptOrg = new Organization ('' , '' , 'https://org.example.com ' );
263+ $ organizations = ['en ' => $ enOrg , 'nl ' => $ nlOrg , 'pt ' => $ ptOrg ];
264+ $ expectation = ['en ' => $ unknownEn , 'nl ' => $ unknownEn , 'pt ' => $ unknownEn ];
265+ $ exceptionMessage = 'Failed asserting rule: else return "unknown" ' ;
266+ yield [$ organizations , $ expectation , $ exceptionMessage ];
267+
268+ $ enOrg = new Organization ($ nameEn , '' , 'https://org.example.com ' );
269+ $ nlOrg = new Organization ('' , $ displayNameNl , 'https://org.example.com ' );
270+ $ ptOrg = new Organization ('' , '' , 'https://org.example.com ' );
271+ $ organizations = ['en ' => $ enOrg , 'nl ' => $ nlOrg , 'pt ' => $ ptOrg ];
272+ $ expectation = ['en ' => $ nameEn , 'nl ' => $ displayNameNl , 'pt ' => $ nameEn ];
273+ $ exceptionMessage = 'Failed asserting rule: mixed ' ;
274+ yield [$ organizations , $ expectation , $ exceptionMessage ];
275+
276+ $ enOrg = new Organization ('' , '' , 'https://org.example.com ' );
277+ $ nlOrg = new Organization ('' , $ displayNameNl , 'https://org.example.com ' );
278+ $ ptOrg = new Organization ($ namePt , '' , 'https://org.example.com ' );
279+ $ organizations = ['en ' => $ enOrg , 'nl ' => $ nlOrg , 'pt ' => $ ptOrg ];
280+ $ expectation = ['en ' => $ unknownEn , 'nl ' => $ displayNameNl , 'pt ' => $ namePt ];
281+ $ exceptionMessage = 'Failed asserting rule: mixed EN is unknown ' ;
282+ yield [$ organizations , $ expectation , $ exceptionMessage ];
283+ }
284+
174285 private function setCoin (ServiceProvider $ sp , $ key , $ name )
175286 {
176287 $ jsonData = $ sp ->getCoins ()->toJson ();
0 commit comments