Skip to content

Commit

Permalink
added method Domain:getAllLocales() that returns all locales that are…
Browse files Browse the repository at this point in the history
… used the system
  • Loading branch information
Svaťa Šimara committed Feb 12, 2019
1 parent 89bf5c3 commit 3056ac2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/framework/src/Component/Domain/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ public function getAllIds()
return $ids;
}

/**
* @return string[]
*/
public function getAllLocales(): array
{
$locales = [];
foreach ($this->getAll() as $domainConfig) {
$locales[] = $domainConfig->getLocale();
}

return array_unique($locales);
}

/**
* @return int[]
*/
Expand Down
15 changes: 15 additions & 0 deletions packages/framework/tests/Unit/Component/Domain/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,19 @@ public function testGetDomainConfigById()
$this->expectException(\Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException::class);
$domain->getDomainConfigById(3);
}

public function testGetAllLocales(): void
{
$domainConfigs = [
new DomainConfig(1, 'http://example.com:8080', 'example.com', 'cs'),
new DomainConfig(2, 'http://example.org:8080', 'example.org', 'en'),
new DomainConfig(3, 'http://example.cz:8080', 'example.cz', 'cs'),
];
$settingMock = $this->createMock(Setting::class);

$domain = new Domain($domainConfigs, $settingMock);

$expectedLocales = ['cs', 'en'];
$this->assertSame($expectedLocales, $domain->getAllLocales());
}
}

0 comments on commit 3056ac2

Please sign in to comment.