function setUp()
 {
     parent::setUp();
     $baoObj = new CRM_Core_DAO();
     $baoObj->createTestObject('CRM_Pledge_BAO_Pledge', array(), 1, 0);
     $baoObj->createTestObject('CRM_Core_BAO_Phone', array(), 1, 0);
     $this->hookClass = CRM_Utils_Hook::singleton();
     $config = CRM_Core_Config::singleton();
     $config->userPermissionClass->permissions = array();
 }
示例#2
0
 /**
  * Set up permissions for test.
  */
 public function setUp()
 {
     $this->useTransaction(TRUE);
     parent::setUp();
     $individualID = $this->individualCreate();
     $daoObj = new CRM_Core_DAO();
     $this->callAPISuccess('Attachment', 'create', array('entity_table' => 'civicrm_contact', 'entity_id' => $individualID, 'mime_type' => 'k', 'name' => 'p', 'content' => 'l'));
     $daoObj->createTestObject('CRM_Activity_BAO_Activity', array(), 1, 0);
     $daoObj->createTestObject('CRM_Case_BAO_Case', array(), 1, 0);
     $entities = $this->getTagOptions();
     foreach ($entities as $key => $entity) {
         $this->callAPISuccess('Tag', 'create', array('used_for' => $key, 'name' => $entity, 'description' => $entity));
     }
     CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
 }
 public function testGet()
 {
     $testObject = CRM_Core_DAO::createTestObject('CRM_Booking_DAO_ResourceConfigOption')->toArray();
     $configOption = $this->callAPISuccess('ResourceConfigOption', 'Create', $testObject);
     $result = $this->callAPISuccess('ResourceConfigOption', 'Get', array('id' => $configOption['id'], 'sequential' => 1));
     $this->assertEquals(1, $result['count']);
     $this->assertEquals($testObject['id'], $result['id']);
 }
 function setUp()
 {
     $this->_apiversion = 3;
     parent::setUp();
     $this->quickCleanup(array('civicrm_msg_template'));
     $template = CRM_Core_DAO::createTestObject('CRM_Core_DAO_MessageTemplate')->toArray();
     $this->params = array('msg_title' => $template['msg_title'], 'msg_subject' => $template['msg_subject'], 'msg_text' => $template['msg_text'], 'msg_html' => $template['msg_html'], 'workflow_id' => $template['workflow_id'], 'is_default' => $template['is_default'], 'is_reserved' => $template['is_reserved'], 'pdf_format_id' => $template['pdf_format_id']);
 }
 public function setUp()
 {
     $this->_apiversion = 3;
     parent::setUp();
     $this->useTransaction(TRUE);
     $template = CRM_Core_DAO::createTestObject('CRM_Core_DAO_MessageTemplate')->toArray();
     $this->params = array('msg_title' => $template['msg_title'], 'msg_subject' => $template['msg_subject'], 'msg_text' => $template['msg_text'], 'msg_html' => $template['msg_html'], 'workflow_id' => $template['workflow_id'], 'is_default' => $template['is_default'], 'is_reserved' => $template['is_reserved']);
 }
 /**
  * Tests CRM_Volunteer_BAO_Assignment::createVolunteerActivity() to ensure
  * that the project beneficiary is made the activity target.
  */
 function testActivityTarget()
 {
     $beneficiaryContactId = $need = $project = $volunteerContactId = NULL;
     extract($this->setUpProject(), EXTR_IF_EXISTS);
     $projectContact = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_ProjectContact', array('contact_id' => $beneficiaryContactId, 'project_id' => $project->id, 'relationship_type_id' => CRM_Core_OptionGroup::getValue('volunteer_project_relationship', 'volunteer_beneficiary', 'name')));
     $this->assertObjectHasAttribute('id', $projectContact, 'Failed to prepopulate VolunteerContact');
     $assignmentId = CRM_Volunteer_BAO_Assignment::createVolunteerActivity(array('assignee_contact_id' => $volunteerContactId, 'source_contact_id' => $volunteerContactId, 'volunteer_need_id' => $need->id));
     $targetContactId = civicrm_api3('ActivityContact', 'getvalue', array('activity_id' => $assignmentId, 'record_type_id' => 'Activity Targets', 'return' => 'contact_id'));
     $this->assertEquals($beneficiaryContactId, $targetContactId);
 }
 /**
  * Test simple get via API
  */
 function testGetProjectContactById()
 {
     $relTypeId = CRM_Core_OptionGroup::getValue(CRM_Volunteer_BAO_ProjectContact::RELATIONSHIP_OPTION_GROUP, 'volunteer_owner', 'name');
     $relTypeLabel = CRM_Core_OptionGroup::getLabel(CRM_Volunteer_BAO_ProjectContact::RELATIONSHIP_OPTION_GROUP, $relTypeId);
     $dao = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_ProjectContact', array('relationship_type_id' => $relTypeId));
     $this->assertObjectHasAttribute('id', $dao, 'Failed to prepopulate Volunteer Project Contact');
     $api = $this->callAPIAndDocument('VolunteerProjectContact', 'get', array('id' => $dao->id), __FUNCTION__, __FILE__);
     // make sure the label and machine name are returned
     $vpc = $api['values'][1];
     $this->assertEquals('volunteer_owner', $vpc['relationship_type_name']);
     $this->assertEquals($relTypeLabel, $vpc['relationship_type_label']);
 }
 /**
  * Test case for getGroupId( )
  */
 public function testGetGroupId()
 {
     //creates a test groupContact object
     //force group_id to 1 so we can compare
     $groupContact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_GroupContact');
     //check the group contact id is not null
     $this->assertNotNull($groupContact->id);
     $groupId = CRM_Core_DAO::singleValueQuery('select max(id) from civicrm_group');
     $this->assertEquals($groupContact->group_id, $groupId, 'Check for group_id');
     //cleanup
     $groupContact->deleteTestObjects('CRM_Contact_DAO_GroupContact');
 }
