*/ class DatatableRequestTest extends TestCase { public function setUp(): void { parent::setUp(); } /** * @dataProvider environmentsProvider * @preserveGlobalState disabled * * @param Environment $env * @param array $result expected results */ public function testGetRows($env, $result) { $request = Request::createFromEnvironment($env); $datatableRequest = new DatatableRequest($request); $this->assertEquals($result['rows'], $datatableRequest->getRows()); } /** * @dataProvider environmentsProvider * @preserveGlobalState disabled * * @param Environment $env * @param array $result expected results */ public function testGetPage($env, $result) { $request = Request::createFromEnvironment($env); $datatableRequest = new DatatableRequest($request); $this->assertEquals($result['page'], $datatableRequest->getPage()); } /** * @dataProvider environmentsProvider * @preserveGlobalState disabled * * @param Environment $env * @param array $result expected results */ public function testGetSortBy($env, $result) { $request = Request::createFromEnvironment($env); $datatableRequest = new DatatableRequest($request); $this->assertEquals($result['sortby'], $datatableRequest->getSortBy()); } /** * @dataProvider environmentsProvider * @preserveGlobalState disabled * * @param Environment $env * @param array $result expected results */ public function testGetSortOrder($env, $result) { $request = Request::createFromEnvironment($env); $datatableRequest = new DatatableRequest($request); $this->assertEquals($result['sortorder'], $datatableRequest->getSortOrder()); } /** * @dataProvider environmentsProvider * @preserveGlobalState disabled * * @param Environment $env * @param array $result expected results */ public function testGetFilters($env, $result) { $request = Request::createFromEnvironment($env); $datatableRequest = new DatatableRequest($request); $this->assertEquals($result['filters'], $datatableRequest->getFilters()); } public function environmentsProvider() { return [ [ 'env' => Environment::mock([ 'QUERY_STRING' => http_build_query([ 'rows' => '5', 'page' => '1', 'sortby' => 'id', 'sortorder' => 'asc', 'filtercolumns' => ['lastname' => 'John'], ]), 'REQUEST_METHOD' => 'GET', ]), 'result' => [ 'rows' => 5, 'page' => 1, 'sortby' => 'id', 'sortorder' => 'asc', 'filters' => ['lastname' => 'John'], ], ], [ 'env' => Environment::mock([ 'QUERY_STRING' => http_build_query([ 'rows' => '5', 'page' => '1', 'sortby' => 'id', 'sortorder' => 'DESC', 'filtercolumns' => ['lastname' => 'John', 'firstname' => 'Doe'], ]), 'REQUEST_METHOD' => 'GET', ]), 'result' => [ 'rows' => 5, 'page' => 1, 'sortby' => 'id', 'sortorder' => 'desc', 'filters' => ['lastname' => 'John', 'firstname' => 'Doe'], ], ], [ 'env' => Environment::mock([ 'QUERY_STRING' => http_build_query([ 'rows' => 25, 'sortby' => 'id', ]), 'REQUEST_METHOD' => 'GET', ]), 'result' => [ 'rows' => 25, 'page' => 1, 'sortby' => 'id', 'sortorder' => 'asc', 'filters' => [], ], ], [ 'env' => Environment::mock([ 'QUERY_STRING' => http_build_query([ 'rows' => 25, 'page' => 2, 'sortby' => 'id', 'sortorder' => 'abc', ]), 'REQUEST_METHOD' => 'GET', ]), 'result' => [ 'rows' => 25, 'page' => 2, 'sortby' => 'id', 'sortorder' => 'asc', 'filters' => [], ], ], ]; } }