1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\Http; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\Tests\BaseTestClass; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers Backpack\CRUD\app\Http\Controllers\CrudController |
9
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\CrudPanel |
10
|
|
|
*/ |
11
|
|
|
class CrudControllerTest extends BaseTestClass |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Define environment setup. |
15
|
|
|
* |
16
|
|
|
* @param \Illuminate\Foundation\Application $app |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
protected function defineEnvironment($app) |
20
|
|
|
{ |
21
|
|
|
parent::defineEnvironment($app); |
22
|
|
|
|
23
|
|
|
//$this->crudPanel = app('crud'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testSetRouteName() |
27
|
|
|
{ |
28
|
|
|
$crudPanel = app('crud'); |
29
|
|
|
$crudPanel->setRouteName('users'); |
30
|
|
|
|
31
|
|
|
$this->assertEquals(url('admin/users'), $crudPanel->getRoute()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testSetRoute() |
35
|
|
|
{ |
36
|
|
|
$crudPanel = app('crud'); |
37
|
|
|
$crudPanel->setRoute(backpack_url('users')); |
38
|
|
|
$crudPanel->setEntityNameStrings('singular', 'plural'); |
39
|
|
|
$this->assertEquals(route('users.index'), $crudPanel->getRoute()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @group fail |
44
|
|
|
*/ |
45
|
|
|
public function testCrudRequestUpdatesOnEachRequest() |
46
|
|
|
{ |
47
|
|
|
// create a first request |
48
|
|
|
$firstRequest = request()->create('admin/users/1/edit', 'GET'); |
49
|
|
|
|
50
|
|
|
app()->handle($firstRequest); |
|
|
|
|
51
|
|
|
$firstRequest = app()->request; |
52
|
|
|
|
53
|
|
|
// see if the first global request has been passed to the CRUD object |
54
|
|
|
$this->assertSame(app('crud')->getRequest(), $firstRequest); |
55
|
|
|
|
56
|
|
|
// create a second request |
57
|
|
|
$secondRequest = request()->create('admin/users/1', 'PUT', ['name' => 'foo']); |
58
|
|
|
app()->handle($secondRequest); |
59
|
|
|
$secondRequest = app()->request; |
60
|
|
|
|
61
|
|
|
// see if the second global request has been passed to the CRUD object |
62
|
|
|
$this->assertSame(app('crud')->getRequest(), $secondRequest); |
63
|
|
|
|
64
|
|
|
// the CRUD object's request should no longer hold the first request, but the second one |
65
|
|
|
$this->assertNotSame(app('crud')->getRequest(), $firstRequest); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|