6 changed files with 156 additions and 1 deletions
-
2src/CrudApiMake.php
-
4src/Generators/ModelGenerator.php
-
4src/Generators/ModelTestGenerator.php
-
26src/stubs/models/model-formfield.stub
-
37src/stubs/testcases/unit/model-formfield.stub
-
84tests/CommandOptions/FullCrudFormfieldOptionsTest.php
@ -0,0 +1,26 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace mstrNmspc; |
||||
|
|
||||
|
use App\User; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class Master extends Model |
||||
|
{ |
||||
|
protected $fillable = ['name', 'description', 'creator_id']; |
||||
|
|
||||
|
public function getNameLinkAttribute() |
||||
|
{ |
||||
|
return link_to_route('masters.show', $this->name, [$this], [ |
||||
|
'title' => __( |
||||
|
'app.show_detail_title', |
||||
|
['name' => $this->name, 'type' => __('master.master')] |
||||
|
), |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
public function creator() |
||||
|
{ |
||||
|
return $this->belongsTo(User::class); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Unit\Models; |
||||
|
|
||||
|
use App\User; |
||||
|
use fullMstr; |
||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations; |
||||
|
use Tests\BrowserKitTest as TestCase; |
||||
|
|
||||
|
class MasterTest extends TestCase |
||||
|
{ |
||||
|
use DatabaseMigrations; |
||||
|
|
||||
|
/** @test */ |
||||
|
public function a_master_has_name_link_attribute() |
||||
|
{ |
||||
|
$singleMstr = factory(Master::class)->create(); |
||||
|
|
||||
|
$this->assertEquals( |
||||
|
link_to_route('masters.show', $singleMstr->name, [$singleMstr], [ |
||||
|
'title' => __( |
||||
|
'app.show_detail_title', |
||||
|
['name' => $singleMstr->name, 'type' => __('master.master')] |
||||
|
), |
||||
|
]), $singleMstr->name_link |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function a_master_has_belongs_to_creator_relation() |
||||
|
{ |
||||
|
$singleMstr = factory(Master::class)->make(); |
||||
|
|
||||
|
$this->assertInstanceOf(User::class, $singleMstr->creator); |
||||
|
$this->assertEquals($singleMstr->creator_id, $singleMstr->creator->id); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue