Browse Source

Change order of model name replacements order

Remove unused import clas on test feature stub
Make generator tests to adopt modelName property of TestCase
tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
376d6471c1
  1. 6
      src/CrudMake.php
  2. 2
      src/stubs/test-feature.stub
  3. 42
      tests/Generators/ControllerGeneratorTest.php
  4. 82
      tests/Generators/FeatureTestGeneratorTest.php
  5. 36
      tests/Generators/LangGeneratorTest.php
  6. 6
      tests/Generators/MigrationGeneratorTest.php
  7. 4
      tests/Generators/ModelFactoryGeneratorTest.php
  8. 2
      tests/Generators/ModelGeneratorTest.php
  9. 8
      tests/Generators/ModelTestGeneratorTest.php
  10. 2
      tests/Generators/RouteWebGeneratorTest.php
  11. 72
      tests/Generators/ViewsGeneratorTest.php
  12. 2
      tests/TestCase.php

6
src/CrudMake.php

@ -27,7 +27,7 @@ class CrudMake extends Command
* *
* @var array * @var array
*/ */
private $stubModelNames = ['Master', 'Masters', 'master', 'masters'];
private $stubModelNames = ['Masters', 'Master', 'masters', 'master'];
/** /**
* Construct CrudMake class * Construct CrudMake class
@ -85,10 +85,10 @@ class CrudMake extends Command
$modelName = $this->argument('name'); $modelName = $this->argument('name');
$this->modelNames = [ $this->modelNames = [
'model_name' => $modelName,
'plural_model_name' => str_plural($modelName), 'plural_model_name' => str_plural($modelName),
'lowercase_single_model_name' => strtolower($modelName),
'model_name' => $modelName,
'lowercase_plural_model_name' => strtolower(str_plural($modelName)), 'lowercase_plural_model_name' => strtolower(str_plural($modelName)),
'lowercase_single_model_name' => strtolower($modelName),
]; ];
} }

2
src/stubs/test-feature.stub

@ -4,8 +4,6 @@ namespace Tests\Feature;
use App\Master; use App\Master;
use Tests\BrowserKitTest as TestCase; use Tests\BrowserKitTest as TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
class ManageMastersTest extends TestCase class ManageMastersTest extends TestCase

42
tests/Generators/ControllerGeneratorTest.php

@ -16,32 +16,32 @@ class ControllerGeneratorTest extends TestCase
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Item;
use App\\{$this->modelName};
use Illuminate\Http\Request; use Illuminate\Http\Request;
class ItemsController extends Controller
class {$this->pluralModelName}Controller extends Controller
{ {
/** /**
* Display a listing of the item.
* Display a listing of the {$this->singleModelName}.
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function index() public function index()
{ {
\$editableItem = null;
\$items = Item::where(function (\$query) {
\$editable{$this->modelName} = null;
\${$this->tableName} = {$this->modelName}::where(function (\$query) {
\$query->where('name', 'like', '%'.request('q').'%'); \$query->where('name', 'like', '%'.request('q').'%');
})->paginate(25); })->paginate(25);
if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) {
\$editableItem = Item::find(request('id'));
\$editable{$this->modelName} = {$this->modelName}::find(request('id'));
} }
return view('items.index', compact('items', 'editableItem'));
return view('{$this->tableName}.index', compact('{$this->tableName}', 'editable{$this->modelName}'));
} }
/** /**
* Store a newly created item in storage.
* Store a newly created {$this->singleModelName} in storage.
* *
* @param \Illuminate\Http\Request \$request * @param \Illuminate\Http\Request \$request
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
@ -53,19 +53,19 @@ class ItemsController extends Controller
'description' => 'nullable|max:255', 'description' => 'nullable|max:255',
]); ]);
Item::create(\$request->only('name', 'description'));
{$this->modelName}::create(\$request->only('name', 'description'));
return redirect()->route('items.index');
return redirect()->route('{$this->tableName}.index');
} }
/** /**
* Update the specified item in storage.
* Update the specified {$this->singleModelName} in storage.
* *
* @param \Illuminate\Http\Request \$request * @param \Illuminate\Http\Request \$request
* @param \App\Item \$item
* @param \App\\{$this->modelName} \${$this->singleModelName}
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function update(Request \$request, Item \$item)
public function update(Request \$request, {$this->modelName} \${$this->singleModelName})
{ {
\$this->validate(\$request, [ \$this->validate(\$request, [
'name' => 'required|max:60', 'name' => 'required|max:60',
@ -74,27 +74,27 @@ class ItemsController extends Controller
\$routeParam = request()->only('page', 'q'); \$routeParam = request()->only('page', 'q');
\$item = \$item->update(\$request->only('name', 'description'));
\${$this->singleModelName} = \${$this->singleModelName}->update(\$request->only('name', 'description'));
return redirect()->route('items.index', \$routeParam);
return redirect()->route('{$this->tableName}.index', \$routeParam);
} }
/** /**
* Remove the specified item from storage.
* Remove the specified {$this->singleModelName} from storage.
* *
* @param \App\Item \$item
* @param \App\\{$this->modelName} \${$this->singleModelName}
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function destroy(Item \$item)
public function destroy({$this->modelName} \${$this->singleModelName})
{ {
\$this->validate(request(), [ \$this->validate(request(), [
'item_id' => 'required',
'{$this->singleModelName}_id' => 'required',
]); ]);
\$routeParam = request()->only('page', 'q'); \$routeParam = request()->only('page', 'q');
if (request('item_id') == \$item->id && \$item->delete()) {
return redirect()->route('items.index', \$routeParam);
if (request('{$this->singleModelName}_id') == \${$this->singleModelName}->id && \${$this->singleModelName}->delete()) {
return redirect()->route('{$this->tableName}.index', \$routeParam);
} }
return back(); return back();

82
tests/Generators/FeatureTestGeneratorTest.php

@ -53,89 +53,87 @@ abstract class BrowserKitTest extends BaseTestCase
namespace Tests\Feature; namespace Tests\Feature;
use App\Item;
use App\\{$this->modelName};
use Tests\BrowserKitTest as TestCase; use Tests\BrowserKitTest as TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
class ManageItemsTest extends TestCase
class Manage{$this->pluralModelName}Test extends TestCase
{ {
use DatabaseMigrations; use DatabaseMigrations;
/** @test */ /** @test */
public function user_can_see_item_list_in_item_index_page()
public function user_can_see_{$this->singleModelName}_list_in_{$this->singleModelName}_index_page()
{ {
\$item1 = factory(Item::class)->create(['name' => 'Testing name', 'description' => 'Testing 123']);
\$item2 = factory(Item::class)->create(['name' => 'Testing name', 'description' => 'Testing 456']);
\${$this->singleModelName}1 = factory({$this->modelName}::class)->create(['name' => 'Testing name', 'description' => 'Testing 123']);
\${$this->singleModelName}2 = factory({$this->modelName}::class)->create(['name' => 'Testing name', 'description' => 'Testing 456']);
\$this->loginAsUser(); \$this->loginAsUser();
\$this->visit(route('items.index'));
\$this->see(\$item1->name);
\$this->see(\$item2->name);
\$this->visit(route('{$this->tableName}.index'));
\$this->see(\${$this->singleModelName}1->name);
\$this->see(\${$this->singleModelName}2->name);
} }
/** @test */ /** @test */
public function user_can_create_a_item()
public function user_can_create_a_{$this->singleModelName}()
{ {
\$this->loginAsUser(); \$this->loginAsUser();
\$this->visit(route('items.index'));
\$this->visit(route('{$this->tableName}.index'));
\$this->click(trans('item.create'));
\$this->seePageIs(route('items.index', ['action' => 'create']));
\$this->click(trans('{$this->singleModelName}.create'));
\$this->seePageIs(route('{$this->tableName}.index', ['action' => 'create']));
\$this->type('Item 1 name', 'name');
\$this->type('Item 1 description', 'description');
\$this->press(trans('item.create'));
\$this->type('{$this->modelName} 1 name', 'name');
\$this->type('{$this->modelName} 1 description', 'description');
\$this->press(trans('{$this->singleModelName}.create'));
\$this->seePageIs(route('items.index'));
\$this->seePageIs(route('{$this->tableName}.index'));
\$this->seeInDatabase('items', [
'name' => 'Item 1 name',
'description' => 'Item 1 description',
\$this->seeInDatabase('{$this->tableName}', [
'name' => '{$this->modelName} 1 name',
'description' => '{$this->modelName} 1 description',
]); ]);
} }
/** @test */ /** @test */
public function user_can_edit_a_item_within_search_query()
public function user_can_edit_a_{$this->singleModelName}_within_search_query()
{ {
\$this->loginAsUser(); \$this->loginAsUser();
\$item = factory(Item::class)->create(['name' => 'Testing 123']);
\${$this->singleModelName} = factory({$this->modelName}::class)->create(['name' => 'Testing 123']);
\$this->visit(route('items.index', ['q' => '123']));
\$this->click('edit-item-'.\$item->id);
\$this->seePageIs(route('items.index', ['action' => 'edit', 'id' => \$item->id, 'q' => '123']));
\$this->visit(route('{$this->tableName}.index', ['q' => '123']));
\$this->click('edit-{$this->singleModelName}-'.\${$this->singleModelName}->id);
\$this->seePageIs(route('{$this->tableName}.index', ['action' => 'edit', 'id' => \${$this->singleModelName}->id, 'q' => '123']));
\$this->type('Item 1 name', 'name');
\$this->type('Item 1 description', 'description');
\$this->press(trans('item.update'));
\$this->type('{$this->modelName} 1 name', 'name');
\$this->type('{$this->modelName} 1 description', 'description');
\$this->press(trans('{$this->singleModelName}.update'));
\$this->seePageIs(route('items.index', ['q' => '123']));
\$this->seePageIs(route('{$this->tableName}.index', ['q' => '123']));
\$this->seeInDatabase('items', [
'name' => 'Item 1 name',
'description' => 'Item 1 description',
\$this->seeInDatabase('{$this->tableName}', [
'name' => '{$this->modelName} 1 name',
'description' => '{$this->modelName} 1 description',
]); ]);
} }
/** @test */ /** @test */
public function user_can_delete_a_item()
public function user_can_delete_a_{$this->singleModelName}()
{ {
\$this->loginAsUser(); \$this->loginAsUser();
\$item = factory(Item::class)->create();
\${$this->singleModelName} = factory({$this->modelName}::class)->create();
\$this->visit(route('items.index', [\$item->id]));
\$this->click('del-item-'.\$item->id);
\$this->seePageIs(route('items.index', ['action' => 'delete', 'id' => \$item->id]));
\$this->visit(route('{$this->tableName}.index', [\${$this->singleModelName}->id]));
\$this->click('del-{$this->singleModelName}-'.\${$this->singleModelName}->id);
\$this->seePageIs(route('{$this->tableName}.index', ['action' => 'delete', 'id' => \${$this->singleModelName}->id]));
\$this->seeInDatabase('items', [
'id' => \$item->id,
\$this->seeInDatabase('{$this->tableName}', [
'id' => \${$this->singleModelName}->id,
]); ]);
\$this->press(trans('app.delete_confirm_button')); \$this->press(trans('app.delete_confirm_button'));
\$this->dontSeeInDatabase('items', [
'id' => \$item->id,
\$this->dontSeeInDatabase('{$this->tableName}', [
'id' => \${$this->singleModelName}->id,
]); ]);
} }
} }