示例#9
0
 public function testGetChain()
 {
     $set = $this->callAPISuccess('ResourceConfigSet', 'Create', array("title" => "title_1", "weight" => 1, "is_enabled" => 1, "is_deleted" => 0));
     $this->callAPISuccess('ResourceConfigOption', 'Create', array("set_id" => $set['id'], "label" => "label_3", "price" => 20.0, "max_size" => "max_size_3", "unit_id" => "unit_id_3", "weight" => 3, "is_enabled" => 1));
     $this->callAPISuccess('ResourceConfigOption', 'Create', array("set_id" => $set['id'], "label" => "label_4", "price" => 30.0, "max_size" => "max_size_4", "unit_id" => "unit_id_4", "weight" => 3, "is_enabled" => 1));
     $testObject = CRM_Core_DAO::createTestObject('CRM_Booking_DAO_Resource')->toArray();
     $params = array('set_id' => $set['id'], 'label' => $testObject['label'], 'description' => $testObject['description'], 'weight' => $testObject['weight'], 'resource_type' => $testObject['resource_type'], 'resource_location' => $testObject['resource_location'], 'is_unlimited' => 0, 'is_enabled' => 1, 'is_deleted' => 0);
     $resource = $this->callAPISuccess('Resource', 'Create', $params);
     $result = $this->callAPISuccess('Resource', 'Get', array('id' => $resource['id'], 'sequential' => 1, 'api.resource_config_set.get' => array('id' => '$value.set_id', 'api.resource_config_option.get' => array('set_id' => '$value.id'))));
     $this->assertEquals(1, $result['count']);
     $this->assertEquals(1, $result['values'][0]['api.resource_config_set.get']['count']);
     $this->assertEquals(2, $result['values'][0]['api.resource_config_set.get']['values'][0]['api.resource_config_option.get']['count']);
 }
 /**
  * VOL-154: Verifies that an activity created in a project is tagged with the
  * project's campaign.
  */
 function testCampaignInheritance()
 {
     // begin setup
     $campaign = CRM_Core_DAO::createTestObject('CRM_Campaign_BAO_Campaign');
     $this->assertObjectHasAttribute('id', $campaign, 'Failed to prepopulate Campaign');
     $project = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Project', array('campaign_id' => $campaign->id));
     $this->assertObjectHasAttribute('id', $project, 'Failed to prepopulate Volunteer Project');
     $need = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Need', array('project_id' => $project->id));
     $this->assertObjectHasAttribute('id', $need, 'Failed to prepopulate Volunteer Need');
     // end setup
     $activityId = CRM_Volunteer_BAO_Assignment::createVolunteerActivity(array('assignee_contact_id' => 1, 'source_contact_id' => 1, 'volunteer_need_id' => $need->id));
     $this->assertNotSame(FALSE, $activityId, 'Failed to create Volunteer Activity');
     $createdActivity = CRM_Volunteer_BAO_Assignment::findById($activityId);
     $this->assertEquals($campaign->id, $createdActivity->campaign_id, 'Activity did not inherit campaign from volunteer project');
 }
 public function testCrossOver()
 {
     $domain = \CRM_Core_DAO::createTestObject('CRM_Core_DAO_Domain');
     $contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact');
     $manager = $this->createManager()->useDefaults();
     // Store different values for the 'monkeywrench' setting on domain and contact
     $domainSettings = $manager->getBagByDomain($domain->id);
     $domainSettings->set('monkeywrench', 'from domain');
     $this->assertEquals('from domain', $domainSettings->get('monkeywrench'));
     $contactSettings = $manager->getBagByContact($domain->id, $contact->id);
     $contactSettings->set('monkeywrench', 'from contact');
     $this->assertEquals('from contact', $contactSettings->get('monkeywrench'));
     // Read settings from freshly initialized objects.
     $manager = $this->createManager()->useDefaults();
     $domainSettings = $manager->getBagByDomain($domain->id);
     $this->assertEquals('from domain', $domainSettings->get('monkeywrench'));
     $contactSettings = $manager->getBagByContact($domain->id, $contact->id);
     $this->assertEquals('from contact', $contactSettings->get('monkeywrench'));
 }
