Skip to content

Commit

Permalink
Align with changes in dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
prwater committed Sep 29, 2024
1 parent 59e3387 commit 9c3e233
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 36 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/.idea/
/.phpunit.result.cache
/.phpunit.cache/
/bin/
/composer.lock
/custom.task.properties
/custom.type.properties
/test/coverage.xml
/test/report/
/vendor/
14 changes: 6 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
"require": {
"php": ">=8.3",
"plaisio/babel-core": "^2.0.0",
"plaisio/kernel": "^3.0",
"plaisio/language-resolver": "^1.2",
"plaisio/request": "^0.13.1"
"plaisio/kernel": "^3.2.1",
"plaisio/language-resolver": "^1.3.0",
"plaisio/request": "^1.0.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"phing/phing": "^3.0.0-RC4",
"phpunit/phpunit": "^9.6.3",
"phing/phing": "^3.0.0",
"phpunit/phpunit": "^10.5.35",
"plaisio/console-kernel": "^1.0.1",
"plaisio/request-core": "^0.13.0"
"plaisio/request-core": "^1.0.0"
},
"autoload": {
"psr-4": {
Expand Down
40 changes: 22 additions & 18 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<phpunit bootstrap="test/bootstrap.php">
<testsuites>
<testsuite name="Tests">
<directory>test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<directory suffix=".php">vendor/setbased</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="test/report"/>
<log type="coverage-clover" target="test/coverage.xml"/>
</logging>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="test/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<report>
<clover outputFile="test/coverage.xml"/>
<html outputDirectory="test/report"/>
</report>
</coverage>
<testsuites>
<testsuite name="Tests">
<directory>test</directory>
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".php">vendor/setbased</directory>
</exclude>
</source>
</phpunit>
12 changes: 5 additions & 7 deletions src/CoreLanguageResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ class CoreLanguageResolver extends PlaisioObject implements LanguageResolver
private int $lanIdDefault;

//--------------------------------------------------------------------------------------------------------------------

/**
* Object constructor.
*
* @param PlaisioInterface $object The parent PhpPlaisio object.
* @param int $lanIdDefault The ID of the language when to requested language can not be resolved.
* @param int $lanIdDefault The ID of the language when the requested language can not be resolved.
*/
public function __construct(PlaisioInterface $object, int $lanIdDefault)
{
Expand Down Expand Up @@ -63,10 +62,10 @@ public function getLanId(): int
*/
private function resolveLanId(): void
{
$codes = explode(',', $this->nub->request->getAcceptLanguage() ?? '');
$languages = $this->nub->request->acceptLanguages;

// If HTTP_ACCEPT_LANGUAGE is not set or empty return the default language.
if (empty($codes))
if (empty($languages))
{
$this->lanId = $this->lanIdDefault;

Expand All @@ -77,7 +76,7 @@ private function resolveLanId(): void

// Try to find the language code. Examples: en, en-US, zh, zh-Hans.
// BTW We assume HTTP_ACCEPT_LANGUAGE is sorted properly.
foreach ($codes as $code)
foreach (array_keys($languages) as $code)
{
if ($code==='')
{
Expand All @@ -98,10 +97,9 @@ private function resolveLanId(): void
}

// We did not find the language code. Try without county code. Examples: en, zh.
foreach ($codes as $code)
foreach (array_keys($languages) as $code)
{
$code = substr($code, 0, 2);

if (isset($map[$code]))
{
$this->lanId = $map[$code];
Expand Down
13 changes: 13 additions & 0 deletions test/CoreLanguageResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CoreLanguageResolverTest extends TestCase
private PlaisioKernel $kernel;

//--------------------------------------------------------------------------------------------------------------------

/**
* Creates the concrete implementation of the ABC Framework.
*/
Expand Down Expand Up @@ -150,6 +151,18 @@ public function testGetLanIdEmpty02(): void
self::assertEquals(C::LAN_ID_EN, $lanId);
}

//--------------------------------------------------------------------------------------------------------------------
/**
* Test language code without country.
*/
public function testGetLanIdOrderAndWeightDifferent(): void
{
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-GB;q=0.2,en-US;q=0.4,hu;q=0.6,de-DE;q=0.8,nl-NL;q=1.0';

$lanId = $this->kernel->languageResolver->getLanId();
self::assertEquals(C::LAN_ID_NL, $lanId);
}

//--------------------------------------------------------------------------------------------------------------------
/**
* Test unsupported language code.
Expand Down

0 comments on commit 9c3e233

Please sign in to comment.