diff --git a/src/Generators/ShowViewGenerator.php b/src/Generators/ShowViewGenerator.php index 11f10b7..7454aaf 100644 --- a/src/Generators/ShowViewGenerator.php +++ b/src/Generators/ShowViewGenerator.php @@ -28,6 +28,10 @@ class ShowViewGenerator extends BaseGenerator $stubName .= '-formfield'; } + if ($this->command->option('bs3')) { + $stubName .= '-bs3'; + } + return $this->replaceStubString($this->getStubFileContent($stubName)); } } diff --git a/tests/CommandOptions/FullCrudBs3OptionsTest.php b/tests/CommandOptions/FullCrudBs3OptionsTest.php new file mode 100644 index 0000000..b231cec --- /dev/null +++ b/tests/CommandOptions/FullCrudBs3OptionsTest.php @@ -0,0 +1,257 @@ +artisan('make:crud', ['name' => $this->model_name, '--bs3' => true]); + + $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); + + $this->assertFileExists(app_path($this->model_name.'.php')); + $this->assertFileExists(app_path("Http/Controllers/{$this->model_name}Controller.php")); + + $migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->table_name.'_table.php'); + $this->assertFileExists($migrationFilePath); + + $this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php")); + $this->assertFileExists(resource_path("views/{$this->table_name}/create.blade.php")); + $this->assertFileExists(resource_path("views/{$this->table_name}/edit.blade.php")); + $this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php")); + + $localeConfig = config('app.locale'); + $this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php")); + + $this->assertFileExists(base_path("routes/web.php")); + $this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php")); + $this->assertFileExists(database_path("factories/{$this->model_name}Factory.php")); + $this->assertFileExists(base_path("tests/Unit/Models/{$this->model_name}Test.php")); + $this->assertFileExists(base_path("tests/Feature/Manage{$this->model_name}Test.php")); + } + + /** @test */ + public function it_creates_correct_index_view_content_with_bootstrap3() + { + $this->artisan('make:crud', ['name' => $this->model_name, '--bs3' => true]); + + $indexViewPath = resource_path("views/{$this->table_name}/index.blade.php"); + $this->assertFileExists($indexViewPath); + $indexViewContent = "@extends('layouts.app') + +@section('title', __('{$this->lang_name}.list')) + +@section('content') +
| {{ __('app.table_no') }} | +{{ __('{$this->lang_name}.name') }} | +{{ __('{$this->lang_name}.description') }} | +{{ __('app.action') }} | +
|---|---|---|---|
| {{ \${$this->collection_model_var_name}->firstItem() + \$key }} | +{!! \${$this->single_model_var_name}->name_link !!} | +{{ \${$this->single_model_var_name}->description }} | ++ @can('view', \${$this->single_model_var_name}) + table_name}.show', \${$this->single_model_var_name}) }}\" id=\"show-{$this->lang_name}-{{ \${$this->single_model_var_name}->id }}\" class=\"btn btn-default btn-xs\">{{ __('app.show') }} + @endcan + | +
| {{ __('{$this->lang_name}.name') }} | {{ \${$this->single_model_var_name}->name }} |
| {{ __('{$this->lang_name}.description') }} | {{ \${$this->single_model_var_name}->description }} |
{{ \${$this->single_model_var_name}->name }}
+ +{{ \${$this->single_model_var_name}->description }}
+ {!! \$errors->first('{$this->lang_name}_id', ':message') !!} +