/** * Saves a survey result to the database. * If the survey result is not saved yet, its srid will be added to the * survey_result_entity. * @param Survey_result_entity (by reference) * * @return boolean * Whether or not the save was successful. */ public function save(Survey_result_entity &$entity) { // To ensure date consistency. $date = Mongo_db::date(); // Set update date: $entity->updated = $date; if ($entity->author === NULL) { $entity->author = current_user()->uid; } $prepared_data = array(); foreach ($entity as $field_name => $field_value) { $prepared_data[$field_name] = $field_value; } if ($entity->is_new()) { // Add new properties. $entity->srid = increment_counter(self::COUNTER_COLLECTION); $entity->created = clone $date; // Add properties to prepared_data. $prepared_data['srid'] = $entity->srid; $prepared_data['created'] = $entity->created; $result = $this->mongo_db->insert(self::COLLECTION, $prepared_data); return $result !== FALSE ? TRUE : FALSE; } else { $result = $this->mongo_db->set($prepared_data)->where('srid', $entity->srid)->update(self::COLLECTION); return $result !== FALSE ? TRUE : FALSE; } }
public static function setUpBeforeClass() { self::$CI =& get_instance(); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); self::$CI->load->model('call_task_model'); // Some data! $fixture = array(array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000000", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000001", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000002", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::INVALID_NUMBER, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000003", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::SUCCESSFUL, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000004", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_CONSENT, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000005", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NUMBER_CHANGE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000006", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::DISCARD, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000007", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000008", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000009", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "9999999999001", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::SUCCESSFUL, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date())))); // Assigned and Not Started. for ($r = 0; $r < 10; $r++) { $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $r + 100), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array()); } // Unassigned. for ($r = 0; $r < 10; $r++) { $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $r + 1000), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => NULL, 'author' => 1, 'assignee_uid' => NULL, 'survey_sid' => 1, 'activity' => array()); } self::$CI->mongo_db->batchInsert(Call_task_model::COLLECTION, $fixture); // Add a few more to other users and surveys. $fixture = array(array('ctid' => increment_counter('call_task_ctid'), 'number' => "2000000000000", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 2, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "2000000000006", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 2, 'activity' => array(array('code' => Call_task_status::DISCARD, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "2000000000007", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 2, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date())))); self::$CI->mongo_db->batchInsert(Call_task_model::COLLECTION, $fixture); // More call tasks. // These are used to test the clean reserved function and some call tasks // with the assigned date far in the past are needed $fixture = array(); for ($r = 0; $r < 4; $r++) { $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (3000000000000 + $r + 1000), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(time() - 86400 * 4), 'author' => 1, 'assignee_uid' => 4, 'survey_sid' => 4, 'activity' => array()); } // Not expired. $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (3000000000000 + $r + 1 + 1000), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 4, 'survey_sid' => 4, 'activity' => array()); // Old one but started. $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (3000000000000 + $r + 1 + 1000), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(time() - 86400 * 4), 'author' => 1, 'assignee_uid' => 4, 'survey_sid' => 4, 'activity' => array(array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 4, 'created' => Mongo_db::date()))); self::$CI->mongo_db->batchInsert(Call_task_model::COLLECTION, $fixture); }
public static function _fix_data() { $date = Mongo_db::date(); // We need to generate a large amount of varied data but we need // to ensure that is always the same. $surveys = array(1, 2, 3, 4, 5); $no_reply_x5 = array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // once every 17 $amount_no_reply = array(0, 0, 1, 0, 0, 1, 0, 2, 0, 0, 0, 2, 0, 3, 0, 0, 0, 1, 3, 0, 0, 0); $final_status = array(Call_task_status::SUCCESSFUL, Call_task_status::NO_CONSENT, Call_task_status::NUMBER_CHANGE, Call_task_status::DISCARD, Call_task_status::INVALID_NUMBER, Call_task_status::SUCCESSFUL, Call_task_status::SUCCESSFUL, Call_task_status::SUCCESSFUL, Call_task_status::DISCARD, Call_task_status::SUCCESSFUL, Call_task_status::SUCCESSFUL, Call_task_status::NO_CONSENT, Call_task_status::SUCCESSFUL, Call_task_status::SUCCESSFUL, Call_task_status::NO_CONSENT, Call_task_status::SUCCESSFUL); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); ////////////////////////////////////////////////////////////// // Not assigned: for ($total_ct = 1; $total_ct <= 10000; $total_ct++) { $resp = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $total_ct), 'created' => $date, 'updated' => $date, 'assigned' => NULL, 'author' => 1, 'assignee_uid' => NULL, 'survey_sid' => get_next($surveys), 'activity' => array()); self::$CI->mongo_db->insert(Call_task_model::COLLECTION, $resp); } ////////////////////////////////////////////////////////////// // Assigned // 30000 per user (3 users) for ($assignee = 1; $assignee <= 3; $assignee++) { $status = array('message' => NULL, 'author' => $assignee, 'created' => $date); // Resolved 20000 for ($total_ct = 1; $total_ct <= 20000; $total_ct++) { $resp = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $assignee * 100000 + $total_ct), 'created' => $date, 'updated' => $date, 'assigned' => $date, 'author' => 1, 'assignee_uid' => $assignee, 'survey_sid' => get_next($surveys)); // Some no-reply. if (get_next($no_reply_x5)) { $status['code'] = Call_task_status::NO_REPLY; for ($i = 0; $i < Call_task_status::THRESHOLD_NO_REPLY; $i++) { $resp['activity'][] = $status; } } else { for ($i = 0; $i < get_next($amount_no_reply); $i++) { $status['code'] = Call_task_status::NO_REPLY; $resp['activity'][] = $status; } $status['code'] = get_next($final_status); $resp['activity'][] = $status; } self::$CI->mongo_db->insert(Call_task_model::COLLECTION, $resp); } // Unresolved 10000 for ($total_ct = 1; $total_ct <= 10000; $total_ct++) { $resp = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $assignee * 1000000 + $total_ct), 'created' => $date, 'updated' => $date, 'assigned' => $date, 'author' => 1, 'assignee_uid' => $assignee, 'survey_sid' => get_next($surveys)); for ($i = 0; $i < get_next($amount_no_reply); $i++) { $status['code'] = Call_task_status::NO_REPLY; $resp['activity'][] = $status; } $status['code'] = Call_task_status::CANT_COMPLETE; $resp['activity'][] = $status; self::$CI->mongo_db->insert(Call_task_model::COLLECTION, $resp); } } // Add index: ctid. self::$CI->mongo_db->addIndex(Call_task_model::COLLECTION, array('ctid' => 1)); // Add index: survey_sid. self::$CI->mongo_db->addIndex(Call_task_model::COLLECTION, array('survey_sid' => 1)); }
public static function setUpBeforeClass() { self::$CI =& get_instance(); // Load model self::$CI->load->model('survey_model'); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); // Some data! $fixture = array(array('sid' => 1, 'title' => 'Meteor usage', 'status' => Survey_entity::STATUS_DRAFT, 'files' => array('xls' => NULL, 'xml' => NULL, 'last_conversion' => array('date' => 1390493562, 'warnings' => NULL)), 'agents' => array(1, 2, 3), 'created' => Mongo_db::date()), array('sid' => 123456, 'title' => 'Second survey', 'status' => Survey_entity::STATUS_CANCELED, 'files' => array('xls' => NULL, 'xml' => NULL, 'last_conversion' => array('date' => NULL, 'warnings' => NULL)), 'agents' => array(1, 2), 'created' => Mongo_db::date())); self::$CI->mongo_db->batchInsert(Survey_model::COLLECTION, $fixture); }
public static function setUpBeforeClass() { self::$CI =& get_instance(); // Load model self::$CI->load->model('survey_result_model'); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); // Some data! $fixture = array(array('srid' => 100, 'call_task_ctid' => 1, 'survey_sid' => 1, 'files' => array('xml' => 'file_location.xml'), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'author' => 1), array('srid' => 101, 'call_task_ctid' => 1, 'survey_sid' => 1, 'files' => array('xml' => 'file_location.xml'), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'author' => 1)); self::$CI->mongo_db->batchInsert(Survey_result_model::COLLECTION, $fixture); }
public static function setUpBeforeClass() { self::$CI =& get_instance(); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); // Change Controller. self::$CI = new Survey(); self::$CI->mongo_db->switchDb('mongodb://*****:*****@localhost.dev', 'name' => 'Admin', 'username' => 'admin', 'password' => hash_password('admin'), 'roles' => array(ROLE_ADMINISTRATOR), 'author' => null, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()))); }
public static function setUpBeforeClass() { self::$CI =& get_instance(); self::$CI->load->helper('password_hashing'); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); // Some data! $fixture = array(array('uid' => increment_counter('user_uid'), 'email' => '*****@*****.**', 'name' => 'Admin', 'username' => 'admin', 'password' => hash_password('admin'), 'roles' => array(ROLE_ADMINISTRATOR), 'author' => null, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => increment_counter('user_uid'), 'email' => '*****@*****.**', 'name' => 'test user', 'username' => 'test_user', 'password' => hash_password('test_user'), 'roles' => array(), 'author' => null, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => 99, 'email' => '*****@*****.**', 'name' => 'multiple roles user', 'username' => 'multiple', 'password' => hash_password('multiple'), 'roles' => array(ROLE_ADMINISTRATOR, ROLE_CC_AGENT), 'author' => null, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => increment_counter('user_uid'), 'email' => '*****@*****.**', 'name' => 'blocked user', 'username' => 'blocked', 'password' => hash_password('blocked'), 'roles' => array(), 'author' => null, 'status' => User_entity::STATUS_BLOCKED, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => increment_counter('user_uid'), 'email' => '*****@*****.**', 'name' => 'Deleted user', 'username' => 'deleted', 'password' => hash_password('deleted'), 'roles' => array(), 'author' => null, 'status' => User_entity::STATUS_DELETED, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date())); self::$CI->mongo_db->batchInsert(User_model::COLLECTION, $fixture); // User model is autoloaded. // No need to load. }
public function test_api_survey_with_status_restrictions() { // Here we are testing all the API but only for status restrictions. // Every other test case should be tested elsewhere. // Cleanup self::$CI->mongo_db->dropCollection('aw_datacollection_test', 'surveys'); self::$CI->mongo_db->dropCollection('aw_datacollection_test', 'call_tasks'); $this->_reset_status_restrictions(); // Shorter statuses. $draft = Survey_entity::STATUS_DRAFT; $open = Survey_entity::STATUS_OPEN; $closed = Survey_entity::STATUS_CLOSED; $canceled = Survey_entity::STATUS_CANCELED; // Login user $this->_change_user(9903); ///////////////////////////////////////////////////////////////// // Set actions to be allowed only in Draft status. $mock_config = self::$status_resctriction_config; $mock_config['enketo collect data'] = array(Survey_entity::STATUS_DRAFT); $mock_config['enketo testrun'] = array(Survey_entity::STATUS_DRAFT); $this->_set_status_restrictions($mock_config); // Logged user is 9903 // User is agent. // Create survey. // Status open. // Valid xml file. // User is assigned to survey. $survey = Survey_entity::build(array('sid' => 1, 'status' => Survey_entity::STATUS_OPEN, 'files' => array('xml' => 'valid_survey.xml'), 'agents' => array(9903))); self::$CI->survey_model->save($survey); // Create call task self::$CI->mongo_db->insert('call_tasks', array('ctid' => 1001, 'number' => "1100500000000", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 9903, 'survey_sid' => 1, 'activity' => array())); self::$CI->api_survey_xslt_transform(1); $result = json_decode(self::$CI->output->get_output(), TRUE); $this->assertEquals(array('code' => 403, 'message' => 'Not allowed.'), $result['status']); $this->assertArrayHasKey('xml_form', $result); self::$CI->api_survey_request_respondents(1); $result = json_decode(self::$CI->output->get_output(), TRUE); $this->assertEquals(array('code' => 403, 'message' => 'Not allowed.'), $result['status']); // User assigned to call task. // Call task is assigned to survey. // User is assigned to survey. // Survey is the one data is being submitted for. $_POST = array('csrf_aw_datacollection' => self::$CI->security->get_csrf_hash(), 'respondent' => array('ctid' => 1001, 'form_data' => '<valid><tag/></valid>')); self::$CI->api_survey_enketo_form_submit(1); $result = json_decode(self::$CI->output->get_output(), TRUE); $this->assertEquals(array('code' => 403, 'message' => 'Not allowed.'), $result['status']); ///////////////////////////////////////////////////////////////// // Test again with correct status restrictions. $mock_config = self::$status_resctriction_config; $mock_config['enketo collect data'] = array(Survey_entity::STATUS_OPEN); $mock_config['enketo testrun'] = array(Survey_entity::STATUS_OPEN); $this->_set_status_restrictions($mock_config); self::$CI->api_survey_xslt_transform(1); $result = json_decode(self::$CI->output->get_output(), TRUE); $this->assertEquals(array('code' => 200, 'message' => 'Ok!'), $result['status']); $this->assertArrayHasKey('xml_form', $result); self::$CI->api_survey_request_respondents(1); $result = json_decode(self::$CI->output->get_output(), TRUE); $this->assertEquals(array('code' => 200, 'message' => 'Ok!'), $result['status']); // User assigned to call task. // Call task is assigned to survey. // User is assigned to survey. // Survey is the one data is being submitted for. $_POST = array('csrf_aw_datacollection' => self::$CI->security->get_csrf_hash(), 'respondent' => array('ctid' => 1001, 'form_data' => '<valid><tag/></valid>')); self::$CI->api_survey_enketo_form_submit(1); $result = json_decode(self::$CI->output->get_output(), TRUE); $this->assertEquals(array('code' => 200, 'message' => 'Ok!'), $result['status']); ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// // To test the manage agents api we need an admin. $this->_change_user(9901); // Logged user 9901. // User is administrator. // Create survey. // Status open. // Valid xml file. $survey = Survey_entity::build(array('sid' => 2, 'status' => Survey_entity::STATUS_OPEN, 'files' => array('xml' => 'valid_survey.xml'), 'agents' => array())); self::$CI->survey_model->save($survey); // Create new agent. // Absolute minimum properties for the test. $user_agent = User_entity::build(array('uid' => 8801, 'status' => User_entity::STATUS_ACTIVE, 'roles' => array(ROLE_CC_AGENT))); self::$CI->user_model->save($user_agent); // Set conditions. $mock_config = self::$status_resctriction_config; $mock_config['manage agents'] = array(Survey_entity::STATUS_DRAFT); $this->_set_status_restrictions($mock_config); // User is an agent. // Action assign $_POST = array('uid' => 8801, 'action' => 'assign', 'csrf_aw_datacollection' => self::$CI->security->get_csrf_hash()); self::$CI->api_survey_manage_agents(1); $result = json_decode(self::$CI->output->get_output(), TRUE); $this->assertEquals(array('code' => 403, 'message' => 'Not allowed.'), $result['status']); ///////////////////////////////////////////////////////////////// // Set conditions. $mock_config = self::$status_resctriction_config; $mock_config['manage agents'] = array(Survey_entity::STATUS_OPEN); $this->_set_status_restrictions($mock_config); // User is an agent. // Action assign $_POST = array('uid' => 8801, 'action' => 'assign', 'csrf_aw_datacollection' => self::$CI->security->get_csrf_hash()); self::$CI->api_survey_manage_agents(1); $result = json_decode(self::$CI->output->get_output(), TRUE); $this->assertEquals(array('code' => 200, 'message' => 'Ok!'), $result['status']); }
/** * Eases the creation of Call_task_status by setting some properties. * * @access public * @static * * @param int $code * Call Task Status code * @param string $msg * Call Task Status Message. * * @throws Exception * If the given code is not valid. * * @return Call_task_entity */ static function create($code, $msg) { $ct = new Call_task_status(array()); $ct->set_code($code); $ct->message = $msg; $ct->created = Mongo_db::date(); $ct->author = current_user()->uid; return $ct; }
copy('resources/fixtures_data/survey_2_xml.xml', 'files/surveys/survey_2_xml.xml'); // Survey 2. $survey = new Survey_entity(array('title' => 'Handlebars', 'client' => 'Digital Dreams Inc', 'status' => Survey_entity::STATUS_OPEN, 'goal' => 20, 'introduction' => 'Hi, my name is ______ and I am calling on behalf of Digital Dreams. Handlebars is interested in learning more about you and your relation with it. You are being contacted because of your participation in the workshop held near your house. We would like to ask you some questions about your coffee consumption while using handlebars. Your participation is very important, because your responses will help us improve our framework and thus make it more usable. This survey will only take about 5 minutes of your time.', 'description' => 'This survey will help us understand how handlebars is used by developers and how it can be improved.', 'files' => array('xls' => "survey_2_xls.xls", 'xml' => "survey_2_xml.xml", 'last_conversion' => array('date' => NULL, 'warnings' => NULL)))); // Assign agent, user 3 $survey->assign_agent(3); $this->survey_model->save($survey); ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Call task. $call_task = new Call_task_entity(array('number' => "1000000000001", 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 3, 'survey_sid' => 2)); $call_task->add_status(new Call_task_status(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 3, 'created' => Mongo_db::date()))); $call_task->add_status(new Call_task_status(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 3, 'created' => Mongo_db::date()))); $this->call_task_model->save($call_task); /////////////////////////////////////////////////////// // Call task. $call_task = new Call_task_entity(array('number' => "1000000000002", 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 3, 'survey_sid' => 2)); $call_task->add_status(new Call_task_status(array('code' => Call_task_status::CANT_COMPLETE, 'message' => 'Not to be done right now. Maybe later.', 'author' => 3, 'created' => Mongo_db::date()))); $this->call_task_model->save($call_task); /////////////////////////////////////////////////////// // Call task. $call_task = new Call_task_entity(array('number' => "1000000000003", 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 3, 'survey_sid' => 2)); $call_task->add_status(new Call_task_status(array('code' => Call_task_status::INVALID_NUMBER, 'message' => NULL, 'author' => 3, 'created' => Mongo_db::date()))); $this->call_task_model->save($call_task); /////////////////////////////////////////////////////// // Add some respondents to be used for data collection. for ($r = 0; $r < 100; $r++) { // Call task. $call_task = new Call_task_entity(array('number' => (string) (2000000000000 + $r), 'assigned' => Mongo_db::date(), 'author' => 1, 'survey_sid' => 2)); $this->call_task_model->save($call_task); }