forked from sleeping-owl/admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTitleTest.php
87 lines (74 loc) · 1.88 KB
/
TitleTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
use SleepingOwl\Admin\Models\Filters\Title;
class TitleTestModel
{
public $title;
public $name;
public static function findOrFail($id, $columns = ['*'])
{
if ($id == 10)
{
throw new \Exception;
}
$instance = new static;
$instance->title = 'title from model';
$instance->name = 'title from model custom field';
return $instance;
}
}
class TitleTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Mockery\Mock
*/
protected $from;
protected function setUp()
{
parent::setUp();
$this->from = Mockery::mock('\Illuminate\Database\Eloquent\Model');
}
/** @test */
public function it_can_use_static_title()
{
$title = new Title;
$title->title('static title');
$this->assertEquals('static title', $title->get(1));
}
/** @test */
public function it_can_use_model_to_load_title_from()
{
$title = new Title;
$title->from(TitleTestModel::class);
$this->assertEquals('title from model', $title->get(1));
}
/** @test */
public function it_can_use_model_custom_attribute_to_load_title_from()
{
$title = new Title;
$title->from(TitleTestModel::class, 'name');
$this->assertEquals('title from model custom field', $title->get(1));
}
/** @test */
public function it_throws_an_exception_when_title_fields_not_set()
{
$title = new Title;
$this->setExpectedException('\SleepingOwl\Admin\Exceptions\TitleNotFormattedException');
$title->get(1);
}
/** @test */
public function it_throws_an_exception_when_title_attribute_not_found()
{
$title = new Title;
$this->setExpectedException('\SleepingOwl\Admin\Exceptions\ModelAttributeNotFoundException');
$title->from(TitleTestModel::class, 'unsetAttribute');
$title->get(1);
}
/** @test */
public function it_throws_an_exception_when_model_not_found()
{
$title = new Title;
$this->setExpectedException('\Exception');
$title->from(TitleTestModel::class, 'title');
$title->get(10);
}
}