/** * Test civicrm_contact_check_params with a duplicate. * and request the error in array format */ public function testCheckParamsWithDuplicateContact2() { // Insert a row in civicrm_contact creating individual contact $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createXMLDataSet(dirname(__FILE__) . '/../../api/v3/dataset/contact_17.xml')); $op->execute($this->_dbconn, $this->createXMLDataSet(dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml')); $params = array('first_name' => 'Test', 'last_name' => 'Contact', 'email' => '*****@*****.**', 'contact_type' => 'Individual'); $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE, TRUE); $this->assertEquals(1, $contact['is_error']); $this->assertRegexp("/matching contacts.*17/s", $contact['error_message']['message']); }
protected function setUp() { parent::setUp(); $this->quickCleanup(array('civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_match')); $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml')); $this->callAPISuccess('uf_field', 'getfields', array('cache_clear' => 1)); $this->_params = array('field_name' => 'phone', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', 'weight' => 1, 'label' => 'Test Phone', 'is_searchable' => 1, 'is_active' => 1, 'location_type_id' => 1, 'phone_type_id' => 1, 'uf_group_id' => $this->_ufGroupId); }
/** * Test setup for every test * * Connect to the database, truncate the tables that will be used * and redirect stdin to a temporary file */ public function setUp() { // Connect to the database parent::setUp(); $this->quickCleanup(array('civicrm_address_format', 'civicrm_currency', 'civicrm_domain', 'civicrm_file', 'civicrm_financial_account', 'civicrm_financial_trxn', 'civicrm_job', 'civicrm_job_log', 'civicrm_location_type', 'civicrm_mail_settings', 'civicrm_mapping', 'civicrm_navigation', 'civicrm_option_group', 'civicrm_payment_processor', 'civicrm_payment_processor_type', 'civicrm_preferences_date', 'civicrm_worldregion', 'civicrm_component', 'civicrm_persistent', 'civicrm_prevnext_cache', 'civicrm_action_mapping', 'civicrm_acl', 'civicrm_acl_entity_role', 'civicrm_contact', 'civicrm_acl_contact_cache', 'civicrm_relationship_type', 'civicrm_saved_search', 'civicrm_contact_type', 'civicrm_mailing_component', 'civicrm_mailing_bounce_type', 'civicrm_mailing_bounce_pattern', 'civicrm_financial_type', 'civicrm_premiums', 'civicrm_product', 'civicrm_premiums_product', 'civicrm_sms_provider', 'civicrm_membership_status', 'civicrm_campaign', 'civicrm_campaign_group', 'civicrm_survey', 'civicrm_participant_status_type', 'civicrm_event_carts', 'civicrm_dedupe_rule_group', 'civicrm_dedupe_rule', 'civicrm_dedupe_exception', 'civicrm_case', 'civicrm_case_contact', 'civicrm_grant', 'civicrm_tell_friend', 'civicrm_pledge_block', 'civicrm_queue_item', 'civicrm_report_instance', 'civicrm_price_set', 'civicrm_price_set_entity', 'civicrm_pcp', 'civicrm_batch', 'civicrm_cache', 'civicrm_country', 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_dashboard', 'civicrm_email', 'civicrm_entity_batch', 'civicrm_entity_file', 'civicrm_entity_financial_trxn', 'civicrm_im', 'civicrm_log', 'civicrm_mapping_field', 'civicrm_menu', 'civicrm_note', 'civicrm_option_value', 'civicrm_phone', 'civicrm_state_province', 'civicrm_tag', 'civicrm_uf_match', 'civicrm_timezone', 'civicrm_openid', 'civicrm_discount', 'civicrm_website', 'civicrm_setting', 'civicrm_acl_cache', 'civicrm_dashboard_contact', 'civicrm_group', 'civicrm_subscription_history', 'civicrm_group_contact_cache', 'civicrm_group_nesting', 'civicrm_group_organization', 'civicrm_relationship', 'civicrm_mailing_event_subscribe', 'civicrm_mailing_event_confirm', 'civicrm_contribution_recur', 'civicrm_contribution_page', 'civicrm_contribution_widget', 'civicrm_activity', 'civicrm_activity_contact', 'civicrm_case_activity', 'civicrm_pledge', 'civicrm_price_field', 'civicrm_county', 'civicrm_entity_tag', 'civicrm_msg_template', 'civicrm_uf_group', 'civicrm_uf_field', 'civicrm_uf_join', 'civicrm_action_schedule', 'civicrm_action_log', 'civicrm_mailing', 'civicrm_mailing_group', 'civicrm_mailing_trackable_url', 'civicrm_mailing_job', 'civicrm_mailing_recipients', 'civicrm_mailing_spool', 'civicrm_mailing_event_queue', 'civicrm_mailing_event_bounce', 'civicrm_mailing_event_delivered', 'civicrm_mailing_event_forward', 'civicrm_mailing_event_opened', 'civicrm_mailing_event_reply', 'civicrm_mailing_event_trackable_url_open', 'civicrm_mailing_event_unsubscribe', 'civicrm_membership_type', 'civicrm_membership', 'civicrm_membership_block', 'civicrm_membership_log', 'civicrm_price_field_value', 'civicrm_line_item', 'civicrm_pcp_block', 'civicrm_address', 'civicrm_loc_block', 'civicrm_group_contact', 'civicrm_contribution', 'civicrm_contribution_product', 'civicrm_contribution_soft', 'civicrm_membership_payment', 'civicrm_event', 'civicrm_participant', 'civicrm_participant_payment', 'civicrm_events_in_carts', 'civicrm_pledge_payment')); // Insert test data $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/data.xml')); }
protected function setUp() { parent::setUp(); // Truncate the tables $this->quickCleanup(array('civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_join', 'civicrm_uf_match')); $this->_apiversion = 3; $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml')); }
protected function setUp() { parent::setUp(); $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml')); // FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together $GLOBALS['_HTML_QuickForm_registered_rules'] = array('required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'), 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'), 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'), 'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php')); // FIXME: …ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array('group' => array('HTML/QuickForm/group.php', 'HTML_QuickForm_group'), 'hidden' => array('HTML/QuickForm/hidden.php', 'HTML_QuickForm_hidden'), 'reset' => array('HTML/QuickForm/reset.php', 'HTML_QuickForm_reset'), 'checkbox' => array('HTML/QuickForm/checkbox.php', 'HTML_QuickForm_checkbox'), 'file' => array('HTML/QuickForm/file.php', 'HTML_QuickForm_file'), 'image' => array('HTML/QuickForm/image.php', 'HTML_QuickForm_image'), 'password' => array('HTML/QuickForm/password.php', 'HTML_QuickForm_password'), 'radio' => array('HTML/QuickForm/radio.php', 'HTML_QuickForm_radio'), 'button' => array('HTML/QuickForm/button.php', 'HTML_QuickForm_button'), 'submit' => array('HTML/QuickForm/submit.php', 'HTML_QuickForm_submit'), 'select' => array('HTML/QuickForm/select.php', 'HTML_QuickForm_select'), 'hiddenselect' => array('HTML/QuickForm/hiddenselect.php', 'HTML_QuickForm_hiddenselect'), 'text' => array('HTML/QuickForm/text.php', 'HTML_QuickForm_text'), 'textarea' => array('HTML/QuickForm/textarea.php', 'HTML_QuickForm_textarea'), 'fckeditor' => array('HTML/QuickForm/fckeditor.php', 'HTML_QuickForm_FCKEditor'), 'tinymce' => array('HTML/QuickForm/tinymce.php', 'HTML_QuickForm_TinyMCE'), 'dojoeditor' => array('HTML/QuickForm/dojoeditor.php', 'HTML_QuickForm_dojoeditor'), 'link' => array('HTML/QuickForm/link.php', 'HTML_QuickForm_link'), 'advcheckbox' => array('HTML/QuickForm/advcheckbox.php', 'HTML_QuickForm_advcheckbox'), 'date' => array('HTML/QuickForm/date.php', 'HTML_QuickForm_date'), 'static' => array('HTML/QuickForm/static.php', 'HTML_QuickForm_static'), 'header' => array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'), 'html' => array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'), 'hierselect' => array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'), 'autocomplete' => array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'), 'xbutton' => array('HTML/QuickForm/xbutton.php', 'HTML_QuickForm_xbutton'), 'advmultiselect' => array('HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect')); }
protected function setUp() { parent::setUp(); $this->_apiversion = 3; $this->quickCleanup(array('civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_join', 'civicrm_uf_match')); $this->_contactId = $this->individualCreate(); $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml')); $this->_params = array('contact_id' => $this->_contactId, 'uf_id' => '2', 'uf_name' => '*****@*****.**', 'domain_id' => 1); }
public function execute(\PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, \PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) { foreach ($dataSet->getTableNames() as $tableName) { $connection->getConnection()->query("Alter Table {$tableName} NOCHECK Constraint All"); } parent::execute($connection, $dataSet); foreach ($dataSet->getTableNames() as $tableName) { $connection->getConnection()->query("Alter Table {$tableName} CHECK Constraint All"); } }
/** * AllIMs() method - get all IMs for our contact, with primary IM first */ public function testAllIMs() { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/im_test.xml')); $contactId = 69; $IMs = CRM_Core_BAO_IM::allIMs($contactId); $this->assertEquals(count($IMs), 3, 'Checking number of returned IMs.'); $firstIMValue = array_slice($IMs, 0, 1); $this->assertEquals('alan1.smith1', $firstIMValue[0]['name'], 'Confirm primary IM value.'); $this->assertEquals(1, $firstIMValue[0]['is_primary'], 'Confirm first IM is primary.'); $this->contactDelete($contactId); }
/** * Test setup for every test * * Connect to the database, truncate the tables that will be used * and redirect stdin to a temporary file */ public function setUp() { $this->_entity = 'case'; parent::setUp(); // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types //. Using XML was causing breakage as id numbers were changing over time // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a // state where tests could run afterwards without re-loading. $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array('name' => 'case_status', 'format.only_id' => 1)); $this->caseTypeGroup = $this->callAPISuccess('option_group', 'get', array('name' => 'case_type', 'format.only_id' => 1)); $caseTypes = $this->callAPISuccess('option_value', 'Create', array('option_group_id' => $this->caseTypeGroup, 'name' => 'housing_support', 'label' => "Housing Support", 'sequential' => 1, 'description' => 'Help homeless individuals obtain temporary and long-term housing')); $this->caseTypeId = $caseTypes['values'][0]['value']; $this->optionValues[] = $caseTypes['id']; $optionValues = array('Medical evaluation' => 'Medical evaluation', 'Mental health evaluation' => "Mental health evaluation", 'Secure temporary housing' => 'Secure temporary housing', 'Long-term housing plan' => 'Long-term housing plan', 'ADC referral' => 'ADC referral', 'Income and benefits stabilization' => 'Income and benefits stabilization'); foreach ($optionValues as $name => $label) { $activityTypes = $this->callAPISuccess('option_value', 'Create', array('option_group_id' => 2, 'name' => $name, 'label' => $label, 'component_id' => 7)); // store for cleanup $this->optionValues[] = $activityTypes['id']; } $tablesToTruncate = array('civicrm_activity', 'civicrm_contact', 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_case', 'civicrm_case_contact', 'civicrm_case_activity', 'civicrm_activity_contact', 'civicrm_relationship', 'civicrm_relationship_type'); $this->quickCleanup($tablesToTruncate); $activityTypes = $this->callAPISuccess('option_value', 'get', array('option_group_id' => 2, 'name' => 'Follow Up', 'label' => 'Follow Up', 'sequential' => 1)); $this->followup_activity_type_value = $activityTypes['values'][0]['value']; // Insert a row in civicrm_contact creating contact 17 $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/contact_17.xml')); //Create relationship types $relTypeParams = array('name_a_b' => 'Case Coordinator is', 'label_a_b' => 'Case Coordinator is', 'name_b_a' => 'Case Coordinator', 'label_b_a' => 'Case Coordinator', 'description' => 'Case Coordinator', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1); $this->relationshipTypeCreate($relTypeParams); $relTypeParams = array('name_a_b' => 'Homeless Services Coordinator is', 'label_a_b' => 'Homeless Services Coordinator is', 'name_b_a' => 'Homeless Services Coordinator', 'label_b_a' => 'Homeless Services Coordinator', 'description' => 'Homeless Services Coordinator', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1); $this->relationshipTypeCreate($relTypeParams); $relTypeParams = array('name_a_b' => 'Health Services Coordinator is', 'label_a_b' => 'Health Services Coordinator is', 'name_b_a' => 'Health Services Coordinator', 'label_b_a' => 'Health Services Coordinator', 'description' => 'Health Services Coordinator', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1); $this->relationshipTypeCreate($relTypeParams); $relTypeParams = array('name_a_b' => 'Senior Services Coordinator is', 'label_a_b' => 'Senior Services Coordinator is', 'name_b_a' => 'Senior Services Coordinator', 'label_b_a' => 'Senior Services Coordinator', 'description' => 'Senior Services Coordinator', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1); $this->relationshipTypeCreate($relTypeParams); $relTypeParams = array('name_a_b' => 'Benefits Specialist is', 'label_a_b' => 'Benefits Specialist is', 'name_b_a' => 'Benefits Specialist', 'label_b_a' => 'Benefits Specialist', 'description' => 'Benefits Specialist', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 1); $this->relationshipTypeCreate($relTypeParams); // enable the default custom templates for the case type xml files $this->customDirectories(array('template_path' => TRUE)); // case is not enabled by default $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase'); $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__); $this->_params = array('case_type_id' => $this->caseTypeId, 'subject' => 'Test case', 'contact_id' => 17); // create a logged in USER since the code references it for source_contact_id $this->createLoggedInUser(); $session = CRM_Core_Session::singleton(); $this->_loggedInUser = $session->get('userID'); /// note that activityType options are cached by the FULL set of options you pass in // ie. because Activity api includes campaign in it's call cache is not flushed unless // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE); }
/** * Test CRM_Contact_BAO_Query::searchQuery() * @dataProvider dataProvider */ function testSearch($fv, $count, $ids, $full) { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/queryDataset.xml')); $params = CRM_Contact_BAO_Query::convertFormValues($fv); $obj = new CRM_Contact_BAO_Query($params); $obj->_useGroupBy = TRUE; $dao = $obj->searchQuery(); $contacts = array(); while ($dao->fetch()) { $contacts[] = $dao->contact_id; } sort($contacts, SORT_NUMERIC); $this->assertEquals($ids, $contacts, 'In line ' . __LINE__); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { parent::setUp(); // Insert a row in civicrm_group creating option group // from_email_address group $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/group_admins.xml')); // Insert a row in civicrm_group creating option group // from_email_address group $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/group_subscribers.xml')); // Insert a row in civicrm_group creating option group // from_email_address group $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/group_nesting.xml')); }
/** * Test CRM_Contact_BAO_Query::searchQuery() * @dataProvider dataProvider * @param $fv * @param $count * @param $ids * @param $full */ public function testSearch($fv, $count, $ids, $full) { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/queryDataset.xml')); $params = CRM_Contact_BAO_Query::convertFormValues($fv); $obj = new CRM_Contact_BAO_Query($params); // let's set useGroupBy=true since we are listing contacts here who might belong to // more than one group / tag / notes etc. $obj->_useGroupBy = TRUE; $dao = $obj->searchQuery(); $contacts = array(); while ($dao->fetch()) { $contacts[] = $dao->contact_id; } sort($contacts, SORT_NUMERIC); $this->assertEquals($ids, $contacts); }
public function setUp() { // Connect to the database parent::setUp(); // Truncate the tables $op = new PHPUnit_Extensions_Database_Operation_Truncate(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/../../CiviTest/truncate-option.xml')); // Insert a row in civicrm_contact creating contact 17 $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/contact_17.xml')); // Insert a row in civicrm_option_group creating option group // activity_type $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/option_group_activity_type.xml')); // Insert a row in civicrm_option_value creating // activity_type 5 $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/option_value_activity_5.xml')); // Insert rows in civicrm_activity creating activities 4 and // 13 $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/activity_4_13.xml')); }
/** * Function to create Contribution Type * * @return int $id of contribution type created */ function contributionTypeCreate() { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/../api/v2/dataset/contribution_types.xml')); // FIXME: CHEATING LIKE HELL HERE, TO BE FIXED return 1; }
/** * Test civicrm_replace_contact_formatted() */ public function testReplaceContactFormatted() { // Insert a row in civicrm_contact creating contact 17 $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/contact_17.xml')); $params = array('contact_type' => 'Individual', 'first_name' => 'Fred', 'last_name' => 'Figby'); $fields = array(); $result = civicrm_replace_contact_formatted(17, $params, $fields); $this->assertTrue(is_array($result)); $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . $result['error_message']); }
/** * Set up helper to create a contact. */ public function createContactFromXML() { // Insert a row in civicrm_contact creating contact 17. $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createXMLDataSet(dirname(__FILE__) . '/dataset/contact_17.xml')); }
public function execute(\PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, \PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) { $connection->getConnection()->query("SET foreign_key_checks = 0"); parent::execute($connection, $dataSet); $connection->getConnection()->query("SET foreign_key_checks = 1"); }
/** * Test setup for every test. * * Connect to the database, truncate the tables that will be used * and redirect stdin to a temporary file. */ public function setUp() { $this->_apiversion = 3; parent::setUp(); $this->_individualId = $this->individualCreate(); $processor = $this->processorCreate(); $this->_paymentProcessorID = $processor->id; // Insert test data. $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/data.xml')); $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array('domain_id' => 1, 'name' => "AnnualFixed", 'member_of_contact_id' => 23, 'duration_unit' => "year", 'duration_interval' => 1, 'period_type' => "fixed", 'fixed_period_start_day' => "101", 'fixed_period_rollover_day' => "1231", 'relationship_type_id' => 20, 'financial_type_id' => 2)); $this->membershipTypeAnnualFixedID = $membershipTypeAnnualFixed['id']; $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); $this->paymentInstruments = $instruments['values']; }
/** * check activity update with status */ function testActivityUpdateWithStatus() { // Insert a row in civicrm_activity creating activity 4 $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/activity_type_5.xml')); $params = array('id' => 4, 'source_contact_id' => 17, 'subject' => 'Hurry update works', 'status_id' => 2, 'activity_name' => 'Test activity type'); $result =& civicrm_activity_update($params); $this->assertNull($result['is_error'], "Error message: " . $result['error_message']); $this->assertEquals($result['id'], 4, "In line " . __LINE__); $this->assertEquals($result['source_contact_id'], 17, "In line " . __LINE__); $this->assertEquals($result['subject'], 'Hurry update works', "In line " . __LINE__); $this->assertEquals($result['status_id'], 2, "In line " . __LINE__); }
function testMailingContactBounced() { $op = new PHPUnit_Extensions_Database_Operation_Insert(); //Create the User $op->execute($this->_dbconn, $this->createXMLDataSet(dirname(__FILE__) . '/dataset/mailing_contact.xml')); //~ Create the Mailing and connections to the user $op->execute($this->_dbconn, $this->createXMLDataSet(dirname(__FILE__) . '/dataset/mailing_bounced.xml')); $params = array('contact_id' => 23, 'type' => 'Bounced'); $result = $this->callAPISuccess('MailingContact', 'get', $params); $this->assertEquals($result['count'], 1, "In line " . __LINE__); $this->assertFalse(empty($result['values']), "In line " . __LINE__); $this->assertEquals($result['values'][2]['mailing_id'], 2, "In line " . __LINE__); $this->assertEquals($result['values'][2]['subject'], "Some Subject", "In line " . __LINE__); $this->assertEquals($result['values'][2]['creator_id'], 1, "In line " . __LINE__); $this->assertEquals($result['values'][2]['creator_name'], "xyz1, abc1", "In line " . __LINE__); }
/** * Read everything from the datasets directory and insert into the db. */ public function loadAllFixtures() { $fixturesDir = __DIR__ . '/../../fixtures'; $this->getConnection()->getConnection()->query("SET FOREIGN_KEY_CHECKS = 0;"); $xmlFiles = glob($fixturesDir . '/*.xml'); foreach ($xmlFiles as $xmlFixture) { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $dataset = $this->createXMLDataSet($xmlFixture); $this->_tablesToTruncate = array_merge($this->_tablesToTruncate, $dataset->getTableNames()); $op->execute($this->_dbconn, $dataset); } $yamlFiles = glob($fixturesDir . '/*.yaml'); foreach ($yamlFiles as $yamlFixture) { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $dataset = new PHPUnit_Extensions_Database_DataSet_YamlDataSet($yamlFixture); $this->_tablesToTruncate = array_merge($this->_tablesToTruncate, $dataset->getTableNames()); $op->execute($this->_dbconn, $dataset); } $this->getConnection()->getConnection()->query("SET FOREIGN_KEY_CHECKS = 1;"); }
/** * Test civicrm_constant_get( 'mailProtocol' ) */ public function testmailProtocol() { // Insert 'mail_protocol' option group $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/option_group_mail_protocol.xml')); // Insert some mail protocol option values $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/option_value_mail_protocol.xml')); $parameters = array(true, false, true); $result = civicrm_constant_get('mailProtocol', $parameters); $this->assertEquals(4, count($result), "In line " . __LINE__); $this->assertContains('IMAP', $result, "In line " . __LINE__); $this->assertContains('Maildir', $result, "In line " . __LINE__); $this->assertContains('POP3', $result, "In line " . __LINE__); $this->assertContains('Localdir', $result, "In line " . __LINE__); $this->assertTrue(empty($result['is_error']), "In line " . __LINE__); }
/** * Test getActivities BAO method. */ public function testGetActivitiesforContactSummaryWithNoActivities() { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/activities_for_dashboard_count.xml')); $params = array('contact_id' => 17, 'admin' => FALSE, 'caseId' => NULL, 'context' => 'home', 'activity_type_id' => NULL, 'offset' => 0, 'rowCount' => 0, 'sort' => NULL); $activities = CRM_Activity_BAO_Activity::getActivities($params); //since we are loading activities from dataset, we know total number of activities for this contact // This contact does not have any activities $this->assertEquals(0, count($activities)); }
/** * Test CRM_Contact_Form_Search_Custom_Group::contactIDs() * @dataProvider dataProvider * @param $fv * @param $count * @param $ids * @param $full * @throws \Exception */ public function testContactIDs($fv, $count, $ids, $full) { // Truncate affected tables $this->quickCleanup($this->_tablesToTruncate); // echo "testContactIDs\n"; $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/datasets/group-dataset.xml')); $obj = new CRM_Contact_Form_Search_Custom_Group($fv); $sql = $obj->contactIDs(); $this->assertTrue(is_string($sql)); $dao = CRM_Core_DAO::executeQuery($sql); $contacts = array(); while ($dao->fetch()) { $contacts[$dao->contact_id] = 1; } $contacts = array_keys($contacts); sort($contacts, SORT_NUMERIC); $this->assertEquals($ids, $contacts); }
public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) { $truncate = new PHPUnit_Extensions_Database_Operation_Truncate(true); $truncate->setCascade(true); $dataset = new OBM_Database_CsvDataSet(';'); $dataset->addTable('Entity'); $truncate->execute($connection, $dataset); $pdo = $connection->getConnection(); // we retrieve the PDO object parent::execute($connection, $dataSet); $dsIterator = $dataSet->getIterator(); foreach ($dsIterator as $table) { $tableName = $table->getTableMetaData()->getTableName(); if ($dataSet->isEntityTable($tableName)) { $entities = $dataSet->getEntityName($tableName); if(!is_array($entities)) $entities = array($entities); foreach($entities as $entity) { for ($i = 1; $i <= $table->getRowCount(); $i++) { $pdo->exec('INSERT INTO Entity (entity_mailing) VALUES (TRUE)'); $entityId = $pdo->lastInsertId(); $query = 'INSERT INTO '.ucfirst($entity).'Entity ('.$entity.'entity_entity_id, '.$entity.'entity_'.$entity.'_id ) SELECT MAX(entity_id), '.$i.' FROM Entity'; $pdo->exec($query); } } } } }
/** * @return array */ function _createContactWithActivity() { // @TODO: Create profile with custom fields $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_contact_activity_26.xml')); // hack: xml data set do not accept (CRM_Core_DAO::VALUE_SEPARATOR) CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', '26', 'group_type', 'Individual,Contact,Activity' . CRM_Core_DAO::VALUE_SEPARATOR . 'ActivityType:1'); $sourceContactId = $this->individualCreate(); $contactParams = array('first_name' => 'abc1', 'last_name' => 'xyz1', 'contact_type' => 'Individual', 'email' => '*****@*****.**', 'api.address.create' => array('location_type_id' => 1, 'is_primary' => 1, 'name' => 'Saint Helier St', 'county' => 'Marin', 'country' => 'United States', 'state_province' => 'Michigan', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village')); $contact = $this->callAPISuccess('contact', 'create', $contactParams); $keys = array_keys($contact['values']); $contactId = array_pop($keys); $this->assertEquals(0, $contact['values'][$contactId]['api.address.create']['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact['values'][$contactId]['api.address.create'])); $activityParams = array('source_contact_id' => $sourceContactId, 'assignee_contact_id' => $contactId, 'activity_type_id' => '1', 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110316', 'duration' => '120', 'location' => 'Pensulvania', 'details' => 'a test activity', 'status_id' => '1', 'priority_id' => '1'); $activity = $this->callAPISuccess('activity', 'create', $activityParams); $activityValues = array_pop($activity['values']); // valid parameters for above profile $profileParams = array('profile_id' => 26, 'contact_id' => $contactId, 'activity_id' => $activityValues['id']); // expected result of above created profile $expected = array('first_name' => 'abc1', 'last_name' => 'xyz1', 'email-Primary' => '*****@*****.**', 'activity_subject' => 'Make-it-Happen Meeting', 'activity_details' => 'a test activity', 'activity_duration' => '120', 'activity_date_time_time' => '12:00AM', 'activity_date_time' => '03/16/2011', 'activity_status_id' => '1'); return array($profileParams, $expected); }
public function testInsert() { $insertOperation = new PHPUnit_Extensions_Database_Operation_Insert(); $insertOperation->execute($this->getConnection(), new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/InsertOperationTest.xml')); $this->assertDataSetsEqual(new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/InsertOperationResult.xml'), $this->getConnection()->createDataSet()); }
/** * Test setup for every test. * * Connect to the database, truncate the tables that will be used * and redirect stdin to a temporary file. */ public function setUp() { $this->_apiversion = 3; parent::setUp(); $this->_individualId = $this->individualCreate(); $this->_paymentProcessorID = $this->processorCreate(); // Insert test data. $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/data.xml')); $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); $this->paymentInstruments = $instruments['values']; }
/** * Function to test getActivities BAO method */ function testGetActivitiesforContactSummaryWithNoActivities() { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/activities_for_dashboard_count.xml')); require_once 'CRM/Activity/BAO/Activity.php'; $contactID = 17; $data = array('contact_id' => $contactID); $activities = CRM_Activity_BAO_Activity::getActivities($data); //since we are loading activities from dataset, we know total number of activities for this contact // This contact does not have any activities $this->assertEquals(0, sizeof($activities), 'In line ' . __LINE__); }
/** * Test CRM_Contact_Form_Search_Custom_Sample with saved_search_id * With true argument it returns list of contact IDs */ public function testSavedSearch() { $this->quickCleanup($this->_tablesToTruncate); $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/datasets/sample-dataset.xml')); $dataset[1] = array('id' => array(12)); $dataset[2] = array('id' => array(10, 11)); $ssdao = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_saved_search"); while ($ssdao->fetch()) { $fv = CRM_Contact_BAO_SavedSearch::getFormValues($ssdao->id); $obj = new CRM_Contact_Form_Search_Custom_Sample($fv); $sql = $obj->contactIDs(); $this->assertTrue(is_string($sql)); $dao = CRM_Core_DAO::executeQuery($sql); $contacts = array(); while ($dao->fetch()) { $contacts[] = $dao->contact_id; } sort($contacts, SORT_NUMERIC); $this->assertEquals($dataset[$ssdao->id]['id'], $contacts); } }