Merge branch 'master' of bitbucket.org:colosa/processmaker
This commit is contained in:
@@ -262,13 +262,19 @@ class Calendar
|
||||
public function create($arrayData)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
||||
|
||||
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
|
||||
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||
|
||||
//Set data
|
||||
$arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER);
|
||||
|
||||
unset($arrayData["CAL_UID"]);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
|
||||
|
||||
$this->throwExceptionIfExistsName($arrayData["CAL_NAME"], $this->arrayFieldNameForException["calendarName"]);
|
||||
@@ -321,11 +327,7 @@ class Calendar
|
||||
$arrayDataAux = array();
|
||||
$arrayDataAux["CALENDAR_UID"] = \G::generateUniqueID();
|
||||
$arrayDataAux["CALENDAR_NAME"] = $arrayData["CAL_NAME"];
|
||||
|
||||
if (isset($arrayData["CAL_DESCRIPTION"])) {
|
||||
$arrayDataAux["CALENDAR_DESCRIPTION"] = $arrayData["CAL_DESCRIPTION"];
|
||||
}
|
||||
|
||||
$arrayDataAux["CALENDAR_DESCRIPTION"] = (isset($arrayData["CAL_DESCRIPTION"]))? $arrayData["CAL_DESCRIPTION"] : "";
|
||||
$arrayDataAux["CALENDAR_WORK_DAYS"] = explode("|", $this->workDaysReplaceData(implode("|", $arrayData["CAL_WORK_DAYS"])));
|
||||
$arrayDataAux["CALENDAR_STATUS"] = $arrayData["CAL_STATUS"];
|
||||
|
||||
@@ -361,11 +363,17 @@ class Calendar
|
||||
public function update($calendarUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
||||
|
||||
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
|
||||
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||
|
||||
//Set data
|
||||
$arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER);
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$this->throwExceptionIfNotExistsCalendar($calendarUid, $this->arrayFieldNameForException["calendarUid"]);
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
|
||||
|
||||
@@ -61,7 +61,9 @@ class Cases
|
||||
if ($start != 0) {
|
||||
$start--;
|
||||
}
|
||||
if ((abs((int)$limit)) == 0) {
|
||||
$limit = (int)$limit;
|
||||
$limit = abs($limit);
|
||||
if ($limit == 0) {
|
||||
G::LoadClass("configuration");
|
||||
$conf = new \Configurations();
|
||||
$generalConfCasesList = $conf->getConfiguration('ENVIRONMENT_SETTINGS', '');
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace ProcessMaker\BusinessModel;
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
class Validator{
|
||||
class Validator
|
||||
{
|
||||
/**
|
||||
* Validate dep_uid
|
||||
* @var string $dep_uid. Uid for Departament
|
||||
@@ -330,6 +331,47 @@ class Validator{
|
||||
throw (new \Exception("The field '$nameField' is empty."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if data is array
|
||||
*
|
||||
* @param string $data Data
|
||||
* @param string $dataNameForException Data name for the exception
|
||||
*
|
||||
* return void Throw exception if data is not array
|
||||
*/
|
||||
public function throwExceptionIfDataIsNotArray($data, $dataNameForException)
|
||||
{
|
||||
try {
|
||||
if (!is_array($data)) {
|
||||
$msg = str_replace(array("{0}"), array($dataNameForException), "The data \"{0}\" is not array");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if data is empty
|
||||
*
|
||||
* @param string $data Data
|
||||
* @param string $dataNameForException Data name for the exception
|
||||
*
|
||||
* return void Throw exception if data is empty
|
||||
*/
|
||||
public function throwExceptionIfDataIsEmpty($data, $dataNameForException)
|
||||
{
|
||||
try {
|
||||
if (empty($data)) {
|
||||
$msg = str_replace(array("{0}"), array($dataNameForException), "The data \"{0}\" is empty");
|
||||
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ if (!class_exists("Propel")) {
|
||||
*/
|
||||
class CalendarTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private static $calendar;
|
||||
private static $numCalendar = 2;
|
||||
protected static $calendar;
|
||||
protected static $numCalendar = 2;
|
||||
|
||||
/**
|
||||
* Set class for test
|
||||
@@ -63,6 +63,22 @@ class CalendarTest extends \PHPUnit_Framework_TestCase
|
||||
$arrayRecord[] = $arrayCalendar;
|
||||
}
|
||||
|
||||
//Create - Japanese characters
|
||||
$arrayData = array(
|
||||
"CAL_NAME" => "私の名前(PHPUnitの)",
|
||||
"CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"),
|
||||
"CAL_STATUS" => "ACTIVE"
|
||||
);
|
||||
|
||||
$arrayCalendar = self::$calendar->create($arrayData);
|
||||
|
||||
$this->assertTrue(is_array($arrayCalendar));
|
||||
$this->assertNotEmpty($arrayCalendar);
|
||||
|
||||
$this->assertTrue(isset($arrayCalendar["CAL_UID"]));
|
||||
|
||||
$arrayRecord[] = $arrayCalendar;
|
||||
|
||||
//Return
|
||||
return $arrayRecord;
|
||||
}
|
||||
@@ -70,10 +86,10 @@ class CalendarTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test update calendars
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::update
|
||||
*
|
||||
* @depends testCreate
|
||||
* @param array $arrayRecord Data of the calendars
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::update
|
||||
*/
|
||||
public function testUpdate($arrayRecord)
|
||||
{
|
||||
@@ -92,10 +108,10 @@ class CalendarTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test get calendars
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::getCalendars
|
||||
*
|
||||
* @depends testCreate
|
||||
* @param array $arrayRecord Data of the calendars
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::getCalendars
|
||||
*/
|
||||
public function testGetCalendars($arrayRecord)
|
||||
{
|
||||
@@ -121,13 +137,14 @@ class CalendarTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Test get calendar
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::getCalendar
|
||||
*
|
||||
* @depends testCreate
|
||||
* @param array $arrayRecord Data of the calendars
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::getCalendar
|
||||
*/
|
||||
public function testGetCalendar($arrayRecord)
|
||||
{
|
||||
//Get
|
||||
$arrayCalendar = self::$calendar->getCalendar($arrayRecord[0]["CAL_UID"]);
|
||||
|
||||
$this->assertTrue(is_array($arrayCalendar));
|
||||
@@ -137,15 +154,249 @@ class CalendarTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($arrayCalendar["CAL_NAME"], $arrayRecord[0]["CAL_NAME"]);
|
||||
$this->assertEquals($arrayCalendar["CAL_DESCRIPTION"], $arrayRecord[0]["CAL_DESCRIPTION"]);
|
||||
$this->assertEquals($arrayCalendar["CAL_STATUS"], $arrayRecord[0]["CAL_STATUS"]);
|
||||
|
||||
//Get - Japanese characters
|
||||
$arrayCalendar = self::$calendar->getCalendar($arrayRecord[self::$numCalendar]["CAL_UID"]);
|
||||
|
||||
$this->assertTrue(is_array($arrayCalendar));
|
||||
$this->assertNotEmpty($arrayCalendar);
|
||||
|
||||
$this->assertEquals($arrayCalendar["CAL_NAME"], "私の名前(PHPUnitの)");
|
||||
$this->assertEquals($arrayCalendar["CAL_WORK_DAYS"], array("MON", "TUE", "WED", "THU", "FRI"));
|
||||
$this->assertEquals($arrayCalendar["CAL_STATUS"], "ACTIVE");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception when data not is array
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::create
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The data "$arrayData" is not array
|
||||
*/
|
||||
public function testCreateExceptionNoIsArrayData()
|
||||
{
|
||||
$arrayData = 0;
|
||||
|
||||
$arrayCalendar = self::$calendar->create($arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for empty data
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::create
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The data "$arrayData" is empty
|
||||
*/
|
||||
public function testCreateExceptionEmptyData()
|
||||
{
|
||||
$arrayData = array();
|
||||
|
||||
$arrayCalendar = self::$calendar->create($arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for required data (CAL_NAME)
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::create
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The "CAL_NAME" attribute is not defined
|
||||
*/
|
||||
public function testCreateExceptionRequiredDataCalName()
|
||||
{
|
||||
$arrayData = array(
|
||||
//"CAL_NAME" => "PHPUnit Calendar",
|
||||
"CAL_DESCRIPTION" => "Description",
|
||||
"CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"),
|
||||
"CAL_STATUS" => "ACTIVE"
|
||||
);
|
||||
|
||||
$arrayCalendar = self::$calendar->create($arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for invalid data (CAL_NAME)
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::create
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The "CAL_NAME" attribute is empty
|
||||
*/
|
||||
public function testCreateExceptionInvalidDataCalName()
|
||||
{
|
||||
$arrayData = array(
|
||||
"CAL_NAME" => "",
|
||||
"CAL_DESCRIPTION" => "Description",
|
||||
"CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"),
|
||||
"CAL_STATUS" => "ACTIVE"
|
||||
);
|
||||
|
||||
$arrayCalendar = self::$calendar->create($arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for invalid data (CAL_WORK_DAYS)
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::create
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value specified for "CAL_WORK_DAYS"
|
||||
*/
|
||||
public function testCreateExceptionInvalidDataCalWorkDays()
|
||||
{
|
||||
$arrayData = array(
|
||||
"CAL_NAME" => "PHPUnit Calendar",
|
||||
"CAL_DESCRIPTION" => "Description",
|
||||
"CAL_WORK_DAYS" => array("MONDAY", "TUE", "WED", "THU", "FRI"),
|
||||
"CAL_STATUS" => "ACTIVE"
|
||||
);
|
||||
|
||||
$arrayCalendar = self::$calendar->create($arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for calendar name existing
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::create
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The calendar name with CAL_NAME: "PHPUnit Calendar0" already exists
|
||||
*/
|
||||
public function testCreateExceptionExistsCalName()
|
||||
{
|
||||
$arrayData = array(
|
||||
"CAL_NAME" => "PHPUnit Calendar0",
|
||||
"CAL_DESCRIPTION" => "Description",
|
||||
"CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"),
|
||||
"CAL_STATUS" => "ACTIVE"
|
||||
);
|
||||
|
||||
$arrayCalendar = self::$calendar->create($arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception when data not is array
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::update
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The data "$arrayData" is not array
|
||||
*/
|
||||
public function testUpdateExceptionNoIsArrayData()
|
||||
{
|
||||
$arrayData = 0;
|
||||
|
||||
$arrayCalendar = self::$calendar->update("", $arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for empty data
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::update
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The data "$arrayData" is empty
|
||||
*/
|
||||
public function testUpdateExceptionEmptyData()
|
||||
{
|
||||
$arrayData = array();
|
||||
|
||||
$arrayCalendar = self::$calendar->update("", $arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for invalid calendar UID
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::update
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The calendar with CAL_UID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx does not exists
|
||||
*/
|
||||
public function testUpdateExceptionInvalidCalUid()
|
||||
{
|
||||
$arrayData = array(
|
||||
"CAL_NAME" => "PHPUnit Calendar",
|
||||
"CAL_DESCRIPTION" => "Description",
|
||||
"CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"),
|
||||
"CAL_STATUS" => "ACTIVE"
|
||||
);
|
||||
|
||||
$arrayCalendar = self::$calendar->update("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", $arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for invalid data (CAL_NAME)
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::update
|
||||
*
|
||||
* @depends testCreate
|
||||
* @param array $arrayRecord Data of the calendars
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The "CAL_NAME" attribute is empty
|
||||
*/
|
||||
public function testUpdateExceptionInvalidDataCalName($arrayRecord)
|
||||
{
|
||||
$arrayData = array(
|
||||
"CAL_NAME" => "",
|
||||
"CAL_DESCRIPTION" => "Description",
|
||||
"CAL_WORK_DAYS" => array("MON", "TUE", "WED", "THU", "FRI"),
|
||||
"CAL_STATUS" => "ACTIVE"
|
||||
);
|
||||
|
||||
$arrayCalendar = self::$calendar->update($arrayRecord[0]["CAL_UID"], $arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for invalid data (CAL_WORK_DAYS)
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::update
|
||||
*
|
||||
* @depends testCreate
|
||||
* @param array $arrayRecord Data of the calendars
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Invalid value specified for "CAL_WORK_DAYS"
|
||||
*/
|
||||
public function testUpdateExceptionInvalidDataCalWorkDays($arrayRecord)
|
||||
{
|
||||
$arrayData = array(
|
||||
"CAL_NAME" => "PHPUnit Calendar",
|
||||
"CAL_DESCRIPTION" => "Description",
|
||||
"CAL_WORK_DAYS" => array("MONDAY", "TUE", "WED", "THU", "FRI"),
|
||||
"CAL_STATUS" => "ACTIVE"
|
||||
);
|
||||
|
||||
$arrayCalendar = self::$calendar->update($arrayRecord[0]["CAL_UID"], $arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exception for calendar name existing
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::update
|
||||
*
|
||||
* @depends testCreate
|
||||
* @param array $arrayRecord Data of the calendars
|
||||
*
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage The calendar name with CAL_NAME: "PHPUnit Calendar1" already exists
|
||||
*/
|
||||
public function testUpdateExceptionExistsCalName($arrayRecord)
|
||||
{
|
||||
$arrayData = $arrayRecord[1];
|
||||
|
||||
$arrayCalendar = self::$calendar->update($arrayRecord[0]["CAL_UID"], $arrayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete calendars
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::delete
|
||||
*
|
||||
* @depends testCreate
|
||||
* @param array $arrayRecord Data of the calendars
|
||||
*
|
||||
* @covers \ProcessMaker\BusinessModel\Calendar::delete
|
||||
*/
|
||||
public function testDelete($arrayRecord)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user