Skip to content

Commit

Permalink
Merge pull request #44 from nafiesl/fix/lang_stubs
Browse files Browse the repository at this point in the history
Fix Lang Stubs and ModelFactoryGenerator
  • Loading branch information
nafiesl authored Nov 14, 2021
2 parents 7063469 + 63d9092 commit cf3ca8a
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 132 deletions.
4 changes: 2 additions & 2 deletions src/Generators/ModelFactoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function getContent(string $stubName)

$userModel = config('auth.providers.users.model');

if ('App\User' !== $userModel) {
$modelFactoryFileContent = str_replace('App\User', $userModel, $modelFactoryFileContent);
if ('App\Models\User' !== $userModel) {
$modelFactoryFileContent = str_replace('App\Models\User', $userModel, $modelFactoryFileContent);
}

if ($this->command->option('uuid')) {
Expand Down
20 changes: 10 additions & 10 deletions src/stubs/resources/lang/en/app.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

return [
// Labels
'table_no' => '#',
'total' => 'Total',
'action' => 'Actions',
'show_detail_title' => 'View :name :type detail',
'table_no' => '#',
'total' => 'Total',
'action' => 'Actions',
'show_detail_title' => 'View :title :type detail',

// Actions
'create' => 'Create',
'show' => 'View Detail',
'edit' => 'Edit',
'delete' => 'Delete',
'cancel' => 'Cancel',
'reset' => 'Reset',
'create' => 'Create',
'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!',
];
44 changes: 22 additions & 22 deletions src/stubs/resources/lang/en/master.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@

return [
// Labels
'master' => 'Master',
'list' => 'Master List',
'search' => 'Search Master',
'search_text' => 'Title ...',
'all' => 'All Master',
'select' => 'Select Master',
'detail' => 'Master Detail',
'not_found' => 'Master not found.',
'empty' => 'Master is empty.',
'back_to_show' => 'Back to Master Detail',
'master' => 'Master',
'list' => 'Master List',
'search' => 'Search Master',
'search_text' => 'Title ...',
'all' => 'All Master',
'select' => 'Select Master',
'detail' => 'Master Detail',
'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' => 'A new Master has been created.',
'show' => 'View Master Detail',
'edit' => 'Edit Master',
'update' => 'Update Master',
'updated' => 'Master data has been updated.',
'delete' => 'Delete Master',
'create' => 'Create new Master',
'created' => 'A new Master has been created.',
'show' => 'View Master Detail',
'edit' => 'Edit Master',
'update' => 'Update Master',
'updated' => 'Master data has been updated.',
'delete' => 'Delete Master',
'delete_confirm' => 'Are you sure to delete this Master?',
'deleted' => 'Master has been deleted.',
'undeleted' => 'Master not deleted.',
'undeleteable' => 'Master data cannot be deleted.',
'deleted' => 'Master has been deleted.',
'undeleted' => 'Master not deleted.',
'undeleteable' => 'Master data cannot be deleted.',

// Attributes
'title' => 'Master Title',
'description' => 'Master Description',
'title' => 'Master Title',
'description' => 'Master Description',
];
20 changes: 10 additions & 10 deletions src/stubs/resources/lang/id/app.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

return [
// Labels
'table_no' => '#',
'total' => 'Total',
'action' => 'Pilihan',
'show_detail_title' => 'Lihat detail :type :name',
'table_no' => '#',
'total' => 'Total',
'action' => 'Pilihan',
'show_detail_title' => 'Lihat detail :type :title',

// Actions
'create' => 'Input',
'show' => 'Lihat Detail',
'edit' => 'Edit',
'delete' => 'Hapus',
'cancel' => 'Batal',
'reset' => 'Reset',
'create' => 'Input',
'show' => 'Lihat Detail',
'edit' => 'Edit',
'delete' => 'Hapus',
'cancel' => 'Batal',
'reset' => 'Reset',
'delete_confirm' => 'Anda yakin akan menghapus?',
'delete_confirm_button' => 'YA, hapus saja!',
];
44 changes: 22 additions & 22 deletions src/stubs/resources/lang/id/master.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@

return [
// Labels
'master' => 'Master',
'list' => 'Daftar Master',
'search' => 'Cari Master',
'search_text' => 'Judul ...',
'all' => 'Semua Master',
'select' => 'Pilih Master',
'detail' => 'Detail Master',
'not_found' => 'Master tidak ditemukan',
'empty' => 'Belum ada Master',
'back_to_show' => 'Kembali ke detail Master',
'master' => 'Master',
'list' => 'Daftar Master',
'search' => 'Cari Master',
'search_text' => 'Judul ...',
'all' => 'Semua Master',
'select' => 'Pilih Master',
'detail' => 'Detail Master',
'not_found' => 'Master tidak ditemukan',
'empty' => 'Belum ada Master',
'back_to_show' => 'Kembali ke detail Master',
'back_to_index' => 'Kembali ke daftar Master',

// Actions
'create' => 'Input Master Baru',
'created' => 'Input Master baru telah berhasil.',
'show' => 'Lihat Detail Master',
'edit' => 'Edit Master',
'update' => 'Update Master',
'updated' => 'Update data Master telah berhasil.',
'delete' => 'Hapus Master',
'create' => 'Input Master Baru',
'created' => 'Input Master baru telah berhasil.',
'show' => 'Lihat Detail Master',
'edit' => 'Edit Master',
'update' => 'Update Master',
'updated' => 'Update data Master telah berhasil.',
'delete' => 'Hapus Master',
'delete_confirm' => 'Anda yakin akan menghapus Master ini?',
'deleted' => 'Hapus data Master telah berhasil.',
'undeleted' => 'Data Master gagal dihapus.',
'undeleteable' => 'Data Master tidak dapat dihapus.',
'deleted' => 'Hapus data Master telah berhasil.',
'undeleted' => 'Data Master gagal dihapus.',
'undeleteable' => 'Data Master tidak dapat dihapus.',

// Attributes
'title' => 'Judul Master',
'description' => 'Deskripsi Master',
'title' => 'Judul Master',
'description' => 'Deskripsi Master',
];
1 change: 1 addition & 0 deletions tests/CommandOptions/UuidOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function down()
/** @test */
public function it_creates_correct_model_factory_content_for_uuid_primary_key()
{
config(['auth.providers.users.model' => 'App\Models\User']);
$this->artisan('make:crud', ['name' => $this->model_name, '--uuid' => true, '--no-interaction' => true]);

$modelFactoryPath = database_path('factories/'.$this->model_name.'Factory.php');
Expand Down
128 changes: 64 additions & 64 deletions tests/Generators/LangGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ public function it_creates_correct_model_lang_content()
return [
// Labels
'{$this->lang_name}' => '{$displayModelName}',
'list' => '{$displayModelName} List',
'search' => 'Search {$displayModelName}',
'search_text' => 'Title ...',
'all' => 'All {$displayModelName}',
'select' => 'Select {$displayModelName}',
'detail' => '{$displayModelName} Detail',
'not_found' => '{$displayModelName} not found.',
'empty' => '{$displayModelName} is empty.',
'back_to_show' => 'Back to {$displayModelName} Detail',
'{$this->lang_name}' => '{$displayModelName}',
'list' => '{$displayModelName} List',
'search' => 'Search {$displayModelName}',
'search_text' => 'Title ...',
'all' => 'All {$displayModelName}',
'select' => 'Select {$displayModelName}',
'detail' => '{$displayModelName} Detail',
'not_found' => '{$displayModelName} not found.',
'empty' => '{$displayModelName} is empty.',
'back_to_show' => 'Back to {$displayModelName} Detail',
'back_to_index' => 'Back to {$displayModelName} List',
// Actions
'create' => 'Create new {$displayModelName}',
'created' => 'A new {$displayModelName} has been created.',
'show' => 'View {$displayModelName} Detail',
'edit' => 'Edit {$displayModelName}',
'update' => 'Update {$displayModelName}',
'updated' => '{$displayModelName} data has been updated.',
'delete' => 'Delete {$displayModelName}',
'create' => 'Create new {$displayModelName}',
'created' => 'A new {$displayModelName} has been created.',
'show' => 'View {$displayModelName} Detail',
'edit' => 'Edit {$displayModelName}',
'update' => 'Update {$displayModelName}',
'updated' => '{$displayModelName} data has been updated.',
'delete' => 'Delete {$displayModelName}',
'delete_confirm' => 'Are you sure to delete this {$displayModelName}?',
'deleted' => '{$displayModelName} has been deleted.',
'undeleted' => '{$displayModelName} not deleted.',
'undeleteable' => '{$displayModelName} data cannot be deleted.',
'deleted' => '{$displayModelName} has been deleted.',
'undeleted' => '{$displayModelName} not deleted.',
'undeleteable' => '{$displayModelName} data cannot be deleted.',
// Attributes
'title' => '{$displayModelName} Title',
'description' => '{$displayModelName} Description',
'title' => '{$displayModelName} Title',
'description' => '{$displayModelName} Description',
];
";
$this->assertEquals($langFileContent, file_get_contents($langPath));
Expand All @@ -67,34 +67,34 @@ public function it_creates_correct_model_lang_content_based_on_locale_config()
return [
// Labels
'{$this->lang_name}' => '{$displayModelName}',
'list' => 'Daftar {$displayModelName}',
'search' => 'Cari {$displayModelName}',
'search_text' => 'Judul ...',
'all' => 'Semua {$displayModelName}',
'select' => 'Pilih {$displayModelName}',
'detail' => 'Detail {$displayModelName}',
'not_found' => '{$displayModelName} tidak ditemukan',
'empty' => 'Belum ada {$displayModelName}',
'back_to_show' => 'Kembali ke detail {$displayModelName}',
'{$this->lang_name}' => '{$displayModelName}',
'list' => 'Daftar {$displayModelName}',
'search' => 'Cari {$displayModelName}',
'search_text' => 'Judul ...',
'all' => 'Semua {$displayModelName}',
'select' => 'Pilih {$displayModelName}',
'detail' => 'Detail {$displayModelName}',
'not_found' => '{$displayModelName} tidak ditemukan',
'empty' => 'Belum ada {$displayModelName}',
'back_to_show' => 'Kembali ke detail {$displayModelName}',
'back_to_index' => 'Kembali ke daftar {$displayModelName}',
// Actions
'create' => 'Input {$displayModelName} Baru',
'created' => 'Input {$displayModelName} baru telah berhasil.',
'show' => 'Lihat Detail {$displayModelName}',
'edit' => 'Edit {$displayModelName}',
'update' => 'Update {$displayModelName}',
'updated' => 'Update data {$displayModelName} telah berhasil.',
'delete' => 'Hapus {$displayModelName}',
'create' => 'Input {$displayModelName} Baru',
'created' => 'Input {$displayModelName} baru telah berhasil.',
'show' => 'Lihat Detail {$displayModelName}',
'edit' => 'Edit {$displayModelName}',
'update' => 'Update {$displayModelName}',
'updated' => 'Update data {$displayModelName} telah berhasil.',
'delete' => 'Hapus {$displayModelName}',
'delete_confirm' => 'Anda yakin akan menghapus {$displayModelName} ini?',
'deleted' => 'Hapus data {$displayModelName} telah berhasil.',
'undeleted' => 'Data {$displayModelName} gagal dihapus.',
'undeleteable' => 'Data {$displayModelName} tidak dapat dihapus.',
'deleted' => 'Hapus data {$displayModelName} telah berhasil.',
'undeleted' => 'Data {$displayModelName} gagal dihapus.',
'undeleteable' => 'Data {$displayModelName} tidak dapat dihapus.',
// Attributes
'title' => 'Judul {$displayModelName}',
'description' => 'Deskripsi {$displayModelName}',
'title' => 'Judul {$displayModelName}',
'description' => 'Deskripsi {$displayModelName}',
];
";
$this->assertEquals($langFileContent, file_get_contents($langPath));
Expand All @@ -113,18 +113,18 @@ public function it_creates_app_lang_if_it_doesnt_exists()
return [
// Labels
'table_no' => '#',
'total' => 'Total',
'action' => 'Actions',
'show_detail_title' => 'View :name :type detail',
'table_no' => '#',
'total' => 'Total',
'action' => 'Actions',
'show_detail_title' => 'View :title :type detail',
// Actions
'create' => 'Create',
'show' => 'View Detail',
'edit' => 'Edit',
'delete' => 'Delete',
'cancel' => 'Cancel',
'reset' => 'Reset',
'create' => 'Create',
'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!',
];
Expand All @@ -146,18 +146,18 @@ public function it_creates_app_lang_based_on_locale_if_stub_exists()
return [
// Labels
'table_no' => '#',
'total' => 'Total',
'action' => 'Pilihan',
'show_detail_title' => 'Lihat detail :type :name',
'table_no' => '#',
'total' => 'Total',
'action' => 'Pilihan',
'show_detail_title' => 'Lihat detail :type :title',
// Actions
'create' => 'Input',
'show' => 'Lihat Detail',
'edit' => 'Edit',
'delete' => 'Hapus',
'cancel' => 'Batal',
'reset' => 'Reset',
'create' => 'Input',
'show' => 'Lihat Detail',
'edit' => 'Edit',
'delete' => 'Hapus',
'cancel' => 'Batal',
'reset' => 'Reset',
'delete_confirm' => 'Anda yakin akan menghapus?',
'delete_confirm_button' => 'YA, hapus saja!',
];
Expand Down
6 changes: 4 additions & 2 deletions tests/Generators/ModelFactoryGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ModelFactoryGeneratorTest extends TestCase
/** @test */
public function it_creates_correct_model_factory_content()
{
config(['auth.providers.users.model' => 'App\Models\User']);
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);

$modelFactoryPath = database_path('factories/'.$this->model_name.'Factory.php');
Expand Down Expand Up @@ -52,6 +53,7 @@ public function it_creates_correct_model_factory_content_with_namespaced_model()
$modelPath = 'Entities/References';
$factoryNamespace = 'Entities\References';

config(['auth.providers.users.model' => 'App\Entities\Users\User']);
$this->artisan('make:crud-api', ['name' => $inputName, '--no-interaction' => true]);

$modelFactoryPath = database_path('factories/'.$inputName.'Factory.php');
Expand All @@ -60,7 +62,7 @@ public function it_creates_correct_model_factory_content_with_namespaced_model()
namespace Database\Factories\\{$factoryNamespace};
use App\Models\User;
use App\Entities\Users\User;
use {$fullModelName};
use Illuminate\Database\Eloquent\Factories\Factory;
Expand All @@ -83,7 +85,6 @@ public function definition()
$this->assertEquals($modelFactoryContent, file_get_contents($modelFactoryPath));
}


/** @test */
public function it_creates_model_factory_file_content_from_published_stub()
{
Expand All @@ -92,6 +93,7 @@ public function it_creates_model_factory_file_content_from_published_stub()
__DIR__.'/../stubs/database/factories/model-factory.stub',
base_path('stubs/simple-crud/database/factories/model-factory.stub')
);
config(['auth.providers.users.model' => 'App\Models\User']);
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);

$modelFactoryPath = database_path('factories/'.$this->model_name.'Factory.php');
Expand Down

0 comments on commit cf3ca8a

Please sign in to comment.