示例#12
0
 public function testReplace()
 {
     // create an example role
     $role = CRM_Core_DAO::createTestObject('CRM_HRJob_DAO_HRJobRole')->toArray();
     $this->assertTrue(is_numeric($role['id']));
     $this->assertTrue(is_numeric($role['job_id']));
     $this->assertNotEmpty($role['title']);
     $this->assertNotEmpty($role['location']);
     // replace the role
     $result = $this->callAPISuccess('HRJobRole', 'replace', array('job_id' => $role['job_id'], 'values' => array(array('id' => $role['id'], 'job_id' => $role['job_id'], 'description' => 'new description', 'location' => ''))));
     // check return format
     $this->assertEquals(1, $result['count']);
     foreach ($result['values'] as $roleResult) {
         $this->assertTrue(is_array($roleResult));
         // unspecified are preserved & returned
         $this->assertEquals($role['job_id'], $roleResult['job_id']);
         $this->assertEquals($role['title'], $roleResult['title']);
         // passed in values are updated
         $this->assertEquals('new description', $roleResult['description']);
         $this->assertEquals('', $roleResult['location']);
         // BUG: $roleResult['location'] === 'null'
     }
 }
 /**
  *  Pass Zero Id for a payment deletion for one pledge
  */
 function testDeletePaymentsZeroId()
 {
     $payment = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_PledgePayment');
     $paymentid = CRM_Pledge_BAO_PledgePayment::deletePayments(0);
     $result = CRM_Pledge_BAO_Pledge::deletePledge($payment->pledge_id);
 }
示例#14
0
 /**
  * This is a test to check if setting fields one at a time alters other fields.
  *
  * Issues Hit so far =
  * 1) Currency keeps getting reset to USD -  BUT this may be the only enabled currency
  *  - in which case it is valid
  * 2)
  */
 public function testCreateAutoGrant()
 {
     $entityName = $this->_entity;
     $baoString = 'CRM_Grant_BAO_Grant';
     $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create'));
     $fields = $fields['values'];
     $return = array_keys($fields);
     $baoObj = new CRM_Core_DAO();
     $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0);
     $getentities = $this->callAPISuccess($entityName, 'get', array('sequential' => 1, 'return' => $return));
     // lets use first rather than assume only one exists
     $entity = $getentities['values'][0];
     $entity2 = $getentities['values'][1];
     foreach ($fields as $field => $specs) {
         if ($field == 'currency' || $field == 'id') {
             continue;
         }
         switch ($specs['type']) {
             case CRM_Utils_Type::T_DATE:
             case CRM_Utils_Type::T_TIMESTAMP:
                 $entity[$field] = '2012-05-20';
                 break;
             case CRM_Utils_Type::T_STRING:
             case CRM_Utils_Type::T_BLOB:
             case CRM_Utils_Type::T_MEDIUMBLOB:
             case CRM_Utils_Type::T_TEXT:
             case CRM_Utils_Type::T_LONGTEXT:
             case CRM_Utils_Type::T_EMAIL:
                 $entity[$field] = 'New String';
                 break;
             case CRM_Utils_Type::T_INT:
                 // probably created with a 1
                 $entity[$field] = 2;
                 if (!empty($specs['FKClassName'])) {
                     $entity[$field] = empty($entity2[$field]) ? $entity2[$specs]['uniqueName'] : $entity2[$field];
                 }
                 break;
             case CRM_Utils_Type::T_BOOLEAN:
                 // probably created with a 1
                 $entity[$field] = 0;
                 break;
             case CRM_Utils_Type::T_FLOAT:
             case CRM_Utils_Type::T_MONEY:
                 $entity[$field] = 222;
                 break;
             case CRM_Utils_Type::T_URL:
                 $entity[$field] = 'warm.beer.com';
         }
         $updateParams = array('id' => $entity['id'], $field => $entity[$field], 'debug' => 1);
         $update = $this->callAPISuccess($entityName, 'create', $updateParams);
         $this->assertAPISuccess($update, "setting {$field} to {$entity[$field]} in line " . __LINE__);
         $checkParams = array('id' => $entity['id'], 'sequential' => 1);
         $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
         $this->assertAPIArrayComparison((array) $entity, $checkEntity);
     }
     $baoObj->deleteTestObjects($baoString);
     $baoObj->free();
 }
示例#15
0
 static function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE)
 {
     static $counter = 0;
     CRM_Core_DAO::$_testEntitiesToSkip = array('CRM_Core_DAO_Worldregion', 'CRM_Core_DAO_StateProvince', 'CRM_Core_DAO_Country', 'CRM_Core_DAO_Domain');
     require_once str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php";
     for ($i = 0; $i < $numObjects; ++$i) {
         ++$counter;
         eval('$object   = new ' . $daoName . '( );');
         $fields =& $object->fields();
         foreach ($fields as $name => $value) {
             $dbName = $value['name'];
             $FKClassName = CRM_Utils_Array::value('FKClassName', $value);
             $required = CRM_Utils_Array::value('required', $value);
             if (CRM_Utils_Array::value($dbName, $params) !== NULL && !is_array($params[$dbName])) {
                 $object->{$dbName} = $params[$dbName];
             } elseif ($dbName != 'id') {
                 if ($FKClassName != NULL) {
                     //skip the FK if it is not required
                     // if it's contact id we should create even if not required
                     if (!$required && $dbName != 'contact_id') {
                         continue;
                     }
                     if (in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)) {
                         $depObject = new $FKClassName();
                         $depObject->find(true);
                     } elseif ($daoName == 'CRM_Member_DAO_MembershipType' && $name == 'member_of_contact_id') {
                         // FIXME: the fields() metadata is not specific enough
                         $depObject = CRM_Core_DAO::createTestObject($FKClassName, array('contact_type' => 'Organization'));
                     } else {
                         //if it is required we need to generate the dependency object first
                         $depObject = CRM_Core_DAO::createTestObject($FKClassName, CRM_Utils_Array::value($dbName, $params, 1));
                     }
                     $object->{$dbName} = $depObject->id;
                     unset($depObject);
                     continue;
                 }
                 $constant = CRM_Utils_Array::value('pseudoconstant', $value);
                 if (!empty($constant)) {
                     $constantOptions = array_keys(CRM_Core_PseudoConstant::getConstant($constant));
                     $object->{$dbName} = $constantOptions[0];
                     continue;
                 }
                 $enum = CRM_Utils_Array::value('enumValues', $value);
                 if (!empty($enum)) {
                     $options = explode(',', $enum);
                     $object->{$dbName} = $options[0];
                     continue;
                 }
                 switch ($value['type']) {
                     case CRM_Utils_Type::T_INT:
                     case CRM_Utils_Type::T_FLOAT:
                     case CRM_Utils_Type::T_MONEY:
                         $object->{$dbName} = $counter;
                         break;
                     case CRM_Utils_Type::T_BOOL:
                     case CRM_Utils_Type::T_BOOLEAN:
                         if (isset($value['default'])) {
                             $object->{$dbName} = $value['default'];
                         } elseif ($value['name'] == 'is_deleted' || $value['name'] == 'is_test') {
                             $object->{$dbName} = 0;
                         } else {
                             $object->{$dbName} = 1;
                         }
                         break;
                     case CRM_Utils_Type::T_DATE:
                     case CRM_Utils_Type::T_TIMESTAMP:
                         $object->{$dbName} = '19700101';
                         break;
                     case CRM_Utils_Type::T_TIME:
                         CRM_Core_Error::fatal('T_TIME shouldnt be used.');
                         //$object->$dbName='000000';
                         //break;
                     //$object->$dbName='000000';
                     //break;
                     case CRM_Utils_Type::T_CCNUM:
                         $object->{$dbName} = '4111 1111 1111 1111';
                         break;
                     case CRM_Utils_Type::T_URL:
                         $object->{$dbName} = 'http://www.civicrm.org';
                         break;
                     case CRM_Utils_Type::T_STRING:
                     case CRM_Utils_Type::T_BLOB:
                     case CRM_Utils_Type::T_MEDIUMBLOB:
                     case CRM_Utils_Type::T_TEXT:
                     case CRM_Utils_Type::T_LONGTEXT:
                     case CRM_Utils_Type::T_EMAIL:
                     default:
                         if (isset($value['enumValues'])) {
                             if (isset($value['default'])) {
                                 $object->{$dbName} = $value['default'];
                             } else {
                                 if (is_array($value['enumValues'])) {
                                     $object->{$dbName} = $value['enumValues'][0];
                                 } else {
                                     $defaultValues = explode(',', $value['enumValues']);
                                     $object->{$dbName} = $defaultValues[0];
                                 }
                             }
                         } else {
                             $object->{$dbName} = $dbName . '_' . $counter;
                             $maxlength = CRM_Utils_Array::value('maxlength', $value);
                             if ($maxlength > 0 && strlen($object->{$dbName}) > $maxlength) {
                                 $object->{$dbName} = substr($object->{$dbName}, 0, $value['maxlength']);
                             }
                         }
                 }
             }
         }
         $object->save();
         if (!$createOnly) {
             $objects[$i] = $object;
         } else {
             unset($object);
         }
     }
     if ($createOnly) {
         return;
     } elseif ($numObjects == 1) {
         return $objects[0];
     } else {
         return $objects;
     }
 }
 /**
  * This is a wrapper for CRM_Core_DAO::createTestObject which tracks
  * created entities and provides for brainless clenaup.
  *
  * @see CRM_Core_DAO::createTestObject
  */
 function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE)
 {
     $objects = CRM_Core_DAO::createTestObject($daoName, $params, $numObjects, $createOnly);
     if (is_array($objects)) {
         $this->registerTestObjects($objects);
     } else {
         $this->registerTestObjects(array($objects));
     }
     return $objects;
 }
 /**
  * Creates test case data for use in the Unit Tests.
  *
  * return $returnObjects array(
  *   'project' => CRM_Volunteer_BAO_Project,
  *   'need' => CRM_Volunteer_BAO_Need,
  *   'activity' => api.VolunteerAssignment.create,
  *   'campaign' => CRM_Campaign_BAO_Campaign
  * )
  */
 function _createTestObjects()
 {
     $project = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Project');
     $this->assertObjectHasAttribute('id', $project, 'Failed to prepopulate Volunteer Project');
     $need = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Need', array('project_id' => $project->id));
     $this->assertObjectHasAttribute('id', $need, 'Failed to prepopulate Volunteer Need');
     $campaign = CRM_Core_DAO::createTestObject('CRM_Campaign_BAO_Campaign');
     $this->assertObjectHasAttribute('id', $campaign, 'Failed to prepopulate Campaign');
     $activity = $this->callAPISuccess('VolunteerAssignment', 'create', array('assignee_contact_id' => 1, 'cache_clear' => 1, 'source_contact_id' => 1, 'volunteer_need_id' => $need->id));
     return array('project' => $project, 'need' => $need, 'activity' => $activity, 'campaign' => $campaign);
 }
示例#18
0
 /**
  * Create 2 entities
  * @param $entity
  */
 public function setUpEntities($entity)
 {
     $baoObj = new CRM_Core_DAO();
     $baoObj->createTestObject(_civicrm_api3_get_BAO($entity), array(), 2, 0);
     CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'access CiviContribute', 'access CiviEvent', 'view event participants');
 }
示例#19
0
 /**
  * @param string $fieldName
  * @param $fieldDef
  * @param array $params
  */
 protected function assignTestFK($fieldName, $fieldDef, $params)
 {
     $required = CRM_Utils_Array::value('required', $fieldDef);
     $FKClassName = CRM_Utils_Array::value('FKClassName', $fieldDef);
     $dbName = $fieldDef['name'];
     $daoName = str_replace('_BAO_', '_DAO_', get_class($this));
     // skip the FK if it is not required
     // if it's contact id we should create even if not required
     // we'll have a go @ fetching first though
     // we WILL create campaigns though for so tests with a campaign pseudoconstant will complete
     if ($FKClassName === 'CRM_Campaign_DAO_Campaign' && $daoName != $FKClassName) {
         $required = TRUE;
     }
     if (!$required && $dbName != 'contact_id') {
         $fkDAO = new $FKClassName();
         if ($fkDAO->find(TRUE)) {
             $this->{$dbName} = $fkDAO->id;
         }
         unset($fkDAO);
     } elseif (in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)) {
         $depObject = new $FKClassName();
         $depObject->find(TRUE);
         $this->{$dbName} = $depObject->id;
         unset($depObject);
     } elseif ($daoName == 'CRM_Member_DAO_MembershipType' && $fieldName == 'member_of_contact_id') {
         // FIXME: the fields() metadata is not specific enough
         $depObject = CRM_Core_DAO::createTestObject($FKClassName, array('contact_type' => 'Organization'));
         $this->{$dbName} = $depObject->id;
         unset($depObject);
     } else {
         //if it is required we need to generate the dependency object first
         $depObject = CRM_Core_DAO::createTestObject($FKClassName, CRM_Utils_Array::value($dbName, $params, 1));
         $this->{$dbName} = $depObject->id;
         unset($depObject);
     }
 }
 protected function setUp()
 {
     /** @var \CRM_Contact_DAO_Contact $contact */
     $contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', array('contact_type' => 'Individual'));
     self::$contactIds[$this->getName()] = $contact->id;
 }
示例#21
0
 /**
  * @param array $fields
  *   List of fields to include in the profile.
  * @return int
  *   field id
  */
 protected function createUFGroup($fields)
 {
     $ufGroup = CRM_Core_DAO::createTestObject('CRM_Core_DAO_UFGroup');
     $this->assertTrue(is_numeric($ufGroup->id));
     foreach ($fields as $field) {
         $defaults = array('version' => 3, 'uf_group_id' => $ufGroup->id, 'visibility' => 'Public Pages and Listings', 'weight' => 1, 'label' => 'Label for ' . $field['field_name'], 'is_searchable' => 1, 'is_active' => 1, 'location_type_id' => NULL);
         $params = array_merge($field, $defaults);
         $ufField = civicrm_api('UFField', 'create', $params);
         $this->assertAPISuccess($ufField);
     }
     return $ufGroup->id;
 }
示例#22
0
 static function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE)
 {
     static $counter = 0;
     CRM_Core_DAO::$_testEntitiesToSkip = array('CRM_Core_DAO_Worldregion', 'CRM_Core_DAO_StateProvince', 'CRM_Core_DAO_Country', 'CRM_Core_DAO_Domain');
     for ($i = 0; $i < $numObjects; ++$i) {
         ++$counter;
         $object = new $daoName();
         $fields =& $object->fields();
         foreach ($fields as $name => $value) {
             $dbName = $value['name'];
             if ($dbName == 'contact_sub_type' && empty($params['contact_sub_type'])) {
                 //coming up with a rule to set this is too complex let's not set it
                 continue;
             }
             $FKClassName = CRM_Utils_Array::value('FKClassName', $value);
             $required = CRM_Utils_Array::value('required', $value);
             if (CRM_Utils_Array::value($dbName, $params) !== NULL && !is_array($params[$dbName])) {
                 $object->{$dbName} = $params[$dbName];
             } elseif ($dbName != 'id') {
                 if ($FKClassName != NULL) {
                     //skip the FK if it is not required
                     // if it's contact id we should create even if not required
                     // we'll have a go @ fetching first though
                     // we WILL create campaigns though for so tests with a campaign pseudoconstant will complete
                     if ($FKClassName === 'CRM_Campaign_DAO_Campaign' && $daoName != $FKClassName) {
                         $required = TRUE;
                     }
                     if (!$required && $dbName != 'contact_id') {
                         $fkDAO = new $FKClassName();
                         if ($fkDAO->find(TRUE)) {
                             $object->{$dbName} = $fkDAO->id;
                         }
                         unset($fkDAO);
                         continue;
                     }
                     if (in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)) {
                         $depObject = new $FKClassName();
                         $depObject->find(TRUE);
                     } elseif ($daoName == 'CRM_Member_DAO_MembershipType' && $name == 'member_of_contact_id') {
                         // FIXME: the fields() metadata is not specific enough
                         $depObject = CRM_Core_DAO::createTestObject($FKClassName, array('contact_type' => 'Organization'));
                     } else {
                         //if it is required we need to generate the dependency object first
                         $depObject = CRM_Core_DAO::createTestObject($FKClassName, CRM_Utils_Array::value($dbName, $params, 1));
                     }
                     $object->{$dbName} = $depObject->id;
                     unset($depObject);
                     continue;
                 }
                 // Pick an option value if needed
                 if ($value['type'] !== CRM_Utils_Type::T_BOOLEAN) {
                     $options = $daoName::buildOptions($dbName, 'create');
                     if ($options) {
                         $object->{$dbName} = key($options);
                         continue;
                     }
                 }
                 switch ($value['type']) {
                     case CRM_Utils_Type::T_INT:
                     case CRM_Utils_Type::T_FLOAT:
                     case CRM_Utils_Type::T_MONEY:
                         $object->{$dbName} = $counter;
                         break;
                     case CRM_Utils_Type::T_BOOLEAN:
                         if (isset($value['default'])) {
                             $object->{$dbName} = $value['default'];
                         } elseif ($value['name'] == 'is_deleted' || $value['name'] == 'is_test') {
                             $object->{$dbName} = 0;
                         } else {
                             $object->{$dbName} = 1;
                         }
                         break;
                     case CRM_Utils_Type::T_DATE:
                     case CRM_Utils_Type::T_TIMESTAMP:
                     case CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME:
                         $object->{$dbName} = '19700101';
                         if ($dbName == 'end_date') {
                             // put this in the future
                             $object->{$dbName} = '20200101';
                         }
                         break;
                     case CRM_Utils_Type::T_TIME:
                         CRM_Core_Error::fatal('T_TIME shouldnt be used.');
                         //$object->$dbName='000000';
                         //break;
                     //$object->$dbName='000000';
                     //break;
                     case CRM_Utils_Type::T_CCNUM:
                         $object->{$dbName} = '4111 1111 1111 1111';
                         break;
                     case CRM_Utils_Type::T_URL:
                         $object->{$dbName} = 'http://www.civicrm.org';
                         break;
                     case CRM_Utils_Type::T_STRING:
                     case CRM_Utils_Type::T_BLOB:
                     case CRM_Utils_Type::T_MEDIUMBLOB:
                     case CRM_Utils_Type::T_TEXT:
                     case CRM_Utils_Type::T_LONGTEXT:
                     case CRM_Utils_Type::T_EMAIL:
                     default:
                         if (isset($value['enumValues'])) {
                             if (isset($value['default'])) {
                                 $object->{$dbName} = $value['default'];
                             } else {
                                 if (is_array($value['enumValues'])) {
                                     $object->{$dbName} = $value['enumValues'][0];
                                 } else {
                                     $defaultValues = explode(',', $value['enumValues']);
                                     $object->{$dbName} = $defaultValues[0];
                                 }
                             }
                         } else {
                             $object->{$dbName} = $dbName . '_' . $counter;
                             $maxlength = CRM_Utils_Array::value('maxlength', $value);
                             if ($maxlength > 0 && strlen($object->{$dbName}) > $maxlength) {
                                 $object->{$dbName} = substr($object->{$dbName}, 0, $value['maxlength']);
                             }
                         }
                 }
             }
         }
         $object->save();
         if (!$createOnly) {
             $objects[$i] = $object;
         } else {
             unset($object);
         }
     }
     if ($createOnly) {
         return;
     } elseif ($numObjects == 1) {
         return $objects[0];
     } else {
         return $objects;
     }
 }
 function testGetContactsByRelationship()
 {
     $contactId = 1;
     $relType = CRM_Core_OptionGroup::getValue(CRM_Volunteer_BAO_ProjectContact::RELATIONSHIP_OPTION_GROUP, 'volunteer_owner', 'name');
     $project = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Project');
     $this->assertObjectHasAttribute('id', $project, 'Failed to prepopulate Volunteer Project');
     $projectContact = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_ProjectContact', array('contact_id' => $contactId, 'project_id' => $project->id, 'relationship_type_id' => $relType));
     $this->assertObjectHasAttribute('id', $projectContact, 'Failed to prepopulate Volunteer Project Contact');
     $contacts = CRM_Volunteer_BAO_Project::getContactsByRelationship($project->id, $relType);
     $this->assertTrue(in_array($contactId, $contacts));
 }
 /**
  * Test simple get via API
  */
 function testGetNeedbyID()
 {
     $need = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Need');
     $this->assertObjectHasAttribute('id', $need, 'Failed to prepopulate Volunteer Need');
     $this->callAPIAndDocument('VolunteerNeed', 'get', array('id' => $need->id), __FUNCTION__, __FILE__);
 }
