Skip to content

Commit 0bb2a4e

Browse files
tvdijenMKodde
authored andcommitted
Translatable configurable metadata
This is a continuation of #1103 where we made the Organization-data in metadata configurable using the translations-files. However, the result would be like this: <md:OrganizationDisplayName lang="en">My fictional organization</md:OrganizationDisplayName> <md:OrganizationDisplayName lang="nl">My fictional organization</md:OrganizationDisplayName> Instead of: <md:OrganizationDisplayName lang="en">My fictional organization</md:OrganizationDisplayName> <md:OrganizationDisplayName lang="nl">Mijn fictieve organisatie</md:OrganizationDisplayName> Everything was being translated using the default locale. This PR attempts to fix that. See: #1292 See: #1103
1 parent d27762c commit 0bb2a4e

16 files changed

+114
-123
lines changed

src/OpenConext/EngineBlock/Metadata/Factory/Adapter/IdentityProviderEntity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ public function hasCompleteOrganizationData(string $locale): bool
126126
}
127127

128128
/**
129-
* @param $locale
129+
* @param string $locale
130130
* @return Organization
131131
*/
132-
public function getOrganization($locale): ?Organization
132+
public function getOrganization(string $locale): ?Organization
133133
{
134134
switch (true) {
135135
case ($locale == 'nl'):

src/OpenConext/EngineBlock/Metadata/Factory/Adapter/ServiceProviderEntity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ public function hasCompleteOrganizationData(string $locale): bool
128128
}
129129

130130
/**
131-
* @param $locale
131+
* @param string $locale
132132
* @return Organization
133133
*/
134-
public function getOrganization($locale): ?Organization
134+
public function getOrganization(string $locale): ?Organization
135135
{
136136
switch (true) {
137137
case ($locale == 'nl'):

src/OpenConext/EngineBlock/Metadata/Factory/Decorator/AbstractIdentityProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ public function hasCompleteOrganizationData(string $locale): bool
114114
}
115115

116116
/**
117-
* @param $locale
117+
* @param string $locale
118118
* @return Organization|null
119119
*/
120-
public function getOrganization($locale): ?Organization
120+
public function getOrganization(string $locale): ?Organization
121121
{
122122
return $this->entity->getOrganization($locale);
123123
}

src/OpenConext/EngineBlock/Metadata/Factory/Decorator/AbstractServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public function hasCompleteOrganizationData(string $locale): bool
107107
}
108108

109109
/**
110-
* @param $locale
110+
* @param string $locale
111111
* @return Organization|null
112112
*/
113-
public function getOrganization($locale): ?Organization
113+
public function getOrganization(string $locale): ?Organization
114114
{
115115
return $this->entity->getOrganization($locale);
116116
}

src/OpenConext/EngineBlock/Metadata/Factory/Decorator/EngineBlockIdentityProviderInformation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public function getLogo(): ?Logo
6060
return $this->engineBlockConfiguration->getLogo();
6161
}
6262

63-
public function getOrganization($locale): ?Organization
63+
public function getOrganization(string $locale): ?Organization
6464
{
65-
return $this->engineBlockConfiguration->getOrganization();
65+
return $this->engineBlockConfiguration->getOrganization($locale);
6666
}
6767

6868
/**

src/OpenConext/EngineBlock/Metadata/Factory/Decorator/EngineBlockServiceProviderInformation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public function getLogo(): ?Logo
6060
return $this->engineBlockConfiguration->getLogo();
6161
}
6262

63-
public function getOrganization($locale): ?Organization
63+
public function getOrganization(string $locale): ?Organization
6464
{
65-
return $this->engineBlockConfiguration->getOrganization();
65+
return $this->engineBlockConfiguration->getOrganization($locale);
6666
}
6767

6868
/**

src/OpenConext/EngineBlock/Metadata/Factory/IdentityProviderEntityInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public function getLogo(): ?Logo;
7171
public function hasCompleteOrganizationData(string $locale): bool;
7272

7373
/**
74-
* @param $locale
74+
* @param string $locale
7575
* @return Organization|null
7676
*/
77-
public function getOrganization($locale): ?Organization;
77+
public function getOrganization(string $locale): ?Organization;
7878

7979
/**
8080
* @param $locale

src/OpenConext/EngineBlock/Metadata/Factory/ServiceProviderEntityInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ public function getLogo(): ?Logo;
6363
public function hasCompleteOrganizationData(string $locale): bool;
6464

6565
/**
66-
* @param $locale
66+
* @param string $locale
6767
* @return Organization|null
6868
*/
69-
public function getOrganization($locale): ?Organization;
69+
public function getOrganization(string $locale): ?Organization;
7070

