1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 16:06:15 +00:00

Add basic tests on SMS datas

This commit is contained in:
Loic Blot 2014-09-12 13:16:46 +00:00
parent 0f85a5341d
commit 29dc4dcf46
3 changed files with 34 additions and 8 deletions

View File

@ -23,5 +23,5 @@ $application = new Application();
$application->registerRoutes($this, array('routes' => array(
array('name' => 'sms#index', 'url' => '/', 'verb' => 'GET'),
array('name' => 'sms#push', 'url' => '/push', 'verb' => 'POST'),
array('name' => 'sms#push', 'url' => '/push', 'verb' => 'POST'),
)));

View File

@ -37,16 +37,42 @@ class SmsController extends Controller {
/**
* @NoAdminRequired
*/
public function push($smsCount, $smsDatas) {
public function push ($smsCount, $smsDatas) {
if ($smsCount != count($smsDatas)) {
return "Error: sms count invalid";
}
$buf = "";
foreach ($sms as $smsDatas) {
$buf .= $sms["id"];
foreach ($smsDatas as $sms) {
if (!array_key_exists("id", $sms) || !array_key_exists("read", $sms) ||
!array_key_exists("draft", $sms) ||
!array_key_exists("date", $sms) || !array_key_exists("seen", $sms) ||
!array_key_exists("body", $sms) || !array_key_exists("address", $sms)) {
return "Error: bad SMS entry";
}
if (!is_numeric($sms["id"])) {
return "Error: Invalid SMS ID";
}
if ($sms["read"] !== "true" && $sms["read"] !== "false") {
return "Error: Invalid SMS Read state";
}
if ($sms["seen"] !== "true" && $sms["seen"] !== "false") {
return "Error: Invalid SMS Seen state";
}
if ($sms["draft"] !== "true" && $sms["draft"] !== "false") {
return "Error: Invalid SMS Draft state";
}
if (!is_numeric($sms["date"]) && $sms["date"] != 0 && $sms["date"] != 1) {
return "Error: Invalid SMS date";
}
// @ TODO: test address and body ?
}
return $buf;
return "OK";
}

View File

@ -16,8 +16,8 @@
var data = {
smsCount: 2,
smsDatas: [
{"read": 1, "date": 1410524385, "seen": 0, "address": "+33612121212", "body": "testSMS", "id": 10},
{"read": 0, "date": 1400524385, "seen": 1, "address": "+33614121212", "body": "test SMS 2", "id": 14},
{"read": true, "date": 1410524385, "seen": false, "draft": false, "address": "+33612121212", "body": "testSMS", "id": 10},
{"read": false, "date": 1400524385, "seen": true, "draft": true, "address": "+33614121212", "body": "test SMS 2", "id": 14},
]
};