示例#25
0
 /**
  * Prepare for contribution Test - involving only contribution objects
  *
  * @param bool $contributionPage
  */
 public function _setUpContributionObjects($contributionPage = FALSE)
 {
     $contribution = new CRM_Contribute_BAO_Contribution();
     $contribution->id = $this->_contributionId;
     $contribution->find(TRUE);
     $contributionPageID = NULL;
     if (!empty($contributionPage)) {
         $dao = new CRM_Core_DAO();
         $contribution_page = $dao->createTestObject('CRM_Contribute_DAO_ContributionPage');
         $contribution_page->payment_processor = 1;
         $contribution_page->save();
         $contribution->contribution_page_id = $contributionPageID = $contribution_page->id;
         //for unknown reasons trying to do a find & save on a contribution with a receive_date set
         // doesn't work. This seems of minimal relevance to this test so ignoring
         // note that in tests it worked sometimes & not others - dependent on which other tests run.
         // running all CRM_Core tests caused failure as did just the single failing test. But running
         // just this class succeeds - because it actually doesn't do a mysql update on the following save
         // (unknown reason)
         unset($contribution->receive_date);
         $contribution->save();
     }
     $this->objects['contribution'] = $contribution;
     $this->input = array('component' => 'contribute', 'contribution_page_id' => $contributionPageID, 'total_amount' => 110.0, 'invoiceID' => "c8acb91e080ad7777a2adc119c192885", 'contactID' => $this->_contactId, 'contributionID' => $this->objects['contribution']->id);
 }
示例#26
0
 /**
  * function to build params
  *
  */
 private function pcpParams()
 {
     $contact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact');
     $contactId = $contact->id;
     $contribPage = CRM_Core_DAO::createTestObject('CRM_Contribute_DAO_ContributionPage');
     $contribPageId = $contribPage->id;
     $params = array('contact_id' => $contactId, 'status_id' => '1', 'title' => 'My PCP', 'intro_text' => 'Hey you, contribute now!', 'page_text' => 'You better give more.', 'donate_link_text' => 'Donate Now', 'page_id' => $contribPageId, 'is_thermometer' => 1, 'is_honor_roll' => 1, 'goal_amount' => 10000.0, 'is_active' => 1);
     return $params;
 }
 /**
  * @param entityName
  */
 private function getMockableBAOObjects($entityName, $count = 2)
 {
     $baoString = _civicrm_api3_get_DAO($entityName);
     if (empty($baoString)) {
         $this->markTestIncomplete("Entity [{$entityName}] cannot be mocked - no known DAO");
         return;
     }
     $baos = array();
     $i = 0;
     while ($i < $count) {
         // create entities
         $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
         $this->assertTrue(is_integer($baoObj->id), 'check first id');
         $this->deletableTestObjects[$baoString][] = $baoObj->id;
         $baos[] = $baoObj;
         $i++;
     }
     return $baos;
 }
示例#28
0
 /**
  * Create an attachment and delete using its ID. Assert that the records are correctly created and destroyed
  * in the DB and the filesystem.
  */
 public function testDeleteByEntity()
 {
     // create 2 entities (keepme,delme) -- each with 2 attachments (first,second)
     foreach (array('keepme', 'delme') as $e) {
         $entities[$e] = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity');
         $this->assertTrue(is_numeric($entities[$e]->id));
         foreach (array('first', 'second') as $n) {
             $createResults[$e][$n] = $this->callAPISuccess('Attachment', 'create', array('name' => self::getFilePrefix() . 'testDeleteByEntity.txt', 'mime_type' => 'text/plain', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entities[$e]->id));
             $this->assertTrue(is_numeric($createResults[$e][$n]['id']));
         }
     }
     $this->assertAttachmentExistence(TRUE, $createResults['keepme']['first']);
     $this->assertAttachmentExistence(TRUE, $createResults['keepme']['second']);
     $this->assertAttachmentExistence(TRUE, $createResults['delme']['first']);
     $this->assertAttachmentExistence(TRUE, $createResults['delme']['second']);
     $this->callAPISuccess('Attachment', 'delete', array('entity_table' => 'civicrm_activity', 'entity_id' => $entities[$e]->id));
     $this->assertAttachmentExistence(TRUE, $createResults['keepme']['first']);
     $this->assertAttachmentExistence(TRUE, $createResults['keepme']['second']);
     $this->assertAttachmentExistence(FALSE, $createResults['delme']['first']);
     $this->assertAttachmentExistence(FALSE, $createResults['delme']['second']);
 }
