Ολοκλήρωση των unit test του model των ραντεβού.

This commit is contained in:
alextselegidis@gmail.com 2013-05-14 19:56:16 +00:00
parent aa26540fd8
commit b6c5cf1ef5
8 changed files with 540 additions and 376 deletions

View file

@ -64,7 +64,7 @@ $autoload['libraries'] = array('database');
| $autoload['helper'] = array('url', 'file'); | $autoload['helper'] = array('url', 'file');
*/ */
$autoload['helper'] = array(); $autoload['helper'] = array('custom_exceptions');
/* /*

View file

@ -19,7 +19,8 @@ class Unit_tests extends CI_Driver_Library {
// Add more subclasses to the following array to expand // Add more subclasses to the following array to expand
// the unit testing classes. // the unit testing classes.
$this->valid_drivers = array( $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. * be run.
*/ */
public function run_all_tests() { public function run_all_tests() {
$this->run_model_tests(); $this->run_model_tests(false);
$this->run_library_tests(); $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. * 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->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. * 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());
}
} }
} }

View file

@ -47,13 +47,10 @@ class Unit_tests_appointments_model extends CI_Driver {
// "test" keyword from the beginning. // "test" keyword from the beginning.
$class_methods = get_class_methods('Unit_tests_appointments_model'); $class_methods = get_class_methods('Unit_tests_appointments_model');
foreach ($class_methods as $method_name) { 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)); 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.'); $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 * Test the find record id method with a record that already
// @task Test get_batch * exists in the databse.
// @task Test get_row */
// @task Test get_value private function test_find_record_id() {
// @task Test validate_data // 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.
*
* <strong>IMPORTANT!</strong> 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 */

View file

