Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
7adf7392
Unverified
Commit
7adf7392
authored
Jul 18, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Testing the eloquent translation repository
parent
d8175f24
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
2 deletions
+74
-2
BaseTranslationTest.php
Modules/Translation/Tests/BaseTranslationTest.php
+4
-0
EloquentTranslationRepositoryTest.php
...s/Translation/Tests/EloquentTranslationRepositoryTest.php
+70
-2
No files found.
Modules/Translation/Tests/BaseTranslationTest.php
View file @
7adf7392
...
...
@@ -44,6 +44,10 @@ abstract class BaseTranslationTest extends TestCase
'prefix'
=>
''
,
));
$app
[
'config'
]
->
set
(
'translatable.locales'
,
[
'en'
,
'fr'
]);
$app
[
'config'
]
->
set
(
'laravellocalization.supportedLocales'
,
[
'en'
=>
[],
'fr'
=>
[],
]);
}
private
function
resetDatabase
()
...
...
Modules/Translation/Tests/EloquentTranslationRepositoryTest.php
View file @
7adf7392
...
...
@@ -2,6 +2,7 @@
namespace
Modules\Translation\Tests
;
use
Modules\Translation\Entities\Translation
;
use
Modules\Translation\Repositories\TranslationRepository
;
class
EloquentTranslationRepositoryTest
extends
BaseTranslationTest
...
...
@@ -18,8 +19,75 @@ class EloquentTranslationRepositoryTest extends BaseTranslationTest
}
/** @test */
public
function
it_
is_true
()
public
function
it_
stores_translations_for_locale_and_key
()
{
$this
->
assertTrue
(
true
);
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'en'
,
'user::index.show'
,
'my key'
);
$this
->
assertCount
(
1
,
$this
->
translation
->
all
());
}
/** @test */
public
function
it_finds_a_translation_value_by_key_and_locale
()
{
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'en'
,
'user::index.show'
,
'my key'
);
$this
->
assertEquals
(
'my key'
,
$this
->
translation
->
findByKeyAndLocale
(
'user::index.show'
,
'en'
));
}
/** @test */
public
function
it_returns_empty_string_if_no_db_match_found
()
{
$this
->
assertEquals
(
''
,
$this
->
translation
->
findByKeyAndLocale
(
'user::index.show'
,
'en'
));
$this
->
assertEquals
(
''
,
$this
->
translation
->
findByKeyAndLocale
(
'user::index.show'
,
'fr'
));
}
/** @test */
public
function
it_finds_a_translation_by_key
()
{
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'en'
,
'user::index.show'
,
'my key'
);
$translation
=
$this
->
translation
->
findTranslationByKey
(
'user::index.show'
);
$this
->
assertInstanceOf
(
Translation
::
class
,
$translation
);
$this
->
assertEquals
(
'user::index.show'
,
$translation
->
key
);
$this
->
assertEquals
(
'my key'
,
$translation
->
translate
(
'en'
)
->
value
);
}
/** @test */
public
function
it_formats_all_translation_for_gui
()
{
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'en'
,
'user::index.show'
,
'Show user'
);
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'en'
,
'user::index.update'
,
'Update user'
);
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'fr'
,
'user::index.show'
,
'Voir user'
);
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'fr'
,
'user::index.update'
,
'Mettre à jour user'
);
$expected
=
[
'en'
=>
[
'user::index.show'
=>
'Show user'
,
'user::index.update'
=>
'Update user'
,
],
'fr'
=>
[
'user::index.show'
=>
'Voir user'
,
'user::index.update'
=>
'Mettre à jour user'
,
],
];
$this
->
assertEquals
(
$expected
,
$this
->
translation
->
allFormatted
());
}
/** @test */
public
function
it_gets_all_translations_for_group_namespace_and_locale
()
{
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'en'
,
'user::index.show'
,
'Show user'
);
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'en'
,
'user::index.update'
,
'Update user'
);
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'fr'
,
'user::index.show'
,
'Voir user'
);
$this
->
translation
->
saveTranslationForLocaleAndKey
(
'fr'
,
'user::index.update'
,
'Mettre à jour user'
);
$expected
=
[
'show'
=>
'Show user'
,
'update'
=>
'Update user'
,
];
$this
->
assertEquals
(
$expected
,
$this
->
translation
->
getTranslationsForGroupAndNamespace
(
'en'
,
'index'
,
'user'
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment