|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the jquery-datatables-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2019 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\JQuery\DataTablesBundle\Tests\Normalizer; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Model\DataTablesColumn; |
|
15
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Model\DataTablesResponse; |
|
16
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Normalizer\DataTablesNormalizer; |
|
17
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Tests\AbstractTestCase; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* DataTables normalizer test. |
|
21
|
|
|
* |
|
22
|
|
|
* @author webeweb <https://github.com/webeweb> |
|
23
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Normalizer |
|
24
|
|
|
*/ |
|
25
|
|
|
class DataTablesNormalizerTest extends AbstractTestCase { |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Test normalizeColumn() |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testNormalizeColumn(): void { |
|
33
|
|
|
|
|
34
|
|
|
// Set a DataTables column mock. |
|
35
|
|
|
$arg = new DataTablesColumn(); |
|
36
|
|
|
|
|
37
|
|
|
$arg->setClassname("classname"); |
|
38
|
|
|
$arg->setContentPadding("contentPadding"); |
|
39
|
|
|
$arg->setData("data"); |
|
40
|
|
|
$arg->setDefaultContent("defaultContent"); |
|
41
|
|
|
$arg->setName("name"); |
|
42
|
|
|
$arg->setOrderData([1]); |
|
43
|
|
|
$arg->setOrderDataType("orderDataType"); |
|
44
|
|
|
$arg->setOrderSequence("asc"); |
|
45
|
|
|
$arg->setOrderable(false); |
|
46
|
|
|
$arg->setSearchable(false); |
|
47
|
|
|
$arg->setType("string"); |
|
48
|
|
|
$arg->setVisible(false); |
|
49
|
|
|
$arg->setWidth("width"); |
|
50
|
|
|
|
|
51
|
|
|
$res = [ |
|
52
|
|
|
"cellType" => "td", |
|
53
|
|
|
"classname" => "classname", |
|
54
|
|
|
"contentPadding" => "contentPadding", |
|
55
|
|
|
"data" => "data", |
|
56
|
|
|
"defaultContent" => "defaultContent", |
|
57
|
|
|
"name" => "name", |
|
58
|
|
|
"orderData" => [1], |
|
59
|
|
|
"orderDataType" => "orderDataType", |
|
60
|
|
|
"orderSequence" => "asc", |
|
61
|
|
|
"orderable" => false, |
|
62
|
|
|
"searchable" => false, |
|
63
|
|
|
"type" => "string", |
|
64
|
|
|
"visible" => false, |
|
65
|
|
|
"width" => "width", |
|
66
|
|
|
]; |
|
67
|
|
|
$this->assertEquals($res, DataTablesNormalizer::normalizeColumn($arg)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Test normalizeColumn() |
|
72
|
|
|
* |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testNormalizeColumnWithoutArguments(): void { |
|
76
|
|
|
|
|
77
|
|
|
// Set a DataTables column mock. |
|
78
|
|
|
$arg = new DataTablesColumn(); |
|
79
|
|
|
|
|
80
|
|
|
$res = ["cellType" => "td"]; |
|
81
|
|
|
$this->assertEquals($res, DataTablesNormalizer::normalizeColumn($arg)); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Test normalizeResponse() |
|
86
|
|
|
* |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testNormalizeResponse(): void { |
|
90
|
|
|
|
|
91
|
|
|
// Set a DataTables response mock. |
|
92
|
|
|
$arg = new DataTablesResponse(); |
|
93
|
|
|
|
|
94
|
|
|
$arg->setError("error"); |
|
95
|
|
|
$arg->setRecordsFiltered(1); |
|
96
|
|
|
$arg->setRecordsTotal(2); |
|
97
|
|
|
|
|
98
|
|
|
$res = [ |
|
99
|
|
|
"data" => [], |
|
100
|
|
|
"draw" => 0, |
|
101
|
|
|
"recordsFiltered" => 1, |
|
102
|
|
|
"recordsTotal" => 2, |
|
103
|
|
|
]; |
|
104
|
|
|
$this->assertEquals($res, DataTablesNormalizer::normalizeResponse($arg)); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|