36
tests/Generators/LangGeneratorTest.php

@ -17,28 +17,28 @@ class LangGeneratorTest extends TestCase
return [ return [
// Labels // 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',
'{$this->singleModelName}' => '{$this->modelName}',
'list' => '{$this->modelName} List',
'search' => 'Search {$this->modelName}',
'not_found' => '{$this->modelName} not found.',
'empty' => '{$this->modelName} is empty.',
'back_to_show' => 'Back to {$this->modelName} Detail',
'back_to_index' => 'Back to {$this->modelName} List',
// Actions // 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.',
'create' => 'Create new {$this->modelName}',
'created' => 'Create new {$this->modelName} succeded.',
'edit' => 'Edit {$this->modelName}',
'update' => 'Update {$this->modelName}',
'updated' => 'Update {$this->modelName} succeded.',
'delete' => 'Delete {$this->modelName}',
'delete_confirm' => 'Are you sure to delete this {$this->modelName}?',
'deleted' => 'Delete {$this->modelName} succeded.',
'undeleted' => '{$this->modelName} not deleted.',
// Attributes // Attributes
'name' => 'Item Name',
'description' => 'Item Description',
'name' => '{$this->modelName} Name',
'description' => '{$this->modelName} Description',
]; ];
"; ";
$this->assertEquals($langFileContent, file_get_contents($langPath)); $this->assertEquals($langFileContent, file_get_contents($langPath));

