artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => 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}) table_name}.create') }}\" class=\"btn btn-success\">{{ __('{$this->lang_name}.create') }} @endcan

{{ __('{$this->lang_name}.list') }} {{ __('app.total') }} : {{ \${$this->collection_model_var_name}->total() }} {{ __('{$this->lang_name}.{$this->lang_name}') }}

lang_name}.search_text') }}\" name=\"q\" type=\"text\" id=\"q\" class=\"form-control mx-sm-2\" value=\"{{ request('q') }}\">
lang_name}.search') }}\" class=\"btn btn-secondary\"> table_name}.index') }}\" class=\"btn btn-link\">{{ __('app.reset') }}
@foreach(\${$this->collection_model_var_name} as \$key => \${$this->single_model_var_name}) @endforeach
{{ __('app.table_no') }} {{ __('{$this->lang_name}.title') }} {{ __('{$this->lang_name}.description') }} {{ __('app.action') }}
{{ \${$this->collection_model_var_name}->firstItem() + \$key }} {!! \${$this->single_model_var_name}->title_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 }}\">{{ __('app.show') }} @endcan
{{ \${$this->collection_model_var_name}->appends(Request::except('page'))->render() }}
@endsection "; $this->assertEquals($indexViewContent, file_get_contents($indexViewPath)); } /** @test */ public function it_creates_correct_show_view_content() { $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); $showFormViewPath = resource_path("views/{$this->table_name}/show.blade.php"); $this->assertFileExists($showFormViewPath); $showFormViewContent = "@extends('layouts.app') @section('title', __('{$this->lang_name}.detail')) @section('content')
{{ __('{$this->lang_name}.detail') }}
{{ __('{$this->lang_name}.title') }}{{ \${$this->single_model_var_name}->title }}
{{ __('{$this->lang_name}.description') }}{{ \${$this->single_model_var_name}->description }}
@endsection "; $this->assertEquals($showFormViewContent, file_get_contents($showFormViewPath)); } /** @test */ public function it_creates_correct_create_view_content() { $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); $createFormViewPath = resource_path("views/{$this->table_name}/create.blade.php"); $this->assertFileExists($createFormViewPath); $createFormViewContent = "@extends('layouts.app') @section('title', __('{$this->lang_name}.create')) @section('content')
{{ __('{$this->lang_name}.create') }}
table_name}.store') }}\" accept-charset=\"UTF-8\"> {{ csrf_field() }}
has('title') ? ' is-invalid' : '' }}\" name=\"title\" value=\"{{ old('title') }}\" required> {!! \$errors->first('title', ':message') !!}
{!! \$errors->first('description', ':message') !!}
@endsection "; $this->assertEquals($createFormViewContent, file_get_contents($createFormViewPath)); } /** @test */ public function it_creates_correct_edit_view_content() { $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); $editFormViewPath = resource_path("views/{$this->table_name}/edit.blade.php"); $this->assertFileExists($editFormViewPath); $editFormViewContent = "@extends('layouts.app') @section('title', __('{$this->lang_name}.edit')) @section('content')
@if (request('action') == 'delete' && \${$this->single_model_var_name}) @can('delete', \${$this->single_model_var_name})
{{ __('{$this->lang_name}.delete') }}

{{ \${$this->single_model_var_name}->title }}

{{ \${$this->single_model_var_name}->description }}

{!! \$errors->first('{$this->lang_name}_id', ':message') !!}

{{ __('{$this->lang_name}.delete_confirm') }}
table_name}.destroy', \${$this->single_model_var_name}) }}\" accept-charset=\"UTF-8\" onsubmit=\"return confirm("{{ __('app.delete_confirm') }}")\" class=\"del-form float-right\" style=\"display: inline;\"> {{ csrf_field() }} {{ method_field('delete') }} lang_name}_id\" type=\"hidden\" value=\"{{ \${$this->single_model_var_name}->id }}\">
table_name}.edit', \${$this->single_model_var_name}) }}\" class=\"btn btn-link\">{{ __('app.cancel') }}
@endcan @else
{{ __('{$this->lang_name}.edit') }}
table_name}.update', \${$this->single_model_var_name}) }}\" accept-charset=\"UTF-8\"> {{ csrf_field() }} {{ method_field('patch') }}
has('title') ? ' is-invalid' : '' }}\" name=\"title\" value=\"{{ old('title', \${$this->single_model_var_name}->title) }}\" required> {!! \$errors->first('title', ':message') !!}
{!! \$errors->first('description', ':message') !!}
@endif @endsection "; $this->assertEquals($editFormViewContent, file_get_contents($editFormViewPath)); } /** @test */ public function it_not_gives_warning_message_if_default_layout_view_does_exists() { $defaultLayoutView = config('simple-crud.default_layout_view'); $this->generateDefaultLayoutView($defaultLayoutView); $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); $this->assertDoesNotMatchRegularExpression("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output()); } /** @test */ public function it_gives_warning_message_if_default_layout_view_does_not_exists() { $this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]); $defaultLayoutView = config('simple-crud.default_layout_view'); $this->assertMatchesRegularExpression("/{$defaultLayoutView} view does not exists./", app(Kernel::class)->output()); } public function generateDefaultLayoutView($defaultLayoutView) { $dataViewPathArray = explode('.', $defaultLayoutView); $fileName = array_pop($dataViewPathArray); $defaultLayoutPath = resource_path('views/'.implode('/', $dataViewPathArray)); $files = app('Illuminate\Filesystem\Filesystem'); $files->makeDirectory($defaultLayoutPath); $files->put($defaultLayoutPath.'/'.$fileName.'.blade.php', ''); } }