diff --git a/src/stubs/resources/views/simple/index-formfield.stub b/src/stubs/resources/views/simple/index-formfield.stub index b602cbe..79d78ff 100644 --- a/src/stubs/resources/views/simple/index-formfield.stub +++ b/src/stubs/resources/views/simple/index-formfield.stub @@ -39,12 +39,12 @@ {{ $singleMstr->description }} @can('update', $singleMstr) - {!! link_to_route( + {{ link_to_route( 'masters.index', __('app.edit'), ['action' => 'edit', 'id' => $singleMstr->id] + Request::only('page', 'q'), ['id' => 'edit-master-'.$singleMstr->id] - ) !!} + ) }} @endcan diff --git a/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php b/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php index 8891e9d..afec724 100644 --- a/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php +++ b/tests/CommandOptions/SimpleCrudFormfieldOptionsTest.php @@ -10,10 +10,7 @@ class SimpleCrudFormfieldOptionsTest extends TestCase /** @test */ public function it_can_generate_views_with_formfield_for_simple_crud() { - $this->artisan('make:crud-simple', [ - 'name' => $this->model_name, - '--formfield' => true, - ]); + $this->artisan('make:crud-simple', ['name' => $this->model_name, '--formfield' => true]); $this->assertNotContains("{$this->model_name} model already exists.", app(Kernel::class)->output()); @@ -35,4 +32,152 @@ class SimpleCrudFormfieldOptionsTest extends TestCase $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_formfield() + { + $this->artisan('make:crud-simple', ['name' => $this->model_name, '--formfield' => 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') +

+
+ @can('create', new {$this->full_model_name}) + {{ link_to_route('{$this->table_name}.index', __('{$this->lang_name}.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }} + @endcan +
+ {{ __('{$this->lang_name}.list') }} + {{ __('app.total') }} : {{ \${$this->collection_model_var_name}->total() }} {{ __('{$this->lang_name}.{$this->lang_name}') }} +

+
+
+
+
+ {{ Form::open(['method' => 'get', 'class' => 'form-inline']) }} + {!! FormField::text('q', ['label' => __('{$this->lang_name}.search'), 'placeholder' => __('{$this->lang_name}.search_text'), 'class' => 'input-sm']) !!} + {{ Form::submit(__('{$this->lang_name}.search'), ['class' => 'btn btn-sm']) }} + {{ link_to_route('{$this->table_name}.index', __('app.reset')) }} + {{ Form::close() }} +
+ + + + + + + + + + + @foreach(\${$this->collection_model_var_name} as \$key => \${$this->single_model_var_name}) + + + + + + + @endforeach + +
{{ __('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 }}{{ \${$this->single_model_var_name}->description }} + @can('update', \${$this->single_model_var_name}) + {{ link_to_route( + '{$this->table_name}.index', + __('app.edit'), + ['action' => 'edit', 'id' => \${$this->single_model_var_name}->id] + Request::only('page', 'q'), + ['id' => 'edit-{$this->lang_name}-'.\${$this->single_model_var_name}->id] + ) }} + @endcan +
+
{{ \${$this->collection_model_var_name}->appends(Request::except('page'))->render() }}
+
+
+
+ @if(Request::has('action')) + @include('{$this->table_name}.forms') + @endif +
+
+@endsection +"; + $this->assertEquals($indexViewContent, file_get_contents($indexViewPath)); + } + + /** @test */ + public function it_creates_correct_forms_view_content_with_formfield() + { + $this->artisan('make:crud-simple', ['name' => $this->model_name, '--formfield' => true]); + + $formViewPath = resource_path("views/{$this->table_name}/forms.blade.php"); + $this->assertFileExists($formViewPath); + $formViewContent = "@if (Request::get('action') == 'create') +@can('create', new {$this->full_model_name}) + {{ Form::open(['route' => '{$this->table_name}.store']) }} + {!! FormField::text('name', ['required' => true, 'label' => __('{$this->lang_name}.name')]) !!} + {!! FormField::textarea('description', ['label' => __('{$this->lang_name}.description')]) !!} + {{ Form::submit(__('{$this->lang_name}.create'), ['class' => 'btn btn-success']) }} + {{ link_to_route('{$this->table_name}.index', __('app.cancel'), [], ['class' => 'btn btn-default']) }} + {{ Form::close() }} +@endcan +@endif +@if (Request::get('action') == 'edit' && \$editable{$this->model_name}) +@can('update', \$editable{$this->model_name}) + {{ Form::model(\$editable{$this->model_name}, ['route' => ['{$this->table_name}.update', \$editable{$this->model_name}], 'method' => 'patch']) }} + {!! FormField::text('name', ['required' => true, 'label' => __('{$this->lang_name}.name')]) !!} + {!! FormField::textarea('description', ['label' => __('{$this->lang_name}.description')]) !!} + @if (request('q')) + {{ Form::hidden('q', request('q')) }} + @endif + @if (request('page')) + {{ Form::hidden('page', request('page')) }} + @endif + {{ Form::submit(__('{$this->lang_name}.update'), ['class' => 'btn btn-success']) }} + {{ link_to_route('{$this->table_name}.index', __('app.cancel'), Request::only('page', 'q'), ['class' => 'btn btn-default']) }} + @can('delete', \$editable{$this->model_name}) + {{ link_to_route( + '{$this->table_name}.index', + __('app.delete'), + ['action' => 'delete', 'id' => \$editable{$this->model_name}->id] + Request::only('page', 'q'), + ['id' => 'del-{$this->lang_name}-'.\$editable{$this->model_name}->id, 'class' => 'btn btn-danger pull-right'] + ) }} + @endcan + {{ Form::close() }} +@endcan +@endif +@if (Request::get('action') == 'delete' && \$editable{$this->model_name}) +@can('delete', \$editable{$this->model_name}) +
+

{{ __('{$this->lang_name}.delete') }}

+
+ +

{{ \$editable{$this->model_name}->name }}

+ +

{{ \$editable{$this->model_name}->description }}

+ {!! \$errors->first('{$this->lang_name}_id', ':message') !!} +
+
+
{{ __('{$this->lang_name}.delete_confirm') }}
+
+ {!! FormField::delete( + ['route' => ['{$this->table_name}.destroy', \$editable{$this->model_name}]], + __('app.delete_confirm_button'), + ['class'=>'btn btn-danger'], + [ + '{$this->lang_name}_id' => \$editable{$this->model_name}->id, + 'page' => request('page'), + 'q' => request('q'), + ] + ) !!} + {{ link_to_route('{$this->table_name}.index', __('app.cancel'), Request::only('page', 'q'), ['class' => 'btn btn-default']) }} +
+
+@endcan +@endif +"; + $this->assertEquals($formViewContent, file_get_contents($formViewPath)); + } }