Advertisement
Guest User

Untitled

a guest
Dec 7th, 2010
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.36 KB | None | 0 0
  1. <?php
  2. require_once(APPPATH . '/controllers/test/Toast.php');
  3.  
  4. class Contact_tests extends Toast
  5. {
  6.     function Contact_tests()
  7.     {
  8.         parent::Toast(__FILE__);
  9.         // Load any models, libraries etc. you need here
  10.                 $this->load->model('contact_model', 'contact');
  11.     }
  12.  
  13.     /**
  14.      * OPTIONAL; Anything in this function will be run before each test
  15.      * Good for doing cleanup: resetting sessions, renewing objects, etc.
  16.      */
  17.     function _pre() {}
  18.  
  19.     /**
  20.      * OPTIONAL; Anything in this function will be run after each test
  21.      * I use it for setting $this->message = $this->My_model->getError();
  22.      */
  23.     function _post() {}
  24.  
  25.  
  26.     /* TESTS BELOW */
  27.  
  28.     function test_add_contact()
  29.     {
  30.             $message = array(
  31.                 'name' => 'Test Name',
  32.                 'email' =>  'Test@email.com',
  33.                 'subject' => 'Test Subject',
  34.                 'message' => 'Test Message',
  35.                 'ip_address' => $this->input->ip_address(),
  36.                 'stamp' => $stamp = date("Y-m-d H:i:s")
  37.             );
  38.  
  39.             // Add message
  40.             $insert_id = $this->contact->add_message($message);
  41.  
  42.             // Get saved message
  43.             $saved_message = $this->contact->get_message(array('id' => $insert_id));
  44.  
  45.             // Remove message
  46.             $this->contact->remove_message(array('id' => $insert_id));
  47.  
  48.             // Remove ID from retreived message
  49.             unset($saved_message['id']);
  50.  
  51.             $this->_assert_equals($message, $saved_message);
  52.     }
  53.  
  54.         function test_remove_contact()
  55.         {
  56.             $message = array(
  57.                 'name' => 'Test Name',
  58.                 'email' =>  'Test@email.com',
  59.                 'subject' => 'Test Subject',
  60.                 'message' => 'Test Message',
  61.                 'ip_address' => $this->input->ip_address(),
  62.                 'stamp' => $stamp = date("Y-m-d H:i:s")
  63.             );
  64.  
  65.             // Add Message
  66.             $insert_id = $this->contact->add_message($message);
  67.  
  68.             // Remove message
  69.             $this->contact->remove_message(array('id' => $insert_id));
  70.  
  71.             // Get message
  72.             $saved_message = $this->contact->get_message(array('id' => $insert_id));
  73.  
  74.             $this->_assert_equals(false, $saved_message);
  75.         }
  76. }
  77.  
  78. // End of file contact_test.php */
  79. // Location: ./system/application/controllers/test/contact_test.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement