Skip to content

Commit

Permalink
Fix BrowserAcceptedLanguage and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
helhum committed Oct 12, 2021
1 parent 03fb63b commit d46c8ca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Classes/FactProvider/BrowserAcceptedLanguage.php
Expand Up @@ -48,9 +48,9 @@ public function process(): self
public function isGuilty($prosecution): bool
{
LocateUtility::mainstreamValue($prosecution);
$this->priority = (int)($this->getSubject()[$prosecution] ?? 0);
$this->priority = (int)($this->facts[$prosecution] ?? 0);

return isset($this->getSubject()[$prosecution]);
return isset($this->facts[$prosecution]);
}

protected function getAcceptedLanguages(): array
Expand Down
45 changes: 45 additions & 0 deletions Tests/Unit/FactProvider/BrowserAcceptedLanguageTest.php
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Leuchtfeuer\Locate\Tests\Unit\FactProvider;

use Leuchtfeuer\Locate\FactProvider\BrowserAcceptedLanguage;
use PHPUnit\Framework\TestCase;

class BrowserAcceptedLanguageTest extends TestCase
{
/**
* @test
*/
public function askingForIsGuiltyTwiceReturnsCorrectState(): void
{
$subject = new BrowserAcceptedLanguage('dummy');
$classReflection = new \ReflectionClass($subject);
$reflectionProperty = $classReflection->getProperty('facts');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($subject, [
'en' => 1,
]);

self::assertTrue($subject->isGuilty('en'));
self::assertFalse($subject->isGuilty('de'));
}

/**
* @test
*/
public function askingForIsGuiltyThreeTimesForMultipleLanguagesReturnsCorrectState(): void
{
$subject = new BrowserAcceptedLanguage('dummy');
$classReflection = new \ReflectionClass($subject);
$reflectionProperty = $classReflection->getProperty('facts');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($subject, [
'de' => 12,
'en' => 1,
]);

self::assertTrue($subject->isGuilty('en'));
self::assertTrue($subject->isGuilty('de'));
self::assertFalse($subject->isGuilty('fr'));
}
}

0 comments on commit d46c8ca

Please sign in to comment.