testSerializeActionWithStatus404()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 12
c 2
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the jquery-datatables-bundle 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\Controller;
13
14
use WBW\Bundle\JQuery\DataTablesBundle\Controller\DataTablesController;
15
use WBW\Bundle\JQuery\DataTablesBundle\Tests\AbstractWebTestCase;
16
use WBW\Bundle\JQuery\DataTablesBundle\Tests\Fixtures\TestFixtures;
17
18
/**
19
 * DataTables controller test.
20
 *
21
 * @author webeweb <https://github.com/webeweb>
22
 * @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Controller
23
 */
24
class DataTablesControllerTest extends AbstractWebTestCase {
25
26
    /**
27
     * {@inheritDoc}
28
     */
29
    public static function setUpBeforeClass(): void {
30
        parent::setUpBeforeClass();
31
32
        parent::setUpEmployeeFixtures();
33
    }
34
35
    /**
36
     * Test deleteAction()
37
     *
38
     * @return void
39
     */
40
    public function testDeleteAction(): void {
41
42
        $client = $this->client;
43
44
        $client->request("GET", "/datatables/employee/delete/49");
45
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
46
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
47
        $this->assertEquals("/datatables/employee/index", $client->getResponse()->headers->get("location"));
48
49
        $client->followRedirect();
50
        $this->assertStringContainsString("Successful deletion", $client->getResponse()->getContent());
51
    }
52
53
    /**
54
     * Test deleteAction()
55
     *
56
     * @return void
57
     */
58
    public function testDeleteActionWithNotify404(): void {
59
60
        $client = $this->client;
61
62
        $client->request("GET", "/datatables/employee/delete/49");
63
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
64
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
65
        $this->assertEquals("/datatables/employee/index", $client->getResponse()->headers->get("location"));
66
67
        $client->followRedirect();
68
        $this->assertStringContainsString("Record not found", $client->getResponse()->getContent());
69
    }
70
71
    /**
72
     * Test deleteAction()
73
     *
74
     * @return void
75
     */
76
    public function testDeleteActionWithStatus200(): void {
77
78
        $client = $this->client;
79
80
        $client->request("GET", "/datatables/employee/delete/48", [], [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
81
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
82
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
83
84
        // Check the JSON response.
85
        $res = json_decode($client->getResponse()->getContent(), true);
86
87
        $this->assertArrayHasKey("status", $res);
88
        $this->assertArrayHasKey("notify", $res);
89
90
        $this->assertEquals(200, $res["status"]);
91
        $this->assertEquals("Successful deletion", $res["notify"]);
92
    }
93
94
    /**
95
     * Test deleteAction()
96
     *
97
     * @return void
98
     */
99
    public function testDeleteActionWithStatus404(): void {
100
101
        $client = $this->client;
102
103
        $client->request("GET", "/datatables/employee/delete/49", [], [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
104
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
105
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
106
107
        // Check the JSON response.
108
        $res = json_decode($client->getResponse()->getContent(), true);
109
110
        $this->assertArrayHasKey("status", $res);
111
        $this->assertArrayHasKey("notify", $res);
112
113
        $this->assertEquals(404, $res["status"]);
114
        $this->assertEquals("Record not found", $res["notify"]);
115
    }
116
117
    /**
118
     * Test editAction()
119
     *
120
     * @return void
121
     */
122
    public function testEditAction(): void {
123
124
        $client = $this->client;
125
126
        $client->request("POST", "/datatables/employee/edit/55/name", ["value" => "Shad decker"]);
127
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
128
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
129
130
        // Check the JSON response.
131
        $res = json_decode($client->getResponse()->getContent(), true);
132
133
        $this->assertArrayHasKey("status", $res);
134
        $this->assertArrayHasKey("notify", $res);
135
136
        $this->assertEquals(200, $res["status"]);
137
        $this->assertEquals("Successful editing", $res["notify"]);
138
    }
139
140
    /**
141
     * Test editAction()
142
     *
143
     * @return void
144
     */
145
    public function testEditActionWithBadDatatablesColumnException(): void {
146
147
        $client = $this->client;
148
149
        $client->request("GET", "/datatables/employee/edit/55/data/value");
150
        $this->assertEquals(500, $client->getResponse()->getStatusCode());
151
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
152
153
        $this->assertStringContainsString("BadDataTablesColumnException", $client->getResponse()->getContent());
154
    }
155
156
    /**
157
     * Test editAction()
158
     *
159
     * @return void
160
     */
161
    public function testEditActionWithBadDatatablesEditorException(): void {
162
163
        $client = $this->client;
164
165
        $client->request("GET", "/datatables/office/edit/1/name/value");
166
        $this->assertEquals(500, $client->getResponse()->getStatusCode());
167
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
168
169
        $this->assertStringContainsString("BadDataTablesEditorException", $client->getResponse()->getContent());
170
    }
171
172
    /**
173
     * Test editAction()
174
     *
175
     * @return void
176
     */
177
    public function testEditActionWithStatus404(): void {
178
179
        $client = $this->client;
180
181
        $client->request("GET", "/datatables/employee/edit/49/name/value");
182
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
183
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
184
185
        // Check the JSON response.
186
        $res = json_decode($client->getResponse()->getContent(), true);
187
188
        $this->assertArrayHasKey("status", $res);
189
        $this->assertArrayHasKey("notify", $res);
190
191
        $this->assertEquals(404, $res["status"]);
192
        $this->assertEquals("Record not found", $res["notify"]);
193
    }
194
195
    /**
196
     * Test editAction()
197
     *
198
     * @return void
199
     */
200
    public function testEditActionWithStatus500(): void {
201
202
        $client = $this->client;
203
204
        $client->request("GET", "/datatables/employee/edit/55/age/value");
205
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
206
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
207
208
        // Check the JSON response.
209
        $res = json_decode($client->getResponse()->getContent(), true);
210
211
        $this->assertArrayHasKey("status", $res);
212
        $this->assertArrayHasKey("notify", $res);
213
214
        $this->assertEquals(500, $res["status"]);
215
        $this->assertEquals("Failed editing", $res["notify"]);
216
    }
217
218
    /**
219
     * Test exportAction()
220
     *
221
     * @return void
222
     */
223
    public function testExportAction(): void {
224
225
        $parameters = TestFixtures::getPostData();
226
227
        $client = $this->client;
228
229
        $client->request("GET", "/datatables/employee/export", $parameters);
230
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
231
        $this->assertEquals("text/csv; charset=utf-8", $client->getResponse()->headers->get("Content-Type"));
232
        $this->assertRegExp('/attachment; filename="[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}-[0-9]{2}\\.[0-9]{2}\\.[0-9]{2}-employee\\.csv"/', $client->getResponse()->headers->get("Content-Disposition"));
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertRegExp() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/4086 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

232
        /** @scrutinizer ignore-deprecated */ $this->assertRegExp('/attachment; filename="[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}-[0-9]{2}\\.[0-9]{2}\\.[0-9]{2}-employee\\.csv"/', $client->getResponse()->headers->get("Content-Disposition"));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
233
    }
234
235
    /**
236
     * Test exportAction()
237
     *
238
     * @return void
239
     */
240
    public function testExportActionWithBadDataTablesRepository(): void {
241
242
        $client = $this->client;
243
244
        $client->request("GET", "/datatables/office/export");
245
        $this->assertEquals(500, $client->getResponse()->getStatusCode());
246
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
247
248
        $this->assertStringContainsString("BadDataTablesCSVExporterException", $client->getResponse()->getContent());
249
    }
250
251
    /**
252
     * Test indexAction()
253
     *
254
     * @return void
255
     */
256
    public function testIndexAction(): void {
257
258
        $client = $this->client;
259
260
        $client->request("GET", "/datatables/employee/index");
261
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
262
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
263
    }
264
265
    /**
266
     * Test indexAction()
267
     *
268
     * @return void
269
     */
270
    public function testIndexActionWithBadDataTablesRepository(): void {
271
272
        $client = $this->client;
273
274
        $client->request("GET", "/datatables/office/index", [], [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
275
        $this->assertEquals(500, $client->getResponse()->getStatusCode());
276
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
277
278
        $this->assertStringContainsString("BadDataTablesRepositoryException", $client->getResponse()->getContent());
279
    }
280
281
    /**
282
     * Test indexAction()
283
     *
284
     * @return void
285
     */
286
    public function testIndexActionWithLength(): void {
287
288
        $parameters = TestFixtures::getPostData();
289
290
        $parameters["length"] = "20";
291
292
        $client = $this->client;
293
294
        $client->request("POST", "/datatables/employee/index", $parameters, [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
295
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
296
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
297
298
        // Check the JSON response.
299
        $res = json_decode($client->getResponse()->getContent(), true);
300
301
        $this->assertCount(20, $res["data"]);
302
303
        $this->assertArrayHasKey("DT_RowId", $res["data"][0]);
304
        $this->assertArrayHasKey("DT_RowClass", $res["data"][0]);
305
        $this->assertArrayHasKey("DT_RowData", $res["data"][0]);
306
307
        $this->assertEquals("Airi Satou", $res["data"][0]["name"]);
308
        $this->assertEquals("Angelica Ramos", $res["data"][1]["name"]);
309
        $this->assertEquals("Ashton Cox", $res["data"][2]["name"]);
310
        $this->assertEquals("Bradley Greer", $res["data"][3]["name"]);
311
        $this->assertEquals("Brenden Wagner", $res["data"][4]["name"]);
312
        $this->assertEquals("Brielle Williamson", $res["data"][5]["name"]);
313
        $this->assertEquals("Bruno Nash", $res["data"][6]["name"]);
314
        $this->assertEquals("Caesar Vance", $res["data"][7]["name"]);
315
        $this->assertEquals("Cara Stevens", $res["data"][8]["name"]);
316
        $this->assertEquals("Cedric Kelly", $res["data"][9]["name"]);
317
318
        $this->assertEquals("Charde Marshall", $res["data"][10]["name"]);
319
        $this->assertEquals("Colleen Hurst", $res["data"][11]["name"]);
320
        $this->assertEquals("Dai Rios", $res["data"][12]["name"]);
321
        $this->assertEquals("Donna Snider", $res["data"][13]["name"]);
322
        $this->assertEquals("Doris Wilder", $res["data"][14]["name"]);
323
        $this->assertEquals("Finn Camacho", $res["data"][15]["name"]);
324
        $this->assertEquals("Fiona Green", $res["data"][16]["name"]);
325
        $this->assertEquals("Garrett Winters", $res["data"][17]["name"]);
326
        $this->assertEquals("Gavin Cortez", $res["data"][18]["name"]);
327
        $this->assertEquals("Gavin Joyce", $res["data"][19]["name"]);
328
    }
329
330
    /**
331
     * Test indexAction()
332
     *
333
     * @return void
334
     */
335
    public function testIndexActionWithNegativeLength(): void {
336
337
        $parameters = TestFixtures::getPostData();
338
339
        $parameters["length"] = "-1";
340
341
        // Create a client.
342
        $client = $this->client;
343
344
        $client->request("POST", "/datatables/employee/index", $parameters, [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
345
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
346
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
347
348
        // Check the JSON response.
349
        $res = json_decode($client->getResponse()->getContent(), true);
350
351
        $this->assertCount(55, $res["data"]);
352
353
        $this->assertArrayHasKey("DT_RowId", $res["data"][0]);
354
        $this->assertArrayHasKey("DT_RowClass", $res["data"][0]);
355
        $this->assertArrayHasKey("DT_RowData", $res["data"][0]);
356
357
        $this->assertEquals("Airi Satou", $res["data"][0]["name"]);
358
        $this->assertEquals("Angelica Ramos", $res["data"][1]["name"]);
359
        $this->assertEquals("Ashton Cox", $res["data"][2]["name"]);
360
        $this->assertEquals("Bradley Greer", $res["data"][3]["name"]);
361
        $this->assertEquals("Brenden Wagner", $res["data"][4]["name"]);
362
        $this->assertEquals("Brielle Williamson", $res["data"][5]["name"]);
363
        $this->assertEquals("Bruno Nash", $res["data"][6]["name"]);
364
        $this->assertEquals("Caesar Vance", $res["data"][7]["name"]);
365
        $this->assertEquals("Cara Stevens", $res["data"][8]["name"]);
366
        $this->assertEquals("Cedric Kelly", $res["data"][9]["name"]);
367
368
        // [...]
369
370
        $this->assertEquals("Tiger Nixon", $res["data"][50]["name"]);
371
        $this->assertEquals("Timothy Mooney", $res["data"][51]["name"]);
372
        $this->assertEquals("Unity Butler", $res["data"][52]["name"]);
373
        $this->assertEquals("Vivian Harrell", $res["data"][53]["name"]);
374
        $this->assertEquals("Yuri Berry", $res["data"][54]["name"]);
375
    }
376
377
    /**
378
     * Test indexAction()
379
     *
380
     * @return void
381
     */
382
    public function testIndexActionWithOrder(): void {
383
384
        $parameters = TestFixtures::getPostData();
385
386
        $parameters["order"][0]["dir"] = "desc";
387
388
        $client = $this->client;
389
390
        $client->request("POST", "/datatables/employee/index", $parameters, [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
391
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
392
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
393
394
        // Check the JSON response.
395
        $res = json_decode($client->getResponse()->getContent(), true);
396
397
        $this->assertCount(10, $res["data"]);
398
399
        $this->assertArrayHasKey("DT_RowId", $res["data"][0]);
400
        $this->assertArrayHasKey("DT_RowClass", $res["data"][0]);
401
        $this->assertArrayHasKey("DT_RowData", $res["data"][0]);
402
403
        $this->assertEquals("Yuri Berry", $res["data"][0]["name"]);
404
        $this->assertEquals("Vivian Harrell", $res["data"][1]["name"]);
405
        $this->assertEquals("Unity Butler", $res["data"][2]["name"]);
406
        $this->assertEquals("Timothy Mooney", $res["data"][3]["name"]);
407
        $this->assertEquals("Tiger Nixon", $res["data"][4]["name"]);
408
        $this->assertEquals("Thor Walton", $res["data"][5]["name"]);
409
        $this->assertEquals("Tatyana Fitzpatrick", $res["data"][6]["name"]);
410
        $this->assertEquals("Suki Burks", $res["data"][7]["name"]);
411
        $this->assertEquals("Sonya Frost", $res["data"][8]["name"]);
412
        $this->assertEquals("Shou Itou", $res["data"][9]["name"]);
413
    }
414
415
    /**
416
     * Test indexAction()
417
     *
418
     * @return void
419
     */
420
    public function testIndexActionWithOrderOnNoOrderableColumn(): void {
421
422
        $parameters = TestFixtures::getPostData();
423
424
        $parameters["order"][6]["column"] = "6";
425
        $parameters["order"][6]["dir"]    = "desc";
426
427
        $client = $this->client;
428
429
        $client->request("POST", "/datatables/employee/index", $parameters, [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
430
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
431
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
432
433
        // Check the JSON response.
434
        $res = json_decode($client->getResponse()->getContent(), true);
435
436
        $this->assertCount(10, $res["data"]);
437
438
        $this->assertArrayHasKey("DT_RowId", $res["data"][0]);
439
        $this->assertArrayHasKey("DT_RowClass", $res["data"][0]);
440
        $this->assertArrayHasKey("DT_RowData", $res["data"][0]);
441
442
        $this->assertEquals("Airi Satou", $res["data"][0]["name"]);
443
        $this->assertEquals("Angelica Ramos", $res["data"][1]["name"]);
444
        $this->assertEquals("Ashton Cox", $res["data"][2]["name"]);
445
        $this->assertEquals("Bradley Greer", $res["data"][3]["name"]);
446
        $this->assertEquals("Brenden Wagner", $res["data"][4]["name"]);
447
        $this->assertEquals("Brielle Williamson", $res["data"][5]["name"]);
448
        $this->assertEquals("Bruno Nash", $res["data"][6]["name"]);
449
        $this->assertEquals("Caesar Vance", $res["data"][7]["name"]);
450
        $this->assertEquals("Cara Stevens", $res["data"][8]["name"]);
451
        $this->assertEquals("Cedric Kelly", $res["data"][9]["name"]);
452
    }
453
454
    /**
455
     * Test indexAction()
456
     *
457
     * @return void
458
     */
459
    public function testIndexActionWithParameters(): void {
460
461
        $parameters = TestFixtures::getPostData();
462
463
        $client = $this->client;
464
465
        $client->request("POST", "/datatables/employee/index", $parameters, [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
466
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
467
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
468
469
        // Check the JSON response.
470
        $res = json_decode($client->getResponse()->getContent(), true);
471
472
        $this->assertCount(10, $res["data"]);
473
474
        $this->assertArrayHasKey("DT_RowId", $res["data"][0]);
475
        $this->assertArrayHasKey("DT_RowClass", $res["data"][0]);
476
        $this->assertArrayHasKey("DT_RowData", $res["data"][0]);
477
478
        $this->assertEquals("Airi Satou", $res["data"][0]["name"]);
479
        $this->assertEquals("Angelica Ramos", $res["data"][1]["name"]);
480
        $this->assertEquals("Ashton Cox", $res["data"][2]["name"]);
481
        $this->assertEquals("Bradley Greer", $res["data"][3]["name"]);
482
        $this->assertEquals("Brenden Wagner", $res["data"][4]["name"]);
483
        $this->assertEquals("Brielle Williamson", $res["data"][5]["name"]);
484
        $this->assertEquals("Bruno Nash", $res["data"][6]["name"]);
485
        $this->assertEquals("Caesar Vance", $res["data"][7]["name"]);
486
        $this->assertEquals("Cara Stevens", $res["data"][8]["name"]);
487
        $this->assertEquals("Cedric Kelly", $res["data"][9]["name"]);
488
    }
489
490
    /**
491
     * Test indexAction()
492
     *
493
     * @return void
494
     */
495
    public function testIndexActionWithSearch(): void {
496
497
        $parameters = TestFixtures::getPostData();
498
499
        $parameters["search"]["value"] = "New York";
500
501
        $client = $this->client;
502
503
        $client->request("POST", "/datatables/employee/index", $parameters, [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
504
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
505
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
506
507
        // Check the JSON response.
508
        $res = json_decode($client->getResponse()->getContent(), true);
509
510
        $this->assertCount(10, $res["data"]);
511
512
        $this->assertArrayHasKey("DT_RowId", $res["data"][0]);
513
        $this->assertArrayHasKey("DT_RowClass", $res["data"][0]);
514
        $this->assertArrayHasKey("DT_RowData", $res["data"][0]);
515
516
        $this->assertEquals("Brielle Williamson", $res["data"][0]["name"]);
517
        $this->assertEquals("Caesar Vance", $res["data"][1]["name"]);
518
        $this->assertEquals("Cara Stevens", $res["data"][2]["name"]);
519
        $this->assertEquals("Donna Snider", $res["data"][3]["name"]);
520
        $this->assertEquals("Gloria Little", $res["data"][4]["name"]);
521
        $this->assertEquals("Jackson Bradshaw", $res["data"][5]["name"]);
522
        $this->assertEquals("Jenette Caldwell", $res["data"][6]["name"]);
523
        $this->assertEquals("Paul Byrd", $res["data"][7]["name"]);
524
        $this->assertEquals("Thor Walton", $res["data"][8]["name"]);
525
        $this->assertEquals("Yuri Berry", $res["data"][9]["name"]);
526
    }
527
528
    /**
529
     * Test indexAction()
530
     *
531
     * @return void
532
     */
533
    public function testIndexActionWithSearchColumn(): void {
534
535
        $parameters = TestFixtures::getPostData();
536
537
        $parameters["columns"][0]["search"]["value"] = "Brielle";
538
        $parameters["columns"][2]["search"]["value"] = "New York";
539
540
        $client = $this->client;
541
542
        $client->request("POST", "/datatables/employee/index", $parameters, [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
543
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
544
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
545
546
        // Check the JSON response.
547
        $res = json_decode($client->getResponse()->getContent(), true);
548
549
        $this->assertCount(1, $res["data"]);
550
551
        $this->assertArrayHasKey("DT_RowId", $res["data"][0]);
552
        $this->assertArrayHasKey("DT_RowClass", $res["data"][0]);
553
        $this->assertArrayHasKey("DT_RowData", $res["data"][0]);
554
555
        $this->assertEquals("Brielle Williamson", $res["data"][0]["name"]);
556
    }
557
558
    /**
559
     * Test indexAction()
560
     *
561
     * @return void
562
     */
563
    public function testIndexActionWithSearchColumnOnNoSearchableColumn(): void {
564
565
        $parameters = TestFixtures::getPostData();
566
567
        $parameters["column"][6]["search"]["value"] = "search";
568
569
        $client = $this->client;
570
571
        $client->request("POST", "/datatables/employee/index", $parameters, [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
572
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
573
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
574
575
        // Check the JSON response.
576
        $res = json_decode($client->getResponse()->getContent(), true);
577
578
        $this->assertCount(10, $res["data"]);
579
580
        $this->assertArrayHasKey("DT_RowId", $res["data"][0]);
581
        $this->assertArrayHasKey("DT_RowClass", $res["data"][0]);
582
        $this->assertArrayHasKey("DT_RowData", $res["data"][0]);
583
584
        $this->assertEquals("Airi Satou", $res["data"][0]["name"]);
585
        $this->assertEquals("Angelica Ramos", $res["data"][1]["name"]);
586
        $this->assertEquals("Ashton Cox", $res["data"][2]["name"]);
587
        $this->assertEquals("Bradley Greer", $res["data"][3]["name"]);
588
        $this->assertEquals("Brenden Wagner", $res["data"][4]["name"]);
589
        $this->assertEquals("Brielle Williamson", $res["data"][5]["name"]);
590
        $this->assertEquals("Bruno Nash", $res["data"][6]["name"]);
591
        $this->assertEquals("Caesar Vance", $res["data"][7]["name"]);
592
        $this->assertEquals("Cara Stevens", $res["data"][8]["name"]);
593
        $this->assertEquals("Cedric Kelly", $res["data"][9]["name"]);
594
    }
595
596
    /**
597
     * Test indexAction()
598
     *
599
     * @return void
600
     */
601
    public function testIndexActionWithStart(): void {
602
603
        $parameters = TestFixtures::getPostData();
604
605
        $parameters["start"] = "50";
606
607
        $client = $this->client;
608
609
        $client->request("POST", "/datatables/employee/index", $parameters, [], ["HTTP_X-Requested-With" => "XMLHttpRequest"]);
610
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
611
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
612
613
        // Check the JSON response.
614
        $res = json_decode($client->getResponse()->getContent(), true);
615
616
        $this->assertCount(5, $res["data"]);
617
618
        $this->assertEquals("Tiger Nixon", $res["data"][0]["name"]);
619
        $this->assertEquals("Timothy Mooney", $res["data"][1]["name"]);
620
        $this->assertEquals("Unity Butler", $res["data"][2]["name"]);
621
        $this->assertEquals("Vivian Harrell", $res["data"][3]["name"]);
622
        $this->assertEquals("Yuri Berry", $res["data"][4]["name"]);
623
    }
624
625
    /**
626
     * Test optionsAction()
627
     *
628
     * @return void
629
     */
630
    public function testOptionsAction(): void {
631
632
        $client = $this->client;
633
634
        $client->request("GET", "/datatables/employee/options");
635
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
636
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
637
638
        // Check the JSON response.
639
        $res = json_decode($client->getResponse()->getContent(), true);
640
641
        $this->assertCount(4, $res);
642
        $this->assertCount(7, $res["columns"]);
643
644
        $this->assertEquals("POST", $res["ajax"]["type"]);
645
        $this->assertEquals("/datatables/employee/index", $res["ajax"]["url"]);
646
        $this->assertTrue($res["processing"]);
647
        $this->assertTrue($res["serverSide"]);
648
    }
649
650
    /**
651
     * Test optionsAction()
652
     *
653
     * @return void
654
     */
655
    public function testOptionsActionWithDataTablesRouterInterface(): void {
656
657
        $client = $this->client;
658
659
        $client->request("GET", "/datatables/office/options");
660
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
661
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
662
663
        // Check the JSON response.
664
        $res = json_decode($client->getResponse()->getContent(), true);
665
666
        $this->assertCount(4, $res);
667
        $this->assertCount(2, $res["columns"]);
668
669
        $this->assertEquals("POST", $res["ajax"]["type"]);
670
        $this->assertEquals("url", $res["ajax"]["url"]);
671
        $this->assertTrue($res["processing"]);
672
        $this->assertTrue($res["serverSide"]);
673
    }
674
675
    /**
676
     * Test renderAction()
677
     *
678
     * @return void
679
     */
680
    public function testRenderAction(): void {
681
682
        $client = $this->client;
683
684
        $client->request("GET", "/datatables/employee/render");
685
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
686
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
687
688
        // Get the response content.
689
        $content = $client->getResponse()->getContent();
690
691
        // Check the CSS.
692
        foreach (static::listCSSAssets() as $current) {
693
            $this->assertRegExp("/" . preg_quote($current, "/") . "/", $content);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertRegExp() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/4086 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

693
            /** @scrutinizer ignore-deprecated */ $this->assertRegExp("/" . preg_quote($current, "/") . "/", $content);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
694
        }
695
696
        // Check the Javascript.
697
        foreach (static::listJavascriptAssets() as $current) {
698
            $this->assertRegExp("/" . preg_quote($current, "/") . "/", $content);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertRegExp() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/4086 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

698
            /** @scrutinizer ignore-deprecated */ $this->assertRegExp("/" . preg_quote($current, "/") . "/", $content);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
699
        }
700
    }
701
702
    /**
703
     * Test renderAction()
704
     *
705
     * @return void
706
     */
707
    public function testRenderActionWithAlone(): void {
708
709
        $client = $this->client;
710
711
        $client->request("GET", "/datatables/employee/render/true");
712
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
713
        $this->assertEquals("text/html; charset=UTF-8", $client->getResponse()->headers->get("Content-Type"));
714
715
        // Get the response content.
716
        $content = $client->getResponse()->getContent();
717
718
        // Check the CSS.
719
        foreach (static::listCSSAssets() as $current) {
720
            $this->assertNotRegExp("/" . preg_quote($current, "/") . "/", $content);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertNotRegExp() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/4089 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

720
            /** @scrutinizer ignore-deprecated */ $this->assertNotRegExp("/" . preg_quote($current, "/") . "/", $content);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
721
        }
722
723
        // Check the Javascript.
724
        foreach (static::listJavascriptAssets() as $current) {
725
            $this->assertNotRegExp("/" . preg_quote($current, "/") . "/", $content);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertNotRegExp() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/4089 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

725
            /** @scrutinizer ignore-deprecated */ $this->assertNotRegExp("/" . preg_quote($current, "/") . "/", $content);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
726
        }
727
    }
728
729
    /**
730
     * Test serializeAction()
731
     *
732
     * @return void
733
     */
734
    public function testSerializeAction(): void {
735
736
        $client = $this->client;
737
738
        $client->request("GET", "/datatables/employee/serialize/55");
739
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
740
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
741
742
        // Check the JSON response.
743
        $res = json_decode($client->getResponse()->getContent(), true);
744
745
        $this->assertEquals("Shad decker", $res["name"]);
746
        $this->assertEquals("Regional Director", $res["position"]);
747
        $this->assertEquals("Edinburgh", $res["office"]);
748
        $this->assertEquals(51, $res["age"]);
749
        $this->assertEquals(1226534400, $res["startDate"]["timestamp"]);
750
        $this->assertEquals(183000, $res["salary"]);
751
    }
752
753
    /**
754
     * Test serializeAction()
755
     *
756
     * @return void
757
     */
758
    public function testSerializeActionWithStatus404(): void {
759
760
        $client = $this->client;
761
762
        $client->request("GET", "/datatables/employee/serialize/49");
763
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
764
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
765
766
        // Check the JSON response.
767
        $res = json_decode($client->getResponse()->getContent(), true);
768
769
        $this->assertCount(0, $res);
770
    }
771
772
    /**
773
     * Test showAction()
774
     *
775
     * @return void
776
     */
777
    public function testShowAction(): void {
778
779
        $client = $this->client;
780
781
        $client->request("GET", "/datatables/employee/show/55");
782
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
783
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
784
785
        // Check the JSON response.
786
        $res = json_decode($client->getResponse()->getContent(), true);
787
788
        $this->assertEquals("Shad decker", $res["name"]);
789
        $this->assertEquals("Regional Director", $res["position"]);
790
        $this->assertEquals("Edinburgh", $res["office"]);
791
        $this->assertEquals(51, $res["age"]);
792
        $this->assertEquals(1226534400, $res["startDate"]["timestamp"]);
793
        $this->assertEquals(183000, $res["salary"]);
794
    }
795
796
    /**
797
     * Test showAction()
798
     *
799
     * @return void
800
     */
801
    public function testShowActionWithStatus404(): void {
802
803
        $client = $this->client;
804
805
        $client->request("GET", "/datatables/employee/show/49");
806
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
807
        $this->assertEquals("application/json", $client->getResponse()->headers->get("Content-Type"));
808
809
        // Check the JSON response.
810
        $res = json_decode($client->getResponse()->getContent(), true);
811
812
        $this->assertCount(0, $res);
813
    }
814
815
    /**
816
     * Test __construct()
817
     *
818
     * @return void
819
     */
820
    public function test__construct(): void {
821
822
        $this->assertEquals("wbw.jquery.datatables.controller.datatables", DataTablesController::SERVICE_NAME);
823
    }
824
}
825