Skip to content

Commit

Permalink
Fix test errors with translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Mar 18, 2020
1 parent 2171b55 commit 789c888
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 48 deletions.
41 changes: 1 addition & 40 deletions tests/integration/DashboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ public function setup(): void
{
parent::setUp();

// TODO -- disabled to fix error in Travis
//

$this->skipOnTravis();

$this->loadConfig('{$stubs}/modules/dashboard/twill.php'); /// commenting this line it start working
$this->loadConfig('{$stubs}/modules/dashboard/translatable.php'); /// commenting this line it start working
}

/**
Expand Down Expand Up @@ -62,39 +58,4 @@ public function testCanSearchString()
$result[0]['date']
);
}

/**
* Trying to debug those tests
*/

// public function testCanDisplayDashboard()
// {
// require $this->makeFileName('{$base}/routes/admin.php');
//
// dump(
// file_get_contents($this->makeFileName('{$base}/routes/admin.php'))
// );
//
// try {
// dump(route('admin.personnel.authors.index'));
// } catch (\Exception $e) {
// dump('route admin.personnel.authors.index NOT FOUND');
// }
//
// dump($this->getUriWithNames());
//
// $this->request('/twill')->assertStatus(200);
//
// $this->assertSee('Personnel');
// $this->assertSee('Categories');
//
// $this->request('/twill/personnel/authors')->assertStatus(200);
//
// $this->assertSee('Name');
// $this->assertSee('Languages');
// $this->assertSee('Mine');
// $this->assertSee('Add new');
//
// $this->request('/twill/categories')->assertStatus(200);
// }
}
20 changes: 12 additions & 8 deletions tests/integration/ModulesTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,21 @@ protected function assertNothingWrongHappened()

protected function loadConfig($file = null)
{
$config = require $this->makeFileName(
$file ?? '{$stubs}/modules/authors/twill.php'
);
if (blank($file) || Str::contains($file, 'twill.php')) {
$config = require $this->makeFileName(
$file ?? '{$stubs}/modules/authors/twill.php'
);

config(['twill' => $config + config('twill')]);
config(['twill' => $config + config('twill')]);
}

$config = require $this->makeFileName(
$file ?? '{$stubs}/modules/authors/translatable.php'
);
if (blank($file) || Str::contains($file, 'translatable.php')) {
$config = require $this->makeFileName(
$file ?? '{$stubs}/modules/authors/translatable.php'
);

config(['translatable' => $config]);
config(['translatable' => $config]);
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function configTwill($app)
$app['config']->set('twill.enabled.users-2fa', true);
$app['config']->set('twill.enabled.users-image', true);
$app['config']->set('twill.auth_login_redirect_path', '/twill');
$app['config']->set('translatable.locales', ['en', 'fr', 'pt-BR']);
}

/**
Expand Down
108 changes: 108 additions & 0 deletions tests/stubs/modules/dashboard/translatable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Application Locales
|--------------------------------------------------------------------------
|
| Contains an array with the applications available locales.
|
*/
'locales' => ['en', 'fr', 'pt-BR'],

/*
|--------------------------------------------------------------------------
| Locale separator
|--------------------------------------------------------------------------
|
| This is a string used to glue the language and the country when defining
| the available locales. Example: if set to '-', then the locale for
| colombian spanish will be saved as 'es-CO' into the database.
|
*/
'locale_separator' => '-',

/*
|--------------------------------------------------------------------------
| Default locale
|--------------------------------------------------------------------------
|
| As a default locale, Translatable takes the locale of Laravel's
| translator. If for some reason you want to override this,
| you can specify what default should be used here.
|
*/
'locale' => null,

/*
|--------------------------------------------------------------------------
| Use fallback
|--------------------------------------------------------------------------
|
| Determine if fallback locales are returned by default or not. To add
| more flexibility and configure this option per "translatable"
| instance, this value will be overridden by the property
| $useTranslationFallback when defined
|
*/
'use_fallback' => false,

/*
|--------------------------------------------------------------------------
| Use fallback per property
|--------------------------------------------------------------------------
|
| The property fallback feature will return the translated value of
| the fallback locale if the property is empty for the selected
| locale. Note that 'use_fallback' must be enabled.
|
*/
'use_property_fallback' => true,

/*
|--------------------------------------------------------------------------
| Fallback Locale
|--------------------------------------------------------------------------
|
| A fallback locale is the locale being used to return a translation
| when the requested translation is not existing. To disable it
| set it to false.
|
*/
'fallback_locale' => 'en',

/*
|--------------------------------------------------------------------------
| Translation Suffix
|--------------------------------------------------------------------------
|
| Defines the default 'Translation' class suffix. For example, if
| you want to use CountryTrans instead of CountryTranslation
| application, set this to 'Trans'.
|
*/
'translation_suffix' => 'Translation',

/*
|--------------------------------------------------------------------------
| Locale key
|--------------------------------------------------------------------------
|
| Defines the 'locale' field name, which is used by the
| translation model.
|
*/
'locale_key' => 'locale',

/*
|--------------------------------------------------------------------------
| Always load translations when converting to array
|--------------------------------------------------------------------------
| Setting this to false will have a performance improvement but will
| not return the translations when using toArray(), unless the
| translations relationship is already loaded.
|
*/
'to_array_always_loads_translations' => true,
];

0 comments on commit 789c888

Please sign in to comment.