-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/** @noinspection ReturnTypeCanBeDeclaredInspection */ | ||
|
||
namespace Galahad\Aire\Tests\Feature; | ||
|
||
use Galahad\Aire\Tests\TestCase; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Facades\Route; | ||
use Illuminate\Support\Facades\URL; | ||
|
||
class ResourcefulBindingTest extends TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
Route::post('/users', function() {})->name('users.store'); | ||
Route::put('/users/{user}', function() {})->name('users.update'); | ||
} | ||
|
||
public function test_action_and_method_are_inferred_for_unsaved_models() | ||
{ | ||
$model = new XResourcefulModel(['id' => 1]); | ||
|
||
$html = $this->aire()->form()->resourceful($model)->render(); | ||
|
||
$this->assertSelectorAttribute($html, 'form', 'action', URL::to('/users')); | ||
$this->assertSelectorAttribute($html, 'form', 'method', 'POST'); | ||
$this->assertSelectorDoesNotExist($html, 'input[name="_method"]'); | ||
} | ||
|
||
public function test_action_and_method_are_inferred_for_saved_models() | ||
{ | ||
$model = new XResourcefulModel(['id' => 1]); | ||
$model->exists = true; | ||
|
||
$html = $this->aire()->form()->resourceful($model)->render(); | ||
|
||
$this->assertSelectorAttribute($html, 'form', 'action', URL::to('/users/1')); | ||
$this->assertSelectorAttribute($html, 'input[name="_method"]', 'value', 'PUT'); | ||
} | ||
|
||
public function test_provided_name_overrides_inferred_name() : void | ||
{ | ||
Route::post('/foo/bar', function() {})->name('foo.bar.store'); | ||
|
||
$model = new XResourcefulModel(['id' => 1]); | ||
|
||
$html = $this->aire()->form()->resourceful($model, 'foo.bar')->render(); | ||
|
||
$this->assertSelectorAttribute($html, 'form', 'action', URL::to('/foo/bar')); | ||
} | ||
} | ||
|
||
class XResourcefulModel extends Model | ||
{ | ||
protected $guarded = []; | ||
|
||
protected $table = 'users'; | ||
} |