7171
/**
7272
* @param $locale

src/OpenConext/EngineBlock/Metadata/Factory/ValueObject/EngineBlockConfiguration.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
*/
3131
class EngineBlockConfiguration
3232
{
33+
/**
34+
* @var \Symfony\Component\Translation\TranslatorInterface
35+
*/
36+
private $translator;
37+
3338
/**
3439
* @var string
3540
*/
@@ -84,11 +89,12 @@ public function __construct(
8489
int $logoWidth,
8590
int $logoHeight
8691
) {
92+
$this->translator = $translator;
8793
$this->suiteName = $translator->trans('suite_name');
8894
$this->engineHostName = $engineHostName;
89-
$this->organizationName = $translator->trans('metadata_organization_name');
90-
$this->organizationDisplayName = $translator->trans('metadata_organization_displayname');
91-
$this->organizationUrl = $translator->trans('metadata_organization_url');
95+
$this->organizationName = 'metadata_organization_name';
96+
$this->organizationDisplayName = 'metadata_organization_displayname';
97+
$this->organizationUrl = 'metadata_organization_url';
9298
$this->supportMail = $supportMail;
9399
$this->description = $description;
94100

@@ -101,9 +107,10 @@ public function __construct(
101107
$this->logo->height = $logoHeight;
102108

103109
// Create the contact person data for the EB SP entity
104-
$support = ContactPerson::from('support', $this->organizationName, 'Support', $this->supportMail);
105-
$technical = ContactPerson::from('technical', $this->organizationName, 'Support', $this->supportMail);
106-
$administrative = ContactPerson::from('administrative', $this->organizationName, 'Support', $this->supportMail);
110+
$organizationName = $translator->trans('metadata_organization_name');
111+
$support = ContactPerson::from('support', $organizationName, 'Support', $this->supportMail);
112+
$technical = ContactPerson::from('technical', $organizationName, 'Support', $this->supportMail);
113+
$administrative = ContactPerson::from('administrative', $organizationName, 'Support', $this->supportMail);
107114

108115
$this->contactPersons = [$support, $technical, $administrative];
109116
}
@@ -118,9 +125,12 @@ public function getHostname(): string
118125
return $this->engineHostName;
119126
}
120127

121-
public function getOrganization() : Organization
128+
public function getOrganization(string $locale) : Organization
122129
{
123-
return new Organization($this->organizationName, $this->organizationDisplayName, $this->organizationUrl);
130+
$organizationName = $this->translator->trans($this->organizationName, [], null, $locale);
131+
$organizationDisplayName = $this->translator->trans($this->organizationDisplayName, [], null, $locale);
132+
$organizationUrl = $this->translator->trans($this->organizationUrl, [], null, $locale);
133+
return new Organization($organizationName, $organizationDisplayName, $organizationUrl);
124134
}
125135

126136
public function getLogo(): Logo

tests/unit/OpenConext/EngineBlock/Metadata/Factory/AbstractEntityTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OpenConext\EngineBlock\Metadata\Service;
3434
use OpenConext\EngineBlock\Metadata\ShibMdScope;
3535
use OpenConext\EngineBlock\Metadata\X509\X509Certificate;
36+
use PHPUnit\Framework\MockObject\MockObject;
3637
use PHPUnit\Framework\TestCase;
3738
use ReflectionClass;
3839
use ReflectionProperty;
@@ -512,6 +513,64 @@ protected function getServiceProviderMockProperties()
512513
];
513514
}
514515

516+
protected function setTranslationExpectancies(MockObject $translator)
517+
{
518+
$translator->expects($this->at(0))
519+
->method('trans')
520+
->with('suite_name')
521+
->willReturn('test-suite');
522+
523+
$translator->expects($this->at(1))
524+
->method('trans')
525+
->with('metadata_organization_name')
526+
->willReturn('configuredOrganizationName');
527+
528+
$translator->expects($this->at(2))
529+
->method('trans')
530+
->with('metadata_organization_name', [], null, 'nl')
531+
->willReturn('configuredOrganizationName');
532+
533+
$translator->expects($this->at(3))
534+
->method('trans')
535+
->with('metadata_organization_displayname', [], null, 'nl')
536+
->willReturn('configuredOrganizationDisplayName');
537+
538+
$translator->expects($this->at(4))
539+
->method('trans')
540+
->with('metadata_organization_url', [], null, 'nl')
541+
->willReturn('configuredOrganizationUrl');
542+
543+
$translator->expects($this->at(5))
544+
->method('trans')
545+
->with('metadata_organization_name', [], null, 'en')
546+
->willReturn('configuredOrganizationName');
547+
548+
$translator->expects($this->at(6))
549+
->method('trans')
550+
->with('metadata_organization_displayname', [], null, 'en')
551+
->willReturn('configuredOrganizationDisplayName');
552+
553+
$translator->expects($this->at(7))
554+
->method('trans')
555+
->with('metadata_organization_url', [], null, 'en')
556+
->willReturn('configuredOrganizationUrl');
557+
558+
$translator->expects($this->at(8))
559+
->method('trans')
560+
->with('metadata_organization_name', [], null, 'pt')
561+
->willReturn('configuredOrganizationName');
562+
563+
$translator->expects($this->at(9))
564+
->method('trans')
565+
->with('metadata_organization_displayname', [], null, 'pt')
566+
->willReturn('configuredOrganizationDisplayName');
567+
568+
$translator->expects($this->at(10))
569+
->method('trans')
570+
->with('metadata_organization_url', [], null, 'pt')
571+
->willReturn('configuredOrganizationUrl');
572+
}
573+
515574
private function getParameters($className, $skipParameters = [])
516575
{
517576
$results = [];

0 commit comments

Comments
 (0)