1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\Http; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Library\CrudPanel\CrudPanel; |
6
|
|
|
use Backpack\CRUD\Tests\BaseTest; |
7
|
|
|
|
8
|
|
|
class CrudControllerTest extends BaseTest |
9
|
|
|
{ |
10
|
|
|
private $crudPanel; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Define environment setup. |
14
|
|
|
* |
15
|
|
|
* @param \Illuminate\Foundation\Application $app |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
protected function getEnvironmentSetUp($app) |
19
|
|
|
{ |
20
|
|
|
parent::getEnvironmentSetUp($app); |
21
|
|
|
|
22
|
|
|
$controller = '\Backpack\CRUD\Tests\Unit\Http\Controllers\UserCrudController'; |
23
|
|
|
|
24
|
|
|
$app['router']->get('users/{id}/edit', "$controller@edit"); |
25
|
|
|
$app['router']->put('users/{id}', "$controller@update"); |
26
|
|
|
|
27
|
|
|
$app['router']->get('admin/users', "$controller@index")->name('admin.users.index'); |
28
|
|
|
|
29
|
|
|
$app->singleton('crud', function ($app) { |
30
|
|
|
return new CrudPanel($app); |
|
|
|
|
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
$this->crudPanel = app('crud'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testSetRouteName() |
37
|
|
|
{ |
38
|
|
|
$this->crudPanel->setRouteName('admin.users'); |
39
|
|
|
|
40
|
|
|
$this->assertEquals(url('admin/users'), $this->crudPanel->getRoute()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testCrudRequestUpdatesOnEachRequest() |
44
|
|
|
{ |
45
|
|
|
$crud = app('crud'); |
46
|
|
|
|
47
|
|
|
// create a first request |
48
|
|
|
$firstRequest = request()->create('/users/1/edit', 'GET'); |
49
|
|
|
app()->handle($firstRequest); |
|
|
|
|
50
|
|
|
|
51
|
|
|
// see if the first global request has been passed to the CRUD object |
52
|
|
|
$this->assertSame($crud->getRequest(), $firstRequest); |
53
|
|
|
|
54
|
|
|
// create a second request |
55
|
|
|
$secondRequest = request()->create('/users/1', 'PUT', ['name' => 'foo']); |
56
|
|
|
app()->handle($secondRequest); |
57
|
|
|
|
58
|
|
|
// see if the second global requesst has been passed to the CRUD object |
59
|
|
|
$this->assertSame($crud->getRequest(), $secondRequest); |
60
|
|
|
|
61
|
|
|
// the CRUD object's request should no longer hold the first request, but the second one |
62
|
|
|
$this->assertNotSame($crud->getRequest(), $firstRequest); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.