1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the jquery-datatables package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 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\Fixtures; |
13
|
|
|
|
14
|
|
|
use DateTime; |
15
|
|
|
use Throwable; |
16
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesWrapperInterface; |
17
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Factory\DataTablesFactory; |
18
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesProviderInterface; |
19
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Tests\Fixtures\Entity\Employee; |
20
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Tests\Fixtures\Provider\EmployeeDataTablesProvider; |
21
|
|
|
use WBW\Library\Types\Helper\StringHelper; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Test fixtures. |
25
|
|
|
* |
26
|
|
|
* @author webeweb <https://github.com/webeweb> |
27
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Fixtures\App |
28
|
|
|
*/ |
29
|
|
|
class TestFixtures { |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Build POST data. |
33
|
|
|
* |
34
|
|
|
* @param DataTablesProviderInterface $dtProvider The provider. |
35
|
|
|
* @return array<string, mixed> Returns the POST data. |
36
|
|
|
*/ |
37
|
|
|
public static function buildPOSTData(DataTablesProviderInterface $dtProvider): array { |
38
|
|
|
|
39
|
|
|
$postData = []; |
40
|
|
|
|
41
|
|
|
$postData["columns"] = []; |
42
|
|
|
|
43
|
|
|
foreach ($dtProvider->getColumns() as $current) { |
44
|
|
|
|
45
|
|
|
$buffer = []; |
46
|
|
|
|
47
|
|
|
$buffer["data"] = $current->getData(); |
48
|
|
|
$buffer["name"] = $current->getName(); |
49
|
|
|
$buffer["orderable"] = StringHelper::parseBoolean($current->getOrderable()); |
50
|
|
|
$buffer["search"]["regex"] = StringHelper::parseBoolean(false); |
51
|
|
|
$buffer["search"]["value"] = ""; |
52
|
|
|
$buffer["searchable"] = StringHelper::parseBoolean($current->getSearchable()); |
53
|
|
|
|
54
|
|
|
$postData["columns"][] = $buffer; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$fixtures["draw"] = "1"; |
|
|
|
|
58
|
|
|
$fixtures["length"] = "10"; |
59
|
|
|
|
60
|
|
|
$fixtures["order"][0]["column"] = "0"; |
61
|
|
|
$fixtures["order"][0]["dir"] = "asc"; |
62
|
|
|
|
63
|
|
|
$fixtures["search"]["regex"] = "false"; |
64
|
|
|
$fixtures["search"]["value"] = ""; |
65
|
|
|
|
66
|
|
|
$fixtures["start"] = "0"; |
67
|
|
|
|
68
|
|
|
return $postData; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the employees. |
73
|
|
|
* |
74
|
|
|
* @return Employee[] Returns the employee entities. |
75
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
76
|
|
|
*/ |
77
|
|
|
public static function getEmployees(): array { |
78
|
|
|
|
79
|
|
|
$fixtures = []; |
80
|
|
|
|
81
|
|
|
$fixtures[] = (new Employee())->setName("Tiger Nixon")->setPosition("System Architect")->setOffice("Edinburgh")->setAge(61)->setStartDate(new DateTime("2011-04-25"))->setSalary(320800); |
82
|
|
|
$fixtures[] = (new Employee())->setName("Garrett Winters")->setPosition("Accountant")->setOffice("Tokyo")->setAge(63)->setStartDate(new DateTime("2011-07-25"))->setSalary(170750); |
83
|
|
|
$fixtures[] = (new Employee())->setName("Ashton Cox")->setPosition("Junior Technical Author")->setOffice("San Francisco")->setAge(66)->setStartDate(new DateTime("2009-01-12"))->setSalary(86000); |
84
|
|
|
$fixtures[] = (new Employee())->setName("Cedric Kelly")->setPosition("Senior Javascript Developer")->setOffice("Edinburgh")->setAge(22)->setStartDate(new DateTime("2012-03-29"))->setSalary(433060); |
85
|
|
|
$fixtures[] = (new Employee())->setName("Airi Satou")->setPosition("Accountant")->setOffice("Tokyo")->setAge(33)->setStartDate(new DateTime("2008-11-28"))->setSalary(162700); |
86
|
|
|
$fixtures[] = (new Employee())->setName("Brielle Williamson")->setPosition("Integration Specialist")->setOffice("New York")->setAge(61)->setStartDate(new DateTime("2012-12-02"))->setSalary(372000); |
87
|
|
|
$fixtures[] = (new Employee())->setName("Herrod Chandler")->setPosition("Sales Assistant")->setOffice("San Francisco")->setAge(59)->setStartDate(new DateTime("2012-08-06"))->setSalary(137500); |
88
|
|
|
$fixtures[] = (new Employee())->setName("Rhona Davidson")->setPosition("Integration Specialist")->setOffice("Tokyo")->setAge(55)->setStartDate(new DateTime("2010-10-14"))->setSalary(327900); |
89
|
|
|
$fixtures[] = (new Employee())->setName("Colleen Hurst")->setPosition("Javascript Developer")->setOffice("San Francisco")->setAge(39)->setStartDate(new DateTime("2009-09-15"))->setSalary(205500); |
90
|
|
|
$fixtures[] = (new Employee())->setName("Sonya Frost")->setPosition("Software Engineer")->setOffice("Edinburgh")->setAge(23)->setStartDate(new DateTime("2008-12-13"))->setSalary(103600); |
91
|
|
|
$fixtures[] = (new Employee())->setName("Jena Gaines")->setPosition("Office Manager")->setOffice("London")->setAge(30)->setStartDate(new DateTime("2008-12-19"))->setSalary(90560); |
92
|
|
|
$fixtures[] = (new Employee())->setName("Quinn Flynn")->setPosition("Support Lead")->setOffice("Edinburgh")->setAge(22)->setStartDate(new DateTime("2013-03-03"))->setSalary(342000); |
93
|
|
|
$fixtures[] = (new Employee())->setName("Charde Marshall")->setPosition("Regional Director")->setOffice("San Francisco")->setAge(36)->setStartDate(new DateTime("2008-10-16"))->setSalary(470600); |
94
|
|
|
$fixtures[] = (new Employee())->setName("Haley Kennedy")->setPosition("Senior Marketing Designer")->setOffice("London")->setAge(43)->setStartDate(new DateTime("2012-12-18"))->setSalary(313500); |
95
|
|
|
$fixtures[] = (new Employee())->setName("Tatyana Fitzpatrick")->setPosition("Regional Director")->setOffice("London")->setAge(19)->setStartDate(new DateTime("2010-03-17"))->setSalary(385750); |
96
|
|
|
$fixtures[] = (new Employee())->setName("Michael Silva")->setPosition("Marketing Designer")->setOffice("London")->setAge(66)->setStartDate(new DateTime("2012-11-27"))->setSalary(198500); |
97
|
|
|
$fixtures[] = (new Employee())->setName("Paul Byrd")->setPosition("Chief Financial Officer (CFO)")->setOffice("New York")->setAge(64)->setStartDate(new DateTime("2010-06-09"))->setSalary(725000); |
98
|
|
|
$fixtures[] = (new Employee())->setName("Gloria Little")->setPosition("Systems Administrator")->setOffice("New York")->setAge(59)->setStartDate(new DateTime("2009-04-10"))->setSalary(237500); |
99
|
|
|
$fixtures[] = (new Employee())->setName("Bradley Greer")->setPosition("Software Engineer")->setOffice("London")->setAge(41)->setStartDate(new DateTime("2012-10-13"))->setSalary(132000); |
100
|
|
|
$fixtures[] = (new Employee())->setName("Dai Rios")->setPosition("Personnel Lead")->setOffice("Edinburgh")->setAge(35)->setStartDate(new DateTime("2012-09-26"))->setSalary(217500); |
101
|
|
|
$fixtures[] = (new Employee())->setName("Jenette Caldwell")->setPosition("Development Lead")->setOffice("New York")->setAge(30)->setStartDate(new DateTime("2011-09-03"))->setSalary(345000); |
102
|
|
|
$fixtures[] = (new Employee())->setName("Yuri Berry")->setPosition("Chief Marketing Officer (CMO)")->setOffice("New York")->setAge(40)->setStartDate(new DateTime("2009-06-25"))->setSalary(675000); |
103
|
|
|
$fixtures[] = (new Employee())->setName("Caesar Vance")->setPosition("Pre-Sales Support")->setOffice("New York")->setAge(21)->setStartDate(new DateTime("2011-12-12"))->setSalary(106450); |
104
|
|
|
$fixtures[] = (new Employee())->setName("Doris Wilder")->setPosition("Sales Assistant")->setOffice("Sidney")->setAge(23)->setStartDate(new DateTime("2010-09-20"))->setSalary(85600); |
105
|
|
|
$fixtures[] = (new Employee())->setName("Angelica Ramos")->setPosition("Chief Executive Officer (CEO)")->setOffice("London")->setAge(47)->setStartDate(new DateTime("2009-10-09"))->setSalary(1200000); |
106
|
|
|
$fixtures[] = (new Employee())->setName("Gavin Joyce")->setPosition("Developer")->setOffice("Edinburgh")->setAge(42)->setStartDate(new DateTime("2010-12-22"))->setSalary(92575); |
107
|
|
|
$fixtures[] = (new Employee())->setName("Jennifer Chang")->setPosition("Regional Director")->setOffice("Singapore")->setAge(28)->setStartDate(new DateTime("2010-11-14"))->setSalary(357650); |
108
|
|
|
$fixtures[] = (new Employee())->setName("Brenden Wagner")->setPosition("Software Engineer")->setOffice("San Francisco")->setAge(28)->setStartDate(new DateTime("2011-06-07"))->setSalary(206850); |
109
|
|
|
$fixtures[] = (new Employee())->setName("Fiona Green")->setPosition("Chief Operating Officer (COO)")->setOffice("San Francisco")->setAge(48)->setStartDate(new DateTime("2010-03-11"))->setSalary(850000); |
110
|
|
|
$fixtures[] = (new Employee())->setName("Shou Itou")->setPosition("Regional Marketing")->setOffice("Tokyo")->setAge(20)->setStartDate(new DateTime("2011-08-14"))->setSalary(163000); |
111
|
|
|
$fixtures[] = (new Employee())->setName("Michelle House")->setPosition("Integration Specialist")->setOffice("Sidney")->setAge(37)->setStartDate(new DateTime("2011-06-02"))->setSalary(95400); |
112
|
|
|
$fixtures[] = (new Employee())->setName("Suki Burks")->setPosition("Developer")->setOffice("London")->setAge(53)->setStartDate(new DateTime("2009-10-22"))->setSalary(114500); |
113
|
|
|
$fixtures[] = (new Employee())->setName("Prescott Bartlett")->setPosition("Technical Author")->setOffice("London")->setAge(27)->setStartDate(new DateTime("2011-05-07"))->setSalary(145000); |
114
|
|
|
$fixtures[] = (new Employee())->setName("Gavin Cortez")->setPosition("Team Leader")->setOffice("San Francisco")->setAge(22)->setStartDate(new DateTime("2008-10-26"))->setSalary(235500); |
115
|
|
|
$fixtures[] = (new Employee())->setName("Martena Mccray")->setPosition("Post-Sales support")->setOffice("Edinburgh")->setAge(46)->setStartDate(new DateTime("2011-03-09"))->setSalary(324050); |
116
|
|
|
$fixtures[] = (new Employee())->setName("Unity Butler")->setPosition("Marketing Designer")->setOffice("San Francisco")->setAge(47)->setStartDate(new DateTime("2009-12-09"))->setSalary(85675); |
117
|
|
|
$fixtures[] = (new Employee())->setName("Howard Hatfield")->setPosition("Office Manager")->setOffice("San Francisco")->setAge(51)->setStartDate(new DateTime("2008-12-16"))->setSalary(164500); |
118
|
|
|
$fixtures[] = (new Employee())->setName("Hope Fuentes")->setPosition("Secretary")->setOffice("San Francisco")->setAge(41)->setStartDate(new DateTime("2010-02-12"))->setSalary(109850); |
119
|
|
|
$fixtures[] = (new Employee())->setName("Vivian Harrell")->setPosition("Financial Controller")->setOffice("San Francisco")->setAge(62)->setStartDate(new DateTime("2009-02-14"))->setSalary(452500); |
120
|
|
|
$fixtures[] = (new Employee())->setName("Timothy Mooney")->setPosition("Office Manager")->setOffice("London")->setAge(37)->setStartDate(new DateTime("2008-12-11"))->setSalary(136200); |
121
|
|
|
$fixtures[] = (new Employee())->setName("Jackson Bradshaw")->setPosition("Director")->setOffice("New York")->setAge(65)->setStartDate(new DateTime("2008-09-26"))->setSalary(645750); |
122
|
|
|
$fixtures[] = (new Employee())->setName("Olivia Liang")->setPosition("Support Engineer")->setOffice("Singapore")->setAge(64)->setStartDate(new DateTime("2011-02-03"))->setSalary(234500); |
123
|
|
|
$fixtures[] = (new Employee())->setName("Bruno Nash")->setPosition("Software Engineer")->setOffice("London")->setAge(38)->setStartDate(new DateTime("2011-05-03"))->setSalary(163500); |
124
|
|
|
$fixtures[] = (new Employee())->setName("Sakura Yamamoto")->setPosition("Support Engineer")->setOffice("Tokyo")->setAge(37)->setStartDate(new DateTime("2009-08-19"))->setSalary(139575); |
125
|
|
|
$fixtures[] = (new Employee())->setName("Thor Walton")->setPosition("Developer")->setOffice("New York")->setAge(61)->setStartDate(new DateTime("2013-08-11"))->setSalary(98540); |
126
|
|
|
$fixtures[] = (new Employee())->setName("Finn Camacho")->setPosition("Support Engineer")->setOffice("San Francisco")->setAge(47)->setStartDate(new DateTime("2009-07-07"))->setSalary(87500); |
127
|
|
|
$fixtures[] = (new Employee())->setName("Serge Baldwin")->setPosition("Data Coordinator")->setOffice("Singapore")->setAge(64)->setStartDate(new DateTime("2012-04-09"))->setSalary(138575); |
128
|
|
|
$fixtures[] = (new Employee())->setName("Zenaida Frank")->setPosition("Software Engineer")->setOffice("New York")->setAge(63)->setStartDate(new DateTime("2010-01-04"))->setSalary(125250); |
129
|
|
|
$fixtures[] = (new Employee())->setName("Zorita Serrano")->setPosition("Software Engineer")->setOffice("San Francisco")->setAge(56)->setStartDate(new DateTime("2012-06-01"))->setSalary(115000); |
130
|
|
|
$fixtures[] = (new Employee())->setName("Jennifer Acosta")->setPosition("Junior Javascript Developer")->setOffice("Edinburgh")->setAge(43)->setStartDate(new DateTime("2013-02-01"))->setSalary(75650); |
131
|
|
|
$fixtures[] = (new Employee())->setName("Cara Stevens")->setPosition("Sales Assistant")->setOffice("New York")->setAge(46)->setStartDate(new DateTime("2011-12-06"))->setSalary(145600); |
132
|
|
|
$fixtures[] = (new Employee())->setName("Hermione Butler")->setPosition("Regional Director")->setOffice("London")->setAge(47)->setStartDate(new DateTime("2011-03-21"))->setSalary(356250); |
133
|
|
|
$fixtures[] = (new Employee())->setName("Lael Greer")->setPosition("Systems Administrator")->setOffice("London")->setAge(21)->setStartDate(new DateTime("2009-02-27"))->setSalary(103500); |
134
|
|
|
$fixtures[] = (new Employee())->setName("Jonas Alexander")->setPosition("Developer")->setOffice("San Francisco")->setAge(30)->setStartDate(new DateTime("2010-07-14"))->setSalary(86500); |
135
|
|
|
$fixtures[] = (new Employee())->setName("Shad Decker")->setPosition("Regional Director")->setOffice("Edinburgh")->setAge(51)->setStartDate(new DateTime("2008-11-13"))->setSalary(183000); |
136
|
|
|
$fixtures[] = (new Employee())->setName("Michael Bruce")->setPosition("Javascript Developer")->setOffice("Singapore")->setAge(29)->setStartDate(new DateTime("2011-06-27"))->setSalary(183000); |
137
|
|
|
$fixtures[] = (new Employee())->setName("Donna Snider")->setPosition("Customer Support")->setOffice("New York")->setAge(27)->setStartDate(new DateTime("2011-01-25"))->setSalary(112000); |
138
|
|
|
|
139
|
|
|
return $fixtures; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get the POST data. |
144
|
|
|
* |
145
|
|
|
* @return array<string,mixed> Returns the POST data. |
146
|
|
|
*/ |
147
|
|
|
public static function getPostData(): array { |
148
|
|
|
|
149
|
|
|
$fixtures = []; |
150
|
|
|
|
151
|
|
|
// Name |
152
|
|
|
$fixtures["columns"][0]["data"] = "name"; |
153
|
|
|
$fixtures["columns"][0]["name"] = "Name"; |
154
|
|
|
$fixtures["columns"][0]["orderable"] = "true"; |
155
|
|
|
$fixtures["columns"][0]["search"]["regex"] = "false"; |
156
|
|
|
$fixtures["columns"][0]["search"]["value"] = ""; |
157
|
|
|
$fixtures["columns"][0]["searchable"] = "true"; |
158
|
|
|
|
159
|
|
|
// Position |
160
|
|
|
$fixtures["columns"][1]["data"] = "position"; |
161
|
|
|
$fixtures["columns"][1]["name"] = "Position"; |
162
|
|
|
$fixtures["columns"][1]["orderable"] = "true"; |
163
|
|
|
$fixtures["columns"][1]["search"]["regex"] = "false"; |
164
|
|
|
$fixtures["columns"][1]["search"]["value"] = ""; |
165
|
|
|
$fixtures["columns"][1]["searchable"] = "true"; |
166
|
|
|
|
167
|
|
|
// Office |
168
|
|
|
$fixtures["columns"][2]["data"] = "office"; |
169
|
|
|
$fixtures["columns"][2]["name"] = "Office"; |
170
|
|
|
$fixtures["columns"][2]["orderable"] = "true"; |
171
|
|
|
$fixtures["columns"][2]["search"]["regex"] = "false"; |
172
|
|
|
$fixtures["columns"][2]["search"]["value"] = ""; |
173
|
|
|
$fixtures["columns"][2]["searchable"] = "true"; |
174
|
|
|
|
175
|
|
|
// Age |
176
|
|
|
$fixtures["columns"][3]["data"] = "age"; |
177
|
|
|
$fixtures["columns"][3]["name"] = "Age"; |
178
|
|
|
$fixtures["columns"][3]["orderable"] = "true"; |
179
|
|
|
$fixtures["columns"][3]["search"]["regex"] = "false"; |
180
|
|
|
$fixtures["columns"][3]["search"]["value"] = ""; |
181
|
|
|
$fixtures["columns"][3]["searchable"] = "true"; |
182
|
|
|
|
183
|
|
|
// Start date |
184
|
|
|
$fixtures["columns"][4]["data"] = "startDate"; |
185
|
|
|
$fixtures["columns"][4]["name"] = "Start date"; |
186
|
|
|
$fixtures["columns"][4]["orderable"] = "true"; |
187
|
|
|
$fixtures["columns"][4]["search"]["regex"] = "false"; |
188
|
|
|
$fixtures["columns"][4]["search"]["value"] = ""; |
189
|
|
|
$fixtures["columns"][4]["searchable"] = "true"; |
190
|
|
|
|
191
|
|
|
// Salary |
192
|
|
|
$fixtures["columns"][5]["data"] = "salary"; |
193
|
|
|
$fixtures["columns"][5]["name"] = "Salary"; |
194
|
|
|
$fixtures["columns"][5]["orderable"] = "true"; |
195
|
|
|
$fixtures["columns"][5]["search"]["regex"] = "false"; |
196
|
|
|
$fixtures["columns"][5]["search"]["value"] = ""; |
197
|
|
|
$fixtures["columns"][5]["searchable"] = "true"; |
198
|
|
|
|
199
|
|
|
// Actions. |
200
|
|
|
$fixtures["columns"][6]["data"] = "actions"; |
201
|
|
|
$fixtures["columns"][6]["name"] = "Actions"; |
202
|
|
|
$fixtures["columns"][6]["orderable"] = "false"; |
203
|
|
|
$fixtures["columns"][6]["search"]["regex"] = "false"; |
204
|
|
|
$fixtures["columns"][6]["search"]["value"] = ""; |
205
|
|
|
$fixtures["columns"][6]["searchable"] = "false"; |
206
|
|
|
|
207
|
|
|
// |
208
|
|
|
$fixtures["draw"] = "1"; |
209
|
|
|
$fixtures["length"] = "10"; |
210
|
|
|
|
211
|
|
|
// Order |
212
|
|
|
$fixtures["order"][0]["column"] = "0"; |
213
|
|
|
$fixtures["order"][0]["dir"] = "asc"; |
214
|
|
|
|
215
|
|
|
// Search |
216
|
|
|
$fixtures["search"]["regex"] = "false"; |
217
|
|
|
$fixtures["search"]["value"] = ""; |
218
|
|
|
|
219
|
|
|
// Start |
220
|
|
|
$fixtures["start"] = "0"; |
221
|
|
|
|
222
|
|
|
return $fixtures; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Get a wrapper. |
227
|
|
|
* |
228
|
|
|
* @return DataTablesWrapperInterface Returns the wrapper. |
229
|
|
|
*/ |
230
|
|
|
public static function getWrapper(): DataTablesWrapperInterface { |
231
|
|
|
|
232
|
|
|
$fixture = DataTablesFactory::newWrapper("/datatables/employee/index", new EmployeeDataTablesProvider()); |
233
|
|
|
|
234
|
|
|
$fixture->addColumn(DataTablesFactory::newColumn("name", "Name")); |
235
|
|
|
$fixture->addColumn(DataTablesFactory::newColumn("position", "Position")); |
236
|
|
|
$fixture->addColumn(DataTablesFactory::newColumn("office", "Office")); |
237
|
|
|
$fixture->addColumn(DataTablesFactory::newColumn("age", "Age")); |
238
|
|
|
$fixture->addColumn(DataTablesFactory::newColumn("startDate", "Start date")); |
239
|
|
|
$fixture->addColumn(DataTablesFactory::newColumn("salary", "Salary")); |
240
|
|
|
$fixture->addColumn(DataTablesFactory::newColumn("actions", "Actions")->setOrderable(false)->setSearchable(false)); |
241
|
|
|
|
242
|
|
|
return $fixture; |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|