Skip to content

Commit

Permalink
tests: Update NegotiateTest
Browse files Browse the repository at this point in the history
  • Loading branch information
neznaika0 committed Dec 31, 2024
1 parent d921113 commit f868911
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/system/HTTP/NegotiateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CodeIgniter\HTTP\Exceptions\HTTPException;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
use Config\Feature;
use PHPUnit\Framework\Attributes\Group;

/**
Expand Down Expand Up @@ -111,11 +112,23 @@ public function testNegotiatesEncodingBasics(): void

public function testAcceptLanguageBasics(): void
{
$this->request->setHeader('Accept-Language', 'da, en-gb;q=0.8, en;q=0.7');
$this->request->setHeader('Accept-Language', 'da, en-gb, en-us;q=0.8, en;q=0.7');

$this->assertSame('da', $this->negotiate->language(['da', 'en']));
$this->assertSame('en-gb', $this->negotiate->language(['en-gb', 'en']));
$this->assertSame('en', $this->negotiate->language(['en']));

// Will find the first locale instead of "en-gb"
$this->assertSame('en-us', $this->negotiate->language(['en-us', 'en-gb', 'en']));
$this->assertSame('en', $this->negotiate->language(['en', 'en-us', 'en-gb']));

config(Feature::class)->simpleNegotiateLocale = false;

$this->assertSame('da', $this->negotiate->language(['da', 'en']));
$this->assertSame('en-gb', $this->negotiate->language(['en-gb', 'en']));
$this->assertSame('en', $this->negotiate->language(['en']));
$this->assertSame('en-gb', $this->negotiate->language(['en-us', 'en-gb', 'en']));
$this->assertSame('en-gb', $this->negotiate->language(['en', 'en-us', 'en-gb']));
}

/**
Expand All @@ -125,7 +138,17 @@ public function testAcceptLanguageMatchesBroadly(): void
{
$this->request->setHeader('Accept-Language', 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7');

$this->assertSame('fr', $this->negotiate->language(['fr', 'en']));
$this->assertSame('fr', $this->negotiate->language(['fr', 'fr-FR', 'en']));
$this->assertSame('fr-FR', $this->negotiate->language(['fr-FR', 'fr', 'en']));
$this->assertSame('fr-BE', $this->negotiate->language(['fr-BE', 'fr', 'en']));
$this->assertSame('en', $this->negotiate->language(['en', 'en-US']));

config(Feature::class)->simpleNegotiateLocale = false;

$this->assertSame('fr-FR', $this->negotiate->language(['fr', 'fr-FR', 'en']));
$this->assertSame('fr-FR', $this->negotiate->language(['fr-FR', 'fr', 'en']));
$this->assertSame('fr', $this->negotiate->language(['fr-BE', 'fr', 'en']));
$this->assertSame('en-US', $this->negotiate->language(['en', 'en-US']));
}

public function testBestMatchEmpty(): void
Expand Down

0 comments on commit f868911

Please sign in to comment.