Skip to content

Commit

Permalink
Fix the start and end time vaildation code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpwhite4 committed Jun 14, 2017
1 parent 97840f4 commit 1903ba0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions classes/DataWarehouse/Access/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ protected function checkDateParameters()
);

if ($start_date_parsed['error_count'] !== 0) {
throw new Exception(
throw new \DataWarehouse\Query\Exceptions\BadRequestException(
'start_date param is not in the correct format of Y-m-d.'
);
}

$end_date_parsed = date_parse_from_format('Y-m-d', $this->request['end_date']);

if ($end_date_parsed['error_count'] !== 0) {
throw new Exception(
throw new \DataWarehouse\Query\Exceptions\BadRequestException(
'end_date param is not in the correct format of Y-m-d.'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,51 @@ protected function setUp()
$this->helper = new \TestHarness\XdmodTestHelper();
}

/**
* @dataProvider corruptDataProvider
*/
public function testCorruptRequestData($input, $expectedMessage)
{
$response = $this->helper->post('/controllers/user_interface.php', null, $input);

$expectedErrorMessage = 'start_date param is not in the correct format of Y-m-d.';

$this->assertEquals($response[1]['content_type'], 'application/json');
$this->assertEquals($response[1]['http_code'], 400);
$this->assertEquals($response[0]['message'], $expectedMessage);
}

public function corruptDataProvider()
{
$defaultJson = <<<EOF
{
"public_user": "true",
"realm": "Jobs",
"group_by": "none",
"start_date": "2017-05-01",
"end_date": "2017-05-31",
"statistic": "job_count",
"operation": "get_charts",
"controller_module": "user_interface"
}
EOF;
$tests = array();

$input = json_decode($defaultJson, true);
unset($input['end_date']);
$tests[] = array($input, 'end_date param is not in the correct format of Y-m-d.');

$input = json_decode($defaultJson, true);
unset($input['start_date']);
$tests[] = array($input, 'start_date param is not in the correct format of Y-m-d.');

$input = json_decode($defaultJson, true);
$input['group_by'] = 'elephants';
$tests[] = array($input, 'Query: Unknown Group By "elephants" Specified');

return $tests;
}

/**
* Checks the structure of the get_tabs endpoint.
*/
Expand Down

0 comments on commit 1903ba0

Please sign in to comment.