@@ -96,7 +96,7 @@ public function testDataTableState(): void
9696 $ state ->setGlobalSearch ('foo ' );
9797 $ state ->setOrderBy ([
9898 [$ datatable ->getColumn (0 ), 'asc ' ],
99- [$ datatable ->getColumn (1 ), 'desc0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z ' ], // intentional sql-injection test
99+ [$ datatable ->getColumn (1 ), 'desc ' ],
100100 ]);
101101 $ state ->setColumnSearch ($ datatable ->getColumn (0 ), 'bar ' );
102102
@@ -105,7 +105,6 @@ public function testDataTableState(): void
105105 $ this ->assertSame ('foo ' , $ state ->getGlobalSearch ());
106106 $ this ->assertCount (2 , $ state ->getOrderBy ());
107107 foreach ($ state ->getOrderBy () as $ order ) {
108- // ensure sql-injection failed
109108 $ this ->assertContains ($ order [1 ], [DataTable::SORT_ASCENDING , DataTable::SORT_DESCENDING ]);
110109 }
111110 $ this ->assertSame ('bar ' , $ state ->getSearchColumns (onlySearchable: false )['foo ' ]['search ' ]);
@@ -146,19 +145,23 @@ public function testDataTableStateSearchColumns(): void
146145 /**
147146 * If ordering is false, ensure columns are not ordered.
148147 */
149- public function testDataTablesStateOrdering (): void
148+ public function testSortDirectionValidation (): void
150149 {
150+ $ this ->expectException (\InvalidArgumentException::class);
151+ $ this ->expectExceptionMessage ('direction must be one of ' );
152+
151153 $ datatable = $ this
152- ->createMockDataTable ([ ' ordering ' => false ] )
154+ ->createMockDataTable ()
153155 ->add ('foo ' , TextColumn::class, ['searchable ' => true ])
154- ->add ('bar ' , TextColumn::class, ['searchable ' => false ])
155- ->setMethod (Request::METHOD_GET )
156156 ;
157- $ datatable ->handleRequest (Request::create ('/?_dt= ' . $ datatable ->getName ()));
158-
159- $ state = $ datatable ->getState ();
160- $ state ->addOrderBy ($ datatable ->getColumn (0 ), DataTable::SORT_DESCENDING );
161- $ this ->assertEmpty ($ state ->getOrderBy ());
157+ $ datatable ->handleRequest (Request::create ('/foo ' , Request::METHOD_POST , [
158+ '_dt ' => $ datatable ->getName (),
159+ 'draw ' => 684 ,
160+ 'order ' => [[
161+ 'column ' => 0 ,
162+ 'dir ' => 'foo ' ,
163+ ]],
164+ ]));
162165 }
163166
164167 public function testPostMethod (): void
0 commit comments