forked from elaborate-code/jigsaw-localization
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vitor Mattos <[email protected]>
- Loading branch information
1 parent
b1df39a
commit fb9fd79
Showing
13 changed files
with
202 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
.idea | ||
.vscode | ||
.phpunit.result.cache | ||
.phpunit.cache | ||
build | ||
composer.lock | ||
coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./app</directory> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
executionOrder="depends,defects" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
displayDetailsOnTestsThatTriggerWarnings="true" | ||
failOnRisky="true" | ||
failOnWarning="true"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
<?php | ||
|
||
use ElaborateCode\JigsawLocalization\Mocks\PageMock; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Tests\TestCase; | ||
|
||
it('returns DEFAULT_LOCALE code', function () { | ||
expect([ | ||
current_path_locale((new PageMock)->setPath('/')), | ||
current_path_locale((new PageMock)->setPath('/blog')), | ||
]) | ||
->each | ||
->toBe(packageDefaultLocale()); | ||
}); | ||
final class CurrentPathLocaleTest extends TestCase | ||
{ | ||
#[DataProvider('providerLanguageCode')] | ||
public function testLanguageCode($path, $expected): void | ||
{ | ||
$this->pageData->setPath($path); | ||
$actual = current_path_locale($this->pageData); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
it('returns language code', function () { | ||
expect([ | ||
current_path_locale((new PageMock)->setPath('/es')), | ||
current_path_locale((new PageMock)->setPath('/es/blog')), | ||
]) | ||
->each | ||
->toBe('es'); | ||
}); | ||
|
||
it('returns language+region code', function () { | ||
expect([ | ||
current_path_locale((new PageMock)->setPath('/haw-US')), | ||
current_path_locale((new PageMock)->setPath('/haw-US/blog')), | ||
]) | ||
->each | ||
->toBe('haw-US'); | ||
}); | ||
public static function providerLanguageCode(): array | ||
{ | ||
return [ | ||
['/', packageDefaultLocale()], | ||
['/blog', packageDefaultLocale()], | ||
['/es', 'es'], | ||
['/es/blog', 'es'], | ||
['/raw-US', 'raw-US'], | ||
['/raw-US/blog', 'raw-US'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
<?php | ||
|
||
use ElaborateCode\JigsawLocalization\Mocks\PageMock; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Tests\TestCase; | ||
|
||
it('sets path on DEFAULT_LOCALE for partial path', function () { | ||
$page = new PageMock; | ||
final class LocalePathTest extends TestCase | ||
{ | ||
#[DataProvider('providerLocalePath')] | ||
public function testLocalePath(string $path, ?string $locale, string $expected) { | ||
$actual = locale_path($this->pageData, $path, $locale); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
expect(locale_path($page, 'blog'))->toBe('/blog'); | ||
}); | ||
|
||
it('sets path on locale for partial path', function () { | ||
$page = new PageMock; | ||
|
||
expect(locale_path($page, 'blog', 'ar'))->toBe('/ar/blog'); | ||
}); | ||
public static function providerLocalePath(): array | ||
{ | ||
return [ | ||
['blog', null, '/blog'], | ||
['blog', 'ar', '/ar/blog'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
<?php | ||
|
||
use ElaborateCode\JigsawLocalization\Mocks\PageMock; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Tests\TestCase; | ||
|
||
it('sets URL with base path on DEFAULT_LOCALE for partial path', function () { | ||
$this->app->config = collect(['baseUrl' => 'https://elaboratecode.com/packages']); | ||
final class LocaleUrlTest extends TestCase | ||
{ | ||
#[DataProvider('providerLocaleUrl')] | ||
public function testLocaleUrl(string $path, ?string $locale, string $expected): void | ||
{ | ||
$this->app->config = collect(['baseUrl' => 'https://elaboratecode.com/packages']); | ||
$actual = locale_url($this->pageData, $path, $locale); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
$page = new PageMock; | ||
|
||
expect(locale_url($page, 'blog'))->toBe('https://elaboratecode.com/packages/blog'); | ||
}); | ||
|
||
it('sets URL with base path on locale for partial path', function () { | ||
$this->app->config = collect(['baseUrl' => 'https://elaboratecode.com/packages']); | ||
|
||
$page = new PageMock; | ||
|
||
expect(locale_url($page, 'blog', 'ar'))->toBe('https://elaboratecode.com/packages/ar/blog'); | ||
}); | ||
public static function providerLocaleUrl(): array | ||
{ | ||
return [ | ||
['blog', null, 'https://elaboratecode.com/packages/blog'], | ||
['blog', 'ar', 'https://elaboratecode.com/packages/ar/blog'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
<?php | ||
|
||
use ElaborateCode\JigsawLocalization\Mocks\PageMock; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Tests\TestCase; | ||
|
||
it('translates', function () { | ||
$page = (new PageMock) | ||
->setLocalization([ | ||
'es' => [ | ||
'Cat' => 'Gato', | ||
], | ||
]); | ||
final class TransHelperTest extends TestCase | ||
{ | ||
#[DataProvider('provider__')] | ||
public function test__(string $text, ?string $locale, string $expected): void | ||
{ | ||
$this->pageData | ||
->setLocalization([ | ||
'es' => [ | ||
'Cat' => 'Gato', | ||
], | ||
]); | ||
$actual = __($this->pageData, $text, $locale); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
expect(__($page, 'Cat', 'es'))->toBe('Gato'); | ||
}); | ||
|
||
it('returns the given text when no translation is found', function () { | ||
$page = (new PageMock); | ||
|
||
expect(__($page, 'Dog', 'es'))->toBe('Dog'); | ||
}); | ||
public static function provider__(): array | ||
{ | ||
return [ | ||
['Cat', 'es', 'Gato'], | ||
['Dog', 'es', 'Dog'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
<?php | ||
|
||
use ElaborateCode\JigsawLocalization\Mocks\PageMock; | ||
|
||
test('path es => ar', function () { | ||
$page = (new PageMock)->setPath('/es/blog'); | ||
|
||
expect(translate_path($page, 'ar'))->toBe('/ar/blog'); | ||
}); | ||
|
||
test('path ar <=> fr-CA', function () { | ||
expect(translate_path((new PageMock)->setPath('/ar/blog'), 'fr-CA'))->toBe('/fr-CA/blog'); | ||
expect(translate_path((new PageMock)->setPath('/fr-CA/blog'), 'fr-CA'))->toBe('/fr-CA/blog'); | ||
}); | ||
|
||
test('path ar <=> haw-US', function () { | ||
expect(translate_path((new PageMock)->setPath('/ar/blog'), 'haw-US'))->toBe('/haw-US/blog'); | ||
expect(translate_path((new PageMock)->setPath('/haw-US/blog'), 'haw-US'))->toBe('/haw-US/blog'); | ||
}); | ||
|
||
test('path haw-US <=> fr-CA', function () { | ||
expect(translate_path((new PageMock)->setPath('/fr-CA/blog'), 'haw-US'))->toBe('/haw-US/blog'); | ||
expect(translate_path((new PageMock)->setPath('/haw-US/blog'), 'fr-CA'))->toBe('/fr-CA/blog'); | ||
}); | ||
|
||
test('path from DEFAULT_LOCALE', function () { | ||
expect(translate_path((new PageMock)->setPath('/blog'), 'ar'))->toBe('/ar/blog'); | ||
expect(translate_path((new PageMock)->setPath('/blog'), 'en-UK'))->toBe('/en-UK/blog'); | ||
expect(translate_path((new PageMock)->setPath('/blog'), 'haw-US'))->toBe('/haw-US/blog'); | ||
expect(translate_path((new PageMock)->setPath('/blog'), packageDefaultLocale()))->toBe('/blog'); | ||
}); | ||
|
||
test('path to DEFAULT_LOCALE', function () { | ||
expect([ | ||
translate_path((new PageMock)->setPath('/ar/blog')), | ||
translate_path((new PageMock)->setPath('/en-UK/blog')), | ||
translate_path((new PageMock)->setPath('/haw-US/blog')), | ||
translate_path((new PageMock)->setPath('/blog')), | ||
]) | ||
->each | ||
->toBe('/blog'); | ||
}); | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Tests\TestCase; | ||
|
||
final class TranslatePathTest extends TestCase | ||
{ | ||
#[DataProvider('providerTranslatePath')] | ||
public function testTranslatePath(string $path, ?string $locale, string $expected): void | ||
{ | ||
$this->pageData->setPath($path); | ||
$actual = translate_path($this->pageData, $locale); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
public static function providerTranslatePath(): array | ||
{ | ||
return [ | ||
['/es/blog', 'ar', '/ar/blog'], | ||
['/ar/blog', 'fr-CA', '/fr-CA/blog'], | ||
['/fr-CA/blog', 'fr-CA', '/fr-CA/blog'], | ||
['/ar/blog', 'haw-US', '/haw-US/blog'], | ||
['/haw-US/blog', 'haw-US', '/haw-US/blog'], | ||
['/fr-CA/blog', 'haw-US', '/haw-US/blog'], | ||
['/haw-US/blog', 'fr-CA', '/fr-CA/blog'], | ||
['/blog', 'ar', '/ar/blog'], | ||
['/blog', 'en-UK', '/en-UK/blog'], | ||
['/blog', 'haw-US', '/haw-US/blog'], | ||
['/blog', packageDefaultLocale(), '/blog'], | ||
['/ar/blog', null, '/blog'], | ||
['/en-UK/blog', null, '/blog'], | ||
['/haw-US/blog', null, '/blog'], | ||
['/blog', null, '/blog'], | ||
]; | ||
} | ||
} |
Oops, something went wrong.