|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\CrudPanel; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\Tests\Unit\Models\TestModel; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\CrudPanel |
|
10
|
|
|
*/ |
|
11
|
|
|
class CrudPanelTest extends BaseCrudPanelTest |
|
12
|
|
|
{ |
|
13
|
|
|
public function testSetModelFromModelClass() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->crudPanel->setModel(TestModel::class); |
|
16
|
|
|
|
|
17
|
|
|
$this->assertEquals($this->model, $this->crudPanel->model); |
|
18
|
|
|
$this->assertInstanceOf(TestModel::class, $this->crudPanel->model); |
|
19
|
|
|
$this->assertInstanceOf(Builder::class, $this->crudPanel->query); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testSetModelFromModelClassName() |
|
23
|
|
|
{ |
|
24
|
|
|
$modelClassName = '\Backpack\CRUD\Tests\Unit\Models\TestModel'; |
|
25
|
|
|
|
|
26
|
|
|
$this->crudPanel->setModel($modelClassName); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertEquals($this->model, $this->crudPanel->model); |
|
29
|
|
|
$this->assertInstanceOf($modelClassName, $this->crudPanel->model); |
|
|
|
|
|
|
30
|
|
|
$this->assertInstanceOf(Builder::class, $this->crudPanel->query); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testSetUnknownModel() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->expectException(\Exception::class); |
|
36
|
|
|
|
|
37
|
|
|
$this->crudPanel->setModel('\Foo\Bar'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testSetUnknownRouteName() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->expectException(\Exception::class); |
|
43
|
|
|
|
|
44
|
|
|
$this->crudPanel->setRouteName('unknown.route.name'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testItThrowsExceptionIfModelIsNotUsingCrudTrait() |
|
48
|
|
|
{ |
|
49
|
|
|
try { |
|
50
|
|
|
$this->crudPanel->setModel('\Backpack\CRUD\Tests\Unit\Models\ModelWithoutCrudTrait'); |
|
51
|
|
|
} catch (\Throwable $e) { |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
$this->assertEquals( |
|
54
|
|
|
new \Exception('Please use CrudTrait on the model.', 500), |
|
55
|
|
|
$e |
|
|
|
|
|
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|