mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-09 13:36:07 +09:00
update checkRequiredParamsForArray()
This commit is contained in:
1 parent
2b165891aa
commit
d981df25e4
2 files changed
+52
-1
No files matched your search
@@ -92,7 +92,16 @@ class Box_Validate
|
||||
public function checkRequiredParamsForArray(array $required, array $data, array $variables = NULL, $code = 0)
|
||||
{
|
||||
foreach ($required as $key => $msg) {
|
||||
if (!isset($data[$key]) || empty($data[$key])) {
|
||||
|
||||
if(!isset($data[$key])){
|
||||
throw new \Box_Exception($msg, $variables, $code);
|
||||
}
|
||||
|
||||
if (is_string($data[$key]) && strlen(trim($data[$key])) === 0){
|
||||
throw new \Box_Exception($msg, $variables, $code);
|
||||
}
|
||||
|
||||
if (!is_numeric($data[$key]) && empty($data[$key])){
|
||||
throw new \Box_Exception($msg, $variables, $code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,4 +162,46 @@ class Box_ValidateTest extends PHPUnit_Framework_TestCase
|
||||
$v->checkRequiredParamsForArray($required, $data, array(), 54321);
|
||||
}
|
||||
|
||||
public function testcheckRequiredParamsForArray_KeyValueIsZero()
|
||||
{
|
||||
$data = array(
|
||||
'amount' => 0
|
||||
);
|
||||
$required = array(
|
||||
'amount' => 'amount must be set',
|
||||
);
|
||||
|
||||
$v = new Box_Validate();
|
||||
$v->checkRequiredParamsForArray($required, $data);
|
||||
}
|
||||
|
||||
public function testcheckRequiredParamsForArray_EmptyString()
|
||||
{
|
||||
$data = array(
|
||||
'message' => ''
|
||||
);
|
||||
$required = array(
|
||||
'message' => 'message must be set',
|
||||
);
|
||||
|
||||
$v = new Box_Validate();
|
||||
$this->setExpectedException('\Box_Exception', $required['message']);
|
||||
$v->checkRequiredParamsForArray($required, $data);
|
||||
}
|
||||
|
||||
|
||||
public function testcheckRequiredParamsForArray_EmptyStringFilledWithSpaces()
|
||||
{
|
||||
$data = array(
|
||||
'message' => ' '
|
||||
);
|
||||
$required = array(
|
||||
'message' => 'message must be set',
|
||||
);
|
||||
|
||||
$v = new Box_Validate();
|
||||
$this->setExpectedException('\Box_Exception', $required['message']);
|
||||
$v->checkRequiredParamsForArray($required, $data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user