Browse Source

Add lang file

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
d2bcd7ecec
  1. 22
      src/CrudMake.php
  2. 27
      src/stubs/lang.stub
  3. 1
      tests/CrudMakeCommandTest.php
  4. 46
      tests/Generators/LangGeneratorTest.php
  5. 2
      tests/TestCase.php

22
src/CrudMake.php

@ -12,6 +12,7 @@ class CrudMake extends Command
private $modelName;
private $pluralModelName;
private $lowerCasePluralModel;
private $singleModelName;
public function __construct(Filesystem $files)
{
@ -47,6 +48,7 @@ class CrudMake extends Command
$this->generateMigration();
$this->generateController();
$this->generateViews();
$this->generateLangFile();
$this->generateTests();
$this->info('CRUD files generated successfully!');
@ -58,6 +60,7 @@ class CrudMake extends Command
$this->pluralModelName = str_plural($this->modelName);
$this->lowerCasePluralModel = strtolower($this->pluralModelName);
$this->singleModelName = strtolower($this->modelName);
}
public function generateModel()
@ -97,6 +100,15 @@ class CrudMake extends Command
$this->info($this->modelName.' view files generated.');
}
public function generateLangFile()
{
$langPath = $this->makeDirectory(resource_path('lang/en'));
$this->files->put($langPath.'/'.$this->singleModelName.'.php', $this->getLangFileContent());
$this->info($this->singleModelName.' lang files generated.');
}
public function generateTests()
{
$featureTestPath = $this->makeDirectory(base_path('tests/Feature'));
@ -132,6 +144,12 @@ class CrudMake extends Command
return $this->replaceViewDummyStrings($stub)->replaceClass($stub);
}
public function getLangFileContent()
{
$stub = $this->files->get(__DIR__.'/stubs/lang.stub');
return $this->replaceViewDummyStrings($stub)->replaceClass($stub);
}
public function getFeatureTestContent()
{
$stub = $this->files->get(__DIR__.'/stubs/test.stub');
@ -157,7 +175,7 @@ class CrudMake extends Command
{
$stub = str_replace(
['master', 'Master'],
[strtolower($this->modelName), $this->modelName],
[$this->singleModelName, $this->modelName],
$stub
);
@ -201,7 +219,7 @@ class CrudMake extends Command
{
$stub = str_replace(
['Master', 'master', 'masters'],
[$this->modelName, strtolower($this->modelName), $this->lowerCasePluralModel],
[$this->modelName, $this->singleModelName, $this->lowerCasePluralModel],
$stub
);

27
src/stubs/lang.stub

@ -0,0 +1,27 @@
<?php
return [
// Labels
'item' => 'Master',
'list' => 'Master List',
'search' => 'Search Master',
'not_found' => 'Master not found.',
'empty' => 'Master is empty.',
'back_to_show' => 'Back to Master Detail',
'back_to_index' => 'Back to Master List',
// Actions
'create' => 'Create new Master',
'created' => 'Create new Master succeded.',
'edit' => 'Edit Master',
'update' => 'Update Master',
'updated' => 'Update Master succeded.',
'delete' => 'Delete Master',
'delete_confirm' => 'Are you sure to delete this Master?',
'deleted' => 'Delete Master succeded.',
'undeleted' => 'Master not deleted.',
// Attributes
'name' => 'Master Name',
'description' => 'Master Description',
];

1
tests/CrudMakeCommandTest.php

@ -17,6 +17,7 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$this->tableName}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$this->tableName}/forms.blade.php"));
$this->assertFileExists(resource_path("lang/en/{$this->singleModelName}.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$this->pluralModelName}Test.php"));
$this->assertFileExists(base_path("tests/Unit/Models/{$this->modelName}Test.php"));
}

46
tests/Generators/LangGeneratorTest.php

@ -0,0 +1,46 @@
<?php
namespace Tests\Generators;
use Tests\TestCase;
class LangGeneratorTest extends TestCase
{
/** @test */
public function it_creates_correct_model_lang_content()
{
$this->artisan('make:crud', ['name' => $this->modelName, '--no-interaction' => true]);
$langPath = resource_path('lang/en/'.$this->singleModelName.'.php');
$this->assertFileExists($langPath);
$langFileContent = "<?php
return [
// Labels
'item' => 'Item',
'list' => 'Item List',
'search' => 'Search Item',
'not_found' => 'Item not found.',
'empty' => 'Item is empty.',
'back_to_show' => 'Back to Item Detail',
'back_to_index' => 'Back to Item List',
// Actions
'create' => 'Create new Item',
'created' => 'Create new Item succeded.',
'edit' => 'Edit Item',
'update' => 'Update Item',
'updated' => 'Update Item succeded.',
'delete' => 'Delete Item',
'delete_confirm' => 'Are you sure to delete this Item?',
'deleted' => 'Delete Item succeded.',
'undeleted' => 'Item not deleted.',
// Attributes
'title' => 'Item Title',
'body' => 'Item Content',
];
";
$this->assertEquals($langFileContent, file_get_contents($langPath));
}
}

2
tests/TestCase.php

@ -9,6 +9,7 @@ abstract class TestCase extends BaseTestCase
protected $modelName;
protected $pluralModelName;
protected $tableName;
protected $singleModelName;
public function setUp()
{
@ -17,6 +18,7 @@ abstract class TestCase extends BaseTestCase
$this->pluralModelName = str_plural($this->modelName);
$this->tableName = strtolower($this->pluralModelName);
$this->singleModelName = strtolower($this->modelName);
}
public function tearDown()

Loading…
Cancel
Save