示例#29
0
 /**
  * Helper function to create an associated project and need
  *
  * @return array Contains three elements:
  * <ul>
  *   <li>CRM_Volunteer_BAO_Project</li>
  *   <li>CRM_Volunteer_BAO_Need</li>
  *   <li>int Role ID for the created need</li>
  * </ul>
  */
 private function createProjectWithNeed()
 {
     $role_id = 2;
     $project = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Project');
     $this->assertObjectHasAttribute('id', $project, 'Failed to prepopulate Volunteer Project');
     // attach need to project
     $need = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Need', array('is_active' => 1, 'is_flexible' => 0, 'project_id' => $project->id, 'quantity' => 5, 'role_id' => $role_id, 'start_time' => date('YmdHis', strtotime('tomorrow')), 'visibility_id' => CRM_Core_OptionGroup::getValue('visibility', 'public', 'name')));
     return array($project, $need, $role_id);
 }
示例#30
0
文件: DAO.php 项目: bhirsch/voipdev
 static function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = false)
 {
     static $counter = 0;
     require_once "CRM/Utils/Type.php";
     require_once str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php";
     for ($i = 0; $i < $numObjects; ++$i) {
         ++$counter;
         eval('$object   =& new ' . $daoName . '( );');
         $fields =& $object->fields();
         foreach ($fields as $name => $value) {
             $dbName = $value['name'];
             $FKClassName = CRM_Utils_Array::value('FKClassName', $value);
             $required = CRM_Utils_Array::value('required', $value);
             if (CRM_Utils_Array::value($dbName, $params) && !is_array($params[$dbName])) {
                 $object->{$dbName} = $params[$dbName];
             } elseif ($dbName != 'id') {
                 if ($FKClassName != null) {
                     //skip the FK if it is not required
                     if (!$required) {
                         continue;
                     }
                     //if it is required we need to generate the dependency object first
                     $depObject = CRM_Core_DAO::createTestObject($FKClassName, CRM_Utils_Array::value($dbName, $params, 1));
                     $object->{$dbName} = $depObject->id;
                     unset($depObject);
                     continue;
                 }
                 switch ($value['type']) {
                     case CRM_Utils_Type::T_INT:
                     case CRM_Utils_Type::T_BOOL:
                     case CRM_Utils_Type::T_BOOLEAN:
                     case CRM_Utils_Type::T_FLOAT:
                     case CRM_Utils_Type::T_MONEY:
                         $object->{$dbName} = $counter;
                         break;
                     case CRM_Utils_Type::T_DATE:
                     case CRM_Utils_Type::T_TIMESTAMP:
                         $object->{$dbName} = '19700101';
                         break;
                     case CRM_Utils_Type::T_TIME:
                         CRM_Core_Error::fatal('T_TIME shouldnt be used.');
                         //$object->$dbName='000000';
                         //break;
                     //$object->$dbName='000000';
                     //break;
                     case CRM_Utils_Type::T_CCNUM:
                         $object->{$dbName} = '4111 1111 1111 1111';
                         break;
                     case CRM_Utils_Type::T_URL:
                         $object->{$dbName} = 'http://www.civicrm.org';
                         break;
                     case CRM_Utils_Type::T_STRING:
                     case CRM_Utils_Type::T_BLOB:
                     case CRM_Utils_Type::T_MEDIUMBLOB:
                     case CRM_Utils_Type::T_TEXT:
                     case CRM_Utils_Type::T_LONGTEXT:
                     case CRM_Utils_Type::T_EMAIL:
                     default:
                         if (isset($value['enumValues'])) {
                             if (isset($value['default'])) {
                                 $object->{$dbName} = $value['default'];
                             } else {
                                 $object->{$dbName} = $value['enumValues'][0];
                             }
                         } else {
                             $object->{$dbName} = $dbName . '_' . $counter;
                             if ($value['maxlength'] > 0 && strlen($object->{$dbName}) > $value['maxlength']) {
                                 $object->{$dbName} = substr($object->{$dbName}, 0, $value['maxlength']);
                             }
                         }
                 }
             }
         }
         $object->save();
         if (!$createOnly) {
             $objects[$i] = $object;
         } else {
             unset($object);
         }
     }
     if ($createOnly) {
         return;
     } else {
         if ($numObjects == 1) {
             return $objects[0];
         } else {
             return $objects;
         }
     }
 }