mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-10 01:16:12 +00:00
Add basic tests on SMS datas
This commit is contained in:
parent
0f85a5341d
commit
29dc4dcf46
@ -23,5 +23,5 @@ $application = new Application();
|
|||||||
|
|
||||||
$application->registerRoutes($this, array('routes' => array(
|
$application->registerRoutes($this, array('routes' => array(
|
||||||
array('name' => 'sms#index', 'url' => '/', 'verb' => 'GET'),
|
array('name' => 'sms#index', 'url' => '/', 'verb' => 'GET'),
|
||||||
array('name' => 'sms#push', 'url' => '/push', 'verb' => 'POST'),
|
array('name' => 'sms#push', 'url' => '/push', 'verb' => 'POST'),
|
||||||
)));
|
)));
|
||||||
|
@ -37,16 +37,42 @@ class SmsController extends Controller {
|
|||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function push($smsCount, $smsDatas) {
|
public function push ($smsCount, $smsDatas) {
|
||||||
if ($smsCount != count($smsDatas)) {
|
if ($smsCount != count($smsDatas)) {
|
||||||
return "Error: sms count invalid";
|
return "Error: sms count invalid";
|
||||||
}
|
}
|
||||||
|
|
||||||
$buf = "";
|
foreach ($smsDatas as $sms) {
|
||||||
foreach ($sms as $smsDatas) {
|
if (!array_key_exists("id", $sms) || !array_key_exists("read", $sms) ||
|
||||||
$buf .= $sms["id"];
|
!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";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
var data = {
|
var data = {
|
||||||
smsCount: 2,
|
smsCount: 2,
|
||||||
smsDatas: [
|
smsDatas: [
|
||||||
{"read": 1, "date": 1410524385, "seen": 0, "address": "+33612121212", "body": "testSMS", "id": 10},
|
{"read": true, "date": 1410524385, "seen": false, "draft": false, "address": "+33612121212", "body": "testSMS", "id": 10},
|
||||||
{"read": 0, "date": 1400524385, "seen": 1, "address": "+33614121212", "body": "test SMS 2", "id": 14},
|
{"read": false, "date": 1400524385, "seen": true, "draft": true, "address": "+33614121212", "body": "test SMS 2", "id": 14},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user