public function test__log__notify_admin_failure() { $exception_message = 'Exception'; $log_entry = new Omnilog_entry($this->_log_entry_props); $log_entry->set_notify_admin(TRUE); $saved_entry_props = array_merge($log_entry->to_array(), array('log_entry_id' => 10)); $saved_entry = new Omnilog_entry($saved_entry_props); $this->_model->expectOnce('save_entry_to_log', array($log_entry)); $this->_model->setReturnValue('save_entry_to_log', $saved_entry); $this->_model->expectOnce('notify_site_admin_of_log_entry', array($saved_entry)); $this->_model->throwOn('notify_site_admin_of_log_entry', new Exception($exception_message)); $this->assertIdentical(FALSE, Omnilogger::log($log_entry)); }
public function test__is_populated__not_populated_with_entry_id() { unset($this->_props['log_entry_id']); $subject = new Omnilog_entry($this->_props); $this->assertIdentical(FALSE, $subject->is_populated(TRUE)); }
/** * Saves the supplied OmniLog Entry to the database. * * @access public * @param Omnilog_entry $entry The entry to save. * @return Omnilog_entry */ public function save_entry_to_log(Omnilog_entry $entry) { if (!$entry->is_populated()) { throw new Exception($this->_ee->lang->line('exception__save_entry__missing_data')); } $insert_data = array_merge($entry->to_array(), array('notify_admin' => $entry->get_notify_admin() === TRUE ? 'y' : 'n', 'site_id' => $this->get_site_id())); $this->_ee->db->insert('omnilog_entries', $insert_data); if (!($insert_id = $this->_ee->db->insert_id())) { throw new Exception($this->_ee->lang->line('exception__save_entry__not_saved')); } $entry->set_log_entry_id($insert_id); return $entry; }
/** * Saves the supplied OmniLog Entry to the database. * * @access public * @param Omnilog_entry $entry The entry to save. * @return Omnilog_entry */ public function save_entry_to_log(Omnilog_entry $entry) { /** * This method could conceivably be called when the module is * not installed, but the Omnilogger class is present. */ if (!$this->EE->db->table_exists('omnilog_entries')) { throw new Exception($this->EE->lang->line('exception__save_entry__not_installed')); } if (!$entry->is_populated()) { throw new Exception($this->EE->lang->line('exception__save_entry__missing_data')); } $insert_data = array_merge($entry->to_array(), array('notify_admin' => $entry->get_notify_admin() === TRUE ? 'y' : 'n', 'site_id' => $this->get_site_id())); $insert_data['admin_emails'] = implode($insert_data['admin_emails'], '|'); $this->EE->db->insert('omnilog_entries', $insert_data); if (!($insert_id = $this->EE->db->insert_id())) { throw new Exception($this->EE->lang->line('exception__save_entry__not_saved')); } $entry->set_log_entry_id($insert_id); return $entry; }
public function test__save_entry_to_log__success_with_notify_admin() { $db = $this->EE->db; $email = $this->EE->email; // Ensures that the emails are added to the Omnilog_entry. $email->setReturnValue('valid_email', TRUE); $entry_data = array('addon_name' => 'Example Add-on', 'admin_emails' => array('*****@*****.**', '*****@*****.**'), 'date' => time() - 100, 'message' => 'Example OmniLog entry.', 'extended_data' => 'Example OmniLog extended data.', 'notify_admin' => TRUE, 'type' => Omnilog_entry::ERROR); $insert_data = array('addon_name' => 'Example Add-on', 'admin_emails' => 'adam@ants.com|bob@dylan.com', 'date' => time() - 100, 'message' => 'Example OmniLog entry.', 'extended_data' => 'Example OmniLog extended data.', 'notify_admin' => 'y', 'type' => Omnilog_entry::ERROR, 'site_id' => $this->_site_id); $entry = new Omnilog_entry($entry_data); $insert_id = 10; $db->expectOnce('table_exists', array('omnilog_entries')); $db->setReturnValue('table_exists', TRUE); $db->expectOnce('insert', array('omnilog_entries', $insert_data)); $db->setReturnValue('insert_id', $insert_id); $expected_props = array_merge($entry_data, array('log_entry_id' => $insert_id)); $expected_result = new Omnilog_entry($expected_props); $actual_result = $this->_subject->save_entry_to_log($entry); $this->assertIdentical($expected_result->to_array(TRUE), $actual_result->to_array(TRUE)); }