diff --git a/src/CrudMake.php b/src/CrudMake.php index 13aac5e..9ccc543 100644 --- a/src/CrudMake.php +++ b/src/CrudMake.php @@ -179,12 +179,37 @@ class CrudMake extends Command { $langPath = $this->makeDirectory(resource_path('lang/en')); + $this->createAppLangFile($langPath); $this->generateFile($langPath.'/'.$this->modelNames['lang_name'].'.php', $this->getLangFileContent()); $this->info($this->modelNames['lang_name'].' lang files generated.'); } /** + * Generate lang/app.php file if it doesn't exists + * + * @param string $langPath Directory path of lang files + * @return void + */ + public function createAppLangFile($langPath) + { + if (! $this->files->exists($langPath.'/app.php')) { + $this->generateFile($langPath.'/app.php', $this->getAppLangFileContent()); + $this->info('lang/app.php generated.'); + } + } + + /** + * Get lang/app.php file content + * + * @return string + */ + public function getAppLangFileContent() + { + return $this->files->get(__DIR__.'/stubs/lang-app.stub'); + } + + /** * Generate model factory file * * @return void @@ -232,14 +257,15 @@ class CrudMake extends Command if (! $this->files->exists($testsPath.'/BrowserKitTest.php')) { $this->generateFile($testsPath.'/BrowserKitTest.php', $this->getBrowserKitBaseTestContent()); - } - $this->info('BrowserKitTest generated.'); + $this->info('BrowserKitTest generated.'); + } } /** * Generate API resource version route for CRUD Operation - * @return [type] [description] + * + * @return void */ public function generateResourceRoute() { diff --git a/src/stubs/lang-app.stub b/src/stubs/lang-app.stub new file mode 100644 index 0000000..e7f1080 --- /dev/null +++ b/src/stubs/lang-app.stub @@ -0,0 +1,19 @@ + '#', + 'total' => 'Total', + 'action' => 'Actions', + 'views' => 'Views', + 'downloads' => 'Downloads', + + // Actions + 'show' => 'View Detail', + 'edit' => 'Edit', + 'delete' => 'Delete', + 'cancel' => 'Cancel', + 'reset' => 'Reset', + 'delete_confirm' => 'Are you sure to delete this?', + 'delete_confirm_button' => 'YES, delete it!', +]; diff --git a/tests/Generators/LangGeneratorTest.php b/tests/Generators/LangGeneratorTest.php index 88ba84b..4f8a179 100644 --- a/tests/Generators/LangGeneratorTest.php +++ b/tests/Generators/LangGeneratorTest.php @@ -44,4 +44,34 @@ return [ "; $this->assertEquals($langFileContent, file_get_contents($langPath)); } + + /** @test */ + public function it_creates_app_lang_if_it_doesnt_exists() + { + $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); + + $langPath = resource_path('lang/en/app.php'); + $this->assertFileExists($langPath); + $appLangContent = " '#', + 'total' => 'Total', + 'action' => 'Actions', + 'views' => 'Views', + 'downloads' => 'Downloads', + + // Actions + 'show' => 'View Detail', + 'edit' => 'Edit', + 'delete' => 'Delete', + 'cancel' => 'Cancel', + 'reset' => 'Reset', + 'delete_confirm' => 'Are you sure to delete this?', + 'delete_confirm_button' => 'YES, delete it!', +]; +"; + $this->assertEquals($appLangContent, file_get_contents($langPath)); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 0642dfa..0479d00 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -39,6 +39,7 @@ abstract class TestCase extends BaseTestCase $this->removeFileOrDir(database_path('migrations')); $this->removeFileOrDir(database_path('factories')); $this->removeFileOrDir(resource_path('views/'.$this->table_name)); + $this->removeFileOrDir(resource_path("lang/en/app.php")); $this->removeFileOrDir(resource_path("lang/en/{$this->lang_name}.php")); $this->removeFileOrDir(base_path('routes')); $this->removeFileOrDir(base_path('tests/BrowserKitTest.php'));