forked from Chumper/Datatable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableTest.php
164 lines (130 loc) · 4.36 KB
/
TableTest.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
use Chumper\Datatable\Table;
use Illuminate\Support\Facades\Request;
class TableTest extends PHPUnit_Framework_TestCase {
/**
* @var Table
*/
private $table;
protected function setUp()
{
parent::setUp();
Config::shouldReceive('get')->zeroOrMoreTimes()->with("datatable::table")->andReturn(
array(
'class' => 'table table-bordered',
'id' => '',
'options' => array(
"sPaginationType" => "full_numbers",
"bProcessing" => false
),
'callbacks' => array(),
'noScript' => false,
'table_view' => 'datatable::template',
'script_view' => 'datatable::javascript',
)
);
$this->table = new Table();
}
/**
* @expectedException Exception
*/
public function testSetOptions()
{
$this->table->setOptions('foo','bar');
$this->table->setOptions(array(
'foo2' => 'bar2',
'foo3' => 'bar3'
));
$this->table->setOptions('foo', 'bar', 'baz');
}
/**
* @expectedException Exception
*/
public function testSetCallbacks()
{
$this->table->setCallbacks('foo', 'bar');
$this->assertArrayHasKey('foo', $this->table->getCallbacks());
$this->table->setCallbacks(array(
'foo2' => 'bar2',
'foo3' => 'bar3'
));
$this->assertArrayHasKey('foo2', $this->table->getCallbacks());
$this->assertArrayHasKey('foo3', $this->table->getCallbacks());
$this->table->setCallbacks('foo', 'bar', 'baz');
$this->assertTrue(False); // should throw exception before here
}
/**
* @expectedException Exception
*/
public function testSetCustomValues()
{
$this->table->setCustomValues('foo', 'bar');
$this->assertArrayHasKey('foo', $this->table->getCustomValues());
$this->table->setCustomValues(array(
'foo2' => 'bar2',
'foo3' => 'bar3'
));
$this->assertArrayHasKey('foo2', $this->table->getCustomValues());
$this->assertArrayHasKey('foo3', $this->table->getCustomValues());
$this->table->setCustomValues('foo', 'bar', 'baz');
$this->assertTrue(False); // should throw exception before here
}
public function testAddColumn()
{
$this->table->addColumn('foo');
$this->assertEquals(1, $this->table->countColumns());
$this->table->addColumn('foo1','foo2');
$this->assertEquals(3, $this->table->countColumns());
$this->table->addColumn(array('foo3','foo4'));
$this->assertEquals(5, $this->table->countColumns());
}
public function testRender()
{
Request::shouldReceive('url')->once()->andReturn('fooBar');
View::shouldReceive('make')->once()
->with('datatable::template', array(
'options' => array(
'sAjaxSource' => 'fooBar',
'bServerSide' => true,
'sPaginationType'=>'full_numbers',
'bProcessing'=>false
),
'callbacks' => array(),
'values' => array(),
'data' => array(),
'columns' => array(1=>'foo'),
'noScript' => false,
'class' => $this->table->getClass(),
'id' => $this->table->getId(),
))->andReturn(true);
$table1 = $this->table->addColumn('foo')->render();
$this->assertTrue($table1);
}
public function testSetData()
{
$data = array(
array(
'foo',
'bar'
),
array(
'foo2',
'bar2'
),
);
$this->table->setData($data);
$this->assertEquals($data,$this->table->getData());
}
public function testSetUrl()
{
$this->table->setUrl('foo/url');
$this->assertArrayHasKey('bServerSide',$this->table->getOptions());
$this->assertArrayHasKey('sAjaxSource',$this->table->getOptions());
$return = $this->table->getOptions();
$this->assertEquals('foo/url',$return['sAjaxSource']);
}
protected function tearDown()
{
Mockery::close();
}
}