@ -0,0 +1,39 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Unit_tests_customers_model extends CI_Driver {
private $CI;
public function __construct() {
$this->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 */

View file

@ -6,7 +6,6 @@ class Appointments_Model extends CI_Model {
*/ */
public function __construct() { public function __construct() {
parent::__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.'); 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, * get the unique id from the database: start_datetime, end_datetime,
* id_users_provider, id_users_customer, id_services. * id_users_provider, id_users_customer, id_services.
* *
* <strong>IMPORTANT!</strong> The record must already exists in the
* database, otherwise an exception is raised.
*
* @expectedException DatabaseException * @expectedException DatabaseException
* *
* @param array $appointment_data Array with the appointment data. The * @param array $appointment_data Array with the appointment data. The
@ -136,7 +138,7 @@ class Appointments_Model extends CI_Model {
* update operation is executed. * update operation is executed.
* *
* @param array $appointment_data Contains the appointment data. * @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) { public function validate_data($appointment_data) {
$this->load->helper('data_validation'); $this->load->helper('data_validation');
@ -151,7 +153,35 @@ class Appointments_Model extends CI_Model {
throw new Exception('Appointment end datetime is invalid.'); 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; return TRUE;
} catch (Exception $exc) { } catch (Exception $exc) {
@ -166,6 +196,16 @@ class Appointments_Model extends CI_Model {
* @return bool Returns the delete operation result. * @return bool Returns the delete operation result.
*/ */
public function delete($appointment_id) { 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); $this->db->where('id', $appointment_id);
return $this->db->delete('ea_appointments'); return $this->db->delete('ea_appointments');
} }
@ -179,6 +219,9 @@ class Appointments_Model extends CI_Model {
* field names. * field names.
*/ */
public function get_row($appointment_id) { 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(); 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. * @return string Returns the records value from the database.
*/ */
public function get_value($field_name, $appointment_id) { 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];
} }
/** /**

View file

@ -1,132 +0,0 @@
<?php
class AppointmentsModelTest extends PHPUnit_Framework_TestCase {
private $CI;
private $id_users_provider;
private $id_users_customer;
private $id_services;
public function setUp() {
$this->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 */

View file

@ -1,212 +0,0 @@
<?php
/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
*---------------------------------------------------------------
*
* You can load different configurations depending on your
* current environment. Setting the environment also influences
* things like logging and error reporting.
*
* This can be set to anything, but default usage is:
*
* development
* testing
* production
*
* NOTE: If you change these, also change the error_reporting() code below
*
*/
define('ENVIRONMENT', 'testing');
/*
*---------------------------------------------------------------
* ERROR REPORTING
*---------------------------------------------------------------
*
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.
*/
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
/*
*---------------------------------------------------------------
* SYSTEM FOLDER NAME
*---------------------------------------------------------------
*
* This variable must contain the name of your "system" folder.
* Include the path if the folder is not in the same directory
* as this file.
*
*/
$system_path = '../src/system';
/*
*---------------------------------------------------------------
* APPLICATION FOLDER NAME
*---------------------------------------------------------------
*
* If you want this front controller to use a different "application"
* folder then the default one you can set its name here. The folder
* can also be renamed or relocated anywhere on your server. If
* you do, use a full server path. For more info please see the user guide:
* http://codeigniter.com/user_guide/general/managing_apps.html
*
* NO TRAILING SLASH!
*
*/
$application_folder = '../src/application';
/*
* --------------------------------------------------------------------
* DEFAULT CONTROLLER
* --------------------------------------------------------------------
*
* Normally you will set your default controller in the routes.php file.
* You can, however, force a custom routing by hard-coding a
* specific controller class/function here. For most applications, you
* WILL NOT set your routing here, but it's an option for those
* special instances where you might want to override the standard
* routing in a specific front controller that shares a common CI installation.
*
* IMPORTANT: If you set the routing here, NO OTHER controller will be
* callable. In essence, this preference limits your application to ONE
* specific controller. Leave the function name blank if you need
* to call functions dynamically via the URI.
*
* Un-comment the $routing array below to use this feature
*
*/
// The directory name, relative to the "controllers" folder. Leave blank
// if your controller is not in a sub-folder within the "controllers" folder
// $routing['directory'] = '';
// The controller class file name. Example: Mycontroller
// $routing['controller'] = '';
// The controller function you wish to be called.
// $routing['function'] = '';
/*
* -------------------------------------------------------------------
* CUSTOM CONFIG VALUES
* -------------------------------------------------------------------
*
* The $assign_to_config array below will be passed dynamically to the
* config class when initialized. This allows you to set custom config
* items or override any default config values found in the config.php file.
* This can be handy as it permits you to share one application between
* multiple front controller files, with each file containing different
* config values.
*
* Un-comment the $assign_to_config array below to use this feature
*
*/
// $assign_to_config['name_of_config_item'] = 'value of config item';
$assign_to_config['uri_protocol'] = 'PATH_INFO'; // This is needed to run tests on netbeans and code igniter.
// --------------------------------------------------------------------
// END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE
// --------------------------------------------------------------------
/*
* ---------------------------------------------------------------
* Resolve the system path for increased reliability
* ---------------------------------------------------------------
*/
// Set the current directory correctly for CLI requests
if (defined('STDIN'))
{
chdir(dirname(__FILE__));
}
if (realpath($system_path) !== FALSE)
{
$system_path = realpath($system_path).'/';
}
// ensure there's a trailing slash
$system_path = rtrim($system_path, '/').'/';
// Is the system path correct?
if ( ! is_dir($system_path))
{
exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}
/*
* -------------------------------------------------------------------
* Now that we know the path, set the main path constants
* -------------------------------------------------------------------
*/
// The name of THIS file
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
// The PHP file extension
// this global constant is deprecated.
define('EXT', '.php');
// Path to the system folder
define('BASEPATH', str_replace("\\", "/", $system_path));
// Path to the front controller (this file)
define('FCPATH', str_replace(SELF, '', __FILE__));
// Name of the "system folder"
define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
// The path to the "application" folder
if (is_dir($application_folder))
{
define('APPPATH', $application_folder.'/');
}
else
{
if ( ! is_dir(BASEPATH.$application_folder.'/'))
{
exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
}
define('APPPATH', BASEPATH.$application_folder.'/');
}
/**
* --------------------------------------------------------------------
* CHECK IF EASY!APPOINTMENTS IS INSTALLED AND CONFIGURED
* --------------------------------------------------------------------
*/
// If not show the installer instead of the main page.
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */
/* Location: ./index.php */

View file

@ -1,10 +0,0 @@
<phpunit bootstrap="bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false"
syntaxCheck="true"
verbose="true">
</phpunit>