6
tests/Generators/MigrationGeneratorTest.php

@ -19,7 +19,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
class CreateItemsTable extends Migration
class Create{$this->pluralModelName}Table extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.
@ -28,7 +28,7 @@ class CreateItemsTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('items', function (Blueprint \$table) {
Schema::create('{$this->tableName}', function (Blueprint \$table) {
\$table->increments('id'); \$table->increments('id');
\$table->string('name', 60); \$table->string('name', 60);
\$table->string('description')->nullable(); \$table->string('description')->nullable();
@ -43,7 +43,7 @@ class CreateItemsTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::dropIfExists('items');
Schema::dropIfExists('{$this->tableName}');
} }
} }
"; ";

4
tests/Generators/ModelFactoryGeneratorTest.php

@ -15,10 +15,10 @@ class ModelFactoryGeneratorTest extends TestCase
$this->assertFileExists($modelFactoryPath); $this->assertFileExists($modelFactoryPath);
$modelFactoryContent = "<?php $modelFactoryContent = "<?php
use App\Item;
use App\\{$this->modelName};
use Faker\Generator as Faker; use Faker\Generator as Faker;
\$factory->define(Item::class, function (Faker \$faker) {
\$factory->define({$this->modelName}::class, function (Faker \$faker) {
return [ return [
'name' => \$faker->word, 'name' => \$faker->word,

2
tests/Generators/ModelGeneratorTest.php

@ -19,7 +19,7 @@ namespace App;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class Item extends Model
class {$this->modelName} extends Model
{ {
protected \$fillable = ['name', 'description']; protected \$fillable = ['name', 'description'];
} }

8
tests/Generators/ModelTestGeneratorTest.php

@ -16,19 +16,19 @@ class ModelTestGeneratorTest extends TestCase
namespace Tests\Unit\Models; namespace Tests\Unit\Models;
use App\Item;
use App\\{$this->modelName};
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase; use Tests\TestCase;
class ItemTest extends TestCase
class {$this->modelName}Test extends TestCase
{ {
use DatabaseMigrations; use DatabaseMigrations;
/** @test */ /** @test */
public function it_has_name_attribute() public function it_has_name_attribute()
{ {
\$item = factory(Item::class)->create(['name' => 'Item 1 name']);
\$this->assertEquals('Item 1 name', \$item->name);
\${$this->singleModelName} = factory({$this->modelName}::class)->create(['name' => '{$this->modelName} 1 name']);
\$this->assertEquals('{$this->modelName} 1 name', \${$this->singleModelName}->name);
} }
} }
"; ";

2
tests/Generators/RouteWebGeneratorTest.php

@ -15,7 +15,7 @@ class RouteWebGeneratorTest extends TestCase
$this->assertFileExists($routeWebPath); $this->assertFileExists($routeWebPath);
$routeWebFileContent = "<?php $routeWebFileContent = "<?php
Route::apiResource('items', 'ItemsController');
Route::apiResource('{$this->tableName}', '{$this->pluralModelName}Controller');
"; ";
$this->assertEquals($routeWebFileContent, file_get_contents($routeWebPath)); $this->assertEquals($routeWebFileContent, file_get_contents($routeWebPath));
} }

72
tests/Generators/ViewsGeneratorTest.php

@ -15,64 +15,64 @@ class ViewsGeneratorTest extends TestCase
$this->assertFileExists($indexViewPath); $this->assertFileExists($indexViewPath);
$indexViewContent = "@extends('layouts.app') $indexViewContent = "@extends('layouts.app')
@section('title', trans('item.list'))
@section('title', trans('{$this->singleModelName}.list'))
@section('content') @section('content')
<div class=\"pull-right\"> <div class=\"pull-right\">
{{ link_to_route('items.index', trans('item.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }}
{{ link_to_route('{$this->tableName}.index', trans('{$this->singleModelName}.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }}
</div> </div>
<h3 class=\"page-header\"> <h3 class=\"page-header\">
{{ trans('item.list') }}
<small>{{ trans('app.total') }} : {{ \$items->total() }} {{ trans('item.item') }}</small>
{{ trans('{$this->singleModelName}.list') }}
<small>{{ trans('app.total') }} : {{ \${$this->tableName}->total() }} {{ trans('{$this->singleModelName}.{$this->singleModelName}') }}</small>
</h3> </h3>
<div class=\"row\"> <div class=\"row\">
<div class=\"col-md-8\"> <div class=\"col-md-8\">
<div class=\"panel panel-default table-responsive\"> <div class=\"panel panel-default table-responsive\">
<div class=\"panel-heading\"> <div class=\"panel-heading\">
{{ Form::open(['method' => 'get','class' => 'form-inline']) }} {{ Form::open(['method' => 'get','class' => 'form-inline']) }}
{!! FormField::text('q', ['value' => request('q'), 'label' => trans('item.search'), 'class' => 'input-sm']) !!}
{{ Form::submit(trans('item.search'), ['class' => 'btn btn-sm']) }}
{{ link_to_route('items.index', trans('app.reset')) }}
{!! FormField::text('q', ['value' => request('q'), 'label' => trans('{$this->singleModelName}.search'), 'class' => 'input-sm']) !!}
{{ Form::submit(trans('{$this->singleModelName}.search'), ['class' => 'btn btn-sm']) }}
{{ link_to_route('{$this->tableName}.index', trans('app.reset')) }}
{{ Form::close() }} {{ Form::close() }}
</div> </div>
<table class=\"table table-condensed\"> <table class=\"table table-condensed\">
<thead> <thead>
<tr> <tr>
<th class=\"text-center\">{{ trans('app.table_no') }}</th> <th class=\"text-center\">{{ trans('app.table_no') }}</th>
<th>{{ trans('item.name') }}</th>
<th>{{ trans('item.description') }}</th>
<th>{{ trans('{$this->singleModelName}.name') }}</th>
<th>{{ trans('{$this->singleModelName}.description') }}</th>
<th class=\"text-center\">{{ trans('app.action') }}</th> <th class=\"text-center\">{{ trans('app.action') }}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach(\$items as \$key => \$item)
@foreach(\${$this->tableName} as \$key => \${$this->singleModelName})
<tr> <tr>
<td class=\"text-center\">{{ \$items->firstItem() + \$key }}</td>
<td>{{ \$item->name }}</td>
<td>{{ \$item->description }}</td>
<td class=\"text-center\">{{ \${$this->tableName}->firstItem() + \$key }}</td>
<td>{{ \${$this->singleModelName}->name }}</td>
<td>{{ \${$this->singleModelName}->description }}</td>
<td class=\"text-center\"> <td class=\"text-center\">
{!! link_to_route( {!! link_to_route(
'items.index',
'{$this->tableName}.index',
trans('app.edit'), trans('app.edit'),
['action' => 'edit', 'id' => \$item->id] + Request::only('page', 'q'),
['id' => 'edit-item-' . \$item->id]
['action' => 'edit', 'id' => \${$this->singleModelName}->id] + Request::only('page', 'q'),
['id' => 'edit-{$this->singleModelName}-' . \${$this->singleModelName}->id]
) !!} | ) !!} |
{!! link_to_route( {!! link_to_route(
'items.index',
'{$this->tableName}.index',
trans('app.delete'), trans('app.delete'),
['action' => 'delete', 'id' => \$item->id] + Request::only('page', 'q'),
['id' => 'del-item-' . \$item->id]
['action' => 'delete', 'id' => \${$this->singleModelName}->id] + Request::only('page', 'q'),
['id' => 'del-{$this->singleModelName}-' . \${$this->singleModelName}->id]
) !!} ) !!}
</td> </td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
</table> </table>
<div class=\"panel-body\">{{ \$items->appends(Request::except('page'))->render() }}</div>
<div class=\"panel-body\">{{ \${$this->tableName}->appends(Request::except('page'))->render() }}</div>
</div> </div>
</div> </div>
<div class=\"col-md-4\"> <div class=\"col-md-4\">
@includeWhen(Request::has('action'), 'items.forms')
@includeWhen(Request::has('action'), '{$this->tableName}.forms')
</div> </div>
</div> </div>
@endsection @endsection
@ -88,15 +88,15 @@ class ViewsGeneratorTest extends TestCase
$formViewPath = resource_path("views/{$this->tableName}/forms.blade.php"); $formViewPath = resource_path("views/{$this->tableName}/forms.blade.php");
$this->assertFileExists($formViewPath); $this->assertFileExists($formViewPath);
$formViewContent = "@if (Request::get('action') == 'create') $formViewContent = "@if (Request::get('action') == 'create')
{!! Form::open(['route' => 'items.store']) !!}
{!! Form::open(['route' => '{$this->tableName}.store']) !!}
{!! FormField::text('name', ['required' => true]) !!} {!! FormField::text('name', ['required' => true]) !!}
{!! FormField::textarea('description') !!} {!! FormField::textarea('description') !!}
{!! Form::submit(trans('item.create'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::submit(trans('{$this->singleModelName}.create'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('{$this->tableName}.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!} {!! Form::close() !!}
@endif @endif
@if (Request::get('action') == 'edit' && \$editableItem)
{!! Form::model(\$editableItem, ['route' => ['items.update', \$editableItem->id],'method' => 'patch']) !!}
@if (Request::get('action') == 'edit' && \$editable{$this->modelName})
{!! Form::model(\$editable{$this->modelName}, ['route' => ['{$this->tableName}.update', \$editable{$this->modelName}->id],'method' => 'patch']) !!}
{!! FormField::text('name', ['required' => true]) !!} {!! FormField::text('name', ['required' => true]) !!}
{!! FormField::textarea('description') !!} {!! FormField::textarea('description') !!}
@if (request('q')) @if (request('q'))
@ -105,32 +105,32 @@ class ViewsGeneratorTest extends TestCase
@if (request('page')) @if (request('page'))
{{ Form::hidden('page', request('page')) }} {{ Form::hidden('page', request('page')) }}
@endif @endif
{!! Form::submit(trans('item.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::submit(trans('{$this->singleModelName}.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('{$this->tableName}.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!} {!! Form::close() !!}
@endif @endif
@if (Request::get('action') == 'delete' && \$editableItem)
@if (Request::get('action') == 'delete' && \$editable{$this->modelName})
<div class=\"panel panel-default\"> <div class=\"panel panel-default\">
<div class=\"panel-heading\"><h3 class=\"panel-title\">{{ trans('item.delete') }}</h3></div>
<div class=\"panel-heading\"><h3 class=\"panel-title\">{{ trans('{$this->singleModelName}.delete') }}</h3></div>
<div class=\"panel-body\"> <div class=\"panel-body\">
<label class=\"control-label\">{{ trans('item.name') }}</label>
<p>{{ \$editableItem->name }}</p>
{!! \$errors->first('item_id', '<span class=\"form-error small\">:message</span>') !!}
<label class=\"control-label\">{{ trans('{$this->singleModelName}.name') }}</label>
<p>{{ \$editable{$this->modelName}->name }}</p>
{!! \$errors->first('{$this->singleModelName}_id', '<span class=\"form-error small\">:message</span>') !!}
</div> </div>
<hr style=\"margin:0\"> <hr style=\"margin:0\">
<div class=\"panel-body\">{{ trans('app.delete_confirm') }}</div> <div class=\"panel-body\">{{ trans('app.delete_confirm') }}</div>
<div class=\"panel-footer\"> <div class=\"panel-footer\">
{!! FormField::delete( {!! FormField::delete(
['route'=>['items.destroy',\$editableItem->id]],
['route'=>['{$this->tableName}.destroy',\$editable{$this->modelName}->id]],
trans('app.delete_confirm_button'), trans('app.delete_confirm_button'),
['class'=>'btn btn-danger'], ['class'=>'btn btn-danger'],
[ [
'item_id' => \$editableItem->id,
'{$this->singleModelName}_id' => \$editable{$this->modelName}->id,
'page' => request('page'), 'page' => request('page'),
'q' => request('q'), 'q' => request('q'),
] ]
) !!} ) !!}
{{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{{ link_to_route('{$this->tableName}.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
</div> </div>
</div> </div>
@endif @endif

2
tests/TestCase.php

@ -14,7 +14,7 @@ abstract class TestCase extends BaseTestCase
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->modelName = 'Item';
$this->modelName = 'Category';
$this->pluralModelName = str_plural($this->modelName); $this->pluralModelName = str_plural($this->modelName);
$this->tableName = strtolower($this->pluralModelName); $this->tableName = strtolower($this->pluralModelName);

Loading…
Cancel
Save