diff options
-rw-r--r-- | tests/Data_deleteById/CommonEvents/source.json | 90 | ||||
-rw-r--r-- | tests/Data_getData/DayRecurrings/source.json | 18 | ||||
-rw-r--r-- | tests/Data_getData/DayRecurrings/target.json | 34 | ||||
-rw-r--r-- | tests/Data_saveData/DayRecurrings/source.json | 24 | ||||
-rw-r--r-- | tests/Data_saveData/DayRecurrings/target.json | 20 | ||||
-rw-r--r-- | tests/Data_saveDataUpdate/DayRecurrings/source.json | 64 | ||||
-rw-r--r-- | tests/Data_saveDataUpdate/DayRecurrings/target.json | 34 | ||||
-rw-r--r-- | tests/Data_saveDataUpdate/MonthRecurrings/source.json | 86 | ||||
-rw-r--r-- | tests/Data_saveDataUpdate/MonthRecurrings/target.json | 40 | ||||
-rw-r--r-- | tests/Data_saveDataUpdate/WeekRecurrings/source.json | 68 | ||||
-rw-r--r-- | tests/Data_saveDataUpdate/WeekRecurrings/target.json | 34 | ||||
-rw-r--r-- | tests/Data_saveDataUpdate/YearRecurrings/source.json | 88 | ||||
-rw-r--r-- | tests/Data_saveDataUpdate/YearRecurrings/target.json | 40 | ||||
-rw-r--r-- | tests/Logger.php | 33 | ||||
-rw-r--r-- | tests/SchedulerHelperTest.php | 224 | ||||
-rw-r--r-- | tests/TestBaseHelper.php | 114 | ||||
-rw-r--r-- | tests/TestConfig.php | 20 | ||||
-rw-r--r-- | tests/TestDataHelper.php | 126 |
18 files changed, 1157 insertions, 0 deletions
diff --git a/tests/Data_deleteById/CommonEvents/source.json b/tests/Data_deleteById/CommonEvents/source.json new file mode 100644 index 0000000..619f738 --- /dev/null +++ b/tests/Data_deleteById/CommonEvents/source.json @@ -0,0 +1,90 @@ +{ + "insert_data": [ + { + "start_date": "2016-05-04 10:00:00", + "end_date": "2016-05-04 15:00:00", + "text": "Test event 1", + "id": "1", + "event_pid": "", + "event_length": "", + "rec_pattern": "", + "rec_type": "", + "!nativeeditor_status": "" + }, + { + "start_date": "2016-05-10 00:00:00", + "end_date": "2016-05-18 00:00:00", + "text": "Test event 2", + "id": "2", + "event_pid": "", + "event_length": "300", + "rec_pattern": "day_2___", + "rec_type": "day_2___#4", + "!nativeeditor_status": "" + }, + { + "start_date": "2016-05-03 22:40:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Event 3", + "id": "3", + "event_pid": "", + "event_length": "3600", + "rec_pattern": "week_2___0,2,6", + "rec_type": "week_2___0,2,6#no", + "!nativeeditor_status": "" + }, + { + "start_date": "2016-05-02 00:00:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Event 4", + "id": "4", + "event_pid": "", + "event_length": "300", + "rec_pattern": "month_1___", + "rec_type": "month_1___#no", + "!nativeeditor_status": "" + }, + { + "start_date": "2016-05-09 00:00:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Event 5", + "id": "5", + "event_pid": "", + "event_length": "300", + "rec_pattern": "month_1_5_4_", + "rec_type": "month_1_5_4_#no", + "!nativeeditor_status": "" + }, + { + "start_date": "2016-03-08 00:00:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Event 6", + "id": "6", + "event_pid": "", + "event_length": "300", + "rec_pattern": "year_1___", + "rec_type": "year_1___#no", + "!nativeeditor_status": "" + } + ], + "data": [ + { + "id": 1 + }, + { + "id": 2 + }, + { + "id": 3 + }, + { + "id": 4 + }, + { + "id": 5 + }, + { + "id": 6 + } + ] +}
\ No newline at end of file diff --git a/tests/Data_getData/DayRecurrings/source.json b/tests/Data_getData/DayRecurrings/source.json new file mode 100644 index 0000000..a5620bc --- /dev/null +++ b/tests/Data_getData/DayRecurrings/source.json @@ -0,0 +1,18 @@ +{ + "settings": { + "start_date": "2016-03-09 00:00:00", + "end_date": "2016-03-13 23:00:00" + }, + "data": [ + { + "id": "497", + "start_date": "2016-03-09 00:00:00", + "end_date": "2016-03-15 00:00:00", + "text": "Rec Ev", + "rec_type": "day_2___#3", + "event_pid": "0", + "event_length": "300", + "rec_pattern": "day_2___" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_getData/DayRecurrings/target.json b/tests/Data_getData/DayRecurrings/target.json new file mode 100644 index 0000000..71e73a7 --- /dev/null +++ b/tests/Data_getData/DayRecurrings/target.json @@ -0,0 +1,34 @@ +{ + "data": [ + { + "start_date": "2016-03-09 00:00:00", + "end_date": "2016-03-09 00:05:00", + "event_pid": "0", + "text": "Rec Ev", + "id": "497", + "_timed": true, + "rec_type": "day_2___#3", + "event_length": "300" + }, + { + "start_date": "2016-03-11 00:00:00", + "end_date": "2016-03-11 00:05:00", + "event_pid": "0", + "text": "Rec Ev", + "id": "497", + "_timed": true, + "rec_type": "day_2___#3", + "event_length": "300" + }, + { + "start_date": "2016-03-13 00:00:00", + "end_date": "2016-03-13 00:05:00", + "event_pid": "0", + "text": "Rec Ev", + "id": "497", + "_timed": true, + "rec_type": "day_2___#3", + "event_length": "300" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveData/DayRecurrings/source.json b/tests/Data_saveData/DayRecurrings/source.json new file mode 100644 index 0000000..e700251 --- /dev/null +++ b/tests/Data_saveData/DayRecurrings/source.json @@ -0,0 +1,24 @@ +{ + "data": [ + { + "recurring_type": { + "each": "day", + "step": 1, + "repeat": 10 + }, + "start_date": "2016-03-08 10:15:00", + "length": 600, + "text": "Test Event 1" + }, + { + "recurring_type": { + "each": "day", + "step": 1, + "repeat": 5 + }, + "start_date": "2016-03-08 10:15:00", + "length": 300, + "text": "Test Event 2" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveData/DayRecurrings/target.json b/tests/Data_saveData/DayRecurrings/target.json new file mode 100644 index 0000000..270240e --- /dev/null +++ b/tests/Data_saveData/DayRecurrings/target.json @@ -0,0 +1,20 @@ +{ + "data": [ + { + "start_date": "2016-03-08 10:15:00", + "end_date": "2016-03-18 10:15:00", + "text": "Test Event 1", + "event_pid": "", + "event_length": "600", + "rec_type": "day_1___#10" + }, + { + "start_date": "2016-03-08 10:15:00", + "end_date": "2016-03-13 10:15:00", + "text": "Test Event 2", + "event_pid": "", + "event_length": "300", + "rec_type": "day_1___#5" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveDataUpdate/DayRecurrings/source.json b/tests/Data_saveDataUpdate/DayRecurrings/source.json new file mode 100644 index 0000000..304593e --- /dev/null +++ b/tests/Data_saveDataUpdate/DayRecurrings/source.json @@ -0,0 +1,64 @@ +{ + "insert_data": [ + { + "id": "1", + "start_date": "2015-02-04 11:00:00", + "end_date": "2015-02-04 19:30:00", + "text": "Event X1", + "rec_type": "", + "event_length": "" + }, + { + "id": "2", + "start_date": "2020-07-09 11:00:00", + "end_date": "2020-07-09 19:20:00", + "text": "Event X2", + "rec_type": "day_1___#3", + "event_length": "600" + }, + { + "id": "3", + "start_date": "2014-04-09 18:00:00", + "end_date": "2014-04-09 19:25:00", + "text": "Event X3", + "rec_type": "", + "event_length": "" + } + ], + "data": [ + { + "id": 1, + "recurring_type": { + "each": "day", + "step": 1 + }, + "start_date": "2016-03-08 11:35:00", + "end_date": "9999-02-01 00:00:00", + "length": 19200, + "text": "Test Event 1" + }, + { + "id": 2, + "recurring_type": { + "each": "day", + "step": 2, + "repeat": 33 + }, + "start_date": "2016-03-03 00:00:00", + "length": 300, + "text": "Test Event 2" + }, + { + "id": 3, + "recurring_type": { + "each": "week", + "step": 1, + "days_of_week": "monday,tuesday,wednesday,thursday,friday" + }, + "start_date": "2016-03-01 00:00:00", + "end_date": "2016-08-21 00:00:00", + "length": 300, + "text": "Test Event 3" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveDataUpdate/DayRecurrings/target.json b/tests/Data_saveDataUpdate/DayRecurrings/target.json new file mode 100644 index 0000000..fc46634 --- /dev/null +++ b/tests/Data_saveDataUpdate/DayRecurrings/target.json @@ -0,0 +1,34 @@ +{ + "data": [ + { + "start_date": "2016-03-08 11:35:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Event 1", + "id": "1", + "event_pid": "", + "event_length": "19200", + "rec_pattern": "day_1___", + "rec_type": "day_1___#no" + }, + { + "start_date": "2016-03-03 00:00:00", + "end_date": "2016-05-08 00:00:00", + "text": "Test Event 2", + "id": "2", + "event_pid": "", + "event_length": "300", + "rec_pattern": "day_2___", + "rec_type": "day_2___#33" + }, + { + "start_date": "2016-03-01 00:00:00", + "end_date": "2016-08-21 00:00:00", + "text": "Test Event 3", + "id": "3", + "event_pid": "", + "event_length": "300", + "rec_pattern": "week_1___1,2,3,4,5", + "rec_type": "week_1___1,2,3,4,5#" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveDataUpdate/MonthRecurrings/source.json b/tests/Data_saveDataUpdate/MonthRecurrings/source.json new file mode 100644 index 0000000..17fafba --- /dev/null +++ b/tests/Data_saveDataUpdate/MonthRecurrings/source.json @@ -0,0 +1,86 @@ +{ + "insert_data": [ + { + "id": "1", + "start_date": "2015-02-04 11:00:00", + "end_date": "2015-02-04 19:30:00", + "text": "Event X1", + "rec_type": "", + "event_length": "" + }, + { + "id": "2", + "start_date": "2020-07-09 11:00:00", + "end_date": "2020-07-09 19:20:00", + "text": "Event X2", + "rec_type": "day_1___#3", + "event_length": "600" + }, + { + "id": "3", + "start_date": "2014-04-09 18:00:00", + "end_date": "2014-04-09 19:25:00", + "text": "Event X3", + "rec_type": "", + "event_length": "" + }, + { + "id": "4", + "start_date": "2014-04-20 18:00:00", + "end_date": "2014-05-30 19:25:00", + "text": "Event X4", + "rec_type": "", + "event_length": "" + } + ], + "data": [ + { + "id": 1, + "recurring_type": { + "each": "month", + "step": 3 + }, + "start_date": "2016-03-13 12:00:00", + "end_date": "9999-02-01 00:00:00", + "length": 2100, + "text": "Test Month 1" + }, + { + "id": 2, + "recurring_type": { + "each": "month", + "repeat": 6, + "week_number": 4, + "days_of_week": "friday", + "step": 1 + }, + "start_date": "2016-03-01 15:00:00", + "length": 17700, + "text": "Test Month 2" + }, + { + "id": 3, + "recurring_type": { + "each": "month", + "step": 1, + "days_of_week": "wednesday", + "week_number": 1 + }, + "start_date": "2016-03-01 10:00:00", + "end_date": "2016-08-21 00:00:00", + "length": 26100, + "text": "Test Month 3" + }, + { + "id": 4, + "recurring_type": { + "each": "month", + "step": 1 + }, + "start_date": "2016-03-30 02:50:00", + "end_date": "9999-02-01 00:00:00", + "length": 18000, + "text": "Test Month 4" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveDataUpdate/MonthRecurrings/target.json b/tests/Data_saveDataUpdate/MonthRecurrings/target.json new file mode 100644 index 0000000..704a01e --- /dev/null +++ b/tests/Data_saveDataUpdate/MonthRecurrings/target.json @@ -0,0 +1,40 @@ +{ + "data": [ + { + "start_date": "2016-03-13 12:00:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Month 1", + "id": "1", + "event_pid": "", + "event_length": "2100", + "rec_type": "month_3___#no" + }, + { + "start_date": "2016-03-01 15:00:00", + "end_date": "2016-09-23 15:00:00", + "text": "Test Month 2", + "id": "2", + "event_pid": "", + "event_length": "17700", + "rec_type": "month_1_5_4_#6" + }, + { + "start_date": "2016-03-01 10:00:00", + "end_date": "2016-08-21 00:00:00", + "text": "Test Month 3", + "id": "3", + "event_pid": "", + "event_length": "26100", + "rec_type": "month_1_3_1_#" + }, + { + "start_date": "2016-03-30 02:50:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Month 4", + "id": "4", + "event_pid": "", + "event_length": "18000", + "rec_type": "month_1___#no" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveDataUpdate/WeekRecurrings/source.json b/tests/Data_saveDataUpdate/WeekRecurrings/source.json new file mode 100644 index 0000000..dbce0bb --- /dev/null +++ b/tests/Data_saveDataUpdate/WeekRecurrings/source.json @@ -0,0 +1,68 @@ +{ + "insert_data": [ + { + "id": "1", + "start_date": "2015-02-04 11:00:00", + "end_date": "2015-02-04 19:30:00", + "text": "Event X1", + "rec_type": "", + "event_length": "" + }, + { + "id": "2", + "start_date": "2020-07-09 11:00:00", + "end_date": "2020-07-09 19:20:00", + "text": "Event X2", + "rec_type": "day_1___#3", + "event_length": "600" + }, + { + "id": "3", + "start_date": "2014-04-09 18:00:00", + "end_date": "2014-04-09 19:25:00", + "text": "Event X3", + "rec_type": "", + "event_length": "" + } + ], + "data": [ + { + "id": 1, + "recurring_type": { + "each": "week", + "step": 2, + "days_of_week": "sunday,monday,tuesday,wednesday,thursday,friday,saturday" + }, + "start_date": "2016-03-01 12:20:00", + "end_date": "9999-02-01 00:00:00", + "length": 300, + "text": "Test Week Event 1" + }, + { + "id": 2, + "recurring_type": { + "each": "week", + "repeat": 17, + "step": 1, + "days_of_week": "monday,wednesday,thursday,friday" + + }, + "start_date": "2016-03-02 20:00:00", + "end_date": "2016-03-31 00:00:00", + "length": 300, + "text": "Test Week Event 2" + }, + { + "id": 3, + "recurring_type": { + "each": "week", + "step": 3, + "days_of_week": "monday,wednesday" + }, + "start_date": "2016-03-02 15:55:00", + "end_date": "2016-08-21 00:00:00", + "length": 600, + "text": "Test Week Event 3" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveDataUpdate/WeekRecurrings/target.json b/tests/Data_saveDataUpdate/WeekRecurrings/target.json new file mode 100644 index 0000000..731db63 --- /dev/null +++ b/tests/Data_saveDataUpdate/WeekRecurrings/target.json @@ -0,0 +1,34 @@ +{ + "data": [ + { + "start_date": "2016-03-01 12:20:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Week Event 1", + "id": "1", + "event_pid": "", + "event_length": "300", + "rec_pattern": "week_2___0,1,2,3,4,5,6", + "rec_type": "week_2___0,1,2,3,4,5,6#no" + }, + { + "start_date": "2016-03-02 20:00:00", + "end_date": "2016-03-31 00:00:00", + "text": "Test Week Event 2", + "id": "2", + "event_pid": "", + "event_length": "300", + "rec_pattern": "week_1___1,3,4,5", + "rec_type": "week_1___1,3,4,5#17" + }, + { + "start_date": "2016-03-02 15:55:00", + "end_date": "2016-08-21 00:00:00", + "text": "Test Week Event 3", + "id": "3", + "event_pid": "", + "event_length": "600", + "rec_pattern": "week_3___1,3", + "rec_type": "week_3___1,3#" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveDataUpdate/YearRecurrings/source.json b/tests/Data_saveDataUpdate/YearRecurrings/source.json new file mode 100644 index 0000000..351e8b6 --- /dev/null +++ b/tests/Data_saveDataUpdate/YearRecurrings/source.json @@ -0,0 +1,88 @@ +{ + "insert_data": [ + { + "id": "1", + "start_date": "2015-02-04 11:00:00", + "end_date": "2015-02-04 19:30:00", + "text": "Event X1", + "rec_type": "", + "event_length": "" + }, + { + "id": "2", + "start_date": "2020-07-09 11:00:00", + "end_date": "2020-07-09 19:20:00", + "text": "Event X2", + "rec_type": "day_1___#3", + "event_length": "600" + }, + { + "id": "3", + "start_date": "2014-04-09 18:00:00", + "end_date": "2014-04-09 19:25:00", + "text": "Event X3", + "rec_type": "", + "event_length": "" + }, + { + "id": "4", + "start_date": "2014-04-20 18:00:00", + "end_date": "2014-05-30 19:25:00", + "text": "Event X4", + "rec_type": "", + "event_length": "" + } + ], + "data": [ + { + "id": 1, + "recurring_type": { + "each": "year", + "step": 1 + }, + "start_date": "2016-03-08 11:40:00", + "end_date": "9999-02-01 00:00:00", + "length": 6600, + "text": "Test Year 1" + }, + { + "id": 2, + "recurring_type": { + "each": "year", + "repeat": 4, + "week_number": 1, + "step": 1, + "days_of_week": "monday" + }, + "start_date": "2016-03-01 10:35:00", + "length": 30000, + "text": "Test Year 2" + }, + { + "id": 3, + "recurring_type": { + "each": "year", + "step": 1, + "days_of_week": "sunday", + "week_number": 4 + }, + "start_date": "2016-12-01 22:00:00", + "end_date": "2019-04-21 00:00:00", + "length": 3900, + "text": "Test Year 3" + }, + { + "id": 4, + "recurring_type": { + "each": "year", + "step": 1, + "days_of_week": "tuesday", + "week_number": 1 + }, + "start_date": "2016-01-01 10:40:00", + "end_date": "9999-02-01 00:00:00", + "length": 47700, + "text": "Test Year 4" + } + ] +}
\ No newline at end of file diff --git a/tests/Data_saveDataUpdate/YearRecurrings/target.json b/tests/Data_saveDataUpdate/YearRecurrings/target.json new file mode 100644 index 0000000..5b47acb --- /dev/null +++ b/tests/Data_saveDataUpdate/YearRecurrings/target.json @@ -0,0 +1,40 @@ +{ + "data": [ + { + "start_date": "2016-03-08 11:40:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Year 1", + "id": "1", + "event_pid": "", + "event_length": "6600", + "rec_type": "year_1___#no" + }, + { + "start_date": "2016-03-01 10:35:00", + "end_date": "2020-03-02 10:35:00", + "text": "Test Year 2", + "id": "2", + "event_pid": "", + "event_length": "30000", + "rec_type": "year_1_1_1_#4" + }, + { + "start_date": "2016-12-01 22:00:00", + "end_date": "2019-04-21 00:00:00", + "text": "Test Year 3", + "id": "3", + "event_pid": "", + "event_length": "3900", + "rec_type": "year_1_7_4_#" + }, + { + "start_date": "2016-01-01 10:40:00", + "end_date": "9999-02-01 00:00:00", + "text": "Test Year 4", + "id": "4", + "event_pid": "", + "event_length": "47700", + "rec_type": "year_1_2_1_#no" + } + ] +}
\ No newline at end of file diff --git a/tests/Logger.php b/tests/Logger.php new file mode 100644 index 0000000..115b624 --- /dev/null +++ b/tests/Logger.php @@ -0,0 +1,33 @@ +<?php + +class Logger +{ + private $_stepNumber = 0; + + public function logStart($name = NULL) + { + $this->_stepNumber = 0; + print "Test started. $name\n"; + } + + public function logStep(){ + print "Step ".(++$this->_stepNumber)."\n"; + } + + public function logEnd($name = NULL){ + $this->_stepNumber = 0; + print "Test finished. $name\n"; + } + + public function info($msg){ + print "INFO: $msg\n"; + } + + public function warning($msg){ + print "WARNING: $msg\n"; + } + + public function error($msg){ + print "ERROR: $msg\n"; + } +}
\ No newline at end of file diff --git a/tests/SchedulerHelperTest.php b/tests/SchedulerHelperTest.php new file mode 100644 index 0000000..6f69589 --- /dev/null +++ b/tests/SchedulerHelperTest.php @@ -0,0 +1,224 @@ +<?php +require_once "Logger.php"; +require_once "TestBaseHelper.php"; +require_once "TestDataHelper.php"; +require_once "TestConfig.php"; +use DHTMLX_Scheduler\Helper; + + +class SchedulerHelperTest extends \PHPUnit_Framework_TestCase +{ + private $_baseHelper; + private $_logger; + + public function __construct() + { + $this->_logger = new Logger(); + + $this->_baseHelper = new TestBaseHelper(array( + "dbsm" => TestConfig::DBSM, + "host" => TestConfig::HOST, + "db_name" => TestConfig::DB_NAME, + "user" => TestConfig::USER, + "password" => TestConfig::PASSWORD, + "table_name" => TestConfig::TEMP_TABLE_NAME, + "fields" => TestConfig::$fields + )); + } + + public function __destruct() + { + $this->_baseHelper->dropTable(); + } + + public function testGetData() + { + $testName = "getData"; + + $this->_logger->logStart($testName); + $schedHelper = new Helper( + array( + "dbsm" => TestConfig::DBSM, + "host" => TestConfig::HOST, + "db_name" => TestConfig::DB_NAME, + "user" => TestConfig::USER, + "password" => TestConfig::PASSWORD, + "table_name" => TestConfig::TEMP_TABLE_NAME + ) + ); + $schedHelper->setFieldsNames(array( + $schedHelper::FLD_ID => "id", + )); + + + $dataHelp = new TestDataHelper($testName); + $dataPacks = $dataHelp->getTestDataList(); + + if($dataPacks) { + for ($i = 0; $i < count($dataPacks); $i++) { + $this->_logger->logStep($testName); + $this->_logger->info("$dataPacks[$i] bunch processing...."); + $source = $dataHelp->getTestSourceData($dataPacks[$i]); + $target = $dataHelp->getTestTargetData($dataPacks[$i]); + + if(!$source || !$target){ + $this->_logger->warning("There is no data. Bunch is skipped"); + continue; + } + + $this->_baseHelper->resetTable(); + $this->_baseHelper->insertDataFromJSON($source['data']); + + $helperData = $schedHelper->getData($source["settings"]["start_date"], $source["settings"]["end_date"]); + $dataHelp->writeObjectToFile($helperData, "_helperData.txt", $dataPacks[$i]); + $this->assertTrue($dataHelp->compareDataBunches($helperData, $target["data"], TestConfig::$fields), + "Helper and Scheduler data has difference"); + } + } + + $this->_logger->logEnd($testName); + } + + public function testSaveData_Insert(){ + $testName = "saveData"; + $this->_logger->logStart($testName); + $schedHelper = new Helper( + array( + "dbsm" => TestConfig::DBSM, + "host" => TestConfig::HOST, + "db_name" => TestConfig::DB_NAME, + "user" => TestConfig::USER, + "password" => TestConfig::PASSWORD, + "table_name" => TestConfig::TEMP_TABLE_NAME + ) + ); + $schedHelper->setFieldsNames(array( + $schedHelper::FLD_ID => "id", + )); + + $dataHelp = new TestDataHelper($testName); + $dataPacks = $dataHelp->getTestDataList(); + if($dataPacks) { + for ($i = 0; $i < count($dataPacks); $i++) { + $this->_logger->logStep($testName); + $this->_logger->info("$dataPacks[$i] bunch processing...."); + $source = $dataHelp->getTestSourceData($dataPacks[$i]); + $target = $dataHelp->getTestTargetData($dataPacks[$i]); + + + if(!$source || !$target){ + $this->_logger->warning("There is no data. Bunch is skipped"); + continue; + } + + $this->_baseHelper->resetTable(); + $sourceData = $dataHelp->prepateDataForHelper($source["data"], $schedHelper); + $dataHelp->saveDataWithHelper($sourceData, $schedHelper); + + $dataFromBase = $this->_baseHelper->getDataFromBase(); + + $dataHelp->writeObjectToFile($dataFromBase, "_dataFromBase.txt", $dataPacks[$i]); + $this->assertTrue($dataHelp->compareDataBunches($target["data"], $dataFromBase, TestConfig::$fields), + "Helper and Scheduler data has difference"); + } + } + + $this->_logger->logEnd($testName); + } + + public function testSaveData_Update(){ + $testName = "saveDataUpdate"; + $this->_logger->logStart($testName); + $schedHelper = new Helper( + array( + "dbsm" => TestConfig::DBSM, + "host" => TestConfig::HOST, + "db_name" => TestConfig::DB_NAME, + "user" => TestConfig::USER, + "password" => TestConfig::PASSWORD, + "table_name" => TestConfig::TEMP_TABLE_NAME + ) + ); + $schedHelper->setFieldsNames(array( + $schedHelper::FLD_ID => "id", + )); + + $dataHelp = new TestDataHelper($testName); + $dataPacks = $dataHelp->getTestDataList(); + if($dataPacks) { + for ($i = 0; $i < count($dataPacks); $i++) { + $this->_logger->logStep($testName); + $this->_logger->info("$dataPacks[$i] bunch processing...."); + $source = $dataHelp->getTestSourceData($dataPacks[$i]); + $target = $dataHelp->getTestTargetData($dataPacks[$i]); + + + if(!$source || !$target){ + $this->_logger->warning("There is no data. Bunch is skipped"); + continue; + } + + $this->_baseHelper->resetTable(); + + $this->_baseHelper->insertDataFromJSON($source["insert_data"]); + $sourceData = $dataHelp->prepateDataForHelper($source["data"], $schedHelper); + $dataHelp->saveDataWithHelper($sourceData, $schedHelper); + + $dataFromBase = $this->_baseHelper->getDataFromBase(); + + $dataHelp->writeObjectToFile($dataFromBase, "_dataFromBase.txt", $dataPacks[$i]); + $this->assertTrue($dataHelp->compareDataBunches($target["data"], $dataFromBase, TestConfig::$fields), + "Helper and Scheduler data has difference"); + } + } + + $this->_logger->logEnd($testName); + } + + public function testdeleteById(){ + $testName = "deleteById"; + $this->_logger->logStart($testName); + $schedHelper = new Helper( + array( + "dbsm" => TestConfig::DBSM, + "host" => TestConfig::HOST, + "db_name" => TestConfig::DB_NAME, + "user" => TestConfig::USER, + "password" => TestConfig::PASSWORD, + "table_name" => TestConfig::TEMP_TABLE_NAME + ) + ); + $schedHelper->setFieldsNames(array( + $schedHelper::FLD_ID => "id", + )); + + $dataHelp = new TestDataHelper($testName); + $dataPacks = $dataHelp->getTestDataList(); + if($dataPacks) { + for ($i = 0; $i < count($dataPacks); $i++) { + $this->_logger->logStep($testName); + $this->_logger->info("$dataPacks[$i] bunch processing...."); + $source = $dataHelp->getTestSourceData($dataPacks[$i]); + + + if(!$source){ + $this->_logger->warning("There is no data. Bunch is skipped"); + continue; + } + + $this->_baseHelper->resetTable(); + + $this->_baseHelper->insertDataFromJSON($source["insert_data"]); + + foreach($source["data"] as $event){ + $schedHelper->deleteById($event["id"]); + $dataFromBase = $this->_baseHelper->getDataFromBase($event["id"]); + $this->assertTrue(count($dataFromBase) === 0, + "Event wasn't removed"); + } + } + } + + $this->_logger->logEnd($testName); + } +}
\ No newline at end of file diff --git a/tests/TestBaseHelper.php b/tests/TestBaseHelper.php new file mode 100644 index 0000000..5372d92 --- /dev/null +++ b/tests/TestBaseHelper.php @@ -0,0 +1,114 @@ +<?php + +class TestBaseHelper +{ + private $_dbsm, $_host, $_db_name, $_user, $_password, $_table_name; + private $_PDO = null; + + private $_fields; + + public function __construct($configs = array()) + { + $this->_dbsm = isset($configs["dbsm"]) ? $configs["dbsm"] : "mysql"; + $this->_host = isset($configs["host"]) ? $configs["host"] : "localhost"; + $this->_db_name = $configs["db_name"]; + $this->_user = $configs["user"]; + $this->_password = $configs["password"]; + $this->_table_name = $configs["table_name"]; + $this->_fields = $configs["fields"]; + } + + private function getConnection() + { + $PDO_options = array( + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC + ); + + $dsn = $this->_dbsm . ":host=" . $this->_host . ";dbname=" . $this->_db_name; + $this->_PDO = ($this->_PDO) ? $this->_PDO : new PDO($dsn, $this->_user, $this->_password,$PDO_options); + return $this->_PDO; + } + + private function closeConnection() + { + unset($this->_PDO); + $this->_PDO = null; + } + + public function dropTable() + { + $conn = $this->getConnection(); + $conn->prepare("DROP TABLE IF EXISTS `$this->_table_name`;")->execute(); + $this->closeConnection(); + } + + public function resetTable() + { + $this->dropTable(); + $conn = $this->getConnection(); + $sql = "CREATE TABLE `$this->_table_name`("; + $f = $this->_fields; + $fieldsCount = count($f); + $elNumb = 1; + + foreach($f as $name=>$type) { + $sql .= "`$name` $type"; + if ($elNumb++ != $fieldsCount) + $sql .= ","; + } + $sql .= ");"; + + $conn->prepare($sql)->execute(); + $this->closeConnection(); + } + + public function insertDataFromJSON($data){ + $f = $this->_fields; + $fieldsCount = count($f); + + $sql = "INSERT INTO `$this->_table_name`("; + + $elNumb = 1; + foreach($f as $name=>$type) { + $sql .= "`$name`"; + if ($elNumb++ != $fieldsCount) + $sql .= ","; + } + + $sql.= ") VALUES "; + + $evsCount = count($data); + for($i = 0; $i < $evsCount; $i++) { + $sql .= "("; + $event = $data[$i]; + $elNumb = 1; + foreach($f as $name=>$type) { + $sql .= isset($event[$name]) && !is_null($event[$name]) ? "'".$event[$name]."'":"NULL"; + + if ($elNumb++ != $fieldsCount) + $sql .= ","; + } + $sql.=")"; + if($i + 1 != $evsCount) + $sql.=","; + } + $sql .= ";"; + + $conn = $this->getConnection(); + $conn->prepare($sql)->execute(); + $this->closeConnection(); + } + + public function getDataFromBase($id = NULL){ + $sql = "SELECT * FROM $this->_table_name"; + if(!is_null($id)){ + $sql .= " WHERE id=$id"; + } + $conn = $this->getConnection()->prepare($sql); + $conn->execute(); + $data = $conn->fetchAll(); + $this->closeConnection(); + return $data; + } +}
\ No newline at end of file diff --git a/tests/TestConfig.php b/tests/TestConfig.php new file mode 100644 index 0000000..1a15f09 --- /dev/null +++ b/tests/TestConfig.php @@ -0,0 +1,20 @@ +<?php + +class TestConfig +{ + const DBSM = "mysql"; + const HOST = "localhost"; + const USER = "root"; + const PASSWORD = "root"; + const DB_NAME = "scheduler"; + const TEMP_TABLE_NAME = "temp_table_20160315"; + public static $fields = array( + "id" => "INT(11) DEFAULT NULL", + "start_date" => "DATETIME NOT NULL", + "end_date" => "DATETIME NOT NULL", + "text" => "VARCHAR(255) NOT NULL", + "rec_type" => "VARCHAR(50) DEFAULT NULL", + "event_length" => " BIGINT(20) DEFAULT NULL", + "event_pid" => "INT(11) DEFAULT NULL" + ); +}
\ No newline at end of file diff --git a/tests/TestDataHelper.php b/tests/TestDataHelper.php new file mode 100644 index 0000000..42577ab --- /dev/null +++ b/tests/TestDataHelper.php @@ -0,0 +1,126 @@ +<?php +require_once "TestConfig.php"; + +class TestDataHelper +{ + const DATA_FOLDER_PREFIX = "Data_"; + const SOURCE_NAME = "source.json"; + const TARGET_NAME = "target.json"; + + private $_dataFolder; + + private function getJSONDataFromFile($name, $type) + { + $file = dirname(__FILE__) . "/" . $this->_dataFolder . "/" . $name . "/" . $type; + if (!file_exists($file)) return null; + + return json_decode(file_get_contents($file),true); + } + + private function correctNoEndRecType($type){ + $noPos = strpos($type, "#no"); + if($noPos){ + $type = substr_replace($type, "", $noPos + 1); + } + return $type; + } + + public function __construct($testName) + { + $this->_dataFolder = self::DATA_FOLDER_PREFIX . $testName; + } + + public function getTestDataList() + { + $dir = dirname(__FILE__) . "/" . $this->_dataFolder; + if (!file_exists($dir)) return null; + $folderItems = scandir($dir); + $folders = array(); + foreach ($folderItems as $item) { + if ($item === '.' || $item === '..') continue; + if (is_dir($dir . "/" . $item)) + array_push($folders, $item); + } + return $folders; + } + + public function getTestSourceData($name) + { + return $this->getJSONDataFromFile($name, self::SOURCE_NAME); + } + + public function getTestTargetData($name) + { + return $this->getJSONDataFromFile($name, self::TARGET_NAME); + } + + public function compareDataObjects($helperObj, $schedObj, $fields) + { + foreach($fields as $key=>$value){ + $hVal = isset($helperObj[$key]) ? $helperObj[$key]: ""; + $sVal = isset($schedObj[$key])? $schedObj[$key] : ""; + if($key == "rec_type"){ + $sVal = $this->correctNoEndRecType($sVal); + $hVal = $this->correctNoEndRecType($hVal); + } + if($hVal != $sVal) { + return false; + } + } + return true; + } + + public function compareDataBunches($helperData, $schedData, $fields) + { + $helpLength = count($helperData); + $schedLength = count($schedData); + + if($helpLength != $schedLength) return false; + + for($i = 0; $i < $helpLength; $i++){ + $objHasSame = false; + for($j = 0; $j < $schedLength; $j++){ + if($this->compareDataObjects($helperData[$i], $schedData[$j], $fields)) { + array_splice($schedData, $j, 1); + $schedLength = count($schedData); + $objHasSame = true; + break; + } + } + if(!$objHasSame){ + return false; + } + } + + return true; + } + + public function writeObjectToFile($obj, $name, $bunch="") + { + ob_start(); + var_dump($obj); + $output = ob_get_clean(); + if ($bunch) + $bunch = "/$bunch"; + $file = dirname(__FILE__) . "/" . $this->_dataFolder . $bunch . "/" . $name; + file_put_contents($file, $output); + } + + public function prepateDataForHelper($data, $helper) + { + foreach ($data as &$event) { + if (!isset($event["end_date"]) && isset($event["recurring_type"]) && isset($event["length"])) { + $event["end_date"] = $helper->getRecurringEndDateStr($event["recurring_type"], $event["start_date"], $event["length"]); + } + } + + return $data; + } + + public function saveDataWithHelper($data, $helper) + { + foreach($data as $event){ + $helper->saveData($event); + } + } +}
\ No newline at end of file |