From b6c5cf1ef5a49eeda6bae5f7b3f24bebcf0ec94e Mon Sep 17 00:00:00 2001 From: "alextselegidis@gmail.com" Date: Tue, 14 May 2013 19:56:16 +0000 Subject: [PATCH] =?UTF-8?q?=CE=9F=CE=BB=CE=BF=CE=BA=CE=BB=CE=AE=CF=81?= =?UTF-8?q?=CF=89=CF=83=CE=B7=20=CF=84=CF=89=CE=BD=20unit=20test=20=CF=84?= =?UTF-8?q?=CE=BF=CF=85=20model=20=CF=84=CF=89=CE=BD=20=CF=81=CE=B1=CE=BD?= =?UTF-8?q?=CF=84=CE=B5=CE=B2=CE=BF=CF=8D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/application/config/autoload.php | 2 +- .../libraries/Unit_tests/Unit_tests.php | 27 +- .../drivers/Unit_tests_appointments_model.php | 423 +++++++++++++++++- .../drivers/Unit_tests_customers_model.php | 39 ++ src/application/models/appointments_model.php | 71 ++- test/AppointmentsModelTest.php | 132 ------ test/bootstrap.php | 212 --------- test/phpunit.xml | 10 - 8 files changed, 540 insertions(+), 376 deletions(-) create mode 100644 src/application/libraries/Unit_tests/drivers/Unit_tests_customers_model.php delete mode 100644 test/AppointmentsModelTest.php delete mode 100644 test/bootstrap.php delete mode 100644 test/phpunit.xml diff --git a/src/application/config/autoload.php b/src/application/config/autoload.php index 17c50920..20541f46 100644 --- a/src/application/config/autoload.php +++ b/src/application/config/autoload.php @@ -64,7 +64,7 @@ $autoload['libraries'] = array('database'); | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array(); +$autoload['helper'] = array('custom_exceptions'); /* diff --git a/src/application/libraries/Unit_tests/Unit_tests.php b/src/application/libraries/Unit_tests/Unit_tests.php index 7848429e..e65180cd 100644 --- a/src/application/libraries/Unit_tests/Unit_tests.php +++ b/src/application/libraries/Unit_tests/Unit_tests.php @@ -19,7 +19,8 @@ class Unit_tests extends CI_Driver_Library { // Add more subclasses to the following array to expand // the unit testing classes. $this->valid_drivers = array( - 'Unit_tests_appointments_model' + 'Unit_tests_appointments_model', + 'Unit_tests_customers_model' ); } @@ -31,8 +32,9 @@ class Unit_tests extends CI_Driver_Library { * be run. */ public function run_all_tests() { - $this->run_model_tests(); - $this->run_library_tests(); + $this->run_model_tests(false); + $this->run_library_tests(false); + $this->CI->output->append_output($this->CI->unit->report()); } /////////////////////////////////////////////////////////////////////////// @@ -40,15 +42,30 @@ class Unit_tests extends CI_Driver_Library { /////////////////////////////////////////////////////////////////////////// /** * Run all the models tests. + * + * @param bool $output_report Determines wether the test + * report will be outputted. */ - public function run_model_tests() { + public function run_model_tests($output_report = true) { $this->appointments_model->run_all(); + $this->customers_model->run_all(); + + if ($output_report) { + $this->CI->output->append_output($this->CI->unit->report()); + } } /** * Run all the library tests. + * + * @param bool $output_report Determines wether the test + * report will be outputted. */ - public function run_library_tests() { + public function run_library_tests($output_report = true) { + // @task Implement unit tests for the libraries. + if ($output_report) { + $this->CI->output->append_output($this->CI->unit->report()); + } } } \ No newline at end of file diff --git a/src/application/libraries/Unit_tests/drivers/Unit_tests_appointments_model.php b/src/application/libraries/Unit_tests/drivers/Unit_tests_appointments_model.php index b46fd542..0ba9a5a5 100644 --- a/src/application/libraries/Unit_tests/drivers/Unit_tests_appointments_model.php +++ b/src/application/libraries/Unit_tests/drivers/Unit_tests_appointments_model.php @@ -47,13 +47,10 @@ class Unit_tests_appointments_model extends CI_Driver { // "test" keyword from the beginning. $class_methods = get_class_methods('Unit_tests_appointments_model'); foreach ($class_methods as $method_name) { - if (strpos($method_name, 'test_') !== FALSE) { + if (substr($method_name, 0, 5) === 'test_') { call_user_func(array($this, $method_name)); } } - - // Create a report on the browser. - $this->CI->output->append_output($this->CI->unit->report()); } ///////////////////////////////////////////////////////////////////////// @@ -191,10 +188,414 @@ class Unit_tests_appointments_model extends CI_Driver { $this->CI->unit->run($this->CI->Appointments_Model->exists($appointment_data), FALSE, 'Test exists() method with wrong appointment data.'); } - // @task Test find_record_id - // @task Test delete - // @task Test get_batch - // @task Test get_row - // @task Test get_value - // @task Test validate_data -} \ No newline at end of file + /** + * Test the find record id method with a record that already + * exists in the databse. + */ + private function test_find_record_id() { + // Create a new appointmnet record. + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + $this->CI->db->insert('ea_appointments', $appointment_data); + $appointment_data['id'] = $this->CI->db->insert_id(); + + // Find record id of the new appointment record. + $method_result_id = $this->CI->Appointments_Model->find_record_id($appointment_data); + + $this->CI->unit->run($method_result_id, $appointment_data['id'], 'Test find_record_id() successfully returned the correct record id.'); + + // Delete appointment record. + $this->CI->db->delete('ea_appointments', array('id' => $method_result_id)); + } + + /** + * Try to find the record id of an appointment that doesn't + * exist in the database. + * + * A database exception is expected to be raised. + */ + private function test_find_record_id_appointment_does_not_exist() { + // Define appointment data. These data shouldn't exist in the database. + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + + // Load the appointments model and execute the find record id method. + $hasThrownException = FALSE; + + try { + $this->CI->Appointments_Model->find_record_id($appointment_data); + } catch(DatabaseException $dbExc) { + $hasThrownException = TRUE; + } + + $this->CI->unit->run($hasThrownException, TRUE, 'Test find_record_id() with appointment ' + . 'data that does not exist in the database.', 'A database exception is expected ' + . 'to be raised.'); + } + + /** + * Test the find_record_id() method by providing wrong + * appointment data. + * + * A database exception is expected to be raised. + */ + private function test_find_record_id_wrong_data() { + // Define appointment data array with wrong values. + $appointment_data = array( + 'start_datetime' => '2013WRONG-05-0WRONG1 12:WRONG30:00', + 'end_datetime' => '2013-05-01 13:00:00WRONG', + 'notes' => 'Some notes righWRONGt here...', + 'id_users_provider' => 'WRONG', + 'id_users_customer' => 'WRONG', + 'id_services' => 'WRONG' + ); + + // Try to find the appointmet's record id. A database + // exception should be raised. + $hasThrownException = FALSE; + + try { + $this->CI->Appointments_Model->find_record_id($appointment_data); + } catch(DatabaseException $dbExc) { + $hasThrownException = TRUE; + } + + $this->CI->unit->run($hasThrownException, TRUE, 'Test find_record_id() with appointment ' + . 'data array with wrong values.', 'A database exception is expected to be raised.'); + } + + /** + * Test the normal flow of deleting an appointment record. + */ + private function test_delete() { + // Create a new appointmnet record. + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + $this->CI->db->insert('ea_appointments', $appointment_data); + $appointment_data['id'] = $this->CI->db->insert_id(); + + // Delete new record + $delete_result = $this->CI->Appointments_Model->delete($appointment_data['id']); + $this->CI->unit->run($delete_result, TRUE, 'Test delete() method result (should be TRUE).'); + + // Check if the record has been successfully deleted. + $num_rows = $this->CI->db->get_where('ea_appointments', array('id' => $appointment_data['id']))->num_rows(); + $this->CI->unit->run($num_rows, 0, 'Test if the record was successfully deleted.'); + } + + /** + * Test the delete method with a record that doesn't exist + * in the database. + */ + private function test_delete_record_does_not_exist() { + $random_record_id = 1233265; + + $delete_result = $this->CI->Appointments_Model->delete($random_record_id); + echo $delete_result; + $this->CI->unit->run($delete_result, FALSE, 'Test delete() method with a record id' + . ' that does not exist'); + } + + /** + * Test the delete method by providing a wrong argument + * (string and not integer). + */ + private function test_delete_record_wrong_parameter_given() { + $wrong_record_id = 'not_an_integer'; + + $delete_result = $this->CI->Appointments_Model->delete($wrong_record_id); + echo $delete_result; + $this->CI->unit->run($delete_result, FALSE, 'Test delete() method with a record id' + . ' that is not an integer'); + } + + /** + * Test the get_batch() method of the appointments model. + */ + private function test_get_batch() { + // Get all the appointment records (without using the model). + $db_data = $this->CI->db->get('ea_appointments')->result_array(); + + // Get all the appointment records (by using the model). + $model_data = $this->CI->Appointments_Model->get_batch(); + + // Check that the two arrays are the same. + $this->CI->unit->run($model_data, $db_data, 'Test get_batch() method.'); + } + + /** + * Test the get_batch() method of the appointments model + * with a where clause. + */ + private function test_get_batch_where_clause() { + // Insert new appointment. + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + $this->CI->db->insert('ea_appointments', $appointment_data); + $appointment_data['id'] = $this->CI->db->insert_id(); + + // Get filtered appointment records without using the model. + $db_data = $this->CI->db->get_where('ea_appointments', array('id' => $appointment_data['id']))->result_array(); + + // Get filtered appointment records by using the model. + $model_data = $this->CI->Appointments_Model->get_batch(array('id' => $appointment_data['id'])); + + // Check that the two arrays are the same. + $this->CI->unit->run($model_data, $db_data, 'Test get_batch() method.'); + + // Delete appointment record. + $this->CI->db->delete('ea_appointments', array('id' => $appointment_data['id'])); + } + + /** + * Test the get_batch() method of the appointments model + * with a wrong where clause. + * + * A database exception is expected to be raised. + * + * IMPORTANT! This test is unabled because code + * igniter handles itself wrong queries. + */ + private function unabled_test_get_batch_wrong_where_clause() { + $hasThrownException = FALSE; + + try { + $this->CI->Appointments_Model->get_batch('WRONG QUERY HERE'); + } catch(DatabaseException $dbExc) { + $hasThrownException = TRUE; + } + + $this->CI->unit->run($hasThrownException, TRUE, 'Test get_batch() with wrong where clause.', + 'A database excpetion is expected to be thrown.'); + } + + /** + * Test get_row() method. + */ + private function test_get_row() { + // Insert new appointment record. + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + $this->CI->db->insert('ea_appointments', $appointment_data); + $appointment_data['id'] = $this->CI->db->insert_id(); + + // Get the appointment row from the database. + $db_data = $this->CI->Appointments_Model->get_row($appointment_data['id']); + + // Check if this is the record we seek. + $this->CI->unit->run($db_data, $appointment_data, 'Test get_row() method.'); + + // Delete appointment record. + $this->CI->db->delete('ea_appointments', array('id' => $appointment_data['id'])); + } + + /** + * Test get_row() with a record that doesn't exist in the db. + */ + private function test_get_row_that_does_not_exist() { + $random_record_id = 789453486; + + $row_data = $this->CI->Appointments_Model->get_row($random_record_id); + + $this->CI->unit->run($row_data, NULL, 'Test get_row() with record id that does ' + . 'not exist in the database.'); + } + + /** + * Test get_row() method with wrong argument. + * + * A database exception is expected. + */ + private function test_get_row_wrong_argument_given() { + $wrong_arguement_id = 'THIS IS NOT AN INTEGER'; + + $hasThrownException = FALSE; + try { + $this->CI->Appointments_Model->get_row($wrong_arguement_id); + } catch (DatabaseException $dbExc) { + $hasThrownException = TRUE; + } + + $this->CI->unit->run($hasThrownException, TRUE, 'Test get_row() with wrong arguement.'); + } + + /** + * Test the get field value method. + */ + private function test_get_value() { + // Insert new appointment record. + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + $this->CI->db->insert('ea_appointments', $appointment_data); + $appointment_data['id'] = $this->CI->db->insert_id(); + + // Get a specific value from the database. + + $db_value = $this->CI->Appointments_Model->get_value('start_datetime', $appointment_data['id']); + + // Check if the value was correctly fetched from the database. + $this->CI->unit->run($db_value, $appointment_data['start_datetime'], 'Test get_value() method.'); + + // Delete inserted appointment record. + $this->CI->db->delete('ea_appointments', array('id' => $appointment_data['id'])); + } + + /** + * Test the get field value method with a record id that + * doesn't exist in the db. + * + * A database exception is expected. + */ + private function test_get_value_record_does_not_exist() { + $random_record_id = 843521368768; + + $hasThrownException = FALSE; + + try { + $this->CI->Appointments_Model->get_value('start_datetime', $random_record_id); + } catch (DatabaseException $dbExc) { + $hasThrownException = TRUE; + } + + $this->CI->unit->run($hasThrownException, TRUE, 'Test get_value() with record id that does not exist.'); + } + + /** + * Test the get_value() method with a field that does + * not exist in the db. + * + * A database exception is expected. + */ + private function test_get_value_field_does_not_exist() { + // Insert new appointment record. + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + $this->CI->db->insert('ea_appointments', $appointment_data); + $appointment_data['id'] = $this->CI->db->insert_id(); + + // Try to get record value with wrong field name. + $wrong_field_name = 'THIS IS WRONG'; + $hasThrownException = FALSE; + + try { + $this->CI->Appointments_Model->get_value($wrong_field_name, $appointment_data['id']); + } catch (DatabaseException $dbExc) { + $hasThrownException = TRUE; + } + + $this->CI->unit->run($hasThrownException, TRUE, 'Test get_value() with record id that does not exist.'); + + // Delete inserted record. + $this->CI->db->delete('ea_appointments', array('id' => $appointment_data['id'])); + } + + private function test_validate_data() { + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + $validation_result = $this->CI->Appointments_Model->validate_data($appointment_data); + $this->CI->unit->run($validation_result, TRUE, 'Test validate_data() method.'); + } + + private function test_validate_data_wrong_date_format() { + $appointment_data = array( + 'start_datetime' => '20WRONG13-05-01 12WRONG:30:00', + 'end_datetime' => '2013-05WRONG-01 13:00WRONG:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + $validation_result = $this->CI->Appointments_Model->validate_data($appointment_data); + $this->CI->unit->run($validation_result, FALSE, 'Test validate_data() method with wrong date formats.'); + } + + private function test_validate_data_invalid_provider_id() { + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => 'THIS IS WRONG', + 'id_users_customer' => $this->customer_id, + 'id_services' => $this->service_id + ); + $validation_result = $this->CI->Appointments_Model->validate_data($appointment_data); + $this->CI->unit->run($validation_result, FALSE, 'Test validate_data() method with invalid provider id.'); + } + + private function test_validate_data_invalid_customer_id() { + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => 'THIS IS WRONG', + 'id_services' => $this->service_id + ); + $validation_result = $this->CI->Appointments_Model->validate_data($appointment_data); + $this->CI->unit->run($validation_result, FALSE, 'Test validate_data() method with invalid customer id.'); + } + + private function test_validate_data_invalid_service_id() { + $appointment_data = array( + 'start_datetime' => '2013-05-01 12:30:00', + 'end_datetime' => '2013-05-01 13:00:00', + 'notes' => 'Some notes right here...', + 'id_users_provider' => $this->provider_id, + 'id_users_customer' => $this->customer_id, + 'id_services' => 'THIS IS WRONG' + ); + $validation_result = $this->CI->Appointments_Model->validate_data($appointment_data); + $this->CI->unit->run($validation_result, FALSE, 'Test validate_data() method with invalid service id.'); + } +} + +/* End of file Unit_tests_appointments_model.php */ +/* Location: ./application/libraries/Unit_tests/drivers/Unit_tests_appointments_model.php */ \ No newline at end of file diff --git a/src/application/libraries/Unit_tests/drivers/Unit_tests_customers_model.php b/src/application/libraries/Unit_tests/drivers/Unit_tests_customers_model.php new file mode 100644 index 00000000..dcb7a1d5 --- /dev/null +++ b/src/application/libraries/Unit_tests/drivers/Unit_tests_customers_model.php @@ -0,0 +1,39 @@ +CI =& get_instance(); + $this->CI->load->library('Unit_test'); + $this->CI->load->model('Customers_Model'); + } + + /** + * Run all the available tests + */ + public function run_all() { + // All the methods whose names start with "test" are going to be + // executed. If you want a method to not be executed remove the + // "test" keyword from the beginning. + $class_methods = get_class_methods('Unit_tests_customers_model'); + foreach ($class_methods as $method_name) { + if (substr($method_name, 0, 5) === 'test_') { + call_user_func(array($this, $method_name)); + } + } + } + + ///////////////////////////////////////////////////////////////////////// + // UNIT TESTS + ///////////////////////////////////////////////////////////////////////// + private function test_true() { + $this->CI->unit->run(TRUE, TRUE, 'True!'); + } + + + +} + +/* End of file Unit_tests_customers_model.php */ +/* Location: ./application/libraries/Unit_tests/drivers/Unit_tests_customers_model.php */ \ No newline at end of file diff --git a/src/application/models/appointments_model.php b/src/application/models/appointments_model.php index fe82de27..988e8123 100644 --- a/src/application/models/appointments_model.php +++ b/src/application/models/appointments_model.php @@ -6,7 +6,6 @@ class Appointments_Model extends CI_Model { */ public function __construct() { parent::__construct(); - $this->load->helper('custom_exceptions'); } /** @@ -97,7 +96,7 @@ class Appointments_Model extends CI_Model { throw new DatabaseException('Could not update appointment record.'); } - return $appointment_data['id']; + return intval($appointment_data['id']); } /** @@ -107,6 +106,9 @@ class Appointments_Model extends CI_Model { * get the unique id from the database: start_datetime, end_datetime, * id_users_provider, id_users_customer, id_services. * + * IMPORTANT! The record must already exists in the + * database, otherwise an exception is raised. + * * @expectedException DatabaseException * * @param array $appointment_data Array with the appointment data. The @@ -136,7 +138,7 @@ class Appointments_Model extends CI_Model { * update operation is executed. * * @param array $appointment_data Contains the appointment data. - * @return boolean Returns the validation result. + * @return bool Returns the validation result. */ public function validate_data($appointment_data) { $this->load->helper('data_validation'); @@ -151,7 +153,35 @@ class Appointments_Model extends CI_Model { throw new Exception('Appointment end datetime is invalid.'); } - // @task Check if appointment foreign keys are valid. + // Check if the provider's id is valid. + $num_rows = $this->db + ->select('*') + ->from('ea_users') + ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner') + ->where('ea_users.id', $appointment_data['id_users_provider']) + ->where('ea_roles.slug', DB_SLUG_PROVIDER) + ->get()->num_rows(); + if ($num_rows == 0) { + throw new Exception('Appointment provider id is invalid.'); + } + + // Check if the customer's id is valid. + $num_rows = $this->db + ->select('*') + ->from('ea_users') + ->join('ea_roles', 'ea_roles.id = ea_users.id_roles', 'inner') + ->where('ea_users.id', $appointment_data['id_users_customer']) + ->where('ea_roles.slug', DB_SLUG_CUSTOMER) + ->get()->num_rows(); + if ($num_rows == 0) { + throw new Exception('Appointment customer id is invalid.'); + } + + // Check if the service id is valid. + $num_rows = $this->db->get_where('ea_services', array('id' => $appointment_data['id_services']))->num_rows(); + if ($num_rows == 0) { + throw new Exception('Appointment customer id is invalid.'); + } return TRUE; } catch (Exception $exc) { @@ -166,6 +196,16 @@ class Appointments_Model extends CI_Model { * @return bool Returns the delete operation result. */ public function delete($appointment_id) { + if (!is_int($appointment_id)) { + return FALSE; // Invalid parameter given. + } + + $num_rows = $this->db->get_where('ea_appointments', array('id' => $appointment_id))->num_rows(); + + if ($num_rows == 0) { + return FALSE; // Record does not exist. + } + $this->db->where('id', $appointment_id); return $this->db->delete('ea_appointments'); } @@ -179,6 +219,9 @@ class Appointments_Model extends CI_Model { * field names. */ public function get_row($appointment_id) { + if (!is_int($appointment_id)) { + throw new DatabaseException('Invalid argument given. Expected integer for the $appointment_id.'); + } return $this->db->get_where('ea_appointments', array('id' => $appointment_id))->row_array(); } @@ -191,7 +234,25 @@ class Appointments_Model extends CI_Model { * @return string Returns the records value from the database. */ public function get_value($field_name, $appointment_id) { - return $this->db->get_where('ea_appointments', array('id' => $appointment_id))->row_array()[$field_name]; + if (!is_int($appointment_id)) { + throw new DatabaseException('Invalid argument given, expected integer for the $appointment_id.'); + } + + if (!is_string($field_name)) { + throw new DatabaseException('Invalid argument given, expected string for the $field_name.'); + } + + if ($this->db->get_where('ea_appointments', array('id' => $appointment_id))->num_rows() == 0) { + throw new DatabaseException('The record with the provided id does not exist in the datbase.'); + } + + $row_data = $this->db->get_where('ea_appointments', array('id' => $appointment_id))->row_array(); + + if (!isset($row_data[$field_name])) { + throw new DatabaseException('The given field name does not exist in the database.'); + } + + return $row_data[$field_name]; } /** diff --git a/test/AppointmentsModelTest.php b/test/AppointmentsModelTest.php deleted file mode 100644 index 4ccc0c37..00000000 --- a/test/AppointmentsModelTest.php +++ /dev/null @@ -1,132 +0,0 @@ -CI =& get_instance(); - $this->CI->load->model('Appointments_Model'); // This model will be used in all test methods. - - $this->CI->load->model('Providers_Model'); - $providers = $this->Providers_Model->get_row(2); -// if (count($providers) > 0) { -// $this->id_users_provider = $providers[0]['id']; -// } else { -// throw new Exception('There are no provider records ' -// . 'in the database. Add at least one provider ' -// . 'record before proceeding with the test.'); -// } -// -// $this->CI->load->model('Customers_Model'); -// $customers = $this->Customers_Model->get_batch(); -// if (count($customers) > 0) { -// $this->id_users_customer = $customers[0]['id']; -// } else { -// throw new Exception('There are no customer records ' -// . 'in the database. Add at least one customer ' -// . 'record before proceeding with the test.'); -// } -// -// $this->CI->load->model('Services_Model'); -// $services = $this->Services_Model->get_batch(); -// if (count($services) > 0) { -// $this->id_services = $services[0]['id']; -// } else { -// throw new Exception('There are no customer records ' -// . 'in the database. Add at least one customer ' -// . 'record before proceeding with the test.'); -// } - } - - public function test_sample() { - //$this->assertEquals(1,1); - } - - ///////////////////////////////////////////////////////////////////////////////// - // ADD RECORD METHOD TESTS - ///////////////////////////////////////////////////////////////////////////////// -// public function test_add_appointment_insert() { -// // To trigger the insert method no record id needs to be -// // provided. -// $appointment_data = array( -// 'start_datetime' => '2013-05-01 12:30:00', -// 'end_datetime' => '2013-05-01 13:00:00', -// 'notes' => 'Some notes right here...', -// 'id_users_provider' => $this->id_users_provider, -// 'id_users_customer' => $this->id_users_customer, -// 'id_services' => $this->id_services -// ); -// -// $appointment_id = $this->Appointments_Model->add($appointment_data); -// -// // Check if the record is the one that was inserted. -// $db_data = $this->Appointments_Model->get_row($appointment_id); -// -// $this->assertEquals($appointment_data['start_datetime'], $db_data['start_datetime']); -// $this->assertEquals($appointment_data['end_datetime'], $db_data['end_datetime']); -// $this->assertEquals($appointment_data['notes'], $db_data['notes']); -// $this->assertEquals($appointment_data['id_users_provider'], $db_data['id_users_provider']); -// $this->assertEquals($appointment_data['id_users_customer'], $db_data['id_users_customer']); -// $this->assertEquals($appointment_data['id_services'], $db_data['id_services']); -// -// // Delete inserted record. -// $this->Appointments_Model->delete($appointment_id); -// } -// -// public function test_add_appointment_update() { -// // Insert new record. -// $appointment_data = array( -// 'start_datetime' => '2013-05-01 12:30:00', -// 'end_datetime' => '2013-05-01 13:00:00', -// 'notes' => 'Some notes right here...', -// 'id_users_provider' => $this->id_users_provider, -// 'id_users_customer' => $this->id_users_customer, -// 'id_services' => $this->id_services -// ); -// -// $appointment_id = $this->Appointments_Model->add($appointment_data); -// -// // Update new record. -// $new_notes_content = 'Some OTHER notes here ...'; -// $appointment_data['notes'] = $new_notes_content; -// $this->Appointments_Model->add($appointment_data); -// -// // Check if the record was successfully updated. -// $db_data = $this->Appointments_Model->get_row($appointment_id); -// -// $this->assertEquals($appointment_data['start_datetime'], $db_data['start_datetime']); -// $this->assertEquals($appointment_data['end_datetime'], $db_data['end_datetime']); -// $this->assertEquals($appointment_data['notes'], $db_data['notes']); -// $this->assertEquals($appointment_data['id_users_provider'], $db_data['id_users_provider']); -// $this->assertEquals($appointment_data['id_users_customer'], $db_data['id_users_customer']); -// $this->assertEquals($appointment_data['id_services'], $db_data['id_services']); -// -// // Delete inserted record. -// $this->Appointments_Model->delete($appointment_id); -// } -// -// public function test_add_appointment_no_foreign_keys() { -// -// -// } -// -// ///////////////////////////////////////////////////////////////////////////////// -// // RECORD EXISTS METHOD TESTS -// ///////////////////////////////////////////////////////////////////////////////// -// public function test_exists_true() { -// -// } -// -// public function test_exists_false() { -// -// } -// -// public function test_exists_wrong_data() { -// -// } -} - -/* End of file appointments_modelTest.php */ -/* Location: ../test/appointments_modelTest.php */ \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php deleted file mode 100644 index 6f59dd91..00000000 --- a/test/bootstrap.php +++ /dev/null @@ -1,212 +0,0 @@ - - \ No newline at end of file