parent::setUp();
// $this->quickCleanup(array('civicrm_acl_contact_cache'), TRUE);
$this->useTransaction(TRUE);
- $this->allowedContactsACL = array();
+ $this->allowedContactsACL = [];
}
/**
$this->assertEquals($result, $contacts, "Contacts should be viewable when 'view all contacts'");
// test WITH explicit permission
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('view all contacts');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view all contacts'];
$result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::VIEW);
sort($result);
$this->assertEquals($result, $contacts, "Contacts should be viewable when 'view all contacts'");
// test WITH EDIT permissions (should imply VIEW)
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit all contacts'];
$result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::VIEW);
sort($result);
$this->assertEquals($result, $contacts, "Contacts should be viewable when 'edit all contacts'");
// test WITHOUT permission
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array();
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = [];
$result = CRM_Contact_BAO_Contact_Permission::allowList($contacts);
sort($result);
$this->assertEmpty($result, "Contacts should NOT be viewable when 'view all contacts' is not set");
$contacts = $this->createScenarioPlain();
// test WITH explicit permission
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit all contacts'];
$result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::EDIT);
sort($result);
$this->assertEquals($result, $contacts, "Contacts should be viewable when 'edit all contacts'");
// test WITHOUT permission
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array();
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = [];
$result = CRM_Contact_BAO_Contact_Permission::allowList($contacts);
sort($result);
$this->assertEmpty($result, "Contacts should NOT be viewable when 'edit all contacts' is not set");
// delete one contact
$deleted_contact_id = $contacts[2];
- $this->callAPISuccess('Contact', 'create', array('id' => $deleted_contact_id, 'contact_is_deleted' => 1));
- $deleted_contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $deleted_contact_id));
+ $this->callAPISuccess('Contact', 'create', ['id' => $deleted_contact_id, 'contact_is_deleted' => 1]);
+ $deleted_contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $deleted_contact_id]);
$this->assertEquals($deleted_contact['contact_is_deleted'], 1, "Contact should've been deleted");
// test WITH explicit permission
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts', 'view all contacts');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit all contacts', 'view all contacts'];
$result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::EDIT);
sort($result);
$this->assertNotContains($deleted_contact_id, $result, "Deleted contacts should be excluded");
// remove all permissions
$config = CRM_Core_Config::singleton();
- $config->userPermissionClass->permissions = array();
- $permissions_to_check = array(CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit');
+ $config->userPermissionClass->permissions = [];
+ $permissions_to_check = [CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit'];
// run this for SIMPLE relations
$config->secondDegRelPermissions = FALSE;
$contacts = $this->createScenarioPlain();
// set custom hook
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'hook_civicrm_aclWhereClause'));
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']);
// run simple test
- $permissions_to_check = array(CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit');
+ $permissions_to_check = [CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit'];
- $this->allowedContactsACL = array($contacts[0], $contacts[1], $contacts[4]);
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array();
+ $this->allowedContactsACL = [$contacts[0], $contacts[1], $contacts[4]];
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = [];
$result = CRM_Contact_BAO_Contact_Permission::allowList($contacts);
sort($result);
$contacts = $this->createScenarioRelations();
// set custom hook
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'hook_civicrm_aclWhereClause'));
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']);
$config = CRM_Core_Config::singleton();
- $config->userPermissionClass->permissions = array();
+ $config->userPermissionClass->permissions = [];
$config->secondDegRelPermissions = TRUE;
- $this->allowedContactsACL = array($contacts[0], $contacts[1], $contacts[4]);
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array();
+ $this->allowedContactsACL = [$contacts[0], $contacts[1], $contacts[4]];
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = [];
$result = CRM_Contact_BAO_Contact_Permission::allowList($contacts);
sort($result);
$contact_index = array_flip($contacts);
// set custom hook
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'hook_civicrm_aclWhereClause'));
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']);
$config = CRM_Core_Config::singleton();
- $this->allowedContactsACL = array($contacts[0], $contacts[1], $contacts[4]);
+ $this->allowedContactsACL = [$contacts[0], $contacts[1], $contacts[4]];
$config->secondDegRelPermissions = TRUE;
// test configurations
- $permissions_to_check = array(CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit');
- $user_permission_options = array(/*ALL*/ NULL, /*NONE*/ array(), array('view all contacts'), array('edit all contacts'), array('view all contacts', 'edit all contacts'));
+ $permissions_to_check = [CRM_Core_Permission::VIEW => 'View', CRM_Core_Permission::EDIT => 'Edit'];
+ $user_permission_options = [/*ALL*/ NULL, /*NONE*/ [], ['view all contacts'], ['edit all contacts'], ['view all contacts', 'edit all contacts']];
// run all combinations of those
foreach ($permissions_to_check as $permission_to_check => $permission_label) {
$this->assertNotEmpty($user_id);
// create test contacts
- $bush_sr_id = $this->individualCreate(array('first_name' => 'George', 'middle_name' => 'H. W.', 'last_name' => 'Bush'));
- $bush_jr_id = $this->individualCreate(array('first_name' => 'George', 'middle_name' => 'W.', 'last_name' => 'Bush'));
- $bush_laura_id = $this->individualCreate(array('first_name' => 'Laura Lane', 'last_name' => 'Bush'));
- $bush_brbra_id = $this->individualCreate(array('first_name' => 'Barbara', 'last_name' => 'Bush'));
- $bush_brother_id = $this->individualCreate(array('first_name' => 'Brother', 'last_name' => 'Bush'));
- $bush_nephew_id = $this->individualCreate(array('first_name' => 'Nephew', 'last_name' => 'Bush'));
- $bush_nephew2_id = $this->individualCreate(array('first_name' => 'Nephew2', 'last_name' => 'Bush'));
- $bush_otherbro_id = $this->individualCreate(array('first_name' => 'Other Brother', 'last_name' => 'Bush'));
- $bush_otherneph_id = $this->individualCreate(array('first_name' => 'Other Nephew', 'last_name' => 'Bush'));
-
- $contacts = array($user_id, $bush_sr_id, $bush_jr_id, $bush_laura_id, $bush_brbra_id, $bush_brother_id, $bush_nephew_id, $bush_nephew2_id, $bush_otherbro_id, $bush_otherneph_id);
+ $bush_sr_id = $this->individualCreate(['first_name' => 'George', 'middle_name' => 'H. W.', 'last_name' => 'Bush']);
+ $bush_jr_id = $this->individualCreate(['first_name' => 'George', 'middle_name' => 'W.', 'last_name' => 'Bush']);
+ $bush_laura_id = $this->individualCreate(['first_name' => 'Laura Lane', 'last_name' => 'Bush']);
+ $bush_brbra_id = $this->individualCreate(['first_name' => 'Barbara', 'last_name' => 'Bush']);
+ $bush_brother_id = $this->individualCreate(['first_name' => 'Brother', 'last_name' => 'Bush']);
+ $bush_nephew_id = $this->individualCreate(['first_name' => 'Nephew', 'last_name' => 'Bush']);
+ $bush_nephew2_id = $this->individualCreate(['first_name' => 'Nephew2', 'last_name' => 'Bush']);
+ $bush_otherbro_id = $this->individualCreate(['first_name' => 'Other Brother', 'last_name' => 'Bush']);
+ $bush_otherneph_id = $this->individualCreate(['first_name' => 'Other Nephew', 'last_name' => 'Bush']);
+
+ $contacts = [$user_id, $bush_sr_id, $bush_jr_id, $bush_laura_id, $bush_brbra_id, $bush_brother_id, $bush_nephew_id, $bush_nephew2_id, $bush_otherbro_id, $bush_otherneph_id];
sort($contacts);
return $contacts;
}
$contacts = $this->createScenarioPlain();
// create some relationships
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[1],
'contact_id_b' => $contacts[0],
'is_permission_b_a' => 1,
'is_active' => 1,
- ));
+ ]);
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[2],
'contact_id_b' => $contacts[1],
'is_permission_b_a' => 1,
'is_active' => 1,
- ));
+ ]);
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[4],
'contact_id_b' => $contacts[2],
'is_permission_b_a' => 1,
'is_active' => 1,
- ));
+ ]);
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
// SIBLING OF
'relationship_type_id' => 4,
'contact_id_a' => $contacts[5],
// View
'is_permission_b_a' => 2,
'is_active' => 1,
- ));
+ ]);
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[6],
// Edit
'is_permission_b_a' => 1,
'is_active' => 1,
- ));
+ ]);
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[7],
// View
'is_permission_b_a' => 2,
'is_active' => 1,
- ));
+ ]);
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
// SIBLING OF
'relationship_type_id' => 4,
'contact_id_a' => $contacts[0],
// edit (as a_b)
'is_permission_a_b' => 1,
'is_active' => 1,
- ));
+ ]);
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[9],
// view
'is_permission_b_a' => 2,
'is_active' => 1,
- ));
+ ]);
return $contacts;
}
* - subject: regex
*/
public function createTestCases() {
- $cs = array();
+ $cs = [];
- $cs[] = array(
+ $cs[] = [
'2015-02-01 00:00:00',
'addAliceMeeting scheduleForAny startOnTime useHelloFirstName recipientIsActivitySource',
- array(
- array(
+ [
+ [
'time' => '2015-02-01 00:00:00',
- 'to' => array('alice@example.org'),
+ 'to' => ['alice@example.org'],
'subject' => '/Hello, Alice.*via subject/',
- ),
- ),
- );
+ ],
+ ],
+ ];
// FIXME: CRM-19415: This test should pass...
// $cs[] = array(
// ),
// );
- $cs[] = array(
+ $cs[] = [
'2015-02-01 00:00:00',
'addAliceMeeting addBobPhoneCall scheduleForMeeting startOnTime useHelloFirstName recipientIsActivitySource',
- array(
- array(
+ [
+ [
'time' => '2015-02-01 00:00:00',
- 'to' => array('alice@example.org'),
+ 'to' => ['alice@example.org'],
'subject' => '/Hello, Alice.*via subject/',
- ),
- ),
- );
+ ],
+ ],
+ ];
- $cs[] = array(
+ $cs[] = [
'2015-02-01 00:00:00',
'addAliceMeeting addBobPhoneCall scheduleForAny startOnTime useHelloFirstName recipientIsActivitySource',
- array(
- array(
+ [
+ [
'time' => '2015-02-01 00:00:00',
- 'to' => array('alice@example.org'),
+ 'to' => ['alice@example.org'],
'subject' => '/Hello, Alice.*via subject/',
- ),
- array(
+ ],
+ [
'time' => '2015-02-01 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- ),
- );
+ ],
+ ],
+ ];
- $cs[] = array(
+ $cs[] = [
'2015-02-02 00:00:00',
'addAliceMeeting addBobPhoneCall scheduleForPhoneCall startWeekBefore repeatTwoWeeksAfter useHelloFirstName recipientIsActivitySource',
- array(
- array(
+ [
+ [
'time' => '2015-01-26 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- array(
+ ],
+ [
'time' => '2015-02-02 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- array(
+ ],
+ [
'time' => '2015-02-09 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- array(
+ ],
+ [
'time' => '2015-02-16 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- ),
- );
+ ],
+ ],
+ ];
return $cs;
}
* Create an activity record for Alice with type "Meeting".
*/
public function addAliceMeeting() {
- $this->callAPISuccess('Activity', 'create', array(
+ $this->callAPISuccess('Activity', 'create', [
'source_contact_id' => $this->contacts['alice']['id'],
'activity_type_id' => 'Meeting',
'subject' => 'Subject for Alice',
'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate)),
'status_id' => 2,
- 'assignee_contact_id' => array($this->contacts['carol']['id']),
- ));
+ 'assignee_contact_id' => [$this->contacts['carol']['id']],
+ ]);
}
/**
* Create a contribution record for Bob with type "Donation".
*/
public function addBobPhoneCall() {
- $this->callAPISuccess('Activity', 'create', array(
+ $this->callAPISuccess('Activity', 'create', [
'source_contact_id' => $this->contacts['bob']['id'],
'activity_type_id' => 'Phone Call',
'subject' => 'Subject for Bob',
'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate)),
'status_id' => 2,
- 'assignee_contact_id' => array($this->contacts['carol']['id']),
- ));
+ 'assignee_contact_id' => [$this->contacts['carol']['id']],
+ ]);
}
/**
$actTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id');
$this->schedule->mapping_id = CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID;
$this->schedule->start_action_date = 'receive_date';
- $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(array_search('Meeting', $actTypes)));
- $this->schedule->entity_status = CRM_Utils_Array::implodePadded(array(2));
+ $this->schedule->entity_value = CRM_Utils_Array::implodePadded([array_search('Meeting', $actTypes)]);
+ $this->schedule->entity_status = CRM_Utils_Array::implodePadded([2]);
}
/**
$actTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id');
$this->schedule->mapping_id = CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID;
$this->schedule->start_action_date = 'receive_date';
- $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(array_search('Phone Call', $actTypes)));
+ $this->schedule->entity_value = CRM_Utils_Array::implodePadded([array_search('Phone Call', $actTypes)]);
$this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL);
}
*/
public function testGetAssigneeNamesOneId() {
$activity = $this->activityCreate();
- $assignees = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activity['id']));
+ $assignees = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames([$activity['id']]);
$this->assertEquals(count($assignees), 1, '1 assignee names retrieved');
}
public function testRetrieveTargetIdsByActivityIdZeroID() {
$this->activityCreate();
$target = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId(0);
- $this->assertSame($target, array(), 'No targets returned');
+ $this->assertSame($target, [], 'No targets returned');
}
public function testRetrieveTargetIdsByActivityIdOneID() {
public function setUp() {
parent::setUp();
$this->prepareForACLs();
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('view all contacts', 'access CiviCRM');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['view all contacts', 'access CiviCRM'];
$this->setupForSmsTests();
}
* Clean up after tests.
*/
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_activity',
'civicrm_activity_contact',
'civicrm_uf_match',
'civicrm_campaign',
'civicrm_email',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
$this->cleanUpAfterACLs();
$this->setupForSmsTests(TRUE);
public function testCreate() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'source_contact_id' => $contactId,
'subject' => 'Scheduling Meeting',
'activity_type_id' => 2,
- );
+ ];
CRM_Activity_BAO_Activity::create($params);
);
// Now call create() to modify an existing Activity.
- $params = array(
+ $params = [
'id' => $activityId,
'source_contact_id' => $contactId,
'subject' => 'Scheduling Interview',
'activity_type_id' => 3,
- );
+ ];
CRM_Activity_BAO_Activity::create($params);
*/
public function testGetContactActivity() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'first_name' => 'liz',
'last_name' => 'hurleey',
- );
+ ];
$targetContactId = $this->individualCreate($params);
- $params = array(
+ $params = [
'source_contact_id' => $contactId,
'subject' => 'Scheduling Meeting',
'activity_type_id' => 2,
- 'target_contact_id' => array($targetContactId),
+ 'target_contact_id' => [$targetContactId],
'activity_date_time' => date('Ymd'),
- );
+ ];
$this->callAPISuccess('Activity', 'create', $params);
*/
public function testRetrieve() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'first_name' => 'liz',
'last_name' => 'hurleey',
- );
+ ];
$targetContactId = $this->individualCreate($params);
- $params = array(
+ $params = [
'source_contact_id' => $contactId,
'subject' => 'Scheduling Meeting',
'activity_type_id' => 2,
- 'target_contact_id' => array($targetContactId),
+ 'target_contact_id' => [$targetContactId],
'activity_date_time' => date('Ymd'),
- );
+ ];
CRM_Activity_BAO_Activity::create($params);
'Database check for created activity target.'
);
- $defaults = array();
+ $defaults = [];
$activity = CRM_Activity_BAO_Activity::retrieve($params, $defaults);
$this->assertEquals($activity->subject, 'Scheduling Meeting', 'Verify activity subject is correct.');
*/
public function testTargetContactNotavaliable() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'first_name' => 'liz',
'last_name' => 'hurleey',
- );
+ ];
$targetContactId = $this->individualCreate($params);
- $params = array(
+ $params = [
'source_contact_id' => $contactId,
'subject' => 'Scheduling Meeting',
'activity_type_id' => 2,
- 'target_contact_id' => array($targetContactId),
+ 'target_contact_id' => [$targetContactId],
'activity_date_time' => date('Ymd'),
- );
+ ];
CRM_Activity_BAO_Activity::create($params);
// set custom hook
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'hook_civicrm_aclWhereClause'));
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'hook_civicrm_aclWhereClause']);
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
- $this->allowedContactsACL = array($contactId);
+ $this->allowedContactsACL = [$contactId];
// get logged in user
$user_id = $this->createLoggedInUser();
*/
public function testDeleteActivity() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'first_name' => 'liz',
'last_name' => 'hurleey',
- );
+ ];
$targetContactId = $this->individualCreate($params);
- $params = array(
+ $params = [
'source_contact_id' => $contactId,
'source_record_id' => $contactId,
'subject' => 'Scheduling Meeting',
'activity_type_id' => 2,
- 'target_contact_id' => array($targetContactId),
+ 'target_contact_id' => [$targetContactId],
'activity_date_time' => date('Ymd'),
- );
+ ];
CRM_Activity_BAO_Activity::create($params);
'id', 'contact_id',
'Database check for created activity target.'
);
- $params = array(
+ $params = [
'source_contact_id' => $contactId,
'source_record_id' => $contactId,
'subject' => 'Scheduling Meeting',
'activity_type_id' => 2,
- );
+ ];
CRM_Activity_BAO_Activity::deleteActivity($params);
*/
public function testDeleteActivityTarget() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'first_name' => 'liz',
'last_name' => 'hurleey',
- );
+ ];
$targetContactId = $this->individualCreate($params);
- $params = array(
+ $params = [
'source_contact_id' => $contactId,
'subject' => 'Scheduling Meeting',
'activity_type_id' => 2,
- 'target_contact_id' => array($targetContactId),
+ 'target_contact_id' => [$targetContactId],
'activity_date_time' => date('Ymd'),
- );
+ ];
CRM_Activity_BAO_Activity::create($params);
*/
public function testDeleteActivityAssignment() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'first_name' => 'liz',
'last_name' => 'hurleey',
- );
+ ];
$assigneeContactId = $this->individualCreate($params);
- $params = array(
+ $params = [
'source_contact_id' => $contactId,
'subject' => 'Scheduling Meeting',
'activity_type_id' => 2,
- 'assignee_contact_id' => array($assigneeContactId),
+ 'assignee_contact_id' => [$assigneeContactId],
'activity_date_time' => date('Ymd'),
- );
+ ];
CRM_Activity_BAO_Activity::create($params);
public function testGetActivitiesCountforNonAdminDashboard() {
$this->createTestActivities();
- $params = array(
+ $params = [
'contact_id' => 9,
'admin' => FALSE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- );
+ ];
//since we are loading activities from dataset, we know total number of activities for this contact
// 5 activities ( 2 scheduled, 3 Completed ), note that dashboard shows only scheduled activities
public function testGetActivitiesCountforContactSummary() {
$this->createTestActivities();
- $params = array(
+ $params = [
'contact_id' => 9,
'admin' => FALSE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- );
+ ];
//since we are loading activities from dataset, we know total number of activities for this contact
// 5 activities, Contact Summary should show all activities
$this->createLoggedInUser();
global $_GET;
- $_GET = array(
+ $_GET = [
'cid' => 9,
'context' => 'activity',
'activity_type_id' => 1,
'is_unit_test' => 1,
- );
- $expectedFilters = array(
+ ];
+ $expectedFilters = [
'activity_type_filter_id' => 1,
- );
+ ];
list($activities, $activityFilter) = CRM_Activity_Page_AJAX::getContactActivity();
//Assert whether filters are correctly set.
public function testGetActivitiesCountforContactSummaryWithNoActivities() {
$this->createTestActivities();
- $params = array(
+ $params = [
'contact_id' => 17,
'admin' => FALSE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- );
+ ];
//since we are loading activities from dataset, we know total number of activities for this contact
// this contact does not have any activity
//since we are loading activities from dataset, we know total number of activities
// with no contact ID and there should be 8 schedule activities shown on dashboard
$count = 8;
- foreach (array($activitiesNew) as $activities) {
+ foreach ([$activitiesNew] as $activities) {
$this->assertEquals($count, count($activities));
foreach ($activities as $key => $value) {
* Test getActivities BAO method.
*/
public function testGetActivitiesForAdminDashboardNoViewContacts() {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
$this->setUpForActivityDashboardTests();
- foreach (array(CRM_Activity_BAO_Activity::getActivities($this->_params)) as $activities) {
+ foreach ([CRM_Activity_BAO_Activity::getActivities($this->_params)] as $activities) {
// Skipped until we get back to the upgraded version properly.
$this->assertEquals(0, count($activities));
}
* Test getActivities BAO method.
*/
public function testGetActivitiesForAdminDashboardAclLimitedViewContacts() {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
- $this->allowedContacts = array(1, 3, 4, 5);
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereMultipleContacts'));
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
+ $this->allowedContacts = [1, 3, 4, 5];
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereMultipleContacts']);
$this->setUpForActivityDashboardTests();
$this->assertEquals(7, count(CRM_Activity_BAO_Activity::getActivities($this->_params)));
}
$this->createTestActivities();
$contactID = 9;
- $params = array(
+ $params = [
'contact_id' => $contactID,
'admin' => FALSE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- );
+ ];
- foreach (array(CRM_Activity_BAO_Activity::getActivities($params)) as $activities) {
+ foreach ([CRM_Activity_BAO_Activity::getActivities($params)] as $activities) {
//since we are loading activities from dataset, we know total number of activities for this contact
// 5 activities ( 2 scheduled, 3 Completed ), note that dashboard shows only scheduled activities
$count = 2;
public function testTargetCountforContactSummary() {
$targetCount = 5;
$contactId = $this->individualCreate();
- $targetContactIDs = array();
+ $targetContactIDs = [];
for ($i = 0; $i < $targetCount; $i++) {
- $targetContactIDs[] = $this->individualCreate(array(), $i);
+ $targetContactIDs[] = $this->individualCreate([], $i);
}
// Create activities with 5 target contacts.
- $activityParams = array(
+ $activityParams = [
'source_contact_id' => $contactId,
'target_contact_id' => $targetContactIDs,
- );
+ ];
$this->activityCreate($activityParams);
- $params = array(
+ $params = [
'contact_id' => $contactId,
'context' => 'activity',
- );
+ ];
$activities = CRM_Activity_BAO_Activity::getActivities($params);
//verify target count
$this->assertEquals($targetCount, $activities[1]['target_contact_count']);
$this->createTestActivities();
$contactID = 9;
- $params = array(
+ $params = [
'contact_id' => $contactID,
'admin' => FALSE,
'caseId' => NULL,
'activity_type_id' => NULL,
'offset' => 0,
'rowCount' => 0,
- );
+ ];
//since we are loading activities from dataset, we know total number of activities for this contact
// 5 activities, Contact Summary should show all activities
$this->createTestActivities();
// parameters for different test cases, check each array key for the specific test-case
- $testCases = array(
- 'with-no-activity' => array(
- 'params' => array(
+ $testCases = [
+ 'with-no-activity' => [
+ 'params' => [
'contact_id' => 17,
'admin' => FALSE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- ),
- ),
- 'with-activity' => array(
- 'params' => array(
+ ],
+ ],
+ 'with-activity' => [
+ 'params' => [
'contact_id' => 1,
'admin' => FALSE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- ),
- ),
- 'with-activity_type' => array(
- 'params' => array(
+ ],
+ ],
+ 'with-activity_type' => [
+ 'params' => [
'contact_id' => 3,
'admin' => FALSE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- ),
- ),
- 'exclude-all-activity_type' => array(
- 'params' => array(
+ ],
+ ],
+ 'exclude-all-activity_type' => [
+ 'params' => [
'contact_id' => 3,
'admin' => FALSE,
'caseId' => NULL,
'context' => 'home',
- 'activity_type_exclude_id' => array(1, 2),
+ 'activity_type_exclude_id' => [1, 2],
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- ),
- ),
- 'sort-by-subject' => array(
- 'params' => array(
+ ],
+ ],
+ 'sort-by-subject' => [
+ 'params' => [
'contact_id' => 1,
'admin' => FALSE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => 'subject DESC',
- ),
- ),
- );
+ ],
+ ],
+ ];
foreach ($testCases as $caseName => $testCase) {
$activityCount = CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params']);
$activitiesNew = CRM_Activity_BAO_Activity::getActivities($testCase['params']);
- foreach (array($activitiesNew) as $activities) {
+ foreach ([$activitiesNew] as $activities) {
//$this->assertEquals($activityCount, CRM_Activity_BAO_Activity::getActivitiesCount($testCase['params']));
if ($caseName == 'with-no-activity') {
$this->assertEquals(0, count($activities));
$this->assertEquals(3, count($activities));
$this->assertEquals(3, $activityCount);
// activities should be order by 'subject DESC'
- $subjectOrder = array(
+ $subjectOrder = [
'subject 8',
'subject 7',
'subject 1',
- );
+ ];
$count = 0;
foreach ($activities as $activity) {
$this->assertEquals($subjectOrder[$count], $activity['subject']);
$this->createTestActivities();
// activity IDs catagorised by date
- $lastWeekActivities = array(1, 2, 3);
- $todayActivities = array(4, 5, 6, 7);
- $lastTwoMonthsActivities = array(8, 9, 10, 11);
- $lastOrNextYearActivities = array(12, 13, 14, 15, 16);
+ $lastWeekActivities = [1, 2, 3];
+ $todayActivities = [4, 5, 6, 7];
+ $lastTwoMonthsActivities = [8, 9, 10, 11];
+ $lastOrNextYearActivities = [12, 13, 14, 15, 16];
// date values later used to set activity date value
$lastWeekDate = date('YmdHis', strtotime('1 week ago'));
elseif (in_array($i, $todayActivities)) {
$date = $today;
}
- $this->callAPISuccess('Activity', 'create', array(
+ $this->callAPISuccess('Activity', 'create', [
'id' => $i,
'activity_date_time' => $date,
- ));
+ ]);
}
// parameters for different test cases, check each array key for the specific test-case
- $testCases = array(
- 'todays-activity' => array(
- 'params' => array(
+ $testCases = [
+ 'todays-activity' => [
+ 'params' => [
'contact_id' => 1,
'admin' => TRUE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- ),
- ),
- 'todays-activity-filtered-by-range' => array(
- 'params' => array(
+ ],
+ ],
+ 'todays-activity-filtered-by-range' => [
+ 'params' => [
'contact_id' => 1,
'admin' => TRUE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- ),
- ),
- 'last-week-activity' => array(
- 'params' => array(
+ ],
+ ],
+ 'last-week-activity' => [
+ 'params' => [
'contact_id' => 1,
'admin' => TRUE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- ),
- ),
- 'this-quarter-activity' => array(
- 'params' => array(
+ ],
+ ],
+ 'this-quarter-activity' => [
+ 'params' => [
'contact_id' => 1,
'admin' => TRUE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- ),
- ),
- 'activity-of-all-statuses' => array(
- 'params' => array(
+ ],
+ ],
+ 'activity-of-all-statuses' => [
+ 'params' => [
'contact_id' => 1,
'admin' => TRUE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- ),
- ),
- );
+ ],
+ ],
+ ];
foreach ($testCases as $caseName => $testCase) {
CRM_Utils_Date::convertFormDateToApiFormat($testCase['params'], 'activity_date_time', FALSE);
// Case 1: assert the 'From' Email Address of source Actvity Contact ID
// create activity with source contact ID which has email address
$assigneeContactId = $this->individualCreate();
- $sourceContactParams = array(
+ $sourceContactParams = [
'first_name' => 'liz',
'last_name' => 'hurleey',
'email' => substr(sha1(rand()), 0, 7) . '@testemail.com',
- );
+ ];
$sourceContactID = $this->individualCreate($sourceContactParams);
$sourceDisplayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $sourceContactID, 'display_name');
// create an activity using API
- $params = array(
+ $params = [
'source_contact_id' => $sourceContactID,
'subject' => 'Scheduling Meeting ' . substr(sha1(rand()), 0, 4),
'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Meeting'),
- 'assignee_contact_id' => array($assigneeContactId),
+ 'assignee_contact_id' => [$assigneeContactId],
'activity_date_time' => date('Ymd'),
- );
+ ];
$activity = $this->callAPISuccess('Activity', 'create', $params);
// Check that from address is in "Source-Display-Name <source-email>"
// Case 2: System Default From Address
// but first erase the email address of existing source contact ID
- $withoutEmailParams = array(
+ $withoutEmailParams = [
'email' => '',
- );
+ ];
$sourceContactID = $this->individualCreate($withoutEmailParams);
- $params = array(
+ $params = [
'source_contact_id' => $sourceContactID,
'subject' => 'Scheduling Meeting ' . substr(sha1(rand()), 0, 4),
'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Meeting'),
'activity_date_time' => date('Ymd'),
- );
+ ];
$activity = $this->callAPISuccess('Activity', 'create', $params);
// fetch domain info
- $domainInfo = $this->callAPISuccess('Domain', 'getsingle', array('id' => CRM_Core_Config::domainID()));
+ $domainInfo = $this->callAPISuccess('Domain', 'getsingle', ['id' => CRM_Core_Config::domainID()]);
$formAddress = CRM_Case_BAO_Case::getReceiptFrom($activity['id']);
if (!empty($domainInfo['from_email'])) {
protected function setUpForActivityDashboardTests() {
$this->createTestActivities();
- $this->_params = array(
+ $this->_params = [
'contact_id' => NULL,
'admin' => TRUE,
'caseId' => NULL,
'offset' => 0,
'rowCount' => 0,
'sort' => NULL,
- );
+ ];
}
public function testSendEmailBasic() {
$session = CRM_Core_Session::singleton();
$loggedInUser = $session->get('userID');
- $contact = $this->civicrm_api('contact', 'getsingle', array('id' => $contactId, 'version' => $this->_apiversion));
- $contactDetailsIntersectKeys = array(
+ $contact = $this->civicrm_api('contact', 'getsingle', ['id' => $contactId, 'version' => $this->_apiversion]);
+ $contactDetailsIntersectKeys = [
'contact_id' => '',
'sort_name' => '',
'display_name' => '',
'is_deceased' => '',
'email' => '',
'on_hold' => '',
- );
- $contactDetails = array(
+ ];
+ $contactDetails = [
array_intersect_key($contact, $contactDetailsIntersectKeys),
- );
+ ];
$subject = __FUNCTION__ . ' subject';
$html = __FUNCTION__ . ' html';
$from = __FUNCTION__ . '@example.com'
);
- $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activity_id, 'version' => $this->_apiversion));
+ $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activity_id, 'version' => $this->_apiversion]);
$details = "-ALTERNATIVE ITEM 0-
$html
-ALTERNATIVE ITEM 1-
$session = CRM_Core_Session::singleton();
$loggedInUser = $session->get('userID');
- $contact = $this->civicrm_api('contact', 'getsingle', array('id' => $contactId, 'version' => $this->_apiversion));
- $contactDetailsIntersectKeys = array(
+ $contact = $this->civicrm_api('contact', 'getsingle', ['id' => $contactId, 'version' => $this->_apiversion]);
+ $contactDetailsIntersectKeys = [
'contact_id' => '',
'sort_name' => '',
'display_name' => '',
'is_deceased' => '',
'email' => '',
'on_hold' => '',
- );
- $contactDetails = array(
+ ];
+ $contactDetails = [
array_intersect_key($contact, $contactDetailsIntersectKeys),
- );
+ ];
// Create a campaign.
- $result = $this->civicrm_api('Campaign', 'create', array(
+ $result = $this->civicrm_api('Campaign', 'create', [
'version' => $this->_apiversion,
'title' => __FUNCTION__ . ' campaign',
- ));
+ ]);
$campaign_id = $result['id'];
$subject = __FUNCTION__ . ' subject';
NULL,
$campaign_id
);
- $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activity_id, 'version' => $this->_apiversion));
+ $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activity_id, 'version' => $this->_apiversion]);
$this->assertEquals($activity['campaign_id'], $campaign_id, 'Activity campaign_id does not match.');
}
public function testSendSMSWithoutPermission() {
$dummy = NULL;
$session = CRM_Core_Session::singleton();
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
CRM_Activity_BAO_Activity::sendSMS(
$dummy,
public function testSendSmsNoPhoneNumber() {
list($sent, $activityId, $success) = $this->createSendSmsTest(0);
- $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activityId, 'version' => $this->_apiversion));
+ $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion]);
$outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS');
$activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
public function testSendSmsFixedPhoneNumber() {
list($sent, $activityId, $success) = $this->createSendSmsTest(1);
- $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activityId, 'version' => $this->_apiversion));
+ $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion]);
$outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS');
$activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
public function testSendSmsMobilePhoneNumber() {
list($sent, $activityId, $success) = $this->createSendSmsTest(2);
- $activity = $this->civicrm_api('activity', 'getsingle', array('id' => $activityId, 'version' => $this->_apiversion));
+ $activity = $this->civicrm_api('activity', 'getsingle', ['id' => $activityId, 'version' => $this->_apiversion]);
$outBoundSmsActivityId = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS');
$activityStatusCompleted = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
* @param array $additionalContactParams additional contact creation params
*/
public function createSendSmsTest($phoneType = 0, $passPhoneTypeInContactDetails = FALSE, $additionalContactParams = []) {
- $provider = civicrm_api3('SmsProvider', 'create', array(
+ $provider = civicrm_api3('SmsProvider', 'create', [
'name' => "CiviTestSMSProvider",
'api_type' => "1",
"username" => "1",
"is_default" => "1",
"is_active" => "1",
"domain_id" => "1",
- ));
+ ]);
$smsProviderParams['provider_id'] = $provider['id'];
$this->_testSmsContactId = $this->createLoggedInUser();
// Give user permission to 'send SMS'
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'send SMS');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'send SMS'];
// Create a phone number
switch ($phoneType) {
case 2:
// Create a mobile phone number
- $phone = civicrm_api3('Phone', 'create', array(
+ $phone = civicrm_api3('Phone', 'create', [
'contact_id' => $contactId,
'phone' => 123456,
'phone_type_id' => "Mobile",
- ));
+ ]);
if ($passPhoneTypeInContactDetails) {
$contactDetails[$contactId]['phone'] = $phone['values'][$phone['id']]['phone'];
$contactDetails[$contactId]['phone_type_id'] = $phone['values'][$phone['id']]['phone_type_id'];
case 1:
// Create a fixed phone number
- $phone = civicrm_api3('Phone', 'create', array(
+ $phone = civicrm_api3('Phone', 'create', [
'contact_id' => $contactId,
'phone' => 654321,
'phone_type_id' => "Phone",
- ));
+ ]);
if ($passPhoneTypeInContactDetails) {
$contactDetails[$contactId]['phone'] = $phone['values'][$phone['id']]['phone'];
$contactDetails[$contactId]['phone_type_id'] = $phone['values'][$phone['id']]['phone_type_id'];
$sourceContactId
);
- return array($sent, $activityId, $success);
+ return [$sent, $activityId, $success];
}
protected function createTestActivities() {
public function setUp() {
parent::setUp();
- $this->assignee1 = $this->individualCreate(array(
+ $this->assignee1 = $this->individualCreate([
'first_name' => 'testassignee1',
'last_name' => 'testassignee1',
'email' => 'testassignee1@gmail.com',
- ));
- $this->assignee2 = $this->individualCreate(array(
+ ]);
+ $this->assignee2 = $this->individualCreate([
'first_name' => 'testassignee2',
'last_name' => 'testassignee2',
'email' => 'testassignee2@gmail.com',
- ));
+ ]);
$this->target = $this->individualCreate();
$this->source = $this->individualCreate();
}
public function testActivityCreate() {
Civi::settings()->set('activity_assignee_notification', TRUE);
//Reset filter to none.
- Civi::settings()->set('do_not_notify_assignees_for', array());
+ Civi::settings()->set('do_not_notify_assignees_for', []);
$mut = new CiviMailUtils($this, TRUE);
$mut->clearMessages();
$form = new CRM_Activity_Form_Activity();
$activityTypeId = CRM_Core_PseudoConstant::getKey('CRM_Activity_DAO_Activity', 'activity_type_id', 'Meeting');
- $params = array(
+ $params = [
'source_contact_id' => $this->source,
- 'assignee_contact_id' => array($this->assignee1),
- 'target_contact_id' => array($this->target),
- 'followup_assignee_contact_id' => array(),
+ 'assignee_contact_id' => [$this->assignee1],
+ 'target_contact_id' => [$this->target],
+ 'followup_assignee_contact_id' => [],
'activity_type_id' => $activityTypeId,
- );
+ ];
$activityRef = new ReflectionClass('CRM_Activity_Form_Activity');
$method = $activityRef->getMethod('processActivity');
$method->setAccessible(TRUE);
- $method->invokeArgs($form, array(&$params));
+ $method->invokeArgs($form, [&$params]);
$msg = $mut->getMostRecentEmail();
$this->assertNotEmpty($msg);
$mut->clearMessages();
//Block Meeting notification.
- Civi::settings()->set('do_not_notify_assignees_for', array($activityTypeId));
- $params['assignee_contact_id'] = array($this->assignee2);
- $method->invokeArgs($form, array(&$params));
+ Civi::settings()->set('do_not_notify_assignees_for', [$activityTypeId]);
+ $params['assignee_contact_id'] = [$this->assignee2];
+ $method->invokeArgs($form, [&$params]);
$msg = $mut->getMostRecentEmail();
$this->assertEmpty($msg);
}
// create two contributions: one check and one credit card
- $contactId = $this->individualCreate(array('first_name' => 'John', 'last_name' => 'Doe'));
+ $contactId = $this->individualCreate(['first_name' => 'John', 'last_name' => 'Doe']);
$this->contributionCreate([
'contact_id' => $contactId,
'total_amount' => 1,
//create an empty batch to use for the search, and run the search
- $batchParams = array('title' => 'Test Batch');
+ $batchParams = ['title' => 'Test Batch'];
$batchParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Open');
$batch = CRM_Batch_BAO_Batch::create($batchParams);
$entityId = $batch->id;
- $returnvalues = array(
+ $returnvalues = [
'civicrm_financial_trxn.payment_instrument_id as payment_method',
- );
+ ];
$notPresent = TRUE;
$params['contribution_payment_instrument_id']
= CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check');
public function setUp() {
parent::setUp();
- $params = array(
+ $params = [
'contact_type_a' => 'Individual',
'contact_type_b' => 'Organization',
'name_a_b' => 'Test Employee of',
'name_b_a' => 'Test Employer of',
- );
+ ];
$this->_relationshipTypeId = $this->relationshipTypeCreate($params);
$this->_orgContactID = $this->organizationCreate();
$this->_financialTypeId = 1;
$this->_membershipTypeName = 'Mickey Mouse Club Member';
- $params = array(
+ $params = [
'name' => $this->_membershipTypeName,
'description' => NULL,
'minimum_fee' => 1500,
'fixed_period_start_day' => 101,
'fixed_period_rollover_day' => 1231,
'domain_id' => CRM_Core_Config::domainID(),
- );
+ ];
$membershipType = $this->callAPISuccess('membership_type', 'create', $params);
$this->_membershipTypeID = $membershipType['id'];
$this->_orgContactID2 = $this->organizationCreate();
- $params = array(
+ $params = [
'name' => 'General',
'duration_unit' => 'year',
'duration_interval' => 1,
'is_active' => 1,
'sequential' => 1,
'visibility' => 'Public',
- );
+ ];
$membershipType2 = $this->callAPISuccess('membership_type', 'create', $params);
$this->_membershipTypeID2 = $membershipType2['id'];
$this->_membershipStatusID = $this->membershipStatusCreate('test status');
$this->_contactID = $this->individualCreate();
- $contact2Params = array(
+ $contact2Params = [
'first_name' => 'Anthonita',
'middle_name' => 'J.',
'last_name' => 'Anderson',
'suffix_id' => 3,
'email' => 'b@c.com',
'contact_type' => 'Individual',
- );
+ ];
$this->_contactID2 = $this->individualCreate($contact2Params);
- $this->_contactID3 = $this->individualCreate(array('first_name' => 'bobby', 'email' => 'c@d.com'));
- $this->_contactID4 = $this->individualCreate(array('first_name' => 'bobbynita', 'email' => 'c@de.com'));
+ $this->_contactID3 = $this->individualCreate(['first_name' => 'bobby', 'email' => 'c@d.com']);
+ $this->_contactID4 = $this->individualCreate(['first_name' => 'bobbynita', 'email' => 'c@de.com']);
$session = CRM_Core_Session::singleton();
$session->set('dateTypes', 1);
public function tearDown() {
$this->quickCleanUpFinancialEntities();
$this->relationshipTypeDelete($this->_relationshipTypeId);
- if ($this->callAPISuccessGetCount('membership', array('id' => $this->_membershipTypeID))) {
- $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
+ if ($this->callAPISuccessGetCount('membership', ['id' => $this->_membershipTypeID])) {
+ $this->membershipTypeDelete(['id' => $this->_membershipTypeID]);
}
- if ($this->callAPISuccessGetCount('MembershipStatus', array('id' => $this->_membershipStatusID))) {
+ if ($this->callAPISuccessGetCount('MembershipStatus', ['id' => $this->_membershipStatusID])) {
$this->membershipStatusDelete($this->_membershipStatusID);
}
$this->contactDelete($this->_contactID);
$params = $this->getMembershipData();
$this->assertTrue($form->testProcessMembership($params));
- $result = $this->callAPISuccess('membership', 'get', array());
+ $result = $this->callAPISuccess('membership', 'get', []);
$this->assertEquals(3, $result['count']);
//check start dates #1 should default to 1 Jan this year, #2 should be as entered
$this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']);
$this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']);
$this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
$this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
- $result = $this->callAPISuccess('contribution', 'get', array('return' => array('total_amount', 'trxn_id')));
+ $result = $this->callAPISuccess('contribution', 'get', ['return' => ['total_amount', 'trxn_id']]);
$this->assertEquals(3, $result['count']);
foreach ($result['values'] as $key => $contribution) {
- $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
+ $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', [
'contribution_id' => $contribution['id'],
'return' => 'line_total',
- )), $contribution['total_amount']);
+ ]), $contribution['total_amount']);
$this->assertEquals(1500, $contribution['total_amount']);
$this->assertEquals($params['field'][$key]['trxn_id'], $contribution['trxn_id']);
}
$form = new CRM_Batch_Form_Entry();
$params = $this->getContributionData();
$this->assertTrue($form->testProcessContribution($params));
- $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
+ $result = $this->callAPISuccess('contribution', 'get', ['return' => 'total_amount']);
$this->assertEquals(2, $result['count']);
foreach ($result['values'] as $contribution) {
- $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
+ $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', [
'contribution_id' => $contribution['id'],
'return' => 'line_total',
- )), $contribution['total_amount']);
+ ]), $contribution['total_amount']);
}
}
*/
public function testMembershipRenewalDates() {
$form = new CRM_Batch_Form_Entry();
- foreach (array($this->_contactID, $this->_contactID2) as $contactID) {
- $membershipParams = array(
+ foreach ([$this->_contactID, $this->_contactID2] as $contactID) {
+ $membershipParams = [
'membership_type_id' => $this->_membershipTypeID2,
'contact_id' => $contactID,
'start_date' => "01/01/2015",
'join_date' => "01/01/2010",
'end_date' => "12/31/2015",
- );
+ ];
$this->contactMembershipCreate($membershipParams);
}
$params = $this->getMembershipData();
//ensure membership renewal
- $params['member_option'] = array(
+ $params['member_option'] = [
1 => 2,
2 => 2,
- );
- $params['field'][1]['membership_type'] = array(0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2);
+ ];
+ $params['field'][1]['membership_type'] = [0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2];
$params['field'][1]['receive_date'] = date('Y-m-d');
// explicitly specify start and end dates
- $params['field'][2]['membership_type'] = array(0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2);
+ $params['field'][2]['membership_type'] = [0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2];
$params['field'][2]['membership_start_date'] = "2016-04-01";
$params['field'][2]['membership_end_date'] = "2017-03-31";
$params['field'][2]['receive_date'] = "2016-04-01";
$this->assertTrue($form->testProcessMembership($params));
- $result = $this->callAPISuccess('membership', 'get', array());
+ $result = $this->callAPISuccess('membership', 'get', []);
// renewal dates should be from current if start_date and end_date is passed as NULL
$this->assertEquals(date('Y-m-d'), $result['values'][1]['start_date']);
*/
public function getMembershipData() {
- return array(
+ return [
'batch_id' => 4,
- 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
- 'primary_contact_id' => array(
+ 'primary_profiles' => [1 => NULL, 2 => NULL, 3 => NULL],
+ 'primary_contact_id' => [
1 => $this->_contactID,
2 => $this->_contactID2,
3 => $this->_contactID3,
- ),
- 'field' => array(
- 1 => array(
- 'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID),
+ ],
+ 'field' => [
+ 1 => [
+ 'membership_type' => [0 => $this->_orgContactID, 1 => $this->_membershipTypeID],
'join_date' => '2013-07-22',
'membership_start_date' => NULL,
'membership_end_date' => NULL,
'trxn_id' => 'TX101',
'check_number' => NULL,
'contribution_status_id' => 1,
- ),
- 2 => array(
- 'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID),
+ ],
+ 2 => [
+ 'membership_type' => [0 => $this->_orgContactID, 1 => $this->_membershipTypeID],
'join_date' => '2013-07-03',
'membership_start_date' => '2013-02-03',
'membership_end_date' => NULL,
'trxn_id' => 'TX102',
'check_number' => NULL,
'contribution_status_id' => 1,
- ),
+ ],
// no join date, coded end date
- 3 => array(
- 'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID),
+ 3 => [
+ 'membership_type' => [0 => $this->_orgContactID, 1 => $this->_membershipTypeID],
'join_date' => NULL,
'membership_start_date' => NULL,
'membership_end_date' => '2013-12-01',
'trxn_id' => 'TX103',
'check_number' => NULL,
'contribution_status_id' => 1,
- ),
+ ],
- ),
+ ],
'actualBatchTotal' => 0,
- );
+ ];
}
/**
* @return array
*/
public function getContributionData($thousandSeparator = '.') {
- return array(
+ return [
//'batch_id' => 4,
- 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
- 'primary_contact_id' => array(
+ 'primary_profiles' => [1 => NULL, 2 => NULL, 3 => NULL],
+ 'primary_contact_id' => [
1 => $this->_contactID,
2 => $this->_contactID2,
3 => $this->_contactID3,
- ),
- 'field' => array(
- 1 => array(
+ ],
+ 'field' => [
+ 1 => [
'financial_type' => 1,
'total_amount' => $this->formatMoneyInput(1500.15),
'receive_date' => '2013-07-24',
'payment_instrument' => 1,
'check_number' => NULL,
'contribution_status_id' => 1,
- ),
- 2 => array(
+ ],
+ 2 => [
'financial_type' => 1,
'total_amount' => $this->formatMoneyInput(1500.15),
'receive_date' => '2013-07-24',
'payment_instrument' => 1,
'check_number' => NULL,
'contribution_status_id' => 1,
- ),
- ),
+ ],
+ ],
'actualBatchTotal' => $this->formatMoneyInput(3000.30),
- );
+ ];
}
}
* Test that one (ane only one) role (option value) is deleted by the updateCiviACLRole function
*/
public function testACLRoleDeleteFunctionality() {
- $optionGroup = civicrm_api('OptionGroup', 'Get', array(
+ $optionGroup = civicrm_api('OptionGroup', 'Get', [
'version' => 3,
'name' => 'acl_role',
'api.OptionValue.Create' =>
- array(
- array(
+ [
+ [
'label' => 'OG',
'value' => 5,
'description' => 'OG Sync Group ACL :1967:',
- ),
- array(
+ ],
+ [
'label' => 'OG2',
'value' => 6,
'description' => 'OG Sync Group ACL :1969:',
- ),
- ),
- ));
- $getOptionGroupParams = array('version' => 3, 'option_group_id' => $optionGroup['id']);
+ ],
+ ],
+ ]);
+ $getOptionGroupParams = ['version' => 3, 'option_group_id' => $optionGroup['id']];
$originalCount = civicrm_api('OptionValue', 'GetCount', $getOptionGroupParams);
- $params = array('source' => 'OG Sync Group ACL :1969:');
+ $params = ['source' => 'OG Sync Group ACL :1969:'];
// this is the function we are testing
CRM_Bridge_OG_Drupal::updateCiviACLRole($params, 'delete');
$this->assertEquals(1, $originalCount - $newCount);
//clean up
- civicrm_api('OptionValue', 'Get', array('version' => 3, 'label' => 'OG', 'api.option_value.delete'));
- civicrm_api('OptionValue', 'Get', array('version' => 3, 'label' => 'OG2', 'api.option_value.delete'));
+ civicrm_api('OptionValue', 'Get', ['version' => 3, 'label' => 'OG', 'api.option_value.delete']);
+ civicrm_api('OptionValue', 'Get', ['version' => 3, 'label' => 'OG2', 'api.option_value.delete']);
}
}
public function setUp() {
parent::setUp();
- $this->tablesToTruncate = array(
+ $this->tablesToTruncate = [
'civicrm_activity',
'civicrm_contact',
'civicrm_custom_group',
'civicrm_managed',
'civicrm_relationship',
'civicrm_relationship_type',
- );
+ ];
$this->quickCleanup($this->tablesToTruncate);
}
public function testAddCaseToContact() {
- $params = array(
+ $params = [
'case_id' => 1,
'contact_id' => 17,
- );
+ ];
CRM_Case_BAO_CaseContact::create($params);
$recent = CRM_Utils_Recent::get();
// backwards compatibility - but it's more typical that the creator is a different person than the client
$loggedInUser = $clientId;
}
- $caseParams = array(
+ $caseParams = [
'activity_subject' => 'Case Subject',
'client_id' => $clientId,
'case_type_id' => 1,
'start_date_time' => date("YmdHis"),
'medium_id' => 2,
'activity_details' => '',
- );
+ ];
$form = new CRM_Case_Form_Case();
$caseObj = $form->testSubmit($caseParams, "OpenCase", $loggedInUser, "standalone");
return $caseObj;
'contact_type_b' => 'Individual',
]);
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
'contact_id_a' => $contactIdA,
'contact_id_b' => $contactIdB,
'relationship_type_id' => $relationshipType,
'case_id' => $caseId,
'is_active' => $isActive,
- ));
+ ]);
}
/**
*/
private function assertCasesOfUser($loggedInUser, $caseId, $caseCount) {
$summary = CRM_Case_BAO_Case::getCasesSummary(FALSE);
- $upcomingCases = CRM_Case_BAO_Case::getCases(FALSE, array(), 'dashboard', TRUE);
+ $upcomingCases = CRM_Case_BAO_Case::getCases(FALSE, [], 'dashboard', TRUE);
$caseRoles = CRM_Case_BAO_Case::getCaseRoles($loggedInUser, $caseId);
$this->assertEquals($caseCount, $upcomingCases, 'Upcoming case count must be ' . $caseCount);
public function testRetrieveCaseIdsByContactId() {
$caseIds = CRM_Case_BAO_Case::retrieveCaseIdsByContactId(3, FALSE, 'housing_support');
- $this->assertEquals(array(1), $caseIds);
+ $this->assertEquals([1], $caseIds);
}
/**
$this->assertTrue(CRM_Case_BAO_CaseType::isForkable($caseTypeId));
$this->assertFalse(CRM_Case_BAO_CaseType::isForked($caseTypeId));
- $this->callAPISuccess('CaseType', 'create', array(
+ $this->callAPISuccess('CaseType', 'create', [
'id' => $caseTypeId,
- 'definition' => array(
- 'activityTypes' => array(
- array('name' => 'First act'),
- array('name' => 'Second act'),
- ),
- ),
- ));
+ 'definition' => [
+ 'activityTypes' => [
+ ['name' => 'First act'],
+ ['name' => 'Second act'],
+ ],
+ ],
+ ]);
$this->assertTrue(CRM_Case_BAO_CaseType::isForkable($caseTypeId));
$this->assertTrue(CRM_Case_BAO_CaseType::isForked($caseTypeId));
$this->assertDBNotNull('CRM_Case_BAO_CaseType', $caseTypeId, 'definition', 'id', "Should not have DB-based definition");
- $this->callAPISuccess('CaseType', 'create', array(
+ $this->callAPISuccess('CaseType', 'create', [
'id' => $caseTypeId,
'definition' => 'null',
- ));
+ ]);
$this->assertDBNull('CRM_Case_BAO_CaseType', $caseTypeId, 'definition', 'id', "Should not have DB-based definition");
$this->assertTrue(CRM_Case_BAO_CaseType::isForkable($caseTypeId));
$this->assertFalse(CRM_Case_BAO_CaseType::isForkable($caseTypeId));
$this->assertFalse(CRM_Case_BAO_CaseType::isForked($caseTypeId));
- $this->callAPISuccess('CaseType', 'create', array(
+ $this->callAPISuccess('CaseType', 'create', [
'id' => $caseTypeId,
- 'definition' => array(
- 'activityTypes' => array(
- array('name' => 'First act'),
- array('name' => 'Second act'),
- ),
- ),
- ));
+ 'definition' => [
+ 'activityTypes' => [
+ ['name' => 'First act'],
+ ['name' => 'Second act'],
+ ],
+ ],
+ ]);
$this->assertFalse(CRM_Case_BAO_CaseType::isForkable($caseTypeId));
$this->assertFalse(CRM_Case_BAO_CaseType::isForked($caseTypeId));
* @see \CRM_Utils_Hook::caseTypes
*/
public function hook_caseTypes(&$caseTypes) {
- $caseTypes['ForkableCaseType'] = array(
+ $caseTypes['ForkableCaseType'] = [
'module' => 'civicrm',
'name' => 'ForkableCaseType',
'file' => __DIR__ . '/ForkableCaseType.xml',
- );
- $caseTypes['UnforkableCaseType'] = array(
+ ];
+ $caseTypes['UnforkableCaseType'] = [
'module' => 'civicrm',
'name' => 'UnforkableCaseType',
'file' => __DIR__ . '/UnforkableCaseType.xml',
- );
+ ];
}
}
* @return array
*/
public function definitionProvider() {
- $fixtures['empty-defn'] = array(
- 'json' => json_encode(array()),
+ $fixtures['empty-defn'] = [
+ 'json' => json_encode([]),
'xml' => file_get_contents(__DIR__ . '/xml/empty-defn.xml'),
- );
+ ];
- $fixtures['empty-lists'] = array(
- 'json' => json_encode(array(
- 'activitySets' => array(),
- 'activityTypes' => array(),
- 'caseRoles' => array(),
- 'timelineActivityTypes' => array(),
- )),
+ $fixtures['empty-lists'] = [
+ 'json' => json_encode([
+ 'activitySets' => [],
+ 'activityTypes' => [],
+ 'caseRoles' => [],
+ 'timelineActivityTypes' => [],
+ ]),
'xml' => file_get_contents(__DIR__ . '/xml/empty-lists.xml'),
- );
+ ];
- $fixtures['one-item-in-each'] = array(
- 'json' => json_encode(array(
- 'activityTypes' => array(
- array('name' => 'First act (foréign éxamplé, &c)'),
- ),
- 'activitySets' => array(
- array(
+ $fixtures['one-item-in-each'] = [
+ 'json' => json_encode([
+ 'activityTypes' => [
+ ['name' => 'First act (foréign éxamplé, &c)'],
+ ],
+ 'activitySets' => [
+ [
'name' => 'set1',
'label' => 'Label 1',
'timeline' => 1,
- 'activityTypes' => array(
- array('name' => 'Open Case', 'status' => 'Completed'),
- ),
- ),
- ),
- 'timelineActivityTypes' => array(
- array('name' => 'Open Case', 'status' => 'Completed'),
- ),
- 'caseRoles' => array(
- array('name' => 'First role', 'creator' => 1, 'manager' => 1),
- ),
- )),
+ 'activityTypes' => [
+ ['name' => 'Open Case', 'status' => 'Completed'],
+ ],
+ ],
+ ],
+ 'timelineActivityTypes' => [
+ ['name' => 'Open Case', 'status' => 'Completed'],
+ ],
+ 'caseRoles' => [
+ ['name' => 'First role', 'creator' => 1, 'manager' => 1],
+ ],
+ ]),
'xml' => file_get_contents(__DIR__ . '/xml/one-item-in-each.xml'),
- );
+ ];
- $fixtures['two-items-in-each'] = array(
- 'json' => json_encode(array(
- 'activityTypes' => array(
- array('name' => 'First act'),
- array('name' => 'Second act'),
- ),
- 'activitySets' => array(
- array(
+ $fixtures['two-items-in-each'] = [
+ 'json' => json_encode([
+ 'activityTypes' => [
+ ['name' => 'First act'],
+ ['name' => 'Second act'],
+ ],
+ 'activitySets' => [
+ [
'name' => 'set1',
'label' => 'Label 1',
'timeline' => 1,
- 'activityTypes' => array(
- array('name' => 'Open Case', 'status' => 'Completed'),
- array(
+ 'activityTypes' => [
+ ['name' => 'Open Case', 'status' => 'Completed'],
+ [
'name' => 'Meeting',
'reference_activity' => 'Open Case',
'reference_offset' => 1,
'reference_select' => 'newest',
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ [
'name' => 'set2',
'label' => 'Label 2',
'sequence' => 1,
- 'activityTypes' => array(
- array('name' => 'First act'),
- array('name' => 'Second act'),
- ),
- ),
- ),
- 'timelineActivityTypes' => array(
- array('name' => 'Open Case', 'status' => 'Completed'),
- array(
+ 'activityTypes' => [
+ ['name' => 'First act'],
+ ['name' => 'Second act'],
+ ],
+ ],
+ ],
+ 'timelineActivityTypes' => [
+ ['name' => 'Open Case', 'status' => 'Completed'],
+ [
'name' => 'Meeting',
'reference_activity' => 'Open Case',
'reference_offset' => 1,
'reference_select' => 'newest',
- ),
- ),
- 'caseRoles' => array(
- array('name' => 'First role', 'creator' => 1, 'manager' => 1),
- array('name' => 'Second role'),
- ),
- )),
+ ],
+ ],
+ 'caseRoles' => [
+ ['name' => 'First role', 'creator' => 1, 'manager' => 1],
+ ['name' => 'Second role'],
+ ],
+ ]),
'xml' => file_get_contents(__DIR__ . '/xml/two-items-in-each.xml'),
- );
+ ];
- $fixtures['forkable-0'] = array(
- 'json' => json_encode(array(
+ $fixtures['forkable-0'] = [
+ 'json' => json_encode([
'forkable' => 0,
- )),
+ ]),
'xml' => file_get_contents(__DIR__ . '/xml/forkable-0.xml'),
- );
+ ];
- $fixtures['forkable-1'] = array(
- 'json' => json_encode(array(
+ $fixtures['forkable-1'] = [
+ 'json' => json_encode([
'forkable' => 1,
- )),
+ ]),
'xml' => file_get_contents(__DIR__ . '/xml/forkable-1.xml'),
- );
+ ];
- $cases = array();
- foreach (array(
+ $cases = [];
+ foreach ([
'empty-defn',
'empty-lists',
'one-item-in-each',
'two-items-in-each',
'forkable-0',
'forkable-1',
- ) as $key) {
- $cases[] = array($key, $fixtures[$key]['json'], $fixtures[$key]['xml']);
+ ] as $key) {
+ $cases[] = [$key, $fixtures[$key]['json'], $fixtures[$key]['xml']];
}
return $cases;
}
* - case_activity_medium_id
*/
public function testWhereClauseSingle() {
- $params = array(
- 0 => array(
+ $params = [
+ 0 => [
0 => 'case_recent_activity_type',
1 => '=',
2 => 6,
3 => 1,
4 => 0,
- ),
- 1 => array(
+ ],
+ 1 => [
0 => 'case_activity_status_id',
1 => '=',
2 => 1,
3 => 1,
4 => 0,
- ),
- 2 => array(
+ ],
+ 2 => [
0 => 'case_activity_medium_id',
1 => '=',
2 => 1,
3 => 1,
4 => 0,
- ),
- );
+ ],
+ ];
$queryObj = new CRM_Contact_BAO_Query($params, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CASE);
$this->assertEquals(
- array(
+ [
0 => 'Activity Type = Contribution',
1 => 'Activity Type = Scheduled',
2 => 'Activity Medium = In Person',
- ),
+ ],
$queryObj->_qill[1]
);
}
public function testCaseType() {
CRM_Core_PseudoConstant::flush();
$caseTypes = CRM_Case_PseudoConstant::caseType();
- $expectedTypes = array(
+ $expectedTypes = [
1 => 'Housing Support',
2 => 'Adult Day Care Referral',
- );
+ ];
$this->assertEquals($expectedTypes, $caseTypes);
}
* @group headless
*/
class CRM_Case_XMLRepositoryTest extends CiviUnitTestCase {
- protected $fixtures = array();
+ protected $fixtures = [];
protected function setUp() {
parent::setUp();
public function testGetAllDeclaredActivityTypes() {
$repo = new CRM_Case_XMLRepository(
- array('CaseTypeWithTwoActivityTypes', 'CaseTypeWithThreeActivityTypes'),
- array(
+ ['CaseTypeWithTwoActivityTypes', 'CaseTypeWithThreeActivityTypes'],
+ [
'CaseTypeWithTwoActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoActivityTypes']),
'CaseTypeWithThreeActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeActivityTypes']),
/* healthful noise: */
'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']),
- )
+ ]
);
// omitted: 'Single Activity Type'
- $expected = array('First Activity Type', 'Second Activity Type', 'Third Activity Type');
+ $expected = ['First Activity Type', 'Second Activity Type', 'Third Activity Type'];
$actual = $repo->getAllDeclaredActivityTypes();
$this->assertEquals($expected, $actual);
}
public function testGetAllDeclaredRelationshipTypes() {
$repo = new CRM_Case_XMLRepository(
- array('CaseTypeWithTwoRoles', 'CaseTypeWithThreeRoles', 'CaseTypeWithSingleActivityType'),
- array(
+ ['CaseTypeWithTwoRoles', 'CaseTypeWithThreeRoles', 'CaseTypeWithSingleActivityType'],
+ [
'CaseTypeWithTwoRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoRoles']),
'CaseTypeWithThreeRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeRoles']),
/* healthful noise: */
'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']),
- )
+ ]
);
// omitted: 'Single Role'
- $expected = array('First Role', 'Second Role', 'Third Role');
+ $expected = ['First Role', 'Second Role', 'Third Role'];
$actual = $repo->getAllDeclaredRelationshipTypes();
$this->assertEquals($expected, $actual);
}
public function testGetActivityReferenceCount_1() {
$repo = new CRM_Case_XMLRepository(
- array('CaseTypeWithSingleActivityType'),
- array(
+ ['CaseTypeWithSingleActivityType'],
+ [
'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']),
/* healthful noise: */
'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']),
- )
+ ]
);
$this->assertEquals(1, $repo->getActivityReferenceCount('Single Activity Type'));
public function testGetActivityReferenceCount_23() {
$repo = new CRM_Case_XMLRepository(
- array('CaseTypeWithTwoActivityTypes', 'CaseTypeWithThreeActivityTypes'),
- array(
+ ['CaseTypeWithTwoActivityTypes', 'CaseTypeWithThreeActivityTypes'],
+ [
'CaseTypeWithTwoActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoActivityTypes']),
'CaseTypeWithThreeActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeActivityTypes']),
/* noise: */
'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']),
- )
+ ]
);
$this->assertEquals(0, $repo->getActivityReferenceCount('Single Activity Type'));
public function testGetRoleReferenceCount_1() {
$repo = new CRM_Case_XMLRepository(
- array('CaseTypeWithSingleRole', 'CaseTypeWithSingleActivityType'),
- array(
+ ['CaseTypeWithSingleRole', 'CaseTypeWithSingleActivityType'],
+ [
'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']),
/* healthful noise: */
'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']),
- )
+ ]
);
$this->assertEquals(1, $repo->getRelationshipReferenceCount('Single Role'));
public function testGetRoleReferenceCount_23() {
$repo = new CRM_Case_XMLRepository(
- array('CaseTypeWithTwoRoles', 'CaseTypeWithThreeRoles', 'CaseTypeWithSingleActivityType'),
- array(
+ ['CaseTypeWithTwoRoles', 'CaseTypeWithThreeRoles', 'CaseTypeWithSingleActivityType'],
+ [
'CaseTypeWithTwoRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoRoles']),
'CaseTypeWithThreeRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeRoles']),
/* healthful noise: */
'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']),
- )
+ ]
);
$this->assertEquals(0, $repo->getRelationshipReferenceCount('Single Role'));
* test with empty params.
*/
public function testAddWithEmptyParams() {
- $params = array();
+ $params = [];
$contact = CRM_Contact_BAO_Contact::add($params);
// Now check Contact object.
public function testAddWithNames() {
$firstName = 'Shane';
$lastName = 'Whatson';
- $params = array(
+ $params = [
'first_name' => $firstName,
'last_name' => $lastName,
'contact_type' => 'Individual',
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
// Update and change first name and last name, using add( ).
$firstName = 'Jane';
- $params = array(
+ $params = [
'first_name' => $firstName,
'contact_type' => 'Individual',
'contact_id' => $contactId,
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR,
$contact->preferred_communication_method
);
- $checkPrefComm = array();
+ $checkPrefComm = [];
foreach ($dbPrefComm as $key => $value) {
if ($value) {
$checkPrefComm[$value] = 1;
}
$this->assertAttributesEquals($checkPrefComm, $prefComm);
- $updateParams = array(
+ $updateParams = [
'contact_type' => 'Individual',
'first_name' => 'Jane',
'middle_name' => 'abc',
'job_title' => 'software Developer',
'gender_id' => 1,
'is_deceased' => 1,
- 'website' => array(
- 1 => array(
+ 'website' => [
+ 1 => [
'website_type_id' => 1,
'url' => 'http://docs.civicrm.org',
- ),
- ),
+ ],
+ ],
'contact_source' => 'test update contact',
'external_identifier' => 111111111,
'preferred_mail_format' => 'Both',
'is_opt_out' => 0,
'deceased_date' => '1981-03-03',
'birth_date' => '1951-04-04',
- 'privacy' => array(
+ 'privacy' => [
'do_not_phone' => 0,
'do_not_email' => 0,
'do_not_mail' => 0,
'do_not_trade' => 0,
- ),
- 'preferred_communication_method' => array(
+ ],
+ 'preferred_communication_method' => [
'1' => 0,
'2' => 1,
'3' => 0,
'4' => 1,
'5' => 0,
- ),
- );
+ ],
+ ];
$prefComm = $updateParams['preferred_communication_method'];
$updateParams['contact_id'] = $contactId;
$dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR,
$contact->preferred_communication_method
);
- $checkPrefComm = array();
+ $checkPrefComm = [];
foreach ($dbPrefComm as $key => $value) {
if ($value) {
$checkPrefComm[$value] = 1;
public function testAddWithAllContactTypes() {
$firstName = 'Bill';
$lastName = 'Adams';
- $params = array(
+ $params = [
'first_name' => $firstName,
'last_name' => $lastName,
'contact_type' => 'Individual',
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$this->assertEquals($firstName, $contact->first_name, 'Check for first name creation.');
//update and change first name and last name, using create()
$firstName = 'Joan';
- $params = array(
+ $params = [
'first_name' => $firstName,
'contact_type' => 'Individual',
'contact_id' => $contactId,
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$this->assertEquals($firstName, $contact->first_name, 'Check for updated first name.');
$this->contactDelete($contactId);
$householdName = 'Adams house';
- $params = array(
+ $params = [
'household_name' => $householdName,
'contact_type' => 'Household',
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$this->assertEquals($householdName, $contact->sort_name, 'Check for created household.');
$contactId = $contact->id;
//update and change name of household, using create
$householdName = 'Joans home';
- $params = array(
+ $params = [
'household_name' => $householdName,
'contact_type' => 'Household',
'contact_id' => $contactId,
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$this->assertEquals($householdName, $contact->sort_name, 'Check for updated household.');
$this->contactDelete($contactId);
$organizationName = 'My Organization';
- $params = array(
+ $params = [
'organization_name' => $organizationName,
'contact_type' => 'Organization',
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$this->assertEquals($organizationName, $contact->sort_name, 'Check for created organization.');
$contactId = $contact->id;
//update and change name of organization, using create
$organizationName = 'Your Changed Organization';
- $params = array(
+ $params = [
'organization_name' => $organizationName,
'contact_type' => 'Organization',
'contact_id' => $contactId,
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$this->assertEquals($organizationName, $contact->sort_name, 'Check for updated organization.');
$this->contactDelete($contactId);
* Test with missing params.
*/
public function testCreateWithEmptyParams() {
- $params = array(
+ $params = [
'first_name' => 'Bill',
'last_name' => 'Adams',
- );
+ ];
$contact = CRM_Contact_BAO_Contact::create($params);
//Now check Contact object
$this->assertEquals($params['contact_type'], $contact->contact_type, 'Check for contact type creation.');
//Now check DB for Address
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'street_address' => CRM_Utils_Array::value('street_address', $params['address'][1]),
'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1',
$params['address'][1]
),
'geo_code_1' => CRM_Utils_Array::value('geo_code_1', $params['address'][1]),
'geo_code_2' => CRM_Utils_Array::value('geo_code_2', $params['address'][1]),
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
//Now check DB for Email
- $compareParams = array('email' => CRM_Utils_Array::value('email', $params['email'][1]));
+ $compareParams = ['email' => CRM_Utils_Array::value('email', $params['email'][1])];
$this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
//Now check DB for openid
- $compareParams = array('openid' => CRM_Utils_Array::value('openid', $params['openid'][1]));
+ $compareParams = ['openid' => CRM_Utils_Array::value('openid', $params['openid'][1])];
$this->assertDBCompareValues('CRM_Core_DAO_OpenID', $searchParams, $compareParams);
//Now check DB for IM
- $compareParams = array(
+ $compareParams = [
'name' => CRM_Utils_Array::value('name', $params['im'][1]),
'provider_id' => CRM_Utils_Array::value('provider_id', $params['im'][1]),
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams);
//Now check DB for Phone
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][1]),
- );
- $compareParams = array('phone' => CRM_Utils_Array::value('phone', $params['phone'][1]));
+ ];
+ $compareParams = ['phone' => CRM_Utils_Array::value('phone', $params['phone'][1])];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
//Now check DB for Mobile
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][2]),
- );
- $compareParams = array('phone' => CRM_Utils_Array::value('phone', $params['phone'][2]));
+ ];
+ $compareParams = ['phone' => CRM_Utils_Array::value('phone', $params['phone'][2])];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
//Now check DB for Note
- $searchParams = array(
+ $searchParams = [
'entity_id' => $contactId,
'entity_table' => 'civicrm_contact',
- );
- $compareParams = array('note' => $params['note']);
+ ];
+ $compareParams = ['note' => $params['note']];
$this->assertDBCompareValues('CRM_Core_DAO_Note', $searchParams, $compareParams);
//update the contact.
- $updateParams = array(
+ $updateParams = [
'first_name' => 'John',
'last_name' => 'Doe',
'contact_type' => 'Individual',
'note' => 'new test note',
- );
- $updateParams['address'][1] = array(
+ ];
+ $updateParams['address'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
'street_address' => 'Oberoi Garden',
'state_province_id' => 1004,
'geo_code_1' => '31.694842',
'geo_code_2' => '-106.29998',
- );
- $updateParams['email'][1] = array(
+ ];
+ $updateParams['email'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
'email' => 'john.doe@example.org',
- );
+ ];
- $updateParams['phone'][1] = array(
+ $updateParams['phone'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
'phone_type_id' => 1,
'phone' => '02115245336',
- );
- $updateParams['phone'][2] = array(
+ ];
+ $updateParams['phone'][2] = [
'location_type_id' => 1,
'phone_type_id' => 2,
'phone' => '9766323895',
- );
+ ];
$updateParams['contact_id'] = $contactId;
//create the contact with given params.
$this->assertEquals($updateParams['contact_type'], $contact->contact_type, 'Check for contact type creation.');
//Now check DB for updated Address
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'street_address' => 'Oberoi Garden',
'supplemental_address_1' => 'A-wing:3037',
'supplemental_address_2' => 'Andhery',
'state_province_id' => 1004,
'geo_code_1' => '31.694842',
'geo_code_2' => '-106.29998',
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
//Now check DB for updated Email
- $compareParams = array('email' => 'john.doe@example.org');
+ $compareParams = ['email' => 'john.doe@example.org'];
$this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
//Now check DB for updated Phone
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
'phone_type_id' => 1,
- );
- $compareParams = array('phone' => '02115245336');
+ ];
+ $compareParams = ['phone' => '02115245336'];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
//Now check DB for updated Mobile
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'phone_type_id' => 2,
- );
- $compareParams = array('phone' => '9766323895');
+ ];
+ $compareParams = ['phone' => '9766323895'];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
// As we are not updating note.
// Now check DB for New Note.
// Cleanup DB by deleting the contact.
$this->contactDelete($contactId);
- $this->quickCleanup(array('civicrm_contact', 'civicrm_note'));
+ $this->quickCleanup(['civicrm_contact', 'civicrm_note']);
}
/**
* Test all pseudoConstant, stateProvince, country.
*/
public function testResolveDefaults() {
- $params = array(
+ $params = [
'prefix_id' => 3,
'suffix_id' => 2,
'gender_id' => 2,
'birth_date' => '1983-12-13',
- );
+ ];
- $params['address'][1] = array(
+ $params['address'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
'country_id' => 1228,
'state_province_id' => 1004,
- );
+ ];
// @todo - we are testing this with $reverse = FALSE but it is never called that way!
CRM_Contact_BAO_Contact::resolveDefaults($params);
$this->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object');
$contactId = $contact->id;
//create the organization contact with the given params.
- $orgParams = array(
+ $orgParams = [
'organization_name' => 'Test Organization ' . substr(sha1(rand()), 0, 4),
'contact_type' => 'Organization',
- );
+ ];
$orgContact = CRM_Contact_BAO_Contact::add($orgParams);
$this->assertInstanceOf('CRM_Contact_DAO_Contact', $orgContact, 'Check for created object');
CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contactId, $orgContact->id);
//retrieve the contact values from database.
- $values = array();
- $searchParams = array('contact_id' => $contactId);
+ $values = [];
+ $searchParams = ['contact_id' => $contactId];
$retrieveContact = CRM_Contact_BAO_Contact::retrieve($searchParams, $values);
//Now check $retrieveContact is object of contact DAO..
//cleanup DB by deleting the contact
$this->contactDelete($contactId);
- $this->quickCleanup(array('civicrm_contact'));
+ $this->quickCleanup(['civicrm_contact']);
}
/**
$contactParams = $this->contactParams();
$customGroup = $this->customGroupCreate();
- $fields = array(
+ $fields = [
'label' => 'testFld',
'data_type' => 'String',
'html_type' => 'Text',
'custom_group_id' => $customGroup['id'],
- );
+ ];
$customField = CRM_Core_BAO_CustomField::create($fields);
- $contactParams['custom'] = array(
- $customField->id => array(
- -1 => array(
+ $contactParams['custom'] = [
+ $customField->id => [
+ -1 => [
'value' => 'Test custom value',
'type' => 'String',
'custom_field_id' => $customField->id,
'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
'column_name' => $customField->column_name,
'file_id' => NULL,
- ),
- ),
- );
+ ],
+ ],
+ ];
//create contact
$contact = CRM_Contact_BAO_Contact::create($contactParams);
);
// Check that the custom field value is no longer present
- $params = array(
+ $params = [
'entityID' => $contactId,
'custom_' . $customField->id => 1,
- );
+ ];
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals(CRM_Utils_Array::value("custom_" . $customField->id, $values), '',
'Verify that the data value is empty for contact ' . $contactId
$this->assertDBNull('CRM_Contact_DAO_Contact', $contactId,
'id', 'sort_name', 'Database check, contact deleted successfully.'
);
- $this->quickCleanup(array('civicrm_contact', 'civicrm_note'));
+ $this->quickCleanup(['civicrm_contact', 'civicrm_note']);
$this->customGroupDelete($customGroup['id']);
}
$fields = CRM_Contact_BAO_Contact::exportableFields('Individual');
//current employer field for individual
- $fields['organization_name'] = array(
+ $fields['organization_name'] = [
'name' => 'organization_name',
'where' => 'civicrm_organization.organization_name',
'title' => 'Current Employer',
- );
+ ];
//get the common params
$contactParams = $this->contactParams();
- $unsetParams = array('location', 'privacy');
+ $unsetParams = ['location', 'privacy'];
foreach ($unsetParams as $param) {
unset($contactParams[$param]);
}
- $profileParams = array(
+ $profileParams = [
'organization_name' => 'Yahoo',
'gender_id' => '2',
'prefix_id' => '3',
'user_unique_id' => '123456789',
'is_bulkmail' => '1',
'world_region' => 'India',
- 'tag' => array(
+ 'tag' => [
'3' => '1',
'4' => '1',
'1' => '1',
- ),
- );
+ ],
+ ];
$createParams = array_merge($contactParams, $profileParams);
//create the contact using create profile contact.
$dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR,
CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'preferred_communication_method', 'id', TRUE)
);
- $checkPrefComm = array();
+ $checkPrefComm = [];
foreach ($dbPrefComm as $key => $value) {
if ($value) {
$checkPrefComm[$value] = 1;
$this->assertAttributesEquals($checkPrefComm, $params['preferred_communication_method']);
//Now check DB for Address
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'street_address' => CRM_Utils_Array::value('street_address-Primary', $profileParams),
'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1-Primary', $profileParams),
'supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2-Primary', $profileParams),
'state_province_id' => CRM_Utils_Array::value('state_province-Primary', $profileParams),
'geo_code_1' => CRM_Utils_Array::value('geo_code_1-Primary', $profileParams),
'geo_code_2' => CRM_Utils_Array::value('geo_code_2-Primary', $profileParams),
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
//Now check DB for Email
- $compareParams = array('email' => CRM_Utils_Array::value('email-Primary', $profileParams));
+ $compareParams = ['email' => CRM_Utils_Array::value('email-Primary', $profileParams)];
$this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
//Now check DB for IM
- $compareParams = array(
+ $compareParams = [
'name' => CRM_Utils_Array::value('im-Primary', $profileParams),
'provider_id' => CRM_Utils_Array::value('im-Primary-provider_id', $profileParams),
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams);
//Now check DB for Phone
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-1', $profileParams));
+ ];
+ $compareParams = ['phone' => CRM_Utils_Array::value('phone-Primary-1', $profileParams)];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
//Now check DB for Mobile
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][2]),
- );
- $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-2', $profileParams));
+ ];
+ $compareParams = ['phone' => CRM_Utils_Array::value('phone-Primary-2', $profileParams)];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
//get the value of relationship
- $values = array();
- $searchParams = array('contact_id' => $contactId);
+ $values = [];
+ $searchParams = ['contact_id' => $contactId];
$relationship = CRM_Contact_BAO_Relationship::getValues($searchParams, $values);
//Now check values of Relationship Count.
$this->assertEquals(0, $values['relationship']['totalCount'], 'Check for total relationship count');
$this->assertAttributesEquals($profileParams['tag'], $tagIds);
//update Contact mode
- $updateCParams = array(
+ $updateCParams = [
'first_name' => 'john',
'last_name' => 'doe',
'contact_type' => 'Individual',
'job_title' => 'software Developer',
'gender_id' => 1,
'is_deceased' => 1,
- 'website' => array(
- 1 => array(
+ 'website' => [
+ 1 => [
'website_type_id' => 1,
'url' => 'http://civicrmUpdate.org',
- ),
- ),
+ ],
+ ],
'contact_source' => 'test contact',
'external_identifier' => 111222333,
'preferred_mail_format' => 'Both',
'image_URL' => 'http://imageupdate.com',
'deceased_date' => '1981-10-10',
'birth_date' => '1951-11-11',
- 'privacy' => array(
+ 'privacy' => [
'do_not_phone' => 1,
'do_not_email' => 1,
- ),
- 'preferred_communication_method' => array(
+ ],
+ 'preferred_communication_method' => [
'1' => 0,
'2' => 1,
'3' => 0,
'4' => 1,
'5' => 0,
- ),
- );
+ ],
+ ];
- $updatePfParams = array(
+ $updatePfParams = [
'organization_name' => 'Google',
'city-Primary' => 'Mumbai',
'contact_type' => 'Individual',
'user_unique_id' => '1122334455',
'is_bulkmail' => '1',
'world_region' => 'India',
- 'tag' => array(
+ 'tag' => [
'2' => '1',
'5' => '1',
- ),
- );
+ ],
+ ];
$createParams = array_merge($updateCParams, $updatePfParams);
$dbPrefComm = explode(CRM_Core_DAO::VALUE_SEPARATOR,
CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'preferred_communication_method', 'id', TRUE)
);
- $checkPrefComm = array();
+ $checkPrefComm = [];
foreach ($dbPrefComm as $key => $value) {
if ($value) {
$checkPrefComm[$value] = 1;
$this->assertAttributesEquals($checkPrefComm, $updateCParams['preferred_communication_method']);
//Now check DB for Address
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'street_address' => CRM_Utils_Array::value('street_address-Primary', $updatePfParams),
'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1-Primary', $updatePfParams),
'supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2-Primary', $updatePfParams),
'state_province_id' => CRM_Utils_Array::value('state_province-Primary', $updatePfParams),
'geo_code_1' => CRM_Utils_Array::value('geo_code_1-Primary', $updatePfParams),
'geo_code_2' => CRM_Utils_Array::value('geo_code_2-Primary', $updatePfParams),
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
//Now check DB for Email
- $compareParams = array('email' => CRM_Utils_Array::value('email-Primary', $updatePfParams));
+ $compareParams = ['email' => CRM_Utils_Array::value('email-Primary', $updatePfParams)];
$this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
//Now check DB for IM
- $compareParams = array(
+ $compareParams = [
'name' => CRM_Utils_Array::value('im-Primary', $updatePfParams),
'provider_id' => CRM_Utils_Array::value('im-Primary-provider_id', $updatePfParams),
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams);
//Now check DB for Phone
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-1', $updatePfParams));
+ ];
+ $compareParams = ['phone' => CRM_Utils_Array::value('phone-Primary-1', $updatePfParams)];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
//Now check DB for Mobile
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'phone_type_id' => CRM_Utils_Array::value('phone_type_id', $params['phone'][2]),
- );
- $compareParams = array('phone' => CRM_Utils_Array::value('phone-Primary-2', $updatePfParams));
+ ];
+ $compareParams = ['phone' => CRM_Utils_Array::value('phone-Primary-2', $updatePfParams)];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
//get the value of relationship
- $values = array();
- $searchParams = array('contact_id' => $contactId);
+ $values = [];
+ $searchParams = ['contact_id' => $contactId];
$relationship = CRM_Contact_BAO_Relationship::getValues($searchParams, $values);
//Now check values of Relationship Count.
$this->assertEquals(0, $values['relationship']['totalCount'], 'Check for total relationship count');
//get the contact details
$contactDetails = CRM_Contact_BAO_Contact::getContactDetails($contactId);
- $compareParams = array(
+ $compareParams = [
$params['first_name'] . ' ' . $params['last_name'],
CRM_Utils_Array::value('email', $params['email'][1]),
(bool ) $params['privacy']['do_not_email'],
- );
+ ];
//Now check the contact details
$this->assertAttributesEquals($compareParams, $contactDetails);
//cleanup DB by deleting the contact
$this->contactDelete($contactId);
- $this->quickCleanup(array('civicrm_contact'));
+ $this->quickCleanup(['civicrm_contact']);
}
/**
//cleanup DB by deleting the contact
$this->contactDelete($contactId);
- $this->quickCleanup(array('civicrm_contact'));
+ $this->quickCleanup(['civicrm_contact']);
}
/**
//cleanup DB by deleting the contact
$this->contactDelete($contactId);
- $this->quickCleanup(array('civicrm_contact'));
+ $this->quickCleanup(['civicrm_contact']);
}
/**
//cleanup DB by deleting the contact
$this->contactDelete($contactId);
- $this->quickCleanup(array('civicrm_contact'));
+ $this->quickCleanup(['civicrm_contact']);
}
/**
//cleanup DB by deleting the contact
$this->contactDelete($contactId);
- $this->quickCleanup(array('civicrm_contact'));
+ $this->quickCleanup(['civicrm_contact']);
}
/**
*/
private function contactParams() {
- $params = array(
+ $params = [
'first_name' => 'john',
'last_name' => 'smith',
'contact_type' => 'Individual',
'job_title' => 'software engg',
'gender_id' => 2,
'is_deceased' => 1,
- 'website' => array(
- 1 => array(
+ 'website' => [
+ 1 => [
'website_type_id' => 1,
'url' => 'http://civicrm.org',
- ),
- ),
+ ],
+ ],
'contact_source' => 'test contact',
'external_identifier' => 123456789,
'preferred_mail_format' => 'Both',
'image_URL' => 'http://image.com',
'deceased_date' => '1991-07-07',
'birth_date' => '1961-06-06',
- 'privacy' => array(
+ 'privacy' => [
'do_not_phone' => 1,
'do_not_email' => 1,
'do_not_mail' => 1,
'do_not_trade' => 1,
- ),
- 'preferred_communication_method' => array(
+ ],
+ 'preferred_communication_method' => [
'1' => 1,
'2' => 0,
'3' => 1,
'4' => 0,
'5' => 1,
- ),
- );
+ ],
+ ];
- $params['address'] = array();
- $params['address'][1] = array(
+ $params['address'] = [];
+ $params['address'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
'street_address' => 'Saint Helier St',
'state_province_id' => 1029,
'geo_code_1' => '18.219023',
'geo_code_2' => '-105.00973',
- );
+ ];
- $params['email'] = array();
- $params['email'][1] = array(
+ $params['email'] = [];
+ $params['email'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
'email' => 'john.smith@example.org',
- );
+ ];
- $params['phone'] = array();
- $params['phone'][1] = array(
+ $params['phone'] = [];
+ $params['phone'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
'phone_type_id' => 1,
'phone' => '303443689',
- );
- $params['phone'][2] = array(
+ ];
+ $params['phone'][2] = [
'location_type_id' => 1,
'phone_type_id' => 2,
'phone' => '9833910234',
- );
+ ];
- $params['openid'] = array();
- $params['openid'][1] = array(
+ $params['openid'] = [];
+ $params['openid'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
'openid' => 'http://civicrm.org/',
- );
+ ];
- $params['im'] = array();
- $params['im'][1] = array(
+ $params['im'] = [];
+ $params['im'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
'name' => 'john.smith',
'provider_id' => 1,
- );
+ ];
return $params;
}
*/
public function testTimestampContact() {
$test = $this;
- $this->_testTimestamps(array(
+ $this->_testTimestamps([
'UPDATE' => function ($contactId) use ($test) {
- $params = array(
+ $params = [
'first_name' => 'Testing',
'contact_type' => 'Individual',
'contact_id' => $contactId,
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$test->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object');
},
- ));
+ ]);
}
/**
*/
public function testTimestampsEmail() {
$test = $this;
- $this->_testTimestamps(array(
+ $this->_testTimestamps([
'INSERT' => function ($contactId) use ($test) {
- $params = array(
+ $params = [
'email' => 'ex-1@example.com',
'is_primary' => 1,
'location_type_id' => 1,
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Email::add($params);
$test->assertDBQuery('ex-1@example.com',
'SELECT email FROM civicrm_email WHERE contact_id = %1 ORDER BY id DESC LIMIT 1',
- array(1 => array($contactId, 'Integer'))
+ [1 => [$contactId, 'Integer']]
);
},
'UPDATE' => function ($contactId) use ($test) {
CRM_Core_DAO::executeQuery(
'UPDATE civicrm_email SET email = "ex-2@example.com" WHERE contact_id = %1',
- array(1 => array($contactId, 'Integer'))
+ [1 => [$contactId, 'Integer']]
);
},
'DELETE' => function ($contactId) use ($test) {
CRM_Core_DAO::executeQuery(
'DELETE FROM civicrm_email WHERE contact_id = %1',
- array(1 => array($contactId, 'Integer'))
+ [1 => [$contactId, 'Integer']]
);
},
- ));
+ ]);
}
/**
*/
public function testTimestampsPhone() {
$test = $this;
- $this->_testTimestamps(array(
+ $this->_testTimestamps([
'INSERT' => function ($contactId) use ($test) {
- $params = array(
+ $params = [
'phone' => '202-555-1000',
'is_primary' => 1,
'location_type_id' => 1,
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Phone::add($params);
$test->assertDBQuery('202-555-1000',
'SELECT phone FROM civicrm_phone WHERE contact_id = %1 ORDER BY id DESC LIMIT 1',
- array(1 => array($contactId, 'Integer'))
+ [1 => [$contactId, 'Integer']]
);
},
'UPDATE' => function ($contactId) use ($test) {
CRM_Core_DAO::executeQuery(
'UPDATE civicrm_phone SET phone = "202-555-2000" WHERE contact_id = %1',
- array(1 => array($contactId, 'Integer'))
+ [1 => [$contactId, 'Integer']]
);
},
'DELETE' => function ($contactId) use ($test) {
CRM_Core_DAO::executeQuery(
'DELETE FROM civicrm_phone WHERE contact_id = %1',
- array(1 => array($contactId, 'Integer'))
+ [1 => [$contactId, 'Integer']]
);
},
- ));
+ ]);
}
/**
public function testTimestampsCustom() {
$customGroup = $this->customGroupCreate();
$customGroup = $customGroup['values'][$customGroup['id']];
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'String',
'html_type' => 'Text',
- );
+ ];
$customField = $this->customFieldCreate($fields);
$customField = $customField['values'][$customField['id']];
$test = $this;
- $this->_testTimestamps(array(
+ $this->_testTimestamps([
'INSERT' => function ($contactId) use ($test, $customGroup, $customField) {
- civicrm_api3('contact', 'create', array(
+ civicrm_api3('contact', 'create', [
'contact_id' => $contactId,
'custom_' . $customField['id'] => 'test-1',
- ));
+ ]);
},
'UPDATE' => function ($contactId) use ($test, $customGroup, $customField) {
CRM_Core_DAO::executeQuery(
"UPDATE {$customGroup['table_name']} SET {$customField['column_name']} = 'test-2' WHERE entity_id = %1",
- array(1 => array($contactId, 'Integer'))
+ [1 => [$contactId, 'Integer']]
);
},
'DELETE' => function ($contactId) use ($test, $customGroup, $customField) {
CRM_Core_DAO::executeQuery(
"DELETE FROM {$customGroup['table_name']} WHERE entity_id = %1",
- array(1 => array($contactId, 'Integer'))
+ [1 => [$contactId, 'Integer']]
);
},
- ));
- $this->quickCleanup(array('civicrm_contact'), TRUE);
+ ]);
+ $this->quickCleanup(['civicrm_contact'], TRUE);
}
/**
public function testUpdateProfileLocationLeak() {
// create a simple contact with address and phone that share the same location type
$defaults = $this->contactParams();
- $params = array(
+ $params = [
'first_name' => $defaults['first_name'],
'last_name' => $defaults['last_name'],
'contact_type' => 'Individual',
- 'address' => array(1 => $defaults['address'][1]),
- 'phone' => array(1 => $defaults['phone'][1]),
- );
+ 'address' => [1 => $defaults['address'][1]],
+ 'phone' => [1 => $defaults['phone'][1]],
+ ];
$contact = CRM_Contact_BAO_Contact::create($params);
$contactId = $contact->id;
// now, update using a profile with phone, email, address... that share the same location type
- $updatePfParams = array(
+ $updatePfParams = [
'first_name' => $params['first_name'],
'last_name' => $params['first_name'],
'street_address-Primary' => $params['address'][1]['street_address'],
'country-Primary' => $params['address'][1]['country_id'],
'phone-Primary-1' => $params['phone'][1]['phone'],
'phone_ext-Primary-1' => '345',
- );
+ ];
//create the contact using create profile contact.
$fields = CRM_Contact_BAO_Contact::exportableFields('Individual');
$this->assertEquals($params['phone'][1]['phone'], $phone['phone']);
//check the values in DB.
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'street_address' => CRM_Utils_Array::value('street_address-Primary', $updatePfParams),
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
//cleanup DB by deleting the contact
list($group, $living, $deceased) = $this->setupSmartGroup();
// Add $n1 to $g
- $this->callAPISuccess('group_contact', 'create', array(
+ $this->callAPISuccess('group_contact', 'create', [
'contact_id' => $living[0]->id,
'group_id' => $group->id,
- ));
+ ]);
CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
$this->assertCacheMatches(
- array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id, $living[0]->id),
+ [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id, $living[0]->id],
$group->id
);
// Remove $y1 from $g
- $this->callAPISuccess('group_contact', 'create', array(
+ $this->callAPISuccess('group_contact', 'create', [
'contact_id' => $deceased[0]->id,
'group_id' => $group->id,
'status' => 'Removed',
- ));
+ ]);
CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
$this->assertCacheMatches(
- array(
+ [
$deceased[1]->id,
$deceased[2]->id,
$living[0]->id,
- ),
+ ],
$group->id
);
}
*/
public function testRemoveFromParentSmartGroup() {
// Create smart group $parent
- $params = array(
+ $params = [
'name' => 'Deceased Contacts',
'title' => 'Deceased Contacts',
'is_active' => 1,
- 'formValues' => array('is_deceased' => 1),
- );
+ 'formValues' => ['is_deceased' => 1],
+ ];
$parent = CRM_Contact_BAO_Group::createSmartGroup($params);
- $this->registerTestObjects(array($parent));
+ $this->registerTestObjects([$parent]);
// Create group $child in $parent
- $params = array(
+ $params = [
'name' => 'Child Group',
'title' => 'Child Group',
'is_active' => 1,
- 'parents' => array($parent->id => 1),
- );
+ 'parents' => [$parent->id => 1],
+ ];
$child = CRM_Contact_BAO_Group::create($params);
- $this->registerTestObjects(array($child));
+ $this->registerTestObjects([$child]);
// Create $c1, $c2, $c3
- $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 1), 3);
+ $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 1], 3);
// Add $c1, $c2, $c3 to $child
foreach ($deceased as $contact) {
- $this->callAPISuccess('group_contact', 'create', array(
+ $this->callAPISuccess('group_contact', 'create', [
'contact_id' => $contact->id,
'group_id' => $child->id,
- ));
+ ]);
}
CRM_Contact_BAO_GroupContactCache::load($parent, TRUE);
$this->assertCacheMatches(
- array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id),
+ [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id],
$parent->id
);
// Remove $c1 from $parent
- $this->callAPISuccess('group_contact', 'create', array(
+ $this->callAPISuccess('group_contact', 'create', [
'contact_id' => $deceased[0]->id,
'group_id' => $parent->id,
'status' => 'Removed',
- ));
+ ]);
// Assert $c1 not in $parent
CRM_Contact_BAO_GroupContactCache::load($parent, TRUE);
$this->assertCacheMatches(
- array(
+ [
$deceased[1]->id,
$deceased[2]->id,
- ),
+ ],
$parent->id
);
// Assert $c1 still in $child
$this->assertDBQuery(1,
'select count(*) from civicrm_group_contact where group_id=%1 and contact_id=%2 and status=%3',
- array(
- 1 => array($child->id, 'Integer'),
- 2 => array($deceased[0]->id, 'Integer'),
- 3 => array('Added', 'String'),
- )
+ [
+ 1 => [$child->id, 'Integer'],
+ 2 => [$deceased[0]->id, 'Integer'],
+ 3 => ['Added', 'String'],
+ ]
);
}
*/
public function assertCacheMatches($expectedContactIds, $groupId) {
$sql = 'SELECT contact_id FROM civicrm_group_contact_cache WHERE group_id = %1';
- $params = array(1 => array($groupId, 'Integer'));
+ $params = [1 => [$groupId, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($sql, $params);
- $actualContactIds = array();
+ $actualContactIds = [];
while ($dao->fetch()) {
$actualContactIds[] = $dao->contact_id;
}
*/
public function testOpportunisticRefreshCacheNoChangeIfNotExpired() {
list($group, $living, $deceased) = $this->setupSmartGroup();
- $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0));
+ $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->assertCacheMatches(
- array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id),
+ [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id],
$group->id
);
CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
*/
public function testOpportunisticRefreshChangeIfCacheDateFieldStale() {
list($group, $living, $deceased) = $this->setupSmartGroup();
- $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0));
+ $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
CRM_Core_DAO::executeQuery('UPDATE civicrm_group SET cache_date = DATE_SUB(NOW(), INTERVAL 7 MINUTE) WHERE id = ' . $group->id);
$group->find(TRUE);
Civi::$statics['CRM_Contact_BAO_GroupContactCache']['is_refresh_init'] = FALSE;
*/
public function testOpportunisticRefreshNoChangeWithDeterministicSetting() {
list($group, $living, $deceased) = $this->setupSmartGroup();
- $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'deterministic'));
- $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0));
+ $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'deterministic']);
+ $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->makeCacheStale($group);
CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
$this->assertCacheNotRefreshed($deceased, $group);
- $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic'));
+ $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']);
}
/**
*/
public function testDeterministicRefreshChangeWithDeterministicSetting() {
list($group, $living, $deceased) = $this->setupSmartGroup();
- $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'deterministic'));
- $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0));
+ $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'deterministic']);
+ $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->makeCacheStale($group);
CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush();
$this->assertCacheRefreshed($group);
- $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic'));
+ $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']);
}
/**
*/
public function testDeterministicRefreshChangeDoesNotTouchNonExpired() {
list($group, $living, $deceased) = $this->setupSmartGroup();
- $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'deterministic'));
- $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0));
+ $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'deterministic']);
+ $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush();
$this->assertCacheNotRefreshed($deceased, $group);
- $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic'));
+ $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']);
}
/**
*/
public function testDeterministicRefreshChangeWithOpportunisticSetting() {
list($group, $living, $deceased) = $this->setupSmartGroup();
- $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic'));
- $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0));
+ $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']);
+ $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->makeCacheStale($group);
CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush();
$this->assertCacheRefreshed($group);
*/
public function testJobWrapper() {
list($group, $living, $deceased) = $this->setupSmartGroup();
- $this->callAPISuccess('Setting', 'create', array('smart_group_cache_refresh_mode' => 'opportunistic'));
- $this->callAPISuccess('Contact', 'create', array('id' => $deceased[0]->id, 'is_deceased' => 0));
+ $this->callAPISuccess('Setting', 'create', ['smart_group_cache_refresh_mode' => 'opportunistic']);
+ $this->callAPISuccess('Contact', 'create', ['id' => $deceased[0]->id, 'is_deceased' => 0]);
$this->makeCacheStale($group);
- $this->callAPISuccess('Job', 'group_cache_flush', array());
+ $this->callAPISuccess('Job', 'group_cache_flush', []);
$this->assertCacheRefreshed($group);
}
* This method is called before a test is executed.
*/
protected function setUp() {
- $this->_testObjects = array();
+ $this->_testObjects = [];
parent::setUp();
}
*
* @return array|NULL|object
*/
- public function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE) {
+ public function createTestObject($daoName, $params = [], $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));
+ $this->registerTestObjects([$objects]);
}
return $objects;
}
public function deleteTestObjects() {
foreach ($this->_testObjects as $daoName => $daoIds) {
foreach ($daoIds as $daoId) {
- CRM_Core_DAO::deleteTestObjects($daoName, array('id' => $daoId));
+ CRM_Core_DAO::deleteTestObjects($daoName, ['id' => $daoId]);
}
}
- $this->_testObjects = array();
+ $this->_testObjects = [];
}
/**
* @return array
*/
protected function setupSmartGroup() {
- $params = array(
+ $params = [
'name' => 'Deceased Contacts',
'title' => 'Deceased Contacts',
'is_active' => 1,
- 'formValues' => array('is_deceased' => 1),
- );
+ 'formValues' => ['is_deceased' => 1],
+ ];
$group = CRM_Contact_BAO_Group::createSmartGroup($params);
- $this->registerTestObjects(array($group));
+ $this->registerTestObjects([$group]);
// Create contacts $y1, $y2, $y3 which do match $g; create $n1, $n2, $n3 which do not match $g
- $living = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 0), 3);
- $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', array('is_deceased' => 1), 3);
+ $living = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 0], 3);
+ $deceased = $this->createTestObject('CRM_Contact_DAO_Contact', ['is_deceased' => 1], 3);
$this->assertEquals(3, count($deceased));
$this->assertEquals(3, count($living));
CRM_Contact_BAO_GroupContactCache::load($group, TRUE);
$group->find(TRUE);
$this->assertCacheMatches(
- array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id),
+ [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id],
$group->id
);
// Reload the group so we have the cache_date & refresh_date.
- return array($group, $living, $deceased);
+ return [$group, $living, $deceased];
}
/**
*/
protected function assertCacheNotRefreshed($deceased, $group) {
$this->assertCacheMatches(
- array($deceased[0]->id, $deceased[1]->id, $deceased[2]->id),
+ [$deceased[0]->id, $deceased[1]->id, $deceased[2]->id],
$group->id
);
- $afterGroup = $this->callAPISuccessGetSingle('Group', array('id' => $group->id));
+ $afterGroup = $this->callAPISuccessGetSingle('Group', ['id' => $group->id]);
$this->assertEquals($group->cache_date, $afterGroup['cache_date']);
}
*/
protected function assertCacheRefreshed($group) {
$this->assertCacheMatches(
- array(),
+ [],
$group->id
);
- $afterGroup = $this->callAPISuccessGetSingle('Group', array('id' => $group->id));
+ $afterGroup = $this->callAPISuccessGetSingle('Group', ['id' => $group->id]);
$this->assertTrue(empty($afterGroup['cache_date']), 'refresh date should not be set as the cache is not built');
$this->assertTrue(empty($afterGroup['refresh_date']), 'refresh date should not be set as the cache is not built');
}
* Test Smart group search
*/
public function testSmartGroupSearchBuilder() {
- $returnProperties = array(
+ $returnProperties = [
'contact_type' => 1,
'contact_sub_type' => 1,
'sort_name' => 1,
'group' => 1,
- );
+ ];
list($group, $living, $deceased) = $this->setupSmartGroup();
- $params = array(
+ $params = [
'name' => 'Living Contacts',
'title' => 'Living Contacts',
'is_active' => 1,
- 'formValues' => array('is_deceased' => 0),
- );
+ 'formValues' => ['is_deceased' => 0],
+ ];
$group2 = CRM_Contact_BAO_Group::createSmartGroup($params);
//Filter on smart group with =, !=, IN and NOT IN operator.
- $params = array(array('group', '=', $group2->id, 1, 0));
+ $params = [['group', '=', $group2->id, 1, 0]];
$query = new CRM_Contact_BAO_Query(
$params, $returnProperties,
NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS,
$this->assertContains($expectedWhere, $query->_whereClause);
$this->_assertContactIds($query, "group_id = {$group2->id}");
- $params = array(array('group', '!=', $group->id, 1, 0));
+ $params = [['group', '!=', $group->id, 1, 0]];
$query = new CRM_Contact_BAO_Query(
$params, $returnProperties,
NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS,
$this->assertContains($expectedWhere, $query->_whereClause);
$this->_assertContactIds($query, "group_id != {$group->id}");
- $params = array(array('group', 'IN', array($group->id, $group2->id), 1, 0));
+ $params = [['group', 'IN', [$group->id, $group2->id], 1, 0]];
$query = new CRM_Contact_BAO_Query(
$params, $returnProperties,
NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS,
$this->assertContains($expectedWhere, $query->_whereClause);
$this->_assertContactIds($query, "group_id IN ({$group->id}, {$group2->id})");
- $params = array(array('group', 'NOT IN', array($group->id), 1, 0));
+ $params = [['group', 'NOT IN', [$group->id], 1, 0]];
$query = new CRM_Contact_BAO_Query(
$params, $returnProperties,
NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS,
}
public function testMultipleGroupWhereClause() {
- $returnProperties = array(
+ $returnProperties = [
'contact_type' => 1,
'contact_sub_type' => 1,
'sort_name' => 1,
'group' => 1,
- );
+ ];
list($group, $living, $deceased) = $this->setupSmartGroup();
- $params = array(
+ $params = [
'name' => 'Living Contacts',
'title' => 'Living Contacts',
'is_active' => 1,
- 'formValues' => array('is_deceased' => 0),
- );
+ 'formValues' => ['is_deceased' => 0],
+ ];
$group2 = CRM_Contact_BAO_Group::createSmartGroup($params);
//Filter on smart group with =, !=, IN and NOT IN operator.
- $params = array(array('group', '=', $group2->id, 1, 0), array('group', '=', $group->id, 1, 0));
+ $params = [['group', '=', $group2->id, 1, 0], ['group', '=', $group->id, 1, 0]];
$query = new CRM_Contact_BAO_Query(
$params, $returnProperties,
NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS,
FALSE, FALSE, FALSE,
TRUE, FALSE
));
- $expectedContactIds = array();
+ $expectedContactIds = [];
$groupDAO = CRM_Core_DAO::executeQuery("SELECT contact_id FROM civicrm_group_contact_cache WHERE {$groupWhereClause}");
while ($groupDAO->fetch()) {
$expectedContactIds[] = $groupDAO->contact_id;
*/
public function testContactSearchByParentGroup() {
// create a parent group
- $parentGroup = $this->callAPISuccess('Group', 'create', array(
+ $parentGroup = $this->callAPISuccess('Group', 'create', [
'title' => 'Parent Group',
'description' => 'Parent Group',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
- ));
+ ]);
// create a child group
- $childGroup = $this->callAPISuccess('Group', 'create', array(
+ $childGroup = $this->callAPISuccess('Group', 'create', [
'title' => 'Child Group',
'description' => 'Child Group',
'visibility' => 'User and User Admin Only',
'parents' => $parentGroup['id'],
'is_active' => 1,
- ));
+ ]);
// create smart group based on saved criteria Gender = Male
- $batch = $this->callAPISuccess('SavedSearch', 'create', array(
+ $batch = $this->callAPISuccess('SavedSearch', 'create', [
'form_values' => 'a:1:{i:0;a:5:{i:0;s:9:"gender_id";i:1;s:1:"=";i:2;i:2;i:3;i:0;i:4;i:0;}}',
- ));
+ ]);
// Create contact with Gender - Male
- $childSmartGroupContact = $this->individualCreate(array(
+ $childSmartGroupContact = $this->individualCreate([
'gender_id' => "Male",
'first_name' => 'C',
- ), 1);
+ ], 1);
// then create smart group
- $childSmartGroup = $this->callAPISuccess('Group', 'create', array(
+ $childSmartGroup = $this->callAPISuccess('Group', 'create', [
'title' => 'Child Smart Group',
'description' => 'Child Smart Group',
'visibility' => 'User and User Admin Only',
'saved_search_id' => $batch['id'],
'is_active' => 1,
'parents' => $parentGroup['id'],
- ));
+ ]);
- $this->callAPISuccess('Group', 'create', array(
+ $this->callAPISuccess('Group', 'create', [
'id' => $parentGroup['id'],
- 'children' => implode(',', array($childGroup['id'], $childSmartGroup['id'])),
- ));
+ 'children' => implode(',', [$childGroup['id'], $childSmartGroup['id']]),
+ ]);
// Create a contact within parent group
- $parentContactParams = array(
+ $parentContactParams = [
'first_name' => 'Parent1 Fname',
'last_name' => 'Parent1 Lname',
- 'group' => array($parentGroup['id'] => 1),
- );
+ 'group' => [$parentGroup['id'] => 1],
+ ];
$parentContact = $this->individualCreate($parentContactParams);
// create a contact within child dgroup
- $childContactParams = array(
+ $childContactParams = [
'first_name' => 'Child1 Fname',
'last_name' => 'Child2 Lname',
'group' => [$childGroup['id'] => 1],
- );
+ ];
$childContact = $this->individualCreate($childContactParams);
// Check if searching by parent group returns both parent and child group contacts
- $result = $this->callAPISuccess('contact', 'get', array(
+ $result = $this->callAPISuccess('contact', 'get', [
'group' => $parentGroup['id'],
- ));
- $validContactIds = array($parentContact, $childContact);
- $resultContactIds = array();
+ ]);
+ $validContactIds = [$parentContact, $childContact];
+ $resultContactIds = [];
foreach ($result['values'] as $k => $v) {
$resultContactIds[] = $v['contact_id'];
}
$this->assertEquals(3, count($resultContactIds), 'Check the count of returned values');
- $this->assertEquals(array(), array_diff($validContactIds, $resultContactIds), 'Check that the difference between two arrays should be blank array');
+ $this->assertEquals([], array_diff($validContactIds, $resultContactIds), 'Check that the difference between two arrays should be blank array');
// Check if searching by child group returns just child group contacts
- $result = $this->callAPISuccess('contact', 'get', array(
+ $result = $this->callAPISuccess('contact', 'get', [
'group' => $childGroup['id'],
- ));
- $validChildContactIds = array($childContact);
- $resultChildContactIds = array();
+ ]);
+ $validChildContactIds = [$childContact];
+ $resultChildContactIds = [];
foreach ($result['values'] as $k => $v) {
$resultChildContactIds[] = $v['contact_id'];
}
$this->assertEquals(1, count($resultChildContactIds), 'Check the count of returned values');
- $this->assertEquals(array(), array_diff($validChildContactIds, $resultChildContactIds), 'Check that the difference between two arrays should be blank array');
+ $this->assertEquals([], array_diff($validChildContactIds, $resultChildContactIds), 'Check that the difference between two arrays should be blank array');
// Check if searching by smart child group returns just smart child group contacts
- $result = $this->callAPISuccess('contact', 'get', array(
+ $result = $this->callAPISuccess('contact', 'get', [
'group' => $childSmartGroup['id'],
- ));
- $validChildContactIds = array($childSmartGroupContact);
- $resultChildContactIds = array();
+ ]);
+ $validChildContactIds = [$childSmartGroupContact];
+ $resultChildContactIds = [];
foreach ($result['values'] as $k => $v) {
$resultChildContactIds[] = $v['contact_id'];
}
$this->assertEquals(1, count($resultChildContactIds), 'Check the count of returned values');
- $this->assertEquals(array(), array_diff($validChildContactIds, $resultChildContactIds), 'Check that the difference between two arrays should be blank array');
+ $this->assertEquals([], array_diff($validChildContactIds, $resultChildContactIds), 'Check that the difference between two arrays should be blank array');
//cleanup
- $this->callAPISuccess('Contact', 'delete', array('id' => $parentContact));
- $this->callAPISuccess('Contact', 'delete', array('id' => $childContact));
- $this->callAPISuccess('Contact', 'delete', array('id' => $childSmartGroupContact));
+ $this->callAPISuccess('Contact', 'delete', ['id' => $parentContact]);
+ $this->callAPISuccess('Contact', 'delete', ['id' => $childContact]);
+ $this->callAPISuccess('Contact', 'delete', ['id' => $childSmartGroupContact]);
}
/**
*/
public function testContactCombineGroupSearch() {
// create regular group based
- $regularGroup = $this->callAPISuccess('Group', 'create', array(
+ $regularGroup = $this->callAPISuccess('Group', 'create', [
'title' => 'Regular Group',
'description' => 'Regular Group',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
- ));
+ ]);
// Create contact with Gender - Male
- $contact1 = $this->individualCreate(array(
+ $contact1 = $this->individualCreate([
'gender_id' => "Male",
'first_name' => 'A',
- ));
+ ]);
// Create contact with Gender - Male and in regular group
- $contact2 = $this->individualCreate(array(
- 'group' => array($regularGroup['id'] => 1),
+ $contact2 = $this->individualCreate([
+ 'group' => [$regularGroup['id'] => 1],
'gender_id' => "Male",
'first_name' => 'B',
- ), 1);
+ ], 1);
// Create contact with Gender - Female and in regular group
- $contact3 = $this->individualCreate(array(
- 'group' => array($regularGroup['id'] => 1),
+ $contact3 = $this->individualCreate([
+ 'group' => [$regularGroup['id'] => 1],
'gender_id' => "Female",
'first_name' => 'C',
- ), 1);
+ ], 1);
// create smart group based on saved criteria Gender = Male
- $batch = $this->callAPISuccess('SavedSearch', 'create', array(
+ $batch = $this->callAPISuccess('SavedSearch', 'create', [
'form_values' => 'a:1:{i:0;a:5:{i:0;s:9:"gender_id";i:1;s:1:"=";i:2;i:2;i:3;i:0;i:4;i:0;}}',
- ));
- $smartGroup = $this->callAPISuccess('Group', 'create', array(
+ ]);
+ $smartGroup = $this->callAPISuccess('Group', 'create', [
'title' => 'Smart Group',
'description' => 'Smart Group',
'visibility' => 'User and User Admin Only',
'saved_search_id' => $batch['id'],
'is_active' => 1,
- ));
+ ]);
- $useCases = array(
+ $useCases = [
//Case 1: Find all contacts in regular group
- array(
- 'form_value' => array('group' => $regularGroup['id']),
+ [
+ 'form_value' => ['group' => $regularGroup['id']],
'expected_count' => 2,
- 'expected_contact' => array($contact2, $contact3),
- ),
+ 'expected_contact' => [$contact2, $contact3],
+ ],
//Case 2: Find all contacts in smart group
- array(
- 'form_value' => array('group' => $smartGroup['id']),
+ [
+ 'form_value' => ['group' => $smartGroup['id']],
'expected_count' => 2,
- 'expected_contact' => array($contact1, $contact2),
- ),
+ 'expected_contact' => [$contact1, $contact2],
+ ],
//Case 3: Find all contacts in regular group and smart group
- array(
- 'form_value' => array('group' => array('IN' => array($regularGroup['id'], $smartGroup['id']))),
+ [
+ 'form_value' => ['group' => ['IN' => [$regularGroup['id'], $smartGroup['id']]]],
'expected_count' => 3,
- 'expected_contact' => array($contact1, $contact2, $contact3),
- ),
- );
+ 'expected_contact' => [$contact1, $contact2, $contact3],
+ ],
+ ];
foreach ($useCases as $case) {
$query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($case['form_value']));
list($select, $from, $where, $having) = $query->query();
$accessControlGT = array_search('Access Control', $groupTypes);
// create group with group type - Mailing list
- $group1 = $this->callAPISuccess('Group', 'create', array(
+ $group1 = $this->callAPISuccess('Group', 'create', [
'title' => 'Group 1',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
'group_type' => $mailingListGT,
- ));
+ ]);
// create group with group type - Access Control
- $group2 = $this->callAPISuccess('Group', 'create', array(
+ $group2 = $this->callAPISuccess('Group', 'create', [
'title' => 'Group 2',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
'group_type' => $accessControlGT,
- ));
+ ]);
// create contact in 'Group 1'
- $contact1 = $this->individualCreate(array(
- 'group' => array($group1['id'] => 1),
+ $contact1 = $this->individualCreate([
+ 'group' => [$group1['id'] => 1],
'first_name' => 'A',
- ));
+ ]);
// create contact in 'Group 2'
- $contact2 = $this->individualCreate(array(
- 'group' => array($group2['id'] => 1),
+ $contact2 = $this->individualCreate([
+ 'group' => [$group2['id'] => 1],
'first_name' => 'B',
- ), 1);
+ ], 1);
- $useCases = array(
+ $useCases = [
//Case 1: Find contacts in group type - Mailing List
- array(
- 'form_value' => array('group_type' => array($mailingListGT)),
+ [
+ 'form_value' => ['group_type' => [$mailingListGT]],
'expected_count' => 1,
- 'expected_contact' => array($contact1),
- ),
+ 'expected_contact' => [$contact1],
+ ],
//Case 2: Find contacts in group type - Access Control
- array(
- 'form_value' => array('group_type' => array($accessControlGT)),
+ [
+ 'form_value' => ['group_type' => [$accessControlGT]],
'expected_count' => 1,
- 'expected_contact' => array($contact2),
- ),
+ 'expected_contact' => [$contact2],
+ ],
//Case 3: Find contacts in group type - Mailing List or Access List
- array(
- 'form_value' => array('group_type' => array($mailingListGT, $accessControlGT)),
+ [
+ 'form_value' => ['group_type' => [$mailingListGT, $accessControlGT]],
'expected_count' => 2,
- 'expected_contact' => array($contact1, $contact2),
- ),
- );
+ 'expected_contact' => [$contact1, $contact2],
+ ],
+ ];
foreach ($useCases as $case) {
$query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($case['form_value']));
* This method is called after a test is executed.
*/
protected function tearDown() {
- $this->quickCleanup(array('civicrm_mapping_field', 'civicrm_mapping', 'civicrm_group', 'civicrm_saved_search'));
+ $this->quickCleanup(['civicrm_mapping_field', 'civicrm_mapping', 'civicrm_group', 'civicrm_saved_search']);
}
/**
*/
public function testAddSimple() {
- $checkParams = $params = array(
+ $checkParams = $params = [
'title' => 'Group Uno',
'description' => 'Group One',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
- );
+ ];
$group = CRM_Contact_BAO_Group::create($params);
$this->assertDBCompareValues(
'CRM_Contact_DAO_Group',
- array('id' => $group->id),
+ ['id' => $group->id],
$checkParams
);
}
// 1. Create two parent group A and B and disable B
// 2. Create a child group C
// 3. Ensure that Group C is present in the group hierarchy
- $params = array(
+ $params = [
'name' => uniqid(),
'title' => 'Parent Group A',
'description' => 'Parent Group One',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
- );
+ ];
$group1 = CRM_Contact_BAO_Group::create($params);
- $params = array_merge($params, array(
+ $params = array_merge($params, [
'name' => uniqid(),
'title' => 'Parent Group B',
'description' => 'Parent Group Two',
// disable
'is_active' => 0,
- ));
+ ]);
$group2 = CRM_Contact_BAO_Group::create($params);
- $params = array_merge($params, array(
+ $params = array_merge($params, [
'name' => uniqid(),
'title' => 'Child Group C',
'description' => 'Child Group C',
- 'parents' => array(
+ 'parents' => [
$group1->id => 1,
$group2->id => 1,
- ),
- ));
+ ],
+ ]);
$group3 = CRM_Contact_BAO_Group::create($params);
- $params = array(
+ $params = [
$group1->id => 1,
$group3->id => 1,
- );
+ ];
$groupsHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($params, NULL, ' ', TRUE);
// check if child group is present in the tree with formatted group title prepended with spacer ' '
$this->assertEquals(' Child Group C', $groupsHierarchy[$group3->id]);
*/
public function testAddSmart() {
- $checkParams = $params = array(
+ $checkParams = $params = [
'title' => 'Group Dos',
'description' => 'Group Two',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
- 'formValues' => array('sort_name' => 'Adams'),
- );
+ 'formValues' => ['sort_name' => 'Adams'],
+ ];
$group = CRM_Contact_BAO_Group::createSmartGroup($params);
unset($checkParams['formValues']);
$this->assertDBCompareValues(
'CRM_Contact_DAO_Group',
- array('id' => $group->id),
+ ['id' => $group->id],
$checkParams
);
}
$this->loadSavedSearches();
$results = CRM_Core_DAO::singleValueQuery('SELECT GROUP_CONCAT(id) FROM civicrm_group WHERE saved_search_id IS NOT NULL');
- return array(explode(',', $results));
+ return [explode(',', $results)];
}
/**
* Ensure that when updating a group with a linked organisation record even tho that record's id doesn't match the group id no db error is produced
*/
public function testGroupUpdateWithOrganization() {
- $params = array(
+ $params = [
'name' => uniqid(),
'title' => 'Group A',
'description' => 'Group One',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
- );
+ ];
$group1 = CRM_Contact_BAO_Group::create($params);
$domain1 = $this->callAPISuccess('Domain', 'get', ['id' => 1]);
- $params2 = array(
+ $params2 = [
'name' => uniqid(),
'title' => 'Group B',
'description' => 'Group Two',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
'organization_id' => $domain1['values'][1]['contact_id'],
- );
+ ];
$group2 = CRM_Contact_BAO_Group::create($params2);
$domain2 = $this->callAPISuccess('Domain', 'get', ['id' => 2]);
- $params3 = array(
+ $params3 = [
'name' => uniqid(),
'title' => 'Group C',
'description' => 'Group Three',
'visibility' => 'User and User Admin Only',
'is_active' => 1,
'organization_id' => $domain2['values'][2]['contact_id'],
- );
+ ];
$group3 = CRM_Contact_BAO_Group::create($params3);
$params2['id'] = $group2->id;
$testUpdate = CRM_Contact_BAO_Group::create($params2);
*/
public function testHiddenSmartGroup() {
$customGroup = $this->customGroupCreate();
- $fields = array(
+ $fields = [
'label' => 'testFld',
'data_type' => 'String',
'html_type' => 'Text',
'custom_group_id' => $customGroup['id'],
- );
+ ];
$customFieldID = CRM_Core_BAO_CustomField::create($fields)->id;
$contactID = $this->individualCreate(['custom_' . $customFieldID => 'abc']);
list($smartGroupID, $savedSearchID) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);
$mailingID = $this->callAPISuccess('Mailing', 'create', [])['id'];
- $this->callAPISuccess('MailingGroup', 'create', array(
+ $this->callAPISuccess('MailingGroup', 'create', [
'mailing_id' => $mailingID,
'group_type' => 'Include',
'entity_table' => 'civicrm_group',
'entity_id' => $smartGroupID,
- ));
+ ]);
CRM_Mailing_BAO_Mailing::getRecipients($mailingID);
$recipients = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $mailingID]);
* See CRM-19123: Merging contacts: blank date fields write as 1970
*/
public function testFormatNullDates() {
- $params = array(
+ $params = [
'contact_type' => 'Individual',
'birth_date' => 'null',
'deceased_date' => 'null',
- );
+ ];
$contact = new CRM_Contact_DAO_Contact();
CRM_Contact_BAO_Individual::format($params, $contact);
*/
public function testFormatDisplayName() {
- $params = array(
+ $params = [
'contact_type' => 'Individual',
'first_name' => 'Ben',
'last_name' => 'Lee',
'individual_prefix' => 'Mr.',
'individual_suffix' => 'Jr.',
- );
+ ];
$contact = new CRM_Contact_DAO_Contact();
*/
public function testFormatDisplayNamePrefixesById() {
- $params = array(
+ $params = [
'contact_type' => 'Individual',
'first_name' => 'Ben',
'last_name' => 'Lee',
'prefix_id' => 4,
// and the doctor is a senior
'suffix_id' => 2,
- );
+ ];
$contact = new CRM_Contact_DAO_Contact();
*/
public function testFormatDisplayNameNoIndividual() {
- $params = array(
+ $params = [
'contact_type' => 'Organization',
'first_name' => 'Ben',
'last_name' => 'Lee',
- );
+ ];
$contact = new CRM_Contact_DAO_Contact();
*/
public function testFormatDisplayNameOnlyEmail() {
- $email['1'] = array('email' => "bleu01@example.com");
- $email['2'] = array('email' => "bleu02@example.com", 'is_primary' => 1);
- $email['3'] = array('email' => "bleu03@example.com");
+ $email['1'] = ['email' => "bleu01@example.com"];
+ $email['2'] = ['email' => "bleu02@example.com", 'is_primary' => 1];
+ $email['3'] = ['email' => "bleu03@example.com"];
- $params = array(
+ $params = [
'contact_type' => 'Individual',
'email' => $email ,
- );
+ ];
$contact = new CRM_Contact_DAO_Contact();
public function testStateName() {
$state_name = 'Norfolk';
$state_abbreviation = 'NFK';
- $create_params = array(
+ $create_params = [
'contact_type' => 'Individual',
'first_name' => 'John',
'last_name' => 'Doe',
- 'api.Address.create' => array(
+ 'api.Address.create' => [
'location_type_id' => 'Home',
'state_province_id' => $state_name,
- ),
- );
+ ],
+ ];
$create_res = civicrm_api3('Contact', 'Create', $create_params);
- $get_params = array(
+ $get_params = [
'id' => $create_res['id'],
'sequential' => 1,
- );
+ ];
$get_res = civicrm_api3('Contact', 'get', $get_params);
$this->assertEquals($state_name, $get_res['values'][0]['state_province_name']);
// Lock in that state_provice should equal that of the abbreviation.
* IDs should be selected when the form values are applied to the
* database in dataset.xml
*/
- private $dataset = array(
+ private $dataset = [
// Include static group 3
- array(
- 'fv' => array('group' => '3'),
- 'id' => array(
+ [
+ 'fv' => ['group' => '3'],
+ 'id' => [
'17',
'18',
'19',
'22',
'23',
'24',
- ),
- ),
+ ],
+ ],
// Include static group 5
- array(
- 'fv' => array('group' => '5'),
- 'id' => array(
+ [
+ 'fv' => ['group' => '5'],
+ 'id' => [
'13',
'14',
'15',
'22',
'23',
'24',
- ),
- ),
+ ],
+ ],
// Include static groups 3 and 5
- array(
- 'fv' => array('group' => array('3', '5')),
- 'id' => array(
+ [
+ 'fv' => ['group' => ['3', '5']],
+ 'id' => [
'13',
'14',
'15',
'22',
'23',
'24',
- ),
- ),
+ ],
+ ],
// Include static groups 3 and 5 in legacy format
- array(
- 'fv' => array('group' => array('3' => 1, '5' => 1)),
- 'id' => array(
+ [
+ 'fv' => ['group' => ['3' => 1, '5' => 1]],
+ 'id' => [
'13',
'14',
'15',
'22',
'23',
'24',
- ),
- ),
+ ],
+ ],
// Include tag 7
- array(
- 'fv' => array('tag' => '7'),
- 'id' => array(
+ [
+ 'fv' => ['tag' => '7'],
+ 'id' => [
'11',
'12',
'15',
'20',
'23',
'24',
- ),
- ),
+ ],
+ ],
// Include tag 9
- array(
- 'fv' => array('tag' => array('9' => 1)),
- 'id' => array(
+ [
+ 'fv' => ['tag' => ['9' => 1]],
+ 'id' => [
'10',
'12',
'14',
'20',
'22',
'24',
- ),
- ),
+ ],
+ ],
// Include tags 7 and 9
- array(
- 'fv' => array('tag' => array('7', '9')),
- 'id' => array(
+ [
+ 'fv' => ['tag' => ['7', '9']],
+ 'id' => [
'10',
'11',
'12',
'22',
'23',
'24',
- ),
- ),
+ ],
+ ],
// gender_id 1 = 'Female'
- array(
- 'fv' => array('gender_id' => 1),
- 'id' => array('9', '20', '22'),
- ),
+ [
+ 'fv' => ['gender_id' => 1],
+ 'id' => ['9', '20', '22'],
+ ],
// prefix_id 2 = 'Ms.'
- array(
- 'fv' => array('prefix_id' => 2),
- 'id' => array('10', '13'),
- ),
+ [
+ 'fv' => ['prefix_id' => 2],
+ 'id' => ['10', '13'],
+ ],
// suffix_id 6 = 'V'
- array(
- 'fv' => array('suffix_id' => 6),
- 'id' => array('16', '19', '20', '21'),
- ),
- );
+ [
+ 'fv' => ['suffix_id' => 6],
+ 'id' => ['16', '19', '20', '21'],
+ ],
+ ];
public function _construct() {
$this->i = 0;
public function current() {
$count = count($this->dataset[$this->i]['id']);
$ids = $this->dataset[$this->i]['id'];
- $full = array();
+ $full = [];
foreach ($this->dataset[$this->i]['id'] as $key => $value) {
- $full[] = array(
+ $full[] = [
'contact_id' => $value,
'contact_type' => 'Individual',
'sort_name' => "Test Contact $value",
- );
+ ];
}
- return array($this->dataset[$this->i]['fv'], $count, $ids, $full);
+ return [$this->dataset[$this->i]['fv'], $count, $ids, $full];
}
/**
}
public function getRelationshipTypeDuplicates() {
- $relationshipTypeList = array(
+ $relationshipTypeList = [
'1_a_b' => 'duplicate one',
'1_b_a' => 'duplicate one',
'2_a_b' => 'two a',
'2_b_a' => 'two b',
- );
- $data = array(
- array(
+ ];
+ $data = [
+ [
$relationshipTypeList,
'a_b',
- array(
+ [
'1_a_b' => 'duplicate one',
'2_a_b' => 'two a',
'2_b_a' => 'two b',
- ),
+ ],
'With suffix a_b',
- ),
- array(
+ ],
+ [
$relationshipTypeList,
'b_a',
- array(
+ [
'1_b_a' => 'duplicate one',
'2_a_b' => 'two a',
'2_b_a' => 'two b',
- ),
+ ],
'With suffix b_a',
- ),
- array(
+ ],
+ [
$relationshipTypeList,
NULL,
- array(
+ [
'1_a_b' => 'duplicate one',
'2_a_b' => 'two a',
'2_b_a' => 'two b',
- ),
+ ],
'With suffix NULL',
- ),
- array(
+ ],
+ [
$relationshipTypeList,
NULL,
- array(
+ [
'1_a_b' => 'duplicate one',
'2_a_b' => 'two a',
'2_b_a' => 'two b',
- ),
+ ],
'With suffix "" (empty string)',
- ),
- );
+ ],
+ ];
return $data;
}
* This method is called after a test is executed.
*/
protected function tearDown() {
- $this->quickCleanup(array(
+ $this->quickCleanup([
'civicrm_mapping_field',
'civicrm_mapping',
'civicrm_group',
'civicrm_saved_search',
- ));
+ ]);
}
/**
public function testDefaultValues() {
$sg = new CRM_Contact_Form_Search_Advanced();
$sg->controller = new CRM_Core_Controller();
- $sg->_formValues = array(
+ $sg->_formValues = [
'group_search_selected' => 'group',
- 'privacy_options' => array('do_not_email'),
+ 'privacy_options' => ['do_not_email'],
'privacy_operator' => 'OR',
'privacy_toggle' => 2,
'operator' => 'AND',
'component_mode' => 1,
- );
+ ];
CRM_Core_DAO::executeQuery(
"INSERT INTO civicrm_saved_search (form_values) VALUES('" . serialize($sg->_formValues) . "')"
);
"INSERT INTO civicrm_saved_search (form_values) VALUES('" . serialize($formValues) . "')"
);
$result = CRM_Contact_BAO_SavedSearch::getFormValues(CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'));
- $this->assertEquals(array('membership_type_id', 'membership_status_id'), array_keys($result));
+ $this->assertEquals(['membership_type_id', 'membership_status_id'], array_keys($result));
foreach ($result as $key => $value) {
$this->assertEquals($expectedResult, $value, 'failure on set ' . $searchDescription);
}
*/
public function testDateRange() {
$savedSearch = new CRM_Contact_BAO_SavedSearch();
- $formValues = array(
+ $formValues = [
'hidden_basic' => 1,
'group_search_selected' => 'group',
'component_mode' => 1,
'participant_register_date_high' => '01/01/2018',
'radio_ts' => 'ts_all',
'title' => 'bah bah bah',
- );
+ ];
- $queryParams = array(
- 0 => array(
+ $queryParams = [
+ 0 => [
0 => 'participant_register_date_low',
1 => '=',
2 => '01/01/2009',
3 => 0,
4 => 0,
- ),
- 1 => array(
+ ],
+ 1 => [
0 => 'participant_register_date_high',
1 => '=',
2 => '01/01/2018',
3 => 0,
4 => 0,
- ),
- );
+ ],
+ ];
CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues);
CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues);
public function testSkippedElements() {
$relTypeID = $this->relationshipTypeCreate();
$savedSearch = new CRM_Contact_BAO_SavedSearch();
- $formValues = array(
+ $formValues = [
'operator' => 'AND',
'title' => 'testsmart',
'radio_ts' => 'ts_all',
'component_mode' => CRM_Contact_BAO_Query::MODE_CONTACTS,
'display_relationship_type' => "{$relTypeID}_a_b",
'uf_group_id' => 1,
- );
- $queryParams = array();
+ ];
+ $queryParams = [];
CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues);
$savedSearch->form_values = serialize($queryParams);
$savedSearch->save();
$result = CRM_Contact_BAO_SavedSearch::getFormValues(CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'));
- $expectedResult = array(
+ $expectedResult = [
'operator' => 'AND',
'component_mode' => CRM_Contact_BAO_Query::MODE_CONTACTS,
'display_relationship_type' => "{$relTypeID}_a_b",
'uf_group_id' => 1,
- );
+ ];
$this->checkArrayEquals($result, $expectedResult);
}
*/
public function testRelativeDateValues() {
$savedSearch = new CRM_Contact_BAO_SavedSearch();
- $formValues = array(
+ $formValues = [
'operator' => 'AND',
'event_relative' => 'this.month',
'participant_relative' => 'today',
'participant_test' => 0,
'title' => 'testsmart',
'radio_ts' => 'ts_all',
- );
+ ];
$queryParams = [];
CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues);
CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues);
*/
public function testCustomFieldRelativeDates() {
// Create a custom field.
- $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'relative_date_test_group'));
- $params = array(
+ $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'relative_date_test_group']);
+ $params = [
'custom_group_id' => $customGroup['id'],
'name' => 'test_datefield',
'label' => 'Date Field for Testing',
'is_searchable' => 1,
'date_format' => 'mm/dd/yy',
'is_active' => 1,
- );
+ ];
$customField = $this->callAPIAndDocument('custom_field', 'create', $params, __FUNCTION__, __FILE__);
$id = $customField['id'];
- $queryParams = array(
- 0 => array(
+ $queryParams = [
+ 0 => [
0 => "custom_${id}_low",
1 => '=',
2 => '20170425000000',
- ),
- 1 => array(
+ ],
+ 1 => [
0 => "custom_${id}_high",
1 => '=',
2 => '20170501235959',
- ),
- );
- $formValues = array(
+ ],
+ ];
+ $formValues = [
"custom_${id}_relative" => 'ending.week',
- );
+ ];
CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues);
// Since custom_13 doesn't have the word 'date' in it, the key is
// set to 0, rather than the field name.
$this->assertArrayNotHasKey('relative_dates', $queryParams, 'Relative date in custom field smart group creation failed.');
$dropCustomValueTables = TRUE;
- $this->quickCleanup(array('civicrm_saved_search'), $dropCustomValueTables);
+ $this->quickCleanup(['civicrm_saved_search'], $dropCustomValueTables);
}
/**
* @return array
*/
public function getSavedSearches() {
- $return = array();
+ $return = [];
$searches = $this->getSearches();
foreach ($searches as $key => $search) {
- $return[] = array($search['form_values'], $search['expected'], $key);
+ $return[] = [$search['form_values'], $search['expected'], $key];
}
return $return;
}
* @return array
*/
public function getSearches() {
- return array(
- 'checkbox_format_1_first' => array(
- 'form_values' => array(
- 'member_membership_type_id' => array(1 => 1, 2 => 1),
- 'member_status_id' => array(1 => 1, 2 => 1),
- ),
- 'expected' => array(1, 2),
- ),
- 'checkbox_format_1_later' => array(
- 'form_values' => array(
- 'member_membership_type_id' => array(2 => 1, 1 => 1),
- 'member_status_id' => array(2 => 1, 1 => 1),
- ),
- 'expected' => array(2, 1),
- ),
- 'checkbox_format_single_use_1' => array(
- 'form_values' => array(
- 'member_membership_type_id' => array(1 => 1),
- 'member_status_id' => array(1 => 1),
- ),
- 'expected' => array(1),
- ),
- 'checkbox_format_single_not_1' => array(
- 'form_values' => array(
- 'member_membership_type_id' => array(2 => 1),
- 'member_status_id' => array(2 => 1),
- ),
- 'expected' => array(2),
- ),
- 'array_format' => array(
- 'form_values' => array(
- 'member_membership_type_id' => array(1, 2),
- 'member_status_id' => array(1, 2),
- ),
- 'expected' => array(1, 2),
- ),
- 'array_format_1_later' => array(
- 'form_values' => array(
- 'member_membership_type_id' => array(2, 1),
- 'member_status_id' => array(2, 1),
- ),
- 'expected' => array(2, 1),
- ),
- 'array_format_single_use_1' => array(
- 'form_values' => array(
- 'member_membership_type_id' => array(1),
- 'member_status_id' => array(1),
- ),
- 'expected' => array(1),
- ),
- 'array_format_single_not_1' => array(
- 'form_values' => array(
- 'member_membership_type_id' => array(2),
- 'member_status_id' => array(2),
- ),
- 'expected' => array(2),
- ),
- 'IN_format_single_not_1' => array(
- 'form_values' => array(
- 'membership_type_id' => array('IN' => array(2)),
- 'membership_status_id' => array('IN' => array(2)),
- ),
- 'expected' => array(2),
- ),
- 'IN_format_1_later' => array(
- 'form_values' => array(
- 'membership_type_id' => array('IN' => array(2, 1)),
- 'membership_status_id' => array('IN' => array(2, 1)),
- ),
- 'expected' => array(2, 1),
- ),
- );
+ return [
+ 'checkbox_format_1_first' => [
+ 'form_values' => [
+ 'member_membership_type_id' => [1 => 1, 2 => 1],
+ 'member_status_id' => [1 => 1, 2 => 1],
+ ],
+ 'expected' => [1, 2],
+ ],
+ 'checkbox_format_1_later' => [
+ 'form_values' => [
+ 'member_membership_type_id' => [2 => 1, 1 => 1],
+ 'member_status_id' => [2 => 1, 1 => 1],
+ ],
+ 'expected' => [2, 1],
+ ],
+ 'checkbox_format_single_use_1' => [
+ 'form_values' => [
+ 'member_membership_type_id' => [1 => 1],
+ 'member_status_id' => [1 => 1],
+ ],
+ 'expected' => [1],
+ ],
+ 'checkbox_format_single_not_1' => [
+ 'form_values' => [
+ 'member_membership_type_id' => [2 => 1],
+ 'member_status_id' => [2 => 1],
+ ],
+ 'expected' => [2],
+ ],
+ 'array_format' => [
+ 'form_values' => [
+ 'member_membership_type_id' => [1, 2],
+ 'member_status_id' => [1, 2],
+ ],
+ 'expected' => [1, 2],
+ ],
+ 'array_format_1_later' => [
+ 'form_values' => [
+ 'member_membership_type_id' => [2, 1],
+ 'member_status_id' => [2, 1],
+ ],
+ 'expected' => [2, 1],
+ ],
+ 'array_format_single_use_1' => [
+ 'form_values' => [
+ 'member_membership_type_id' => [1],
+ 'member_status_id' => [1],
+ ],
+ 'expected' => [1],
+ ],
+ 'array_format_single_not_1' => [
+ 'form_values' => [
+ 'member_membership_type_id' => [2],
+ 'member_status_id' => [2],
+ ],
+ 'expected' => [2],
+ ],
+ 'IN_format_single_not_1' => [
+ 'form_values' => [
+ 'membership_type_id' => ['IN' => [2]],
+ 'membership_status_id' => ['IN' => [2]],
+ ],
+ 'expected' => [2],
+ ],
+ 'IN_format_1_later' => [
+ 'form_values' => [
+ 'membership_type_id' => ['IN' => [2, 1]],
+ 'membership_status_id' => ['IN' => [2, 1]],
+ ],
+ 'expected' => [2, 1],
+ ],
+ ];
}
}
/**
* @var array
*/
- protected $_tablesToTruncate = array(
+ protected $_tablesToTruncate = [
'civicrm_acl_contact_cache',
- );
+ ];
/**
* Test ACL contacts are filtered properly.
$userId = $this->createLoggedInUser();
// remove all permissions
$config = CRM_Core_Config::singleton();
- $config->userPermissionClass->permissions = array();
+ $config->userPermissionClass->permissions = [];
for ($i = 1; $i <= 10; $i++) {
- $contactId = $this->individualCreate(array(), $i);
+ $contactId = $this->individualCreate([], $i);
if ($i <= 5) {
- $queryParams = array(
- 1 => array($userId, 'Integer'),
- 2 => array($contactId, 'Integer'),
- );
+ $queryParams = [
+ 1 => [$userId, 'Integer'],
+ 2 => [$contactId, 'Integer'],
+ ];
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, operation ) VALUES(%1, %2, 'View')", $queryParams);
}
$contactIDs[$i] = $contactId;
}
- $formValues = array('component_mode' => 1, 'operator' => 1, 'is_unit_test' => 1);
+ $formValues = ['component_mode' => 1, 'operator' => 1, 'is_unit_test' => 1];
$fullText = new CRM_Contact_Form_Search_Custom_FullText($formValues);
$fullText->initialize();
//Assert that ACL contacts are filtered.
- $queryParams = array(1 => array($userId, 'Integer'));
+ $queryParams = [1 => [$userId, 'Integer']];
$whereClause = "WHERE NOT EXISTS (SELECT c.contact_id
FROM civicrm_acl_contact_cache c
WHERE c.user_id = %1 AND t.contact_id = c.contact_id )";
* @group headless
*/
class CRM_Contact_Form_Search_Custom_GroupTest extends CiviUnitTestCase {
- protected $_tablesToTruncate = array(
+ protected $_tablesToTruncate = [
'civicrm_group_contact',
'civicrm_group',
'civicrm_saved_search',
'civicrm_contact',
'civicrm_option_value',
'civicrm_option_group',
- );
+ ];
/**
* @return CRM_Contact_Form_Search_Custom_GroupTestDataProvider
$sql = $obj->all();
$this->assertTrue(is_string($sql));
$dao = CRM_Core_DAO::executeQuery($sql);
- $all = array();
+ $all = [];
while ($dao->fetch()) {
- $all[] = array(
+ $all[] = [
'contact_id' => $dao->contact_id,
'contact_type' => $dao->contact_type,
'sort_name' => $dao->sort_name,
- );
+ ];
}
asort($all);
$this->assertEquals($full, $all);
$sql = $obj->contactIDs();
$this->assertTrue(is_string($sql));
$dao = CRM_Core_DAO::executeQuery($sql);
- $contacts = array();
+ $contacts = [];
while ($dao->fetch()) {
$contacts[$dao->contact_id] = 1;
}
* It returns an array of translated name => keys
*/
public function testColumns() {
- $formValues = array();
+ $formValues = [];
$obj = new CRM_Contact_Form_Search_Custom_Group($formValues);
$columns = $obj->columns();
$this->assertTrue(is_array($columns));
* It returns NULL
*/
public function testSummary() {
- $formValues = array();
+ $formValues = [];
$obj = new CRM_Contact_Form_Search_Custom_Group($formValues);
$this->assertNull($obj->summary());
}
* Returns the path to the file as a string
*/
public function testTemplateFile() {
- $formValues = array();
+ $formValues = [];
$obj = new CRM_Contact_Form_Search_Custom_Group($formValues);
$fileName = $obj->templateFile();
$this->assertTrue(is_string($fileName));
* With no arguments it returns '(1)'
*/
public function testWhereNoArgs() {
- $formValues = array(
+ $formValues = [
CRM_Core_Form::CB_PREFIX . '17' => TRUE,
CRM_Core_Form::CB_PREFIX . '23' => TRUE,
- );
+ ];
$obj = new CRM_Contact_Form_Search_Custom_Group($formValues);
$this->assertEquals(' (1) ', $obj->where());
}
* With false argument it returns '(1)'
*/
public function testWhereFalse() {
- $formValues = array(
+ $formValues = [
CRM_Core_Form::CB_PREFIX . '17' => TRUE,
CRM_Core_Form::CB_PREFIX . '23' => TRUE,
- );
+ ];
$obj = new CRM_Contact_Form_Search_Custom_Group($formValues);
$this->assertEquals(' (1) ', $obj->where(FALSE),
'In line ' . __LINE__
* With true argument it returns list of contact IDs
*/
public function testWhereTrue() {
- $formValues = array(
+ $formValues = [
CRM_Core_Form::CB_PREFIX . '17' => TRUE,
CRM_Core_Form::CB_PREFIX . '23' => TRUE,
- );
+ ];
$obj = new CRM_Contact_Form_Search_Custom_Group($formValues);
$this->assertEquals(' (1) AND contact_a.id IN ( 17, 23 )', $obj->where(TRUE),
'In line ' . __LINE__
* IDs should be selected when the form values are applied to the
* database in dataset.xml
*/
- private $dataset = array(
+ private $dataset = [
// Exclude static group 3
- array(
- 'fv' => array('excludeGroups' => array('3')),
- 'id' => array(
+ [
+ 'fv' => ['excludeGroups' => ['3']],
+ 'id' => [
'9',
'10',
'11',
'15',
'16',
'26',
- ),
- ),
+ ],
+ ],
// Include static group 3
- array(
- 'fv' => array('includeGroups' => array('3')),
- 'id' => array(
+ [
+ 'fv' => ['includeGroups' => ['3']],
+ 'id' => [
'17',
'18',
'19',
'24',
'27',
'28',
- ),
- ),
+ ],
+ ],
// Include static group 5
- array(
- 'fv' => array('includeGroups' => array('5')),
- 'id' => array(
+ [
+ 'fv' => ['includeGroups' => ['5']],
+ 'id' => [
'13',
'14',
'15',
'22',
'23',
'24',
- ),
- ),
+ ],
+ ],
// Include static groups 3 and 5
- array(
- 'fv' => array('includeGroups' => array('3', '5')),
- 'id' => array(
+ [
+ 'fv' => ['includeGroups' => ['3', '5']],
+ 'id' => [
'13',
'14',
'15',
'24',
'27',
'28',
- ),
- ),
+ ],
+ ],
// Include static group 3, exclude static group 5
- array(
- 'fv' => array(
- 'includeGroups' => array('3'),
- 'excludeGroups' => array('5'),
- ),
- 'id' => array('17', '18', '19', '20', '27', '28'),
- ),
+ [
+ 'fv' => [
+ 'includeGroups' => ['3'],
+ 'excludeGroups' => ['5'],
+ ],
+ 'id' => ['17', '18', '19', '20', '27', '28'],
+ ],
// Exclude tag 7
- array(
- 'fv' => array('excludeTags' => array('7')),
- 'id' => array(
+ [
+ 'fv' => ['excludeTags' => ['7']],
+ 'id' => [
'9',
'10',
'13',
'21',
'22',
'27',
- ),
- ),
+ ],
+ ],
// Include tag 7
- array(
- 'fv' => array('includeTags' => array('7')),
- 'id' => array(
+ [
+ 'fv' => ['includeTags' => ['7']],
+ 'id' => [
'11',
'12',
'15',
'24',
'26',
'28',
- ),
- ),
+ ],
+ ],
// Include tag 9
- array(
- 'fv' => array('includeTags' => array('9')),
- 'id' => array(
+ [
+ 'fv' => ['includeTags' => ['9']],
+ 'id' => [
'10',
'12',
'14',
'20',
'22',
'24',
- ),
- ),
+ ],
+ ],
// Include tags 7 and 9
- array(
- 'fv' => array('includeTags' => array('7', '9')),
- 'id' => array(
+ [
+ 'fv' => ['includeTags' => ['7', '9']],
+ 'id' => [
'10',
'11',
'12',
'24',
'26',
'28',
- ),
- ),
+ ],
+ ],
// Include tag 7, exclude tag 9
- array(
- 'fv' => array(
- 'includeTags' => array('7'),
- 'excludeTags' => array('9'),
- ),
- 'id' => array('11', '15', '19', '23', '26', '28'),
- ),
+ [
+ 'fv' => [
+ 'includeTags' => ['7'],
+ 'excludeTags' => ['9'],
+ ],
+ 'id' => ['11', '15', '19', '23', '26', '28'],
+ ],
// Include static group 3, include tag 7 (either)
- array(
- 'fv' => array(
- 'includeGroups' => array('3'),
- 'includeTags' => array('7'),
+ [
+ 'fv' => [
+ 'includeGroups' => ['3'],
+ 'includeTags' => ['7'],
'andOr' => 0,
- ),
- 'id' => array(
+ ],
+ 'id' => [
'11',
'12',
'15',
'26',
'27',
'28',
- ),
- ),
+ ],
+ ],
// Include static group 3, include tag 7 (both)
- array(
- 'fv' => array(
- 'includeGroups' => array('3'),
- 'includeTags' => array('7'),
+ [
+ 'fv' => [
+ 'includeGroups' => ['3'],
+ 'includeTags' => ['7'],
'andOr' => 1,
- ),
- 'id' => array('19', '20', '23', '24', '28'),
- ),
+ ],
+ 'id' => ['19', '20', '23', '24', '28'],
+ ],
// Include static group 3, exclude tag 7
- array(
- 'fv' => array(
- 'includeGroups' => array('3'),
- 'excludeTags' => array('7'),
- ),
- 'id' => array('17', '18', '21', '22', '27'),
- ),
+ [
+ 'fv' => [
+ 'includeGroups' => ['3'],
+ 'excludeTags' => ['7'],
+ ],
+ 'id' => ['17', '18', '21', '22', '27'],
+ ],
// Include tag 9, exclude static group 5
- array(
- 'fv' => array(
- 'includeTags' => array('9'),
- 'excludeGroups' => array('5'),
- ),
- 'id' => array('10', '12', '18', '20'),
- ),
+ [
+ 'fv' => [
+ 'includeTags' => ['9'],
+ 'excludeGroups' => ['5'],
+ ],
+ 'id' => ['10', '12', '18', '20'],
+ ],
// Exclude tag 9, exclude static group 5
- array(
- 'fv' => array(
- 'excludeTags' => array('9'),
- 'excludeGroups' => array('5'),
- ),
- 'id' => array(
+ [
+ 'fv' => [
+ 'excludeTags' => ['9'],
+ 'excludeGroups' => ['5'],
+ ],
+ 'id' => [
'9',
'11',
'17',
'26',
'27',
'28',
- ),
- ),
+ ],
+ ],
// Include smart group 6
- array(
- 'fv' => array('includeGroups' => array('6')),
- 'id' => array(
+ [
+ 'fv' => ['includeGroups' => ['6']],
+ 'id' => [
'9',
'10',
'11',
'15',
'16',
'26',
- ),
- ),
+ ],
+ ],
// Include smart group 4
- array(
- 'fv' => array('includeGroups' => array('4')),
- 'id' => array(
+ [
+ 'fv' => ['includeGroups' => ['4']],
+ 'id' => [
'17',
'18',
'19',
'24',
'27',
'28',
- ),
- ),
+ ],
+ ],
// Include smart group 4 and static group 5
- array(
- 'fv' => array('includeGroups' => array('4', '5')),
- 'id' => array(
+ [
+ 'fv' => ['includeGroups' => ['4', '5']],
+ 'id' => [
'13',
'14',
'15',
'24',
'27',
'28',
- ),
- ),
- );
+ ],
+ ],
+ ];
public function _construct() {
$this->i = 0;
public function current() {
$count = count($this->dataset[$this->i]['id']);
$ids = $this->dataset[$this->i]['id'];
- $full = array();
+ $full = [];
foreach ($this->dataset[$this->i]['id'] as $key => $value) {
- $full[] = array(
+ $full[] = [
'contact_id' => $value,
'contact_type' => 'Individual',
'sort_name' => "Test Contact $value",
- );
+ ];
}
- return array($this->dataset[$this->i]['fv'], $count, $ids, $full);
+ return [$this->dataset[$this->i]['fv'], $count, $ids, $full];
}
/**
* @group headless
*/
class CRM_Contact_Form_Search_Custom_SampleTest extends CiviUnitTestCase {
- protected $_tablesToTruncate = array(
+ protected $_tablesToTruncate = [
'civicrm_address',
'civicrm_saved_search',
'civicrm_contact',
'civicrm_option_value',
'civicrm_option_group',
- );
+ ];
/**
* @return CRM_Contact_Form_Search_Custom_SamplTestDataProvider
$sql = $obj->all(0, 0, 'contact_id');
$this->assertTrue(is_string($sql));
$dao = CRM_Core_DAO::executeQuery($sql);
- $all = array();
+ $all = [];
while ($dao->fetch()) {
- $all[] = array(
+ $all[] = [
'contact_id' => $dao->contact_id,
'contact_type' => $dao->contact_type,
'household_name' => $dao->sort_name,
- );
+ ];
}
asort($all);
$this->assertEquals($full, $all);
$sql = $obj->contactIDs();
$this->assertTrue(is_string($sql));
$dao = CRM_Core_DAO::executeQuery($sql);
- $contacts = array();
+ $contacts = [];
while ($dao->fetch()) {
$contacts[$dao->contact_id] = 1;
}
* It returns an array of translated name => keys
*/
public function testColumns() {
- $formValues = array();
+ $formValues = [];
$obj = new CRM_Contact_Form_Search_Custom_Sample($formValues);
$columns = $obj->columns();
$this->assertTrue(is_array($columns));
* It returns NULL
*/
public function testSummary() {
- $formValues = array();
+ $formValues = [];
$obj = new CRM_Contact_Form_Search_Custom_Group($formValues);
$this->assertNull($obj->summary());
}
* Returns the path to the file as a string
*/
public function testTemplateFile() {
- $formValues = array();
+ $formValues = [];
$obj = new CRM_Contact_Form_Search_Custom_Group($formValues);
$fileName = $obj->templateFile();
$this->assertTrue(is_string($fileName));
$this->loadXMLDataSet(dirname(__FILE__) . '/datasets/sample-dataset.xml');
- $dataset[1] = array('id' => array(12));
- $dataset[2] = array('id' => array(10, 11));
+ $dataset[1] = ['id' => [12]];
+ $dataset[2] = ['id' => [10, 11]];
$ssdao = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_saved_search");
while ($ssdao->fetch()) {
$sql = $obj->contactIDs();
$this->assertTrue(is_string($sql));
$dao = CRM_Core_DAO::executeQuery($sql);
- $contacts = array();
+ $contacts = [];
while ($dao->fetch()) {
$contacts[] = $dao->contact_id;
}
* IDs should be selected when the form values are applied to the
* database in dataset.xml
*/
- private $dataset = array(
+ private $dataset = [
// Search by Household name: 'Household 9'
- array(
- 'fv' => array('household_name' => 'Household 9'),
- 'id' => array(
+ [
+ 'fv' => ['household_name' => 'Household 9'],
+ 'id' => [
'9',
- ),
- ),
+ ],
+ ],
// Search by Household name: 'Household'
- array(
- 'fv' => array('household_name' => 'Household'),
- 'id' => array(
+ [
+ 'fv' => ['household_name' => 'Household'],
+ 'id' => [
'9',
'10',
'11',
'12',
- ),
- ),
+ ],
+ ],
// Search by State: California
- array(
- 'fv' => array('state_province_id' => '1004'),
- 'id' => array(
+ [
+ 'fv' => ['state_province_id' => '1004'],
+ 'id' => [
'10',
'11',
- ),
- ),
+ ],
+ ],
// Search by State: New York
- array(
- 'fv' => array('state_province_id' => '1031'),
- 'id' => array(
+ [
+ 'fv' => ['state_province_id' => '1031'],
+ 'id' => [
'12',
- ),
- ),
- );
+ ],
+ ],
+ ];
public function _construct() {
$this->i = 0;
public function current() {
$count = count($this->dataset[$this->i]['id']);
$ids = $this->dataset[$this->i]['id'];
- $full = array();
+ $full = [];
foreach ($this->dataset[$this->i]['id'] as $key => $value) {
- $full[] = array(
+ $full[] = [
'contact_id' => $value,
'contact_type' => 'Household',
'household_name' => "Household $value",
- );
+ ];
}
- return array($this->dataset[$this->i]['fv'], $count, $ids, $full);
+ return [$this->dataset[$this->i]['fv'], $count, $ids, $full];
}
/**
protected function setUp() {
parent::setUp();
- $this->_contactIds = array(
- $this->individualCreate(array('first_name' => 'Antonia', 'last_name' => 'D`souza')),
- $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins')),
- );
- $this->_optionValue = $this->callApiSuccess('optionValue', 'create', array(
+ $this->_contactIds = [
+ $this->individualCreate(['first_name' => 'Antonia', 'last_name' => 'D`souza']),
+ $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']),
+ ];
+ $this->_optionValue = $this->callApiSuccess('optionValue', 'create', [
'label' => '"Seamus Lee" <seamus@example.com>',
'option_group_id' => 'from_email_address',
- ));
+ ]);
}
/**
public function testDomainEmailGeneration() {
$emails = CRM_Core_BAO_Email::domainEmails();
$this->assertNotEmpty($emails);
- $optionValue = $this->callAPISuccess('OptionValue', 'Get', array(
+ $optionValue = $this->callAPISuccess('OptionValue', 'Get', [
'id' => $this->_optionValue['id'],
- ));
+ ]);
$this->assertTrue(array_key_exists('"Seamus Lee" <seamus@example.com>', $emails));
$this->assertEquals('"Seamus Lee" <seamus@example.com>', $optionValue['values'][$this->_optionValue['id']]['label']);
}
$form->controller = new CRM_Core_Controller();
for ($i = 0; $i < 27; $i++) {
$email = 'spy' . $i . '@secretsquirrels.com';
- $contactID = $this->individualCreate(array('email' => $email));
+ $contactID = $this->individualCreate(['email' => $email]);
$form->_contactIds[$contactID] = $contactID;
- $form->_toContactEmails[$this->callAPISuccessGetValue('Email', array('return' => 'id', 'email' => $email))] = $email;
+ $form->_toContactEmails[$this->callAPISuccessGetValue('Email', ['return' => 'id', 'email' => $email])] = $email;
}
$loggedInEmail = $this->callAPISuccess('Email', 'create', [
'email' => 'mickey@mouse.com',
'signature_html' => '<p>This is a test Signature</p>',
]);
$form->_allContactIds = $form->_toContactIds = $form->_contactIds;
- $form->_emails = array($loggedInEmail['id'] => 'mickey@mouse.com');
- $form->_fromEmails = array($loggedInEmail['id'] => 'mickey@mouse.com');
+ $form->_emails = [$loggedInEmail['id'] => 'mickey@mouse.com'];
+ $form->_fromEmails = [$loggedInEmail['id'] => 'mickey@mouse.com'];
CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($form);
CRM_Contact_Form_Task_EmailCommon::buildQuickForm($form);
CRM_Contact_Form_Task_EmailCommon::submit($form, array_merge($form->_defaultValues, [
'from_email_address' => $loggedInEmail['id'],
'subject' => 'Really interesting stuff',
]));
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'This is a test Signature',
- ));
+ ]);
$mut->stop();
Civi::settings()->set('allow_mail_from_logged_in_contact', 0);
}
protected function setUp() {
parent::setUp();
- $this->_contactIds = array(
- $this->individualCreate(array('first_name' => 'Antonia', 'last_name' => 'D`souza')),
- $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins')),
- );
+ $this->_contactIds = [
+ $this->individualCreate(['first_name' => 'Antonia', 'last_name' => 'D`souza']),
+ $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']),
+ ];
$this->_docTypes = CRM_Core_SelectValues::documentApplicationType();
}
* Test the documents got token replaced rightfully.
*/
public function testPrintDocument() {
- foreach (array('docx', 'odt') as $docType) {
- $formValues = array(
- 'document_file' => array(
+ foreach (['docx', 'odt'] as $docType) {
+ $formValues = [
+ 'document_file' => [
'name' => __DIR__ . "/sample_documents/Template.$docType",
'type' => $this->_docTypes[$docType],
- ),
- );
+ ],
+ ];
$this->_testDocumentContent($formValues, $docType);
}
}
* @param array $type
*/
public function _testDocumentContent($formValues, $type) {
- $html = array();
+ $html = [];
$form = new CRM_Contact_Form_Task_PDFLetterCommon();
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = $form->processMessageTemplate($formValues);
list($html_message, $zip) = CRM_Utils_PDF_Document::unzipDoc($formValues['document_file_path'], $formValues['document_type']);
foreach ($this->_contactIds as $item => $contactId) {
- $params = array('contact_id' => $contactId);
+ $params = ['contact_id' => $contactId];
list($contact) = CRM_Utils_Token::getTokenDetails($params,
$returnProperties,
FALSE,
* (Added in conjunction with fixed noting on mapping assignment).
*/
public function testBuildForm() {
- $this->callAPISuccess('Mapping', 'create', array('name' => 'Well dressed ducks', 'mapping_type_id' => 'Import Contact'));
+ $this->callAPISuccess('Mapping', 'create', ['name' => 'Well dressed ducks', 'mapping_type_id' => 'Import Contact']);
$form = $this->getFormObject('CRM_Contact_Import_Form_DataSource');
$form->buildQuickForm();
- $this->assertEquals(array(1 => 'Well dressed ducks'), CRM_Core_Smarty::singleton()->get_template_vars('savedMapping'));
+ $this->assertEquals([1 => 'Well dressed ducks'], CRM_Core_Smarty::singleton()->get_template_vars('savedMapping'));
}
}
* @param array $mapper
* @param array $expecteds
*/
- public function testSubmit($params, $mapper, $expecteds = array()) {
+ public function testSubmit($params, $mapper, $expecteds = []) {
CRM_Core_DAO::executeQuery("CREATE TABLE IF NOT EXISTS civicrm_import_job_xxx (`nada` text, `first_name` text, `last_name` text, `address` text) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
$form = $this->getFormObject('CRM_Contact_Import_Form_MapField');
$form->set('contactType', CRM_Import_Parser::CONTACT_INDIVIDUAL);
- $form->_columnNames = array('nada', 'first_name', 'last_name', 'address');
+ $form->_columnNames = ['nada', 'first_name', 'last_name', 'address'];
$form->set('importTableName', 'civicrm_import_job_xxx');
$form->preProcess();
$form->submit($params, $mapper);
CRM_Core_DAO::executeQuery("DROP TABLE civicrm_import_job_xxx");
if (!empty($expecteds)) {
foreach ($expecteds as $expected) {
- $result = $this->callAPISuccess($expected['entity'], 'get', array_merge($expected['values'], array('sequential' => 1)));
+ $result = $this->callAPISuccess($expected['entity'], 'get', array_merge($expected['values'], ['sequential' => 1]));
$this->assertEquals($expected['count'], $result['count']);
if (isset($expected['result'])) {
foreach ($expected['result'] as $key => $expectedValues) {
}
}
}
- $this->quickCleanup(array('civicrm_mapping', 'civicrm_mapping_field'));
+ $this->quickCleanup(['civicrm_mapping', 'civicrm_mapping_field']);
}
/**
* @return array
*/
public function getSubmitData() {
- return array(
- 'basic_data' => array(
- array(
+ return [
+ 'basic_data' => [
+ [
'saveMappingName' => '',
'saveMappingDesc' => '',
- ),
- array(
- 0 => array(0 => 'do_not_import'),
- 1 => array(0 => 'first_name'),
- 2 => array(0 => 'last_name'),
- 3 => array(0 => 'street_address', 1 => 2),
- ),
- ),
- 'save_mapping' => array(
- array(
+ ],
+ [
+ 0 => [0 => 'do_not_import'],
+ 1 => [0 => 'first_name'],
+ 2 => [0 => 'last_name'],
+ 3 => [0 => 'street_address', 1 => 2],
+ ],
+ ],
+ 'save_mapping' => [
+ [
'saveMappingName' => 'new mapping',
'saveMappingDesc' => 'save it',
'saveMapping' => 1,
- ),
- array(
- 0 => array(0 => 'do_not_import'),
- 1 => array(0 => 'first_name'),
- 2 => array(0 => 'last_name'),
- 3 => array(0 => 'street_address', 1 => 2),
- ),
- array(
- array('entity' => 'mapping', 'count' => 1, 'values' => array('name' => 'new mapping')),
- array(
+ ],
+ [
+ 0 => [0 => 'do_not_import'],
+ 1 => [0 => 'first_name'],
+ 2 => [0 => 'last_name'],
+ 3 => [0 => 'street_address', 1 => 2],
+ ],
+ [
+ ['entity' => 'mapping', 'count' => 1, 'values' => ['name' => 'new mapping']],
+ [
'entity' =>
'mapping_field',
'count' => 4,
- 'values' => array(),
- 'result' => array(
- 0 => array('name' => '- do not import -'),
- 1 => array('name' => 'First Name'),
- 2 => array('name' => 'Last Name'),
- 3 => array('name' => 'Street Address', 'location_type_id' => 2),
- ),
- ),
- ),
- ),
- );
+ 'values' => [],
+ 'result' => [
+ 0 => ['name' => '- do not import -'],
+ 1 => ['name' => 'First Name'],
+ 2 => ['name' => 'Last Name'],
+ 3 => ['name' => 'Street Address', 'location_type_id' => 2],
+ ],
+ ],
+ ],
+ ],
+ ];
}
/**
public function getFormObject($class, $formValues = [], $pageName = '') {
$form = parent::getFormObject($class);
$contactFields = CRM_Contact_BAO_Contact::importableFields();
- $fields = array();
+ $fields = [];
foreach ($contactFields as $name => $field) {
$fields[$name] = $field['title'];
}
* @throws \Exception
*/
public function testImportParserWtihEmployeeOfRelationship() {
- $this->organizationCreate(array(
+ $this->organizationCreate([
"organization_name" => "Agileware",
"legal_name" => "Agileware",
- ));
- $contactImportValues = array(
+ ]);
+ $contactImportValues = [
"first_name" => "Alok",
"last_name" => "Patel",
"Employee of" => "Agileware",
- );
+ ];
$fields = array_keys($contactImportValues);
$values = array_values($contactImportValues);
$parser->init();
$this->mapRelationshipFields($fields, $parser->getAllFields());
- $parser = new CRM_Contact_Import_Parser_Contact($fields, [], [], [], array(
+ $parser = new CRM_Contact_Import_Parser_Contact($fields, [], [], [], [
NULL,
NULL,
$fields[2],
- ), array(
+ ], [
NULL,
NULL,
"Organization",
- ), array(
+ ], [
NULL,
NULL,
"organization_name",
- ), [], [], [], [], []);
+ ], [], [], [], [], []);
$parser->_contactType = 'Individual';
$parser->_onDuplicate = CRM_Import_Parser::DUPLICATE_UPDATE;
$parser->init();
$this->assertEquals(CRM_Import_Parser::VALID, $parser->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), 'Return code from parser import was not as expected');
- $this->callAPISuccess("Contact", "get", array(
+ $this->callAPISuccess("Contact", "get", [
"first_name" => "Alok",
"last_name" => "Patel",
"organization_name" => "Agileware",
- ));
+ ]);
}
/**
* @throws \Exception
*/
public function testImportParserWtihDeletedContactExternalIdentifier() {
- $contactId = $this->individualCreate(array(
+ $contactId = $this->individualCreate([
"external_identifier" => "ext-1",
- ));
+ ]);
CRM_Contact_BAO_Contact::deleteContact($contactId);
- list($originalValues, $result) = $this->setUpBaseContact(array(
+ list($originalValues, $result) = $this->setUpBaseContact([
'external_identifier' => 'ext-1',
- ));
+ ]);
$originalValues['nick_name'] = 'Old Bill';
$this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
$originalValues['id'] = $result['id'];
- $this->assertEquals('ext-1', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'external_identifier')));
+ $this->assertEquals('ext-1', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'external_identifier']));
$this->callAPISuccessGetSingle('Contact', $originalValues);
}
$originalValues['nick_name'] = 'Old Bill';
$this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
$originalValues['id'] = $result['id'];
- $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name')));
+ $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name']));
$this->callAPISuccessGetSingle('Contact', $originalValues);
}
* @throws \Exception
*/
public function testImportParserWithUpdateWithExternalIdentifier() {
- list($originalValues, $result) = $this->setUpBaseContact(array('external_identifier' => 'windows'));
+ list($originalValues, $result) = $this->setUpBaseContact(['external_identifier' => 'windows']);
$this->assertEquals($result['id'], CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', 'windows', 'id', 'external_identifier', TRUE));
$this->assertEquals('windows', $result['external_identifier']);
$this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
$originalValues['id'] = $result['id'];
- $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name')));
+ $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name']));
$this->callAPISuccessGetSingle('Contact', $originalValues);
}
$this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
$originalValues['id'] = $result['id'];
- $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name')));
+ $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name']));
$this->callAPISuccessGetSingle('Contact', $originalValues);
}
* @throws \Exception
*/
public function testImportParserWithUpdateWithContactID() {
- list($originalValues, $result) = $this->setUpBaseContact(array(
+ list($originalValues, $result) = $this->setUpBaseContact([
'external_identifier' => '',
'email' => NULL,
- ));
+ ]);
$updateValues = ['id' => $result['id'], 'email' => 'bill@example.com'];
// This is some deep weirdness - this sets a flag for updatingBlankLocinfo - allowing input to be blanked
// (which IS a good thing but it's pretty weird & all to do with legacy profile stuff).
$originalValues['external_identifier'] = 'windows';
$this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
$originalValues['id'] = $result['id'];
- $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name')));
+ $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name']));
$this->callAPISuccessGetSingle('Contact', $originalValues);
}
* @throws \Exception
*/
public function testImportParserWithUpdateWithChangedExternalIdentifier() {
- list($contactValues, $result) = $this->setUpBaseContact(array('external_identifier' => 'windows'));
+ list($contactValues, $result) = $this->setUpBaseContact(['external_identifier' => 'windows']);
$contact_id = $result['id'];
$contactValues['nick_name'] = 'Old Bill';
$contactValues['external_identifier'] = 'android';
$this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
$contactValues['id'] = $contact_id;
- $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $contact_id, 'return' => 'nick_name')));
+ $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $contact_id, 'return' => 'nick_name']));
$this->callAPISuccessGetSingle('Contact', $contactValues);
}
$contactValues['external_identifier'] = 'android';
$contactValues['street_address'] = 'Big Mansion';
$contactValues['phone'] = '911';
- $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 2, 6 => 2));
- $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
+ $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 2, 6 => 2]);
+ $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion']);
$this->assertEquals(2, $address['location_type_id']);
- $phone = $this->callAPISuccessGetSingle('Phone', array('phone' => '911'));
+ $phone = $this->callAPISuccessGetSingle('Phone', ['phone' => '911']);
$this->assertEquals(2, $phone['location_type_id']);
$contact = $this->callAPISuccessGetSingle('Contact', $contactValues);
- $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+ $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
}
/**
$contactValues['external_identifier'] = 'android';
$contactValues['street_address'] = 'Big Mansion';
$contactValues['phone'] = 12334;
- $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary'));
- $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
+ $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary']);
+ $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion']);
$this->assertEquals(1, $address['location_type_id']);
$this->assertEquals(1, $address['is_primary']);
- $phone = $this->callAPISuccessGetSingle('Phone', array('phone' => '12334'));
+ $phone = $this->callAPISuccessGetSingle('Phone', ['phone' => '12334']);
$this->assertEquals(1, $phone['location_type_id']);
- $this->callAPISuccessGetSingle('Email', array('email' => 'bill.gates@microsoft.com'));
+ $this->callAPISuccessGetSingle('Email', ['email' => 'bill.gates@microsoft.com']);
$contact = $this->callAPISuccessGetSingle('Contact', $contactValues);
- $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+ $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
}
/**
$contactValues['external_identifier'] = 'android';
$contactValues['street_address'] = 'Big Mansion';
$contactValues['custom_' . $ids['custom_field_id']] = 'Update';
- $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary'));
+ $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary']);
$address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion', 'return' => 'custom_' . $ids['custom_field_id']]);
$this->assertEquals('Update', $address['custom_' . $ids['custom_field_id']]);
}
$this->assertEquals('1910-12-17', $contact['birth_date']);
$this->assertEquals('2010-12-17', $contact['deceased_date']);
$this->assertEquals(1, $contact['is_deceased']);
- $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+ $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
}
/**
$contactValues['phone_2'] = 4444;
$fields[] = 'street_address';
$fields[] = 'phone';
- $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 3, 8 => 3), $fields);
- $contact = $this->callAPISuccessGetSingle('Contact', array('external_identifier' => 'android'));
- $address = $this->callAPISuccess('Address', 'get', array('contact_id' => $contact['id'], 'sequential' => 1));
+ $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 3, 8 => 3], $fields);
+ $contact = $this->callAPISuccessGetSingle('Contact', ['external_identifier' => 'android']);
+ $address = $this->callAPISuccess('Address', 'get', ['contact_id' => $contact['id'], 'sequential' => 1]);
$this->assertEquals(3, $address['values'][0]['location_type_id']);
$this->assertEquals(0, $address['values'][0]['is_primary']);
$this->assertEquals(1, $address['values'][1]['is_primary']);
$this->assertEquals('Big Mansion', $address['values'][1]['street_address']);
- $phone = $this->callAPISuccess('Phone', 'get', array('contact_id' => $contact['id'], 'sequential' => 1));
+ $phone = $this->callAPISuccess('Phone', 'get', ['contact_id' => $contact['id'], 'sequential' => 1]);
$this->assertEquals(1, $phone['values'][0]['location_type_id']);
$this->assertEquals(1, $phone['values'][0]['is_primary']);
$this->assertEquals(12334, $phone['values'][0]['phone']);
$this->assertEquals(0, $phone['values'][1]['is_primary']);
$this->assertEquals(4444, $phone['values'][1]['phone']);
- $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+ $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
}
/**
$contactValues['phone_2'] = 4444;
$fields[] = 'street_address';
$fields[] = 'phone';
- $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 3, 6 => 3, 7 => 'Primary', 8 => 'Primary'), $fields);
- $contact = $this->callAPISuccessGetSingle('Contact', array('external_identifier' => 'android'));
- $address = $this->callAPISuccess('Address', 'get', array('contact_id' => $contact['id'], 'sequential' => 1))['values'];
+ $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 3, 6 => 3, 7 => 'Primary', 8 => 'Primary'], $fields);
+ $contact = $this->callAPISuccessGetSingle('Contact', ['external_identifier' => 'android']);
+ $address = $this->callAPISuccess('Address', 'get', ['contact_id' => $contact['id'], 'sequential' => 1])['values'];
$this->assertEquals(1, $address[1]['location_type_id']);
$this->assertEquals(1, $address[1]['is_primary']);
$this->assertEquals(1, $phone[0]['is_primary']);
$this->assertEquals(4444, $phone[0]['phone']);
- $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+ $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
}
/**
* @throws \Exception
*/
public function testImportPrimaryAddressUpdate() {
- list($contactValues) = $this->setUpBaseContact(array('external_identifier' => 'android'));
+ list($contactValues) = $this->setUpBaseContact(['external_identifier' => 'android']);
$contactValues['email'] = 'melinda.gates@microsoft.com';
$contactValues['phone'] = '98765';
$contactValues['external_identifier'] = 'android';
$contactValues['street_address'] = 'Big Mansion';
$contactValues['city'] = 'Big City';
- $contactID = $this->callAPISuccessGetValue('Contact', array('external_identifier' => 'android', 'return' => 'id'));
- $originalAddress = $this->callAPISuccess('Address', 'create', array('location_type_id' => 2, 'street_address' => 'small house', 'contact_id' => $contactID));
- $originalPhone = $this->callAPISuccess('phone', 'create', array('location_type_id' => 2, 'phone' => '1234', 'contact_id' => $contactID));
- $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 'Primary'));
+ $contactID = $this->callAPISuccessGetValue('Contact', ['external_identifier' => 'android', 'return' => 'id']);
+ $originalAddress = $this->callAPISuccess('Address', 'create', ['location_type_id' => 2, 'street_address' => 'small house', 'contact_id' => $contactID]);
+ $originalPhone = $this->callAPISuccess('phone', 'create', ['location_type_id' => 2, 'phone' => '1234', 'contact_id' => $contactID]);
+ $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 'Primary']);
$phone = $this->callAPISuccessGetSingle('Phone', ['phone' => '98765']);
$this->assertEquals(2, $phone['location_type_id']);
$this->assertEquals($originalPhone['id'], $phone['id']);
$email = $this->callAPISuccess('Email', 'getsingle', ['contact_id' => $contactID]);
- $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
+ $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion']);
$this->assertEquals(2, $address['location_type_id']);
$this->assertEquals($originalAddress['id'], $address['id']);
$this->assertEquals('Big City', $address['city']);
* Test the determination of whether a custom field is valid.
*/
public function testCustomFieldValidation() {
- $errorMessage = array();
- $customGroup = $this->customGroupCreate(array(
+ $errorMessage = [];
+ $customGroup = $this->customGroupCreate([
'extends' => 'Contact',
'title' => 'ABC',
- ));
- $customField = $this->customFieldOptionValueCreate($customGroup, 'fieldABC', array('html_type' => 'Multi-Select'));
- $params = array(
+ ]);
+ $customField = $this->customFieldOptionValueCreate($customGroup, 'fieldABC', ['html_type' => 'Multi-Select']);
+ $params = [
'custom_' . $customField['id'] => 'Label1|Label2',
- );
+ ];
CRM_Contact_Import_Parser_Contact::isErrorInCustomData($params, $errorMessage);
- $this->assertEquals(array(), $errorMessage);
+ $this->assertEquals([], $errorMessage);
}
/**
public function testImportFill() {
// Create a custom field group for testing.
$custom_group_name = 'importFillGroup';
- $results = $this->callAPISuccess('customGroup', 'get', array('title' => $custom_group_name));
+ $results = $this->callAPISuccess('customGroup', 'get', ['title' => $custom_group_name]);
if ($results['count'] == 0) {
- $api_params = array(
+ $api_params = [
'title' => $custom_group_name,
'extends' => 'Individual',
'is_active' => TRUE,
- );
+ ];
$customGroup = $this->callAPISuccess('customGroup', 'create', $api_params);
}
// Add two custom fields.
- $api_params = array(
+ $api_params = [
'custom_group_id' => $customGroup['id'],
'label' => 'importFillField1',
'html_type' => 'Select',
'data_type' => 'String',
- 'option_values' => array(
+ 'option_values' => [
'foo' => 'Foo',
'bar' => 'Bar',
- ),
- );
+ ],
+ ];
$result = $this->callAPISuccess('custom_field', 'create', $api_params);
$customField1 = $result['id'];
- $api_params = array(
+ $api_params = [
'custom_group_id' => $customGroup['id'],
'label' => 'importFillField2',
'html_type' => 'Select',
'data_type' => 'String',
- 'option_values' => array(
+ 'option_values' => [
'baz' => 'Baz',
'boo' => 'Boo',
- ),
- );
+ ],
+ ];
$result = $this->callAPISuccess('custom_field', 'create', $api_params);
$customField2 = $result['id'];
// Create contact with both one known core field and one custom
// field filled in.
- $api_params = array(
+ $api_params = [
'contact_type' => 'Individual',
'email' => $original_email,
'gender' => $original_gender,
'custom_' . $customField1 => $original_custom1,
- );
+ ];
$result = $this->callAPISuccess('contact', 'create', $api_params);
$contact_id = $result['id'];
// Run an import.
- $import = array(
+ $import = [
'email' => $original_email,
'gender_id' => $import_gender,
'custom_' . $customField1 => $import_custom1,
'job_title' => $import_job_title,
'custom_' . $customField2 => $import_custom2,
- );
+ ];
$this->runImport($import, CRM_Import_Parser::DUPLICATE_FILL, CRM_Import_Parser::VALID);
- $expected = array(
+ $expected = [
'gender' => $original_gender,
'custom_' . $customField1 => $original_custom1,
'job_title' => $import_job_title,
'custom_' . $customField2 => $import_custom2,
- );
+ ];
- $params = array(
+ $params = [
'id' => $contact_id,
- 'return' => array(
+ 'return' => [
'gender',
'custom_' . $customField1,
'job_title',
'custom_' . $customField2,
- ),
- );
+ ],
+ ];
$result = civicrm_api3('Contact', 'get', $params);
$values = array_pop($result['values']);
foreach ($expected as $field => $expected_value) {
public function testImportAmbiguousStateCountry() {
$this->callAPISuccess('Setting', 'create', ['defaultContactCountry' => 1228]);
$countries = CRM_Core_PseudoConstant::country(FALSE, FALSE);
- $this->callAPISuccess('Setting', 'create', array('countryLimit' => array(array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries))));
- $this->callAPISuccess('Setting', 'create', array('provinceLimit' => array(array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries))));
- $mapper = array(0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL);
+ $this->callAPISuccess('Setting', 'create', ['countryLimit' => [array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)]]);
+ $this->callAPISuccess('Setting', 'create', ['provinceLimit' => [array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)]]);
+ $mapper = [0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL];
list($contactValues) = $this->setUpBaseContact();
$fields = array_keys($contactValues);
- $addressValues = array(
+ $addressValues = [
'street_address' => 'PO Box 2716',
'city' => 'Midway',
'state_province' => 'UT',
'postal_code' => 84049,
'country' => 'United States',
- );
- $locationTypes = $this->callAPISuccess('Address', 'getoptions', array('field' => 'location_type_id'));
+ ];
+ $locationTypes = $this->callAPISuccess('Address', 'getoptions', ['field' => 'location_type_id']);
$locationTypes = $locationTypes['values'];
foreach ($addressValues as $field => $value) {
$contactValues['home_' . $field] = $value;
$contactValues['work_country'] = '';
$this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, $mapper, $fields);
- $addresses = $this->callAPISuccess('Address', 'get', array('contact_id' => array('>' => 2), 'sequential' => 1));
+ $addresses = $this->callAPISuccess('Address', 'get', ['contact_id' => ['>' => 2], 'sequential' => 1]);
$this->assertEquals(2, $addresses['count']);
$this->assertEquals(array_search('United States', $countries), $addresses['values'][0]['country_id']);
$this->assertEquals(array_search('United States', $countries), $addresses['values'][1]['country_id']);
* @return array
* @throws \Exception
*/
- protected function setUpBaseContact($params = array()) {
- $originalValues = array_merge(array(
+ protected function setUpBaseContact($params = []) {
+ $originalValues = array_merge([
'first_name' => 'Bill',
'last_name' => 'Gates',
'email' => 'bill.gates@microsoft.com',
'nick_name' => 'Billy-boy',
- ), $params);
+ ], $params);
$this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
$result = $this->callAPISuccessGetSingle('Contact', $originalValues);
- return array($originalValues, $result);
+ return [$originalValues, $result];
}
}
public function testGetDedupes() {
$_REQUEST['gid'] = 1;
$_REQUEST['rgid'] = 1;
- $_REQUEST['columns'] = array(
- array(
- 'search' => array(
- 'value' => array(
+ $_REQUEST['columns'] = [
+ [
+ 'search' => [
+ 'value' => [
'src' => 'first_name',
- ),
- ),
+ ],
+ ],
'data' => 'src',
- ),
- );
+ ],
+ ];
$_REQUEST['is_unit_test'] = TRUE;
$result = CRM_Contact_Page_AJAX::getDedupes();
- $this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result);
+ $this->assertEquals(['data' => [], 'recordsTotal' => 0, 'recordsFiltered' => 0], $result);
}
/**
$_REQUEST['rgid'] = 1;
$_REQUEST['snippet'] = 4;
$_REQUEST['draw'] = 3;
- $_REQUEST['columns'] = array(
- 0 => array(
+ $_REQUEST['columns'] = [
+ 0 => [
'data' => 'is_selected_input',
'name' => '',
'searchable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 1 => array(
+ 1 => [
'data' => 'src_image',
'name' => '',
'searchable' => TRUE,
'orderable' => FALSE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 2 => array(
+ 2 => [
'data' => 'src',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 3 => array(
+ 3 => [
'data' => 'dst_image',
'name' => '',
'searchable' => TRUE,
'orderable' => FALSE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 4 => array(
+ 4 => [
'data' => 'dst',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 5 => array(
+ 5 => [
'data' => 'src_email',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 6 => array(
+ 6 => [
'data' => 'dst_email',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 7 => array(
+ 7 => [
'data' => 'src_street',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 8 => array(
+ 8 => [
'data' => 'dst_street',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 9 => array(
+ 9 => [
'data' => 'src_postcode',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => 123,
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 10 => array(
+ 10 => [
'data' => 'dst_postcode',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 11 => array(
+ 11 => [
'data' => 'conflicts',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 12 => array(
+ 12 => [
'data' => 'weight',
'name' => '',
'searchable' => TRUE,
'orderable' => TRUE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
+ ],
+ ],
- 13 => array(
+ 13 => [
'data' => 'actions',
'name' => '',
'searchable' => TRUE,
'orderable' => FALSE,
- 'search' => array(
+ 'search' => [
'value' => '',
'regex' => FALSE,
- ),
- ),
- );
+ ],
+ ],
+ ];
$_REQUEST['start'] = 0;
$_REQUEST['length'] = 10;
- $_REQUEST['search'] = array(
+ $_REQUEST['search'] = [
'value' => '',
'regex' => FALSE,
- );
+ ];
$_REQUEST['_'] = 1466478641007;
$_REQUEST['Drupal_toolbar_collapsed'] = 0;
$_REQUEST['is_unit_test'] = TRUE;
$result = CRM_Contact_Page_AJAX::getDedupes();
- $this->assertEquals(array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0), $result);
+ $this->assertEquals(['data' => [], 'recordsTotal' => 0, 'recordsFiltered' => 0], $result);
}
/**
* CRM-20621 : Test to check usage count of Tag tree
*/
public function testGetTagTree() {
- $contacts = array();
+ $contacts = [];
// create three contacts
for ($i = 0; $i < 3; $i++) {
$contacts[] = $this->individualCreate();
}
// Create Tag called as 'Parent Tag'
- $parentTag = $this->tagCreate(array(
+ $parentTag = $this->tagCreate([
'name' => 'Parent Tag',
'used_for' => 'civicrm_contact',
- ));
+ ]);
//assign first contact to parent tag
- $params = array(
+ $params = [
'entity_id' => $contacts[0],
'entity_table' => 'civicrm_contact',
'tag_id' => $parentTag['id'],
- );
+ ];
// TODO: EntityTag.create API is not working
CRM_Core_BAO_EntityTag::add($params);
// Create child Tag of $parentTag
- $childTag1 = $this->tagCreate(array(
+ $childTag1 = $this->tagCreate([
'name' => 'Child Tag Level 1',
'parent_id' => $parentTag['id'],
'used_for' => 'civicrm_contact',
- ));
+ ]);
//assign contact to this level 1 child tag
- $params = array(
+ $params = [
'entity_id' => $contacts[1],
'entity_table' => 'civicrm_contact',
'tag_id' => $childTag1['id'],
- );
+ ];
CRM_Core_BAO_EntityTag::add($params);
// Create child Tag of $childTag1
- $childTag2 = $this->tagCreate(array(
+ $childTag2 = $this->tagCreate([
'name' => 'Child Tag Level 2',
'parent_id' => $childTag1['id'],
'used_for' => 'civicrm_contact',
- ));
+ ]);
//assign contact to this level 2 child tag
- $params = array(
+ $params = [
'entity_id' => $contacts[2],
'entity_table' => 'civicrm_contact',
'tag_id' => $childTag2['id'],
- );
+ ];
CRM_Core_BAO_EntityTag::add($params);
// CASE I : check the usage count of parent tag which need to be 1
unset($_GET['parent_id']);
$_GET['str'] = 'Level';
$tagIDs = CRM_Admin_Page_AJAX::getTagTree();
- $expectedTagIDs = array($parentTag['id'], $childTag1['id'], $childTag2['id']);
+ $expectedTagIDs = [$parentTag['id'], $childTag1['id'], $childTag2['id']];
$this->checkArrayEquals($tagIDs, $expectedTagIDs);
// CASE 4 : check the tag IDs returned on searching with 'Level 1'
// which needs to array('parent tag id', 'level 1 child tag id')
$_GET['str'] = 'Level 1';
$tagIDs = CRM_Admin_Page_AJAX::getTagTree();
- $expectedTagIDs = array($parentTag['id'], $childTag1['id']);
+ $expectedTagIDs = [$parentTag['id'], $childTag1['id']];
$this->checkArrayEquals($tagIDs, $expectedTagIDs);
//cleanup
foreach ($contacts as $id) {
- $this->callAPISuccess('Contact', 'delete', array('id' => $id));
+ $this->callAPISuccess('Contact', 'delete', ['id' => $id]);
}
- $this->callAPISuccess('Tag', 'delete', array('id' => $childTag2['id']));
- $this->callAPISuccess('Tag', 'delete', array('id' => $childTag1['id']));
- $this->callAPISuccess('Tag', 'delete', array('id' => $parentTag['id']));
+ $this->callAPISuccess('Tag', 'delete', ['id' => $childTag2['id']]);
+ $this->callAPISuccess('Tag', 'delete', ['id' => $childTag1['id']]);
+ $this->callAPISuccess('Tag', 'delete', ['id' => $parentTag['id']]);
}
/**
public function testContactReference() {
//create group
$groupId1 = $this->groupCreate();
- $groupId2 = $this->groupCreate(array(
+ $groupId2 = $this->groupCreate([
'name' => 'Test Group 2',
'domain_id' => 1,
'title' => 'New Test Group2 Created',
'description' => 'New Test Group2 Created',
'is_active' => 1,
'visibility' => 'User and User Admin Only',
- ));
+ ]);
- $contactIds = array();
- foreach (array($groupId1, $groupId2) as $groupId) {
+ $contactIds = [];
+ foreach ([$groupId1, $groupId2] as $groupId) {
$this->groupContactCreate($groupId);
$contactIds = array_merge($contactIds, CRM_Contact_BAO_Group::getGroupContacts($groupId));
}
$contactIds = CRM_Utils_Array::collect('contact_id', $contactIds);
// create custom group with contact reference field
- $customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'select_test_group'));
- $params = array(
+ $customGroup = $this->customGroupCreate(['extends' => 'Contact', 'title' => 'select_test_group']);
+ $params = [
'custom_group_id' => $customGroup['id'],
'name' => 'Worker_Lookup',
'label' => 'Worker Lookup',
'weight' => 4,
'is_searchable' => 1,
'is_active' => 1,
- );
+ ];
$customField = $this->callAPISuccess('custom_field', 'create', $params);
- $_GET = array(
+ $_GET = [
'id' => $customField['id'],
'is_unit_test' => TRUE,
- );
+ ];
$contactList = CRM_Contact_Page_AJAX::contactReference();
$contactList = CRM_Utils_Array::collect('id', $contactList);
]);
$page = new CRM_Contact_Page_DedupeException();
$totalitems = civicrm_api3('Exception', "getcount", []);
- $params = array(
+ $params = [
'total' => $totalitems,
'rowCount' => CRM_Utils_Pager::ROWCOUNT,
'status' => ts('Dedupe Exceptions %%StatusMessage%%'),
'buttonBottom' => 'PagerBottomButton',
'buttonTop' => 'PagerTopButton',
'pageID' => $page->get(CRM_Utils_Pager::PAGE_ID),
- );
+ ];
$page->_pager = new CRM_Utils_Pager($params);
$exceptions = $page->getExceptions();
$expectedArray = [
public function testBrowseDisplaysCorrectListOfAddedGroups() {
// create admin-only non-smart group
$adminStdGroupTitle = 'The Admin-only Std Group';
- $adminStdGroup = $this->callAPISuccess('Group', 'create', array(
+ $adminStdGroup = $this->callAPISuccess('Group', 'create', [
'title' => $adminStdGroupTitle,
'visibility' => 'User and User Admin Only',
'is_active' => 1,
- ));
+ ]);
// create public non-smart group
$publicStdGroupTitle = 'The Public Std Group';
- $publicStdGroup = $this->callAPISuccess('Group', 'create', array(
+ $publicStdGroup = $this->callAPISuccess('Group', 'create', [
'title' => $publicStdGroupTitle,
'visibility' => 'Public Pages',
'is_active' => 1,
- ));
+ ]);
// Prepare to create smart groups based on saved criteria Gender = Male.
// Start by creating the saved search.
- $savedSearch = $this->callAPISuccess('SavedSearch', 'create', array(
+ $savedSearch = $this->callAPISuccess('SavedSearch', 'create', [
'form_values' => 'a:1:{i:0;a:5:{i:0;s:9:"gender_id";i:1;s:1:"=";i:2;i:2;i:3;i:0;i:4;i:0;}}',
- ));
+ ]);
// Create contact with Gender - Male
- $savedSearchContact = $this->individualCreate(array(
+ $savedSearchContact = $this->individualCreate([
'gender_id' => "Male",
'first_name' => 'C',
- ), 1);
+ ], 1);
// Create admin-only smart group for this saved search.
$adminSmartGroupTitle = 'The Admin-only Smart Group';
- $adminSmartGroup = $this->callAPISuccess('Group', 'create', array(
+ $adminSmartGroup = $this->callAPISuccess('Group', 'create', [
'title' => $adminSmartGroupTitle,
'visibility' => 'User and User Admin Only',
'saved_search_id' => $savedSearch['id'],
'is_active' => 1,
- ));
+ ]);
// Create public smart group for this saved search.
$publicSmartGroupTitle = 'The Public Smart Group';
- $publicSmartGroup = $this->callAPISuccess('Group', 'create', array(
+ $publicSmartGroup = $this->callAPISuccess('Group', 'create', [
'title' => $publicSmartGroupTitle,
'visibility' => 'Public Pages',
'saved_search_id' => $savedSearch['id'],
'is_active' => 1,
- ));
+ ]);
// Get logged in user contact ID.
$user_id = $this->createLoggedInUser();
$_REQUEST['id'] = $user_id;
// Add current user to the test groups.
- $publicSmartGroup = $this->callAPISuccess('Contact', 'create', array(
+ $publicSmartGroup = $this->callAPISuccess('Contact', 'create', [
'id' => $user_id,
- 'group' => array(
+ 'group' => [
$adminStdGroup['id'] => 1,
$adminSmartGroup['id'] => 1,
$publicStdGroup['id'] => 1,
$publicSmartGroup['id'] => 1,
- ),
- ));
+ ],
+ ]);
// Run the contact dashboard and assert that only the public groups appear
// in the variables.
// create admin-only non-smart group
$adminStdGroupTitle = 'The Admin-only Std Group' . uniqid();
- $adminStdGroup = $this->callAPISuccess('Group', 'create', array(
+ $adminStdGroup = $this->callAPISuccess('Group', 'create', [
'title' => $adminStdGroupTitle,
'visibility' => 'User and User Admin Only',
'is_active' => 1,
- ));
+ ]);
// create public non-smart group
$publicStdGroupTitle = 'The Public Std Group' . uniqid();
- $publicStdGroup = $this->callAPISuccess('Group', 'create', array(
+ $publicStdGroup = $this->callAPISuccess('Group', 'create', [
'title' => $publicStdGroupTitle,
'visibility' => 'Public Pages',
'is_active' => 1,
- ));
+ ]);
// create second public non-smart group
$publicStdGroupTitle2 = 'The 2nd Public Std Group' . uniqid();
- $publicStdGroup2 = $this->callAPISuccess('Group', 'create', array(
+ $publicStdGroup2 = $this->callAPISuccess('Group', 'create', [
'title' => $publicStdGroupTitle2,
'visibility' => 'Public Pages',
'is_active' => 1,
- ));
+ ]);
// Prepare to create smart groups based on saved criteria Gender = Male.
// Start by creating the saved search.
- $savedSearch = $this->callAPISuccess('SavedSearch', 'create', array(
+ $savedSearch = $this->callAPISuccess('SavedSearch', 'create', [
'form_values' => 'a:1:{i:0;a:5:{i:0;s:9:"gender_id";i:1;s:1:"=";i:2;i:2;i:3;i:0;i:4;i:0;}}',
- ));
+ ]);
// Create contact with Gender - Male
- $savedSearchContact = $this->individualCreate(array(
+ $savedSearchContact = $this->individualCreate([
'gender_id' => "Male",
'first_name' => 'C',
- ), 1);
+ ], 1);
// Create admin-only smart group for this saved search.
$adminSmartGroupTitle = 'The Admin-only Smart Group' . uniqid();
- $adminSmartGroup = $this->callAPISuccess('Group', 'create', array(
+ $adminSmartGroup = $this->callAPISuccess('Group', 'create', [
'title' => $adminSmartGroupTitle,
'visibility' => 'User and User Admin Only',
'saved_search_id' => $savedSearch['id'],
'is_active' => 1,
- ));
+ ]);
// Create public smart group for this saved search.
$publicSmartGroupTitle = 'The Public Smart Group' . uniqid();
- $publicSmartGroup = $this->callAPISuccess('Group', 'create', array(
+ $publicSmartGroup = $this->callAPISuccess('Group', 'create', [
'title' => $publicSmartGroupTitle,
'visibility' => 'Public Pages',
'saved_search_id' => $savedSearch['id'],
'is_active' => 1,
- ));
+ ]);
// Get logged in user contact ID.
$user_id = $this->createLoggedInUser();
$this->assertNotContains($adminStdGroupTitle, $group_id_field_html, "Group '$adminStdGroupTitle' should not be in listed available groups, but is.");
// Add current user to the test groups.
- $publicSmartGroup = $this->callAPISuccess('Contact', 'create', array(
+ $publicSmartGroup = $this->callAPISuccess('Contact', 'create', [
'id' => $user_id,
- 'group' => array(
+ 'group' => [
$adminStdGroup['id'] => 1,
$adminSmartGroup['id'] => 1,
$publicStdGroup['id'] => 1,
$publicSmartGroup['id'] => 1,
- ),
- ));
+ ],
+ ]);
// Run the contact dashboard and assert that none of the groups appear
// in select list of available groups.
* - subject: regex
*/
public function createTestCases() {
- $cs = array();
+ $cs = [];
// FIXME: CRM-19415: The right email content goes out, but it appears that the dates are incorrect.
// $cs[] = array(
// ),
// );
- $cs[] = array(
+ $cs[] = [
'2015-02-01 00:00:00',
'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientBob',
- array(),
- );
+ [],
+ ];
- $cs[] = array(
+ $cs[] = [
'2015-02-01 00:00:00',
'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientAlice',
- array(
- array(
+ [
+ [
'time' => '2015-02-01 00:00:00',
- 'to' => array('alice@example.org'),
+ 'to' => ['alice@example.org'],
'subject' => '/Hello, Alice.*via subject/',
- ),
- ),
- );
+ ],
+ ],
+ ];
- $cs[] = array(
+ $cs[] = [
'2015-02-01 00:00:00',
// 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstName',
'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstNameStatus',
- array(
- array(
+ [
+ [
'time' => '2015-02-01 00:00:00',
- 'to' => array('alice@example.org'),
+ 'to' => ['alice@example.org'],
'subject' => '/Hello, Alice. @Completed.*via subject/',
- ),
- ),
- );
+ ],
+ ],
+ ];
- $cs[] = array(
+ $cs[] = [
'2015-02-01 00:00:00',
'addAliceDues addBobDonation scheduleForAny startOnTime useHelloFirstName',
- array(
- array(
+ [
+ [
'time' => '2015-02-01 00:00:00',
- 'to' => array('alice@example.org'),
+ 'to' => ['alice@example.org'],
'subject' => '/Hello, Alice.*via subject/',
- ),
- array(
+ ],
+ [
'time' => '2015-02-01 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- ),
- );
+ ],
+ ],
+ ];
- $cs[] = array(
+ $cs[] = [
'2015-02-02 00:00:00',
'addAliceDues addBobDonation scheduleForDonation startWeekBefore repeatTwoWeeksAfter useHelloFirstName',
- array(
- array(
+ [
+ [
'time' => '2015-01-26 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- array(
+ ],
+ [
'time' => '2015-02-02 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- array(
+ ],
+ [
'time' => '2015-02-09 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- array(
+ ],
+ [
'time' => '2015-02-16 00:00:00',
- 'to' => array('bob@example.org'),
+ 'to' => ['bob@example.org'],
'subject' => '/Hello, Bob.*via subject/',
- ),
- ),
- );
+ ],
+ ],
+ ];
- $cs[] = array(
+ $cs[] = [
'2015-02-03 00:00:00',
'addAliceDues addBobDonation scheduleForSoftCreditor startWeekAfter useHelloFirstName',
- array(
- array(
+ [
+ [
'time' => '2015-02-10 00:00:00',
- 'to' => array('carol@example.org'),
+ 'to' => ['carol@example.org'],
'subject' => '/Hello, Carol.*via subject/',
- ),
- ),
- );
+ ],
+ ],
+ ];
return $cs;
}
* Create a contribution record for Alice with type "Member Dues".
*/
public function addAliceDues() {
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $this->contacts['alice']['id'],
'receive_date' => date('Ymd', strtotime($this->targetDate)),
'total_amount' => '100',
'net_amount' => '95',
'source' => 'SSF',
'contribution_status_id' => 1,
- 'soft_credit' => array(
- '1' => array(
+ 'soft_credit' => [
+ '1' => [
'contact_id' => $this->contacts['carol']['id'],
'amount' => 50,
'soft_credit_type_id' => 3,
- ),
- ),
- ));
+ ],
+ ],
+ ]);
}
/**
* Create a contribution record for Bob with type "Donation".
*/
public function addBobDonation() {
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $this->contacts['bob']['id'],
'receive_date' => date('Ymd', strtotime($this->targetDate)),
'total_amount' => '150',
'net_amount' => '145',
'source' => 'SSF',
'contribution_status_id' => 2,
- ));
+ ]);
}
/**
public function scheduleForDues() {
$this->schedule->mapping_id = CRM_Contribute_ActionMapping_ByType::MAPPING_ID;
$this->schedule->start_action_date = 'receive_date';
- $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(1));
- $this->schedule->entity_status = CRM_Utils_Array::implodePadded(array(1));
+ $this->schedule->entity_value = CRM_Utils_Array::implodePadded([1]);
+ $this->schedule->entity_status = CRM_Utils_Array::implodePadded([1]);
}
/**
public function scheduleForDonation() {
$this->schedule->mapping_id = CRM_Contribute_ActionMapping_ByType::MAPPING_ID;
$this->schedule->start_action_date = 'receive_date';
- $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(2));
+ $this->schedule->entity_value = CRM_Utils_Array::implodePadded([2]);
$this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL);
}
$this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL);
$this->schedule->limit_to = 1;
$this->schedule->recipient = 'soft_credit_type';
- $this->schedule->recipient_listing = CRM_Utils_Array::implodePadded(array(3));
+ $this->schedule->recipient_listing = CRM_Utils_Array::implodePadded([3]);
}
public function useHelloFirstNameStatus() {
*/
public function testCreate() {
- $params = array(
+ $params = [
'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
'title' => 'Test Contribution Page',
'financial_type_id' => $this->_financialTypeID,
'end_date' => '19700101000000',
'end_date_time' => '',
'is_credit_card_only' => '',
- );
+ ];
$contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
$this->assertNotNull($contributionpage->id);
$this->assertType('int', $contributionpage->id);
- $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionpage->id));
+ $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
}
/**
*/
public function testsetIsActive() {
- $params = array(
+ $params = [
'title' => 'Test Contribution Page',
'financial_type_id' => $this->_financialTypeID,
'is_active' => 1,
- );
+ ];
$contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
$id = $contributionpage->id;
$is_active = 1;
$pageActive = CRM_Contribute_BAO_ContributionPage::setIsActive($id, $is_active);
$this->assertEquals($pageActive, TRUE, 'Verify financial types record deletion.');
- $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionpage->id));
+ $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
}
/**
*/
public function testSetValues() {
- $params = array(
+ $params = [
'title' => 'Test Contribution Page',
'financial_type_id' => $this->_financialTypeID,
'is_active' => 1,
- );
+ ];
$contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
$id = $contributionPage->id;
- $values = array();
+ $values = [];
CRM_Contribute_BAO_ContributionPage::setValues($id, $values);
$this->assertEquals($params['title'], $values['title'], 'Verify contribution title.');
$this->assertEquals($this->_financialTypeID, $values['financial_type_id'], 'Verify financial types id.');
$this->assertEquals(1, $values['is_active'], 'Verify contribution is_active value.');
- $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionPage->id));
+ $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
}
/**
* Test copy() method
*/
public function testcopy() {
- $params = array(
+ $params = [
'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
'title' => 'Test Contribution Page',
'financial_type_id' => $this->_financialTypeID,
'end_date' => '19700101000000',
'end_date_time' => '',
'is_credit_card_only' => '',
- );
+ ];
$contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
$copyContributionPage = CRM_Contribute_BAO_ContributionPage::copy($contributionPage->id);
$this->assertEquals($copyContributionPage->financial_type_id, $this->_financialTypeID, 'Check for Financial type id.');
$this->assertEquals($copyContributionPage->goal_amount, 400, 'Check for goal amount.');
- $this->callAPISuccess('ContributionPage', 'delete', array('id' => $contributionPage->id));
- $this->callAPISuccess('ContributionPage', 'delete', array('id' => $copyContributionPage->id));
+ $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
+ $this->callAPISuccess('ContributionPage', 'delete', ['id' => $copyContributionPage->id]);
}
}
* @group headless
*/
class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase {
- protected $_params = array();
+ protected $_params = [];
public function setUp() {
parent::setUp();
$this->_ids['payment_processor'] = $this->paymentProcessorCreate();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->individualCreate(),
'amount' => 3.00,
'frequency_unit' => 'week',
'financial_type_id' => 1,
'payment_instrument_id' => 1,
'campaign_id' => NULL,
- );
+ ];
}
public function teardown() {
- $this->quickCleanup(array('civicrm_contribution_recur', 'civicrm_payment_processor'));
+ $this->quickCleanup(['civicrm_contribution_recur', 'civicrm_payment_processor']);
}
/**
*/
public function testSupportFinancialTypeChange() {
$contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $this->_params);
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'contribution_recur_id' => $contributionRecur['id'],
'total_amount' => '3.00',
'financial_type_id' => 1,
'contact_id' => $this->individualCreate(),
'contribution_status_id' => 1,
'receive_date' => 'yesterday',
- ));
+ ]);
$this->assertTrue(CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($contributionRecur['id']));
}
$createParams = $this->_params;
$createParams['currency'] = 'XAU';
$contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $createParams);
- $editParams = array(
+ $editParams = [
'id' => $contributionRecur['id'],
'end_date' => '+ 4 weeks',
- );
+ ];
$contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $editParams);
$dao = new CRM_Contribute_BAO_ContributionRecur();
$dao->id = $contributionRecur['id'];
public function testCreate() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81',
'thankyou_date' => '20080522',
'sequential' => TRUE,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
$contactId = $this->individualCreate();
//create custom data
- $customGroup = $this->customGroupCreate(array('extends' => 'Contribution'));
+ $customGroup = $this->customGroupCreate(['extends' => 'Contribution']);
$customGroupID = $customGroup['id'];
$customGroup = $customGroup['values'][$customGroupID];
- $fields = array(
+ $fields = [
'label' => 'testFld',
'data_type' => 'String',
'html_type' => 'Text',
'is_active' => 1,
'custom_group_id' => $customGroupID,
- );
+ ];
$customField = CRM_Core_BAO_CustomField::create($fields);
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
'thankyou_date' => '20080522',
'skipCleanMoney' => TRUE,
- );
+ ];
- $params['custom'] = array(
- $customField->id => array(
- -1 => array(
+ $params['custom'] = [
+ $customField->id => [
+ -1 => [
'value' => 'Test custom value',
'type' => 'String',
'custom_field_id' => $customField->id,
'table_name' => $customGroup['table_name'],
'column_name' => $customField->column_name,
'file_id' => NULL,
- ),
- ),
- );
+ ],
+ ],
+ ];
$contribution = CRM_Contribute_BAO_Contribution::create($params);
// Check that the custom field value is saved
- $customValueParams = array(
+ $customValueParams = [
'entityID' => $contribution->id,
'custom_' . $customField->id => 1,
- );
+ ];
$values = CRM_Core_BAO_CustomValueTable::getValues($customValueParams);
$this->assertEquals('Test custom value', $values['custom_' . $customField->id], 'Check the custom field value');
*/
public function testContributionCountDisabledFinancialType() {
$contactId = $this->individualCreate();
- $financialType = array(
+ $financialType = [
'name' => 'grassvariety1' . substr(sha1(rand()), 0, 7),
'is_reserved' => 0,
'is_active' => 0,
- );
+ ];
$finType = $this->callAPISuccess('financial_type', 'create', $financialType);
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => $finType['id'],
'trxn_id' => '22ereerwww322323',
'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
'thankyou_date' => '20080522',
- );
+ ];
$this->callAPISuccess('Contribution', 'create', $params);
- $this->callAPISuccess('financial_type', 'create', array('is_active' => 0, 'id' => $finType['id']));
+ $this->callAPISuccess('financial_type', 'create', ['is_active' => 0, 'id' => $finType['id']]);
$contributionCount = CRM_Contribute_BAO_Contribution::contributionCount($contactId);
$this->assertEquals(1, $contributionCount);
}
public function testDeleteContribution() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'invoice_id' => '33ed39c9e9ee6ef6031621ce0eafe6da70',
'thankyou_date' => '20080522',
'sequential' => TRUE,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
$honoreeProfileId = $ufGroupDAO->id;
}
- $params = array(
+ $params = [
'prefix_id' => 3,
'first_name' => $firstName,
'last_name' => $lastName,
'email-1' => $email,
- );
- $softParam = array('soft_credit_type_id' => 1);
+ ];
+ $softParam = ['soft_credit_type_id' => 1];
$null = [];
$honoreeContactId = CRM_Contact_BAO_Contact::createProfileContact($params, $null,
);
//create contribution on behalf of honary.
- $contactId = $this->individualCreate(array('first_name' => 'John', 'last_name' => 'Doe'));
+ $contactId = $this->individualCreate(['first_name' => 'John', 'last_name' => 'Doe']);
- $param = array(
+ $param = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 4,
'receive_date' => date('Ymd'),
'total_amount' => 66,
'sequential' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0];
$id = $contribution['id'];
);
//get honorary information
$getHonorContact = CRM_Contribute_BAO_Contribution::getHonorContacts($honoreeContactId);
- $this->assertEquals(array(
- $id => array(
+ $this->assertEquals([
+ $id => [
'honor_type' => 'In Honor of',
'honorId' => $contactId,
'display_name' => 'Mr. John Doe II',
'source' => NULL,
'receive_date' => date('Y-m-d 00:00:00'),
'contribution_status' => 'Completed',
- ),
- ), $getHonorContact);
+ ],
+ ], $getHonorContact);
$this->assertDBCompareValue('CRM_Contact_DAO_Contact', $honoreeContactId, 'first_name', 'id', $firstName,
'Database check for created honor contact record.'
* Test that financial type data is not added to the annual query if acls not enabled.
*/
public function testAnnualQueryWithFinancialHook() {
- $this->hookClass->setHook('civicrm_selectWhereClause', array($this, 'aclIdNoZero'));
+ $this->hookClass->setHook('civicrm_selectWhereClause', [$this, 'aclIdNoZero']);
$sql = CRM_Contribute_BAO_Contribution::getAnnualQuery([1, 2, 3]);
$this->assertContains('SUM(total_amount) as amount,', $sql);
$this->assertContains('WHERE b.contact_id IN (1,2,3)', $sql);
* sortName();
*/
public function testsortName() {
- $params = array(
+ $params = [
'first_name' => 'Shane',
'last_name' => 'Whatson',
'contact_type' => 'Individual',
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$this->assertInstanceOf('CRM_Contact_DAO_Contact', $contact, 'Check for created object');
$contactId = $contact->id;
- $param = array(
+ $param = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'invoice_id' => '22ed39c9e9ee621ce0eafe6da70',
'thankyou_date' => '20080522',
'sequential' => TRUE,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0];
public function testAddPremium() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'name' => 'TEST Premium',
'sku' => 111,
'imageOption' => 'noImage',
'cost' => 90.00,
'min_contribution' => 100,
'is_active' => 1,
- );
+ ];
$premium = CRM_Contribute_BAO_Product::create($params);
$this->assertEquals('TEST Premium', $premium->name, 'Check for premium name.');
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'invoice_id' => '98ed34f7u9hh672ce0eafe8fb92',
'thankyou_date' => '20080522',
'sequential' => TRUE,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams)['values'][0];
$this->assertEquals($contributionParams['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.');
$this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
//parameter for adding premium to contribution
- $data = array(
+ $data = [
'product_id' => $premium->id,
'contribution_id' => $contribution['id'],
'product_option' => NULL,
'quantity' => 1,
- );
+ ];
$contributionProduct = CRM_Contribute_BAO_Contribution::addPremium($data);
$this->assertEquals($contributionProduct->product_id, $premium->id, 'Check for Product id .');
public function testcheckDuplicateIds() {
$contactId = $this->individualCreate();
- $param = array(
+ $param = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'invoice_id' => '93ed39a9e9hd621bs0eafe3da82',
'thankyou_date' => '20080522',
'sequential' => TRUE,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0];
$this->assertEquals($param['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.');
$this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
- $data = array(
+ $data = [
'id' => $contribution['id'],
'trxn_id' => $contribution['trxn_id'],
'invoice_id' => $contribution['invoice_id'],
- );
+ ];
$contributionID = CRM_Contribute_BAO_Contribution::checkDuplicateIds($data);
$this->assertEquals($contributionID, $contribution['id'], 'Check for duplicate transcation id .');
}
public function testCreateCreditNoteId() {
$contactId = $this->individualCreate();
- $param = array(
+ $param = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'invoice_id' => '93ed39a9e9hd621bs0eafe3da82',
'thankyou_date' => '20080522',
'sequential' => TRUE,
- );
+ ];
$creditNoteId = CRM_Contribute_BAO_Contribution::createCreditNoteId();
$contribution = $this->callAPISuccess('Contribution', 'create', $param)['values'][0];
$this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id creation.');
$this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
- $trxnArray = array(
+ $trxnArray = [
'trxn_id' => $params['trxn_id'],
'is_payment' => 1,
- );
- $defaults = array();
+ ];
+ $defaults = [];
$financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
$this->assertEquals(1, $financialTrxn->N, 'Mismatch count for is payment flag.');
//update contribution amount
$this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id .');
$this->assertEquals($params['total_amount'], $contribution['total_amount'], 'Check for Amount updation.');
- $trxnArray = array(
+ $trxnArray = [
'trxn_id' => $params['trxn_id'],
'is_payment' => 1,
- );
- $defaults = array();
+ ];
+ $defaults = [];
$financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
$this->assertEquals(2, $financialTrxn->N, 'Mismatch count for is payment flag.');
$trxnArray['is_payment'] = 0;
public function testIsPaymentFlagForPending() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'invoice_id' => '86ed39c9e9yy6ef6541621ce0eafe7eb81',
'thankyou_date' => '20080522',
'sequential' => TRUE,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
$this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transaction id creation.');
$this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
- $trxnArray = array(
+ $trxnArray = [
'trxn_id' => $params['trxn_id'],
'is_payment' => 0,
- );
- $defaults = array();
+ ];
+ $defaults = [];
$financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
$this->assertEquals(2, $financialTrxn->N, 'Mismatch count for is payment flag.');
$trxnArray['is_payment'] = 1;
$this->assertEquals($params['trxn_id'], $contribution['trxn_id'], 'Check for transcation id .');
$this->assertEquals($params['contribution_status_id'], $contribution['contribution_status_id'], 'Check for status updation.');
- $trxnArray = array(
+ $trxnArray = [
'trxn_id' => $params['trxn_id'],
'is_payment' => 1,
- );
- $defaults = array();
+ ];
+ $defaults = [];
$financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
$this->assertEquals(1, $financialTrxn->N, 'Mismatch count for is payment flag.');
$trxnArray['is_payment'] = 0;
INNER JOIN civicrm_entity_financial_trxn eft1 ON (eft1.financial_trxn_id = eft.financial_trxn_id AND eft1.entity_table = 'civicrm_financial_item')
WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
- $queryParams[1] = array($contribution->id, 'Integer');
- $queryParams[2] = array($toFinancialAccount, 'Integer');
+ $queryParams[1] = [$contribution->id, 'Integer'];
+ $queryParams[2] = [$toFinancialAccount, 'Integer'];
$dao = CRM_Core_DAO::executeQuery($query, $queryParams);
- $amounts = array(100.00, 50.00);
+ $amounts = [100.00, 50.00];
while ($dao->fetch()) {
$this->assertEquals(150.00, $dao->total_amount, 'Mismatch of total amount paid.');
$this->assertEquals($dao->amount, array_pop($amounts), 'Mismatch of amount proportionally assigned to financial item');
*/
public function testAssignProportionalLineItems() {
list($lineItems, $contribution) = $this->addParticipantWithContribution();
- $params = array(
+ $params = [
'contribution_id' => $contribution->id,
'total_amount' => 150.00,
- );
+ ];
$trxn = new CRM_Financial_DAO_FinancialTrxn();
$trxn->orderBy('id DESC');
$trxn->find(TRUE);
$this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title',
'id', $paramsSet['title'], 'Check DB for created priceset'
);
- $paramsField = array(
+ $paramsField = [
'label' => 'Price Field',
'name' => CRM_Utils_String::titleToVar('Price Field'),
'html_type' => 'CheckBox',
- 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'),
- 'option_value' => array('1' => 100, '2' => 200),
- 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'),
- 'option_weight' => array('1' => 1, '2' => 2),
- 'option_amount' => array('1' => 100, '2' => 200),
+ 'option_label' => ['1' => 'Price Field 1', '2' => 'Price Field 2'],
+ 'option_value' => ['1' => 100, '2' => 200],
+ 'option_name' => ['1' => 'Price Field 1', '2' => 'Price Field 2'],
+ 'option_weight' => ['1' => 1, '2' => 2],
+ 'option_amount' => ['1' => 100, '2' => 200],
'is_display_amounts' => 1,
'weight' => 1,
'options_per_line' => 1,
- 'is_active' => array('1' => 1, '2' => 1),
+ 'is_active' => ['1' => 1, '2' => 1],
'price_set_id' => $priceset->id,
'is_enter_qty' => 1,
'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'),
- );
+ ];
$priceField = CRM_Price_BAO_PriceField::create($paramsField);
- $eventParams = array(
+ $eventParams = [
'id' => $this->_eventId,
'financial_type_id' => 4,
'is_monetary' => 1,
- );
+ ];
CRM_Event_BAO_Event::create($eventParams);
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceSetId);
- $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id));
- $participantParams = array(
+ $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField->id]);
+ $participantParams = [
'financial_type_id' => 4,
'event_id' => $this->_eventId,
'role_id' => 1,
'status_id' => 14,
'fee_currency' => 'USD',
'contact_id' => $this->_contactId,
- );
+ ];
$participant = CRM_Event_BAO_Participant::add($participantParams);
- $contributionParams = array(
+ $contributionParams = [
'total_amount' => 150,
'currency' => 'USD',
'contact_id' => $this->_contactId,
'contribution_mode' => 'participant',
'participant_id' => $participant->id,
'sequential' => TRUE,
- );
+ ];
foreach ($priceFields['values'] as $key => $priceField) {
- $lineItems[1][$key] = array(
+ $lineItems[1][$key] = [
'price_field_id' => $priceField['price_field_id'],
'price_field_value_id' => $priceField['id'],
'label' => $priceField['label'],
'unit_price' => $priceField['amount'],
'line_total' => $priceField['amount'],
'financial_type_id' => $priceField['financial_type_id'],
- );
+ ];
}
$contributionParams['line_item'] = $lineItems;
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams)['values'][0];
- $paymentParticipant = array(
+ $paymentParticipant = [
'participant_id' => $participant->id,
'contribution_id' => $contribution['id'],
- );
+ ];
CRM_Event_BAO_ParticipantPayment::create($paymentParticipant);
$contributionObject = new CRM_Contribute_BAO_Contribution();
$contributionObject->id = $contribution['id'];
$contributionObject->find(TRUE);
- return array($lineItems, $contributionObject);
+ return [$lineItems, $contributionObject];
}
/**
* checkLineItems() check if total amount matches the sum of line total
*/
public function testcheckLineItems() {
- $params = array(
+ $params = [
'contact_id' => 202,
'receive_date' => '2010-01-20',
'total_amount' => 100,
'financial_type_id' => 3,
- 'line_items' => array(
- array(
- 'line_item' => array(
- array(
+ 'line_items' => [
+ [
+ 'line_item' => [
+ [
'entity_table' => 'civicrm_contribution',
'price_field_id' => 8,
'price_field_value_id' => 16,
'qty' => 1,
'unit_price' => 100,
'line_total' => 100,
- ),
- array(
+ ],
+ [
'entity_table' => 'civicrm_contribution',
'price_field_id' => 8,
'price_field_value_id' => 17,
'unit_price' => 200,
'line_total' => 200,
'financial_type_id' => 1,
- ),
- ),
- 'params' => array(),
- ),
- ),
- );
+ ],
+ ],
+ 'params' => [],
+ ],
+ ],
+ ];
try {
CRM_Contribute_BAO_Contribution::checkLineItems($params);
* floating point values.
*/
public function testCheckLineItemsWithFloatingPointValues() {
- $params = array(
+ $params = [
'contact_id' => 202,
'receive_date' => date('Y-m-d'),
'total_amount' => 16.67,
'financial_type_id' => 3,
- 'line_items' => array(
- array(
- 'line_item' => array(
- array(
+ 'line_items' => [
+ [
+ 'line_item' => [
+ [
'entity_table' => 'civicrm_contribution',
'price_field_id' => 8,
'price_field_value_id' => 16,
'qty' => 1,
'unit_price' => 14.85,
'line_total' => 14.85,
- ),
- array(
+ ],
+ [
'entity_table' => 'civicrm_contribution',
'price_field_id' => 8,
'price_field_value_id' => 17,
'unit_price' => 1.66,
'line_total' => 1.66,
'financial_type_id' => 1,
- ),
- array(
+ ],
+ [
'entity_table' => 'civicrm_contribution',
'price_field_id' => 8,
'price_field_value_id' => 17,
'unit_price' => 0.16,
'line_total' => 0.16,
'financial_type_id' => 1,
- ),
- ),
- 'params' => array(),
- ),
- ),
- );
+ ],
+ ],
+ 'params' => [],
+ ],
+ ],
+ ];
$foundException = FALSE;
*/
public function testActivityCreate() {
$contactId = $this->individualCreate();
- $defaults = array();
+ $defaults = [];
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81',
'thankyou_date' => '20160519',
'sequential' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][0];
$this->assertEquals($contactId, $contribution['contact_id'], 'Check for contact id creation.');
// Check amount in activity.
- $activityParams = array(
+ $activityParams = [
'source_record_id' => $contribution['id'],
'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Contribution'),
- );
+ ];
// @todo use api instead.
$activity = CRM_Activity_BAO_Activity::retrieve($activityParams, $defaults);
*/
public function testAllowUpdateRevenueRecognitionDate() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'receive_date' => '2010-01-20',
'total_amount' => 100,
'financial_type_id' => 4,
- );
+ ];
$order = $this->callAPISuccess('order', 'create', $params);
$allowUpdate = CRM_Contribute_BAO_Contribution::allowUpdateRevenueRecognitionDate($order['id']);
$this->assertTrue($allowUpdate);
$event = $this->eventCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'receive_date' => '2010-01-20',
'total_amount' => 300,
'financial_type_id' => $this->getFinancialTypeId('Event Fee'),
'contribution_status_id' => 'Completed',
- );
+ ];
$priceFields = $this->createPriceSet('event', $event['id']);
foreach ($priceFields['values'] as $key => $priceField) {
- $lineItems[$key] = array(
+ $lineItems[$key] = [
'price_field_id' => $priceField['price_field_id'],
'price_field_value_id' => $priceField['id'],
'label' => $priceField['label'],
'line_total' => $priceField['amount'],
'financial_type_id' => $priceField['financial_type_id'],
'entity_table' => 'civicrm_participant',
- );
+ ];
}
- $params['line_items'][] = array(
+ $params['line_items'][] = [
'line_item' => $lineItems,
- 'params' => array(
+ 'params' => [
'contact_id' => $contactId,
'event_id' => $event['id'],
'status_id' => 1,
'role_id' => 1,
'register_date' => '2007-07-21 00:00:00',
'source' => 'Online Event Registration: API Testing',
- ),
- );
+ ],
+ ];
$order = $this->callAPISuccess('order', 'create', $params);
$allowUpdate = CRM_Contribute_BAO_Contribution::allowUpdateRevenueRecognitionDate($order['id']);
$this->assertFalse($allowUpdate);
- $params = array(
+ $params = [
'contact_id' => $contactId,
'receive_date' => '2010-01-20',
'total_amount' => 200,
'financial_type_id' => $this->getFinancialTypeId('Member Dues'),
'contribution_status_id' => 'Completed',
- );
+ ];
$membershipType = $this->membershipTypeCreate();
$priceFields = $this->createPriceSet();
- $lineItems = array();
+ $lineItems = [];
foreach ($priceFields['values'] as $key => $priceField) {
- $lineItems[$key] = array(
+ $lineItems[$key] = [
'price_field_id' => $priceField['price_field_id'],
'price_field_value_id' => $priceField['id'],
'label' => $priceField['label'],
'financial_type_id' => $priceField['financial_type_id'],
'entity_table' => 'civicrm_membership',
'membership_type_id' => $membershipType,
- );
+ ];
}
- $params['line_items'][] = array(
- 'line_item' => array(array_pop($lineItems)),
- 'params' => array(
+ $params['line_items'][] = [
+ 'line_item' => [array_pop($lineItems)],
+ 'params' => [
'contact_id' => $contactId,
'membership_type_id' => $membershipType,
'join_date' => '2006-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => 1,
- ),
- );
+ ],
+ ];
$order = $this->callAPISuccess('order', 'create', $params);
$allowUpdate = CRM_Contribute_BAO_Contribution::allowUpdateRevenueRecognitionDate($order['id']);
$this->assertFalse($allowUpdate);
* Test calculateFinancialItemAmount().
*/
public function testcalculateFinancialItemAmount() {
- $testParams = array(
- array(
- 'params' => array(),
- 'amountParams' => array(
+ $testParams = [
+ [
+ 'params' => [],
+ 'amountParams' => [
'line_total' => 100,
'previous_line_total' => 300,
'diff' => 1,
- ),
+ ],
'context' => 'changedAmount',
'expectedItemAmount' => -200,
- ),
- array(
- 'params' => array(),
- 'amountParams' => array(
+ ],
+ [
+ 'params' => [],
+ 'amountParams' => [
'line_total' => 100,
'previous_line_total' => 100,
'diff' => -1,
- ),
+ ],
// Most contexts are ignored. Removing refs to change payment instrument so placeholder.
'context' => 'not null',
'expectedItemAmount' => -100,
- ),
- array(
- 'params' => array(
+ ],
+ [
+ 'params' => [
'is_quick_config' => TRUE,
'total_amount' => 110,
'tax_amount' => 10,
- ),
- 'amountParams' => array(
+ ],
+ 'amountParams' => [
'item_amount' => 100,
- ),
+ ],
'context' => 'changedAmount',
'expectedItemAmount' => 100,
- ),
- array(
- 'params' => array(
+ ],
+ [
+ 'params' => [
'is_quick_config' => TRUE,
'total_amount' => 110,
'tax_amount' => 10,
- ),
- 'amountParams' => array(
+ ],
+ 'amountParams' => [
'item_amount' => NULL,
- ),
+ ],
'context' => 'changedAmount',
'expectedItemAmount' => 110,
- ),
- array(
- 'params' => array(
+ ],
+ [
+ 'params' => [
'is_quick_config' => TRUE,
'total_amount' => 110,
'tax_amount' => 10,
- ),
- 'amountParams' => array(
+ ],
+ 'amountParams' => [
'item_amount' => NULL,
- ),
+ ],
'context' => NULL,
'expectedItemAmount' => 100,
- ),
- );
+ ],
+ ];
foreach ($testParams as $params) {
$itemAmount = CRM_Contribute_BAO_Contribution::calculateFinancialItemAmount($params['params'], $params['amountParams'], $params['context']);
$this->assertEquals($itemAmount, $params['expectedItemAmount'], 'Invalid Financial Item amount.');
public function testCommaSeparatorAmount() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'total_amount' => '20000.00',
'partial_payment_total' => '20,000.00',
'partial_amount_to_pay' => '8,000.00',
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('total_amount'),
- )
+ 'return' => ['total_amount'],
+ ]
);
$this->assertEquals($financialTrxn['total_amount'], 8000, 'Invalid Tax amount.');
}
$this->enableTaxAndInvoicing();
$financialType = $this->createFinancialType();
$financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
- $expectedResult = array($financialAccount->financial_account_id => $financialAccount->financial_account_id);
+ $expectedResult = [$financialAccount->financial_account_id => $financialAccount->financial_account_id];
$financialType = $this->createFinancialType();
$financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
$expectedResult[$financialAccount->financial_account_id] = $financialAccount->financial_account_id;
public function testCreateProportionalEntry($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
list($contribution, $financialAccount) = $this->createContributionWithTax();
- $params = array(
+ $params = [
'total_amount' => 55,
'to_financial_account_id' => $financialAccount->financial_account_id,
'payment_instrument_id' => 1,
'trxn_date' => date('Ymd'),
'status_id' => 1,
'entity_id' => $contribution['id'],
- );
+ ];
$financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params);
- $entityParams = array(
+ $entityParams = [
'contribution_total_amount' => $contribution['total_amount'],
'trxn_total_amount' => 55,
'line_item_amount' => 100,
- );
+ ];
$previousLineItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']);
- $eftParams = array(
+ $eftParams = [
'entity_table' => 'civicrm_financial_item',
'entity_id' => $previousLineItem['id'],
'financial_trxn_id' => (string) $financialTrxn['id'],
- );
+ ];
CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams);
- $trxnTestArray = array_merge($eftParams, array(
+ $trxnTestArray = array_merge($eftParams, [
'amount' => '50.00',
- ));
+ ]);
$this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray);
}
*/
public function testCreateProportionalEntryZeroAmount($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
- list($contribution, $financialAccount) = $this->createContributionWithTax(array('total_amount' => 0));
- $params = array(
+ list($contribution, $financialAccount) = $this->createContributionWithTax(['total_amount' => 0]);
+ $params = [
'total_amount' => 0,
'to_financial_account_id' => $financialAccount->financial_account_id,
'payment_instrument_id' => 1,
'trxn_date' => date('Ymd'),
'status_id' => 1,
'entity_id' => $contribution['id'],
- );
+ ];
$financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params);
- $entityParams = array(
+ $entityParams = [
'contribution_total_amount' => $contribution['total_amount'],
'trxn_total_amount' => 0,
'line_item_amount' => 0,
- );
+ ];
$previousLineItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']);
- $eftParams = array(
+ $eftParams = [
'entity_table' => 'civicrm_financial_item',
'entity_id' => $previousLineItem['id'],
'financial_trxn_id' => (string) $financialTrxn['id'],
- );
+ ];
CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams);
- $trxnTestArray = array_merge($eftParams, array(
+ $trxnTestArray = array_merge($eftParams, [
'amount' => '0.00',
- ));
+ ]);
$this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray);
}
*/
public function testProportionallyAssignedForPIChange() {
list($contribution, $financialAccount) = $this->createContributionWithTax();
- $params = array(
+ $params = [
'id' => $contribution['id'],
'payment_instrument_id' => 3,
- );
+ ];
$this->callAPISuccess('Contribution', 'create', $params);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
- $eftParams = array(
+ $eftParams = [
'entity_table' => 'civicrm_financial_item',
'financial_trxn_id' => $lastFinancialTrxnId['financialTrxnId'],
- );
+ ];
$entityFinancialTrxn = $this->callAPISuccess('EntityFinancialTrxn', 'Get', $eftParams);
$this->assertEquals($entityFinancialTrxn['count'], 2, 'Invalid count.');
- $testAmount = array(10, 100);
+ $testAmount = [10, 100];
foreach ($entityFinancialTrxn['values'] as $value) {
$this->assertEquals($value['amount'], array_pop($testAmount), 'Invalid amount stored in civicrm_entity_financial_trxn.');
}
/**
* Function to create contribution with tax.
*/
- public function createContributionWithTax($params = array(), $isCompleted = TRUE) {
+ public function createContributionWithTax($params = [], $isCompleted = TRUE) {
if (!isset($params['total_amount'])) {
$params['total_amount'] = 100;
}
$financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => $params['total_amount'],
'financial_type_id' => $financialType['id'],
'contact_id' => $contactId,
'contribution_status_id' => $isCompleted ? 1 : 2,
'price_set_id' => 0,
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
$contribution = $this->callAPISuccessGetSingle('Contribution',
- array(
+ [
'contact_id' => $contactId,
- 'return' => array('tax_amount', 'total_amount'),
- )
+ 'return' => ['tax_amount', 'total_amount'],
+ ]
);
- return array($contribution, $financialAccount);
+ return [$contribution, $financialAccount];
}
/**
* Test processOnBehalfOrganization() function.
*/
public function testProcessOnBehalfOrganization() {
- $orgInfo = array(
+ $orgInfo = [
'phone' => '11111111',
'email' => 'testorg@gmail.com',
'street_address' => 'test Street',
'state_province' => 'AA',
'postal_code' => '222222',
'country' => 'United States',
- );
+ ];
$contactID = $this->individualCreate();
- $orgId = $this->organizationCreate(array('organization_name' => 'testorg1'));
- $orgCount = $this->callAPISuccessGetCount('Contact', array(
+ $orgId = $this->organizationCreate(['organization_name' => 'testorg1']);
+ $orgCount = $this->callAPISuccessGetCount('Contact', [
'contact_type' => "Organization",
'organization_name' => "testorg1",
- ));
+ ]);
$this->assertEquals($orgCount, 1);
- $values = $params = array();
- $behalfOrganization = array(
+ $values = $params = [];
+ $behalfOrganization = [
'organization_name' => 'testorg1',
- 'phone' => array(
- 1 => array(
+ 'phone' => [
+ 1 => [
'phone' => $orgInfo['phone'],
'is_primary' => 1,
- ),
- ),
- 'email' => array(
- 1 => array(
+ ],
+ ],
+ 'email' => [
+ 1 => [
'email' => $orgInfo['email'],
'is_primary' => 1,
- ),
- ),
- 'address' => array(
- 3 => array(
+ ],
+ ],
+ 'address' => [
+ 3 => [
'street_address' => $orgInfo['street_address'],
'city' => $orgInfo['city'],
'location_type_id' => 3,
'country' => 'US',
'state_province' => 'AA',
'is_primary' => 1,
- ),
- ),
- );
- $fields = array(
+ ],
+ ],
+ ];
+ $fields = [
'organization_name' => 1,
'phone-3-1' => 1,
'email-3' => 1,
'postal_code-3' => 1,
'country-3' => 1,
'state_province-3' => 1,
- );
+ ];
CRM_Contribute_Form_Contribution_Confirm::processOnBehalfOrganization($behalfOrganization, $contactID, $values, $params, $fields);
//Check whether new organisation is not created.
- $result = $this->callAPISuccess('Contact', 'get', array(
+ $result = $this->callAPISuccess('Contact', 'get', [
'contact_type' => "Organization",
'organization_name' => "testorg1",
- ));
+ ]);
$this->assertEquals($result['count'], 1);
//Assert all org values are updated.
}
//Check if alert is assigned to params if more than 1 dupe exists.
- $orgId = $this->organizationCreate(array('organization_name' => 'testorg1', 'email' => 'testorg@gmail.com'));
+ $orgId = $this->organizationCreate(['organization_name' => 'testorg1', 'email' => 'testorg@gmail.com']);
CRM_Contribute_Form_Contribution_Confirm::processOnBehalfOrganization($behalfOrganization, $contactID, $values, $params, $fields);
$this->assertEquals($params['onbehalf_dupe_alert'], 1);
}
$customGroup = $this->customGroupCreate(['extends' => 'Contribution', 'title' => 'contribution stuff']);
$customField = $this->customFieldOptionValueCreate($customGroup, 'myCustomField');
$contactId1 = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId1,
'receive_date' => '20120511',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 2,
"custom_{$customField['id']}" => 'value1',
- );
+ ];
$contribution1 = $this->contributionCreate($params);
$contactId2 = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId2,
'receive_date' => '20150511',
'total_amount' => 200.00,
'source' => 'ABC',
'contribution_status_id' => 1,
"custom_{$customField['id']}" => 'value2',
- );
+ ];
$contribution2 = $this->contributionCreate($params);
- $ids = array($contribution1, $contribution2);
+ $ids = [$contribution1, $contribution2];
$subject = "This is a test for contribution ID: {contribution.contribution_id}";
$text = "Contribution Amount: {contribution.total_amount}";
public function testContributionWithDeferredRevenue() {
$contactId = $this->individualCreate();
Civi::settings()->set('deferred_revenue_enabled', TRUE);
- $params = array(
+ $params = [
'contact_id' => $contactId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 'Completed',
'revenue_recognition_date' => date('Ymd', strtotime("+3 month")),
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccessGetCount('EntityFinancialTrxn', array(
+ $this->callAPISuccessGetCount('EntityFinancialTrxn', [
'entity_table' => "civicrm_contribution",
'entity_id' => $contribution['id'],
- ), 2);
+ ], 2);
- $checkAgainst = array(
+ $checkAgainst = [
'financial_trxn_id.to_financial_account_id.name' => 'Deferred Revenue - Event Fee',
'financial_trxn_id.from_financial_account_id.name' => 'Event Fee',
'financial_trxn_id' => '2',
- );
- $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array(
- 'return' => array(
+ ];
+ $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', [
+ 'return' => [
"financial_trxn_id.from_financial_account_id.name",
"financial_trxn_id.to_financial_account_id.name",
"financial_trxn_id",
- ),
+ ],
'entity_table' => "civicrm_contribution",
'entity_id' => $contribution['id'],
'financial_trxn_id.is_payment' => 0,
- ), $checkAgainst);
+ ], $checkAgainst);
- $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array(
+ $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', [
'entity_table' => "civicrm_financial_item",
'financial_trxn_id' => $result['financial_trxn_id'],
- 'return' => array('entity_id'),
- ));
+ 'return' => ['entity_id'],
+ ]);
- $checkAgainst = array(
+ $checkAgainst = [
'financial_account_id.name' => 'Deferred Revenue - Event Fee',
'id' => $result['entity_id'],
- );
- $result = $this->callAPISuccessGetSingle('FinancialItem', array(
+ ];
+ $result = $this->callAPISuccessGetSingle('FinancialItem', [
'id' => $result['entity_id'],
- 'return' => array("financial_account_id.name"),
- ), $checkAgainst);
+ 'return' => ["financial_account_id.name"],
+ ], $checkAgainst);
}
/**
public function testChangingFinancialTypeWithoutTax() {
$ids = $values = [];
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'receive_date' => date('YmdHis'),
'total_amount' => 100.00,
'financial_type_id' => 'Donation',
'contribution_status_id' => 'Completed',
- );
+ ];
/* first test the scenario when sending an email */
$contributionId = $this->callAPISuccess(
'contribution',
* CRM-21424 Check if the receipt update is set after composing the receipt message
*/
public function testSendMailUpdateReceiptDate() {
- $ids = $values = array();
+ $ids = $values = [];
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'financial_type_id' => 'Donation',
'source' => 'SSF',
'contribution_status_id' => 'Completed',
- );
+ ];
/* first test the scenario when sending an email */
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$contributionId = $contribution['id'];
$this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After creating receipt date must be null');
- $input = array('receipt_update' => 0);
+ $input = ['receipt_update' => 0];
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values);
$this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail, with the explicit instruction not to update receipt date stays null');
- $input = array('receipt_update' => 1);
+ $input = ['receipt_update' => 1];
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values);
$this->assertDBNotNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail with the permission to allow update receipt date must be set');
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$contributionId = $contribution['id'];
$this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After creating receipt date must be null');
- $input = array('receipt_update' => 0);
+ $input = ['receipt_update' => 0];
/* setting the lasast parameter (returnmessagetext) to TRUE is done by the download of the pdf */
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values, TRUE);
$this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail, with the explicit instruction not to update receipt date stays null');
- $input = array('receipt_update' => 1);
+ $input = ['receipt_update' => 1];
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values, TRUE);
$this->assertDBNotNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail with the permission to allow update receipt date must be set');
}
* Check method add()
*/
public function testAdd() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$contributionType = CRM_Financial_BAO_FinancialType::add($params, $ids);
$result = $this->assertDBNotNull('CRM_Financial_BAO_FinancialType', $contributionType->id,
* Check method retrive()
*/
public function testRetrieve() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$contributionType = CRM_Financial_BAO_FinancialType::add($params, $ids);
- $defaults = array();
+ $defaults = [];
$result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults);
$this->assertEquals($result->name, 'Donations', 'Verify financial type name.');
* Check method setIsActive()
*/
public function testSetIsActive() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$contributionType = CRM_Financial_BAO_FinancialType::add($params, $ids);
$result = CRM_Financial_BAO_FinancialType::setIsActive($contributionType->id, 0);
$this->assertEquals($result, TRUE, 'Verify financial type record updation for is_active.');
* Check method del()
*/
public function testdel() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$contributionType = CRM_Financial_BAO_FinancialType::add($params, $ids);
CRM_Financial_BAO_FinancialType::del($contributionType->id);
- $params = array('id' => $contributionType->id);
+ $params = ['id' => $contributionType->id];
$result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults);
$this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
}
* Check method add()
*/
public function testAdd() {
- $params = array(
+ $params = [
'name' => 'Test Product',
'sku' => 'TP-10',
'imageOption' => 'noImage',
'cost' => 5,
'min_contribution' => 5,
'is_active' => 1,
- );
+ ];
$product = CRM_Contribute_BAO_Product::create($params);
$result = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id,
* Check method retrieve( )
*/
public function testRetrieve() {
- $params = array(
+ $params = [
'name' => 'Test Product',
'sku' => 'TP-10',
'imageOption' => 'noImage',
'cost' => 5,
'min_contribution' => 5,
'is_active' => 1,
- );
+ ];
$product = CRM_Contribute_BAO_Product::create($params);
- $params = array('id' => $product->id);
- $default = array();
+ $params = ['id' => $product->id];
+ $default = [];
$result = CRM_Contribute_BAO_Product::retrieve($params, $default);
$this->assertEquals(empty($result), FALSE, 'Verify products record.');
}
* Check method setIsActive( )
*/
public function testSetIsActive() {
- $params = array(
+ $params = [
'name' => 'Test Product',
'sku' => 'TP-10',
'imageOption' => 'noImage',
'cost' => 5,
'min_contribution' => 5,
'is_active' => 1,
- );
+ ];
$product = CRM_Contribute_BAO_Product::create($params);
CRM_Contribute_BAO_Product::setIsActive($product->id, 0);
* Check method del( )
*/
public function testDel() {
- $params = array(
+ $params = [
'name' => 'Test Product',
'sku' => 'TP-10',
'imageOption' => 'noImage',
'cost' => 5,
'min_contribution' => 5,
'is_active' => 1,
- );
+ ];
$product = CRM_Contribute_BAO_Product::create($params);
CRM_Contribute_BAO_Product::del($product->id);
- $params = array('id' => $product->id);
- $defaults = array();
+ $params = ['id' => $product->id];
+ $defaults = [];
$retrievedProduct = CRM_Contribute_BAO_Product::retrieve($params, $defaults);
$this->assertEquals(empty($retrievedProduct), TRUE, 'Verify product record deletion.');
*
* @var array
*/
- protected $_processorParams = array();
+ protected $_processorParams = [];
/**
* Payment instrument mapping.
*
* @var array
*/
- protected $paymentInstruments = array();
+ protected $paymentInstruments = [];
/**
* Dummy payment processor.
$this->createLoggedInUser();
$this->_individualId = $this->individualCreate();
- $this->_params = array(
+ $this->_params = [
'total_amount' => 100,
'currency' => 'USD',
'contact_id' => $this->_individualId,
'financial_type_id' => 1,
- );
- $this->_processorParams = array(
+ ];
+ $this->_processorParams = [
'domain_id' => 1,
'name' => 'Dummy',
'payment_processor_type_id' => 10,
'url_site' => 'http://dummy.com',
'url_recur' => 'http://dummy.com',
'billing_mode' => 1,
- );
+ ];
- $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
+ $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
$this->paymentInstruments = $instruments['values'];
$this->paymentProcessor = $this->dummyProcessorCreate();
// pay additional amount by using Credit Card
$this->submitPayment(70, 'live', TRUE);
- $this->checkResults(array(30, 70), 2);
+ $this->checkResults([30, 70], 2);
$mut->assertSubjects(['Payment Receipt -']);
$mut->checkMailLog([
'Dear Anthony,',
// pay additional amount
$this->submitPayment(70);
- $this->checkResults(array(30, 70), 2);
+ $this->checkResults([30, 70], 2);
}
/**
// pay additional amount
$this->submitPayment(50);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
// pay additional amount
$this->submitPayment(20);
- $this->checkResults(array(30, 50, 20), 3);
+ $this->checkResults([30, 50, 20], 3);
$activities = $this->callAPISuccess('Activity', 'get', [
'source_record_id' => $this->_contributionId,
'activity_type_id' => 'Payment',
// pay additional amount
$this->submitPayment(50, NULL, TRUE);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
// pay additional amount by using credit card
$this->submitPayment(20, 'live');
- $this->checkResults(array(30, 50, 20), 3);
- $mut->assertSubjects(array('Payment Receipt -'));
+ $this->checkResults([30, 50, 20], 3);
+ $mut->assertSubjects(['Payment Receipt -']);
$mut->checkMailLog([
'Dear Anthony,',
'A payment has been received',
// pay additional amount by using Credit Card
$this->submitPayment(100, 'live');
- $this->checkResults(array(100), 1);
+ $this->checkResults([100], 1);
}
/**
// pay additional amount
$this->submitPayment(70);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
// pay additional amount
$this->submitPayment(30);
- $this->checkResults(array(30, 70), 2);
+ $this->checkResults([30, 70], 2);
}
/**
$membership = $this->createPendingMembershipAndRecordContribution($this->_contributionId);
// pay additional amount
$this->submitPayment(100);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
- $contributionMembership = $this->callAPISuccessGetSingle('Membership', array('id' => $membership["id"]));
- $membershipStatus = $this->callAPISuccessGetSingle('MembershipStatus', array('id' => $contributionMembership["status_id"]));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
+ $contributionMembership = $this->callAPISuccessGetSingle('Membership', ['id' => $membership["id"]]);
+ $membershipStatus = $this->callAPISuccessGetSingle('MembershipStatus', ['id' => $contributionMembership["status_id"]]);
$this->assertEquals('New', $membershipStatus['name']);
}
private function createPendingMembershipAndRecordContribution($contributionId) {
$this->_individualId = $this->individualCreate();
- $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array(
+ $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', [
'domain_id' => 1,
'name' => "AnnualFixed",
'member_of_contact_id' => 1,
'fixed_period_rollover_day' => "1231",
'relationship_type_id' => 20,
'financial_type_id' => 2,
- ));
+ ]);
$membershipStatuses = CRM_Member_PseudoConstant::membershipStatus();
$pendingStatusId = array_search('Pending', $membershipStatuses);
- $membership = $this->callAPISuccess('Membership', 'create', array(
+ $membership = $this->callAPISuccess('Membership', 'create', [
'contact_id' => $this->_individualId,
'membership_type_id' => $membershipTypeAnnualFixed['id'],
- ));
+ ]);
// Updating Membership status to Pending
- $membership = $this->callAPISuccess('Membership', 'create', array(
+ $membership = $this->callAPISuccess('Membership', 'create', [
'id' => $membership["id"],
'status_id' => $pendingStatusId,
- ));
- $membershipPayment = $this->callAPISuccess('MembershipPayment', 'create', array(
+ ]);
+ $membershipPayment = $this->callAPISuccess('MembershipPayment', 'create', [
'membership_id' => $membership["id"],
'contribution_id' => $contributionId,
- ));
+ ]);
return $membership;
}
// pay additional amount
$this->submitPayment(40);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
$this->submitPayment(20);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
$this->submitPayment(30);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
$this->submitPayment(10);
- $this->checkResults(array(40, 20, 30, 10), 4);
+ $this->checkResults([40, 20, 30, 10], 4);
}
/**
// pay additional amount
$this->submitPayment(50);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
$this->submitPayment(20, 'live');
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
$this->submitPayment(20);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
$this->submitPayment(10, 'live');
- $this->checkResults(array(50, 20, 20, 10), 4);
+ $this->checkResults([50, 20, 20, 10], 4);
}
/**
*/
public function createContribution($typeofContribution = 'Pending') {
if ($typeofContribution == 'Partially paid') {
- $contributionParams = array_merge($this->_params, array(
+ $contributionParams = array_merge($this->_params, [
'partial_payment_total' => 100.00,
'partial_amount_to_pay' => 30,
'contribution_status_id' => 1,
- ));
+ ]);
}
elseif ($typeofContribution == 'Pending') {
- $contributionParams = array_merge($this->_params, array(
+ $contributionParams = array_merge($this->_params, [
'contribution_status_id' => 2,
'is_pay_later' => 1,
- ));
+ ]);
}
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contribution['id']));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
$this->assertNotEmpty($contribution);
$this->assertEquals($typeofContribution, $contribution['contribution_status']);
$this->_contributionId = $contribution['id'];
public function submitPayment($amount, $mode = NULL, $isEmailReceipt = FALSE) {
$form = new CRM_Contribute_Form_AdditionalPayment();
- $submitParams = array(
+ $submitParams = [
'contribution_id' => $this->_contributionId,
'contact_id' => $this->_individualId,
'total_amount' => $amount,
'payment_processor_id' => 0,
'is_email_receipt' => $isEmailReceipt,
'from_email_address' => 'site@something.com',
- );
+ ];
if ($mode) {
- $submitParams += array(
+ $submitParams += [
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'payment_processor_id' => $this->paymentProcessorID,
- 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025),
+ 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
'credit_card_number' => '411111111111111',
'cvv2' => 234,
'credit_card_type' => 'Visa',
'billing_state_province_id-5' => 1059,
'billing_postal_code-5' => 1321312,
'billing_country_id-5' => 1228,
- );
+ ];
}
else {
- $submitParams += array(
+ $submitParams += [
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'check_number' => 'check-12345',
- );
+ ];
}
$form->cid = $this->_individualId;
$form->testSubmit($submitParams, $mode);
*
*/
public function checkResults($amounts, $count) {
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $this->_contributionId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
$this->assertNotEmpty($contribution);
$this->assertEquals('Completed', $contribution['contribution_status']);
- $this->callAPISuccessGetCount('EntityFinancialTrxn', array(
+ $this->callAPISuccessGetCount('EntityFinancialTrxn', [
'entity_table' => "civicrm_contribution",
'entity_id' => $this->_contributionId,
'financial_trxn_id.is_payment' => 1,
- 'financial_trxn_id.total_amount' => array('IN' => $amounts),
- ), $count);
+ 'financial_trxn_id.total_amount' => ['IN' => $amounts],
+ ], $count);
}
}
*/
public function testPaynowPayment() {
$contactID = $this->individualCreate();
- $paymentProcessorID = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy'));
+ $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']);
// create a contribution page which is later used to make pay-later contribution
- $result = $this->callAPISuccess('ContributionPage', 'create', array(
+ $result = $this->callAPISuccess('ContributionPage', 'create', [
'title' => 'Test Contribution Page',
'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'),
'currency' => 'USD',
'is_allow_other_amount' => 1,
'min_amount' => 20,
'max_amount' => 2000,
- ));
+ ]);
$contributionPageID1 = $result['id'];
// create pending contribution
- $contribution = $this->callAPISuccess('Contribution', 'create', array(
+ $contribution = $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $contactID,
'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'),
'currency' => 'USD',
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'),
'contribution_page_id' => $contributionPageID1,
'source' => 'backoffice pending contribution',
- ));
+ ]);
// create a contribution page which is later used to make online payment for pending contribution
- $result = $this->callAPISuccess('ContributionPage', 'create', array(
+ $result = $this->callAPISuccess('ContributionPage', 'create', [
'title' => 'Test Contribution Page',
'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'),
'currency' => 'USD',
'is_allow_other_amount' => 1,
'min_amount' => 10,
'max_amount' => 1000,
- ));
+ ]);
$form = new CRM_Contribute_Form_Contribution_Confirm();
$contributionPageID2 = $result['id'];
$form->_id = $contributionPageID2;
$form->_values = $result['values'][$contributionPageID2];
- $form->_paymentProcessor = array(
+ $form->_paymentProcessor = [
'id' => $paymentProcessorID,
'billing_mode' => CRM_Core_Payment::BILLING_MODE_FORM,
'object' => Civi\Payment\System::singleton()->getById($paymentProcessorID),
'is_recur' => FALSE,
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Credit card'),
- );
- $form->_params = array(
+ ];
+ $form->_params = [
'qfKey' => 'donotcare',
'contribution_id' => $contribution['id'],
'credit_card_number' => 4111111111111111,
'cvv2' => 234,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 2,
'Y' => 2021,
- ),
+ ],
'credit_card_type' => 'Visa',
'email-5' => 'test@test.com',
'total_amount' => 100.00,
'is_quick_config' => 1,
'description' => $contribution['values'][$contribution['id']]['source'],
'skipLineItem' => 0,
- );
+ ];
$processConfirmResult = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form,
$form->_params,
// Based on the processed contribution, complete transaction which update the contribution status based on payment result.
if (!empty($processConfirmResult['contribution'])) {
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $processConfirmResult['contribution']->id,
'trxn_date' => date('Y-m-d'),
'payment_processor_id' => $paymentProcessorID,
- ));
+ ]);
}
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'id' => $form->_params['contribution_id'],
- 'return' => array(
+ 'return' => [
'contribution_page_id',
'contribution_status',
'contribution_source',
- ),
- ));
+ ],
+ ]);
// check that contribution page ID isn't changed
$this->assertEquals($contributionPageID1, $contribution['contribution_page_id']);
* Test that the membership is set to recurring if the membership type is always autorenew.
*/
public function testSetRecurFunction() {
- $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 2, 'minimum_fee' => 80));
+ $membershipTypeID = $this->membershipTypeCreate(['auto_renew' => 2, 'minimum_fee' => 80]);
$form = $this->getContributionForm();
- $form->testSubmit(array(
+ $form->testSubmit([
'selectMembership' => $membershipTypeID,
- ));
+ ]);
$this->assertEquals(1, $form->_params['is_recur']);
}
* Test that the membership is set to recurring if the membership type is always autorenew.
*/
public function testSetRecurFunctionOptionalYes() {
- $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 1, 'minimum_fee' => 80));
+ $membershipTypeID = $this->membershipTypeCreate(['auto_renew' => 1, 'minimum_fee' => 80]);
$form = $this->getContributionForm();
- $form->testSubmit(array(
+ $form->testSubmit([
'selectMembership' => $membershipTypeID,
'is_recur' => 1,
- ));
+ ]);
$this->assertEquals(1, $form->_params['is_recur']);
}
* Test that the membership is set to recurring if the membership type is always autorenew.
*/
public function testSetRecurFunctionOptionalNo() {
- $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 1, 'minimum_fee' => 80));
+ $membershipTypeID = $this->membershipTypeCreate(['auto_renew' => 1, 'minimum_fee' => 80]);
$form = $this->getContributionForm();
- $form->testSubmit(array(
+ $form->testSubmit([
'selectMembership' => $membershipTypeID,
'is_recur' => 0,
- ));
+ ]);
$this->assertEquals(0, $form->_params['is_recur']);
}
* Test that the membership is set to recurring if the membership type is always autorenew.
*/
public function testSetRecurFunctionNotAvailable() {
- $membershipTypeID = $this->membershipTypeCreate(array('auto_renew' => 0, 'minimum_fee' => 80));
+ $membershipTypeID = $this->membershipTypeCreate(['auto_renew' => 0, 'minimum_fee' => 80]);
$form = $this->getContributionForm();
- $form->testSubmit(array(
+ $form->testSubmit([
'selectMembership' => $membershipTypeID,
- ));
+ ]);
$this->assertArrayNotHasKey('is_recur', $form->_params);
}
$form = new CRM_Contribute_Form_Contribution_Main();
$form->_values['is_monetary'] = 1;
$form->_values['is_pay_later'] = 0;
- $form->_priceSetId = $this->callAPISuccessGetValue('PriceSet', array(
+ $form->_priceSetId = $this->callAPISuccessGetValue('PriceSet', [
'name' => 'default_membership_type_amount',
'return' => 'id',
- ));
- $priceFields = $this->callAPISuccess('PriceField', 'get', array('id' => $form->_priceSetId));
+ ]);
+ $priceFields = $this->callAPISuccess('PriceField', 'get', ['id' => $form->_priceSetId]);
$form->_priceSet['fields'] = $priceFields['values'];
- $paymentProcessorID = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy'));
- $form->_paymentProcessor = array(
+ $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']);
+ $form->_paymentProcessor = [
'billing_mode' => CRM_Core_Payment::BILLING_MODE_FORM,
'object' => Civi\Payment\System::singleton()->getById($paymentProcessorID),
'is_recur' => TRUE,
- );
- $form->_values = array(
+ ];
+ $form->_values = [
'title' => "Test Contribution Page",
'financial_type_id' => 1,
'currency' => 'NZD',
'is_monetary' => TRUE,
'pay_later_text' => 'Front up',
'pay_later_receipt' => 'Ta',
- );
+ ];
return $form;
}
*/
public function testExpiredPriceSet() {
$form = $this->getContributionForm();
- $priceSetParams1 = array(
+ $priceSetParams1 = [
'name' => 'priceset',
'title' => 'Priceset with Multiple Terms',
'is_active' => 1,
'financial_type_id' => 2,
'is_quick_config' => 1,
'is_reserved' => 1,
- );
+ ];
$priceSet = $this->callAPISuccess('price_set', 'create', $priceSetParams1);
$form->_priceSetId = $priceSet['id'];
$form->controller = new CRM_Core_Controller();
$form->set('priceSetId', $form->_priceSetId);
- $params = array(
+ $params = [
'price_set_id' => $form->_priceSetId,
'name' => 'testvalidpf',
'label' => 'test valid pf',
'html_type' => 'Radio',
'is_enter_qty' => 1,
'is_active' => 1,
- );
+ ];
$priceField1 = $this->callAPISuccess('PriceField', 'create', $params);
//Create expired price field.
- $params = array(
+ $params = [
'price_set_id' => $form->_priceSetId,
'name' => 'testexpiredpf',
'label' => 'test expired pf',
'is_enter_qty' => 1,
'is_active' => 1,
'expire_on' => date('Y-m-d', strtotime("-1 days")),
- );
+ ];
$priceField2 = $this->callAPISuccess('PriceField', 'create', $params);
//Create price options.
$membershipOrgId = $this->organizationCreate(NULL);
- $memtype = $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId));
- foreach (array($priceField1, $priceField2) as $priceField) {
- $priceFieldValueParams = array(
+ $memtype = $this->membershipTypeCreate(['member_of_contact_id' => $membershipOrgId]);
+ foreach ([$priceField1, $priceField2] as $priceField) {
+ $priceFieldValueParams = [
'price_field_id' => $priceField['id'],
'name' => 'rye grass',
'membership_type_id' => $memtype,
'amount' => 1,
'membership_num_terms' => 2,
'financial_type_id' => 1,
- );
+ ];
$this->callAPISuccess('PriceFieldValue', 'create', $priceFieldValueParams);
}
* Test that correct contribution status is fetched for both live and test contributions.
*/
public function testLiveAndTestContributionStatus() {
- $paymentProcessorID = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy'));
+ $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']);
$form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, FALSE);
$form->buildQuickForm();
private function getThankYouFormWithContribution($paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) {
$pageContribution = $this->getPageContribution((($withPendingContribution) ? 2 : 1), $isTestContribution);
$form = $this->getThankYouForm();
- $form->_lineItem = array();
+ $form->_lineItem = [];
$form->_params['contributionID'] = $pageContribution['contribution_id'];
$form->_params['invoiceID'] = $pageContribution['invoice_id'];
$individualId = $this->individualCreate();
$invoiceId = rand(100000, 999999);
- $contributionId = $this->contributionCreate(array(
+ $contributionId = $this->contributionCreate([
'contact_id' => $individualId,
'invoice_id' => $invoiceId,
'contribution_status_id' => $contributionStatus,
'is_test' => ($isTest) ? 1 : 0,
- ));
+ ]);
- return array(
+ return [
'contribution_id' => $contributionId,
'invoice_id' => $invoiceId,
- );
+ ];
}
/**
protected $_apiversion;
protected $_entity = 'Contribution';
protected $_params;
- protected $_ids = array();
- protected $_pageParams = array();
+ protected $_ids = [];
+ protected $_pageParams = [];
protected $_userId;
/**
*
* @var array
*/
- protected $_processorParams = array();
+ protected $_processorParams = [];
/**
* ID of created event.
*
* @var array
*/
- protected $paymentInstruments = array();
+ protected $paymentInstruments = [];
/**
* Products.
*
* @var array
*/
- protected $products = array();
+ protected $products = [];
/**
* Dummy payment processor.
$this->_userId = $this->createLoggedInUser();
$this->_individualId = $this->individualCreate();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'net_amount' => 95.00,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
- $this->_processorParams = array(
+ ];
+ $this->_processorParams = [
'domain_id' => 1,
'name' => 'Dummy',
'payment_processor_type_id' => 10,
'url_site' => 'http://dummy.com',
'url_recur' => 'http://dummy.com',
'billing_mode' => 1,
- );
+ ];
- $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
+ $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
$this->paymentInstruments = $instruments['values'];
- $product1 = $this->callAPISuccess('product', 'create', array(
+ $product1 = $this->callAPISuccess('product', 'create', [
'name' => 'Smurf',
'options' => 'brainy smurf, clumsy smurf, papa smurf',
- ));
+ ]);
$this->products[] = $product1['values'][$product1['id']];
$this->paymentProcessor = $this->dummyProcessorCreate();
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
- $this->quickCleanup(array('civicrm_note', 'civicrm_uf_match', 'civicrm_address'));
+ $this->quickCleanup(['civicrm_note', 'civicrm_uf_match', 'civicrm_address']);
}
/**
public function testSubmit($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => $this->formatMoneyInput(1234),
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
- ), CRM_Core_Action::ADD);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
+ ], CRM_Core_Action::ADD);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
$this->assertEmpty($contribution['amount_level']);
$this->assertEquals(1234, $contribution['total_amount']);
$this->assertEquals(1234, $contribution['net_amount']);
*/
public function testSubmitCreditCard() {
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'contribution_status_id' => 1,
- ), CRM_Core_Action::ADD);
- $this->callAPISuccessGetCount('Contribution', array(
+ ], CRM_Core_Action::ADD);
+ $this->callAPISuccessGetCount('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 'Completed',
- ), 1);
+ ], 1);
}
/**
$mut = new CiviMailUtils($this, TRUE);
$mut->clearMessages();
$form = new CRM_Contribute_Form_Contribution();
- $paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0));
+ $paymentProcessorID = $this->paymentProcessorCreate(['is_test' => 0]);
$form->_mode = 'Live';
$error = FALSE;
try {
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'contribution_status_id' => 1,
'credit_card_number' => 4444333322221111,
'cvv2' => 123,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 9,
'Y' => 2025,
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Junko',
'billing_middle_name' => '',
'payment_processor_id' => $paymentProcessorID,
'currency' => 'USD',
'source' => 'bob sled race',
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
}
catch (Civi\Payment\Exception\PaymentProcessorException $e) {
$error = TRUE;
}
- $contribution = $this->callAPISuccess('Contribution', 'get', array(
+ $contribution = $this->callAPISuccess('Contribution', 'get', [
'contact_id' => $this->_individualId,
'contribution_status_id' => $error ? 'Failed' : 'Completed',
- 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array(
+ 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [
'return' => 'payment_instrument_id',
'id' => $paymentProcessorID,
- )),
- ));
+ ]),
+ ]);
$this->assertEquals(1, $contribution["count"], "Contribution count should be one.");
$this->assertTrue(!empty($contribution["values"][$contribution["id"]]["receipt_date"]), "Receipt date should not be blank.");
- $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId));
+ $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]);
$this->assertTrue(empty($contact['source']));
if (!$error) {
$msgs = $mut->getAllMessages();
$form = new CRM_Contribute_Form_Contribution();
$form->_mode = 'Live';
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'contribution_status_id' => 1,
'credit_card_number' => 4444333322221111,
'cvv2' => 123,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 9,
'Y' => 2025,
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Junko',
'billing_middle_name' => '',
'payment_processor_id' => $this->paymentProcessorID,
'currency' => 'USD',
'source' => 'bob sled race',
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
- $this->callAPISuccessGetCount('Contribution', array(
+ $this->callAPISuccessGetCount('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 'Completed',
- 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array(
+ 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [
'return' => 'payment_instrument_id',
'id' => $this->paymentProcessorID,
- )),
- ), 1);
- $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId));
+ ]),
+ ], 1);
+ $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]);
$this->assertTrue(empty($contact['source']));
$msgs = $mut->getAllMessages();
$this->assertEquals(1, count($msgs));
$form->_mode = 'Live';
$error = FALSE;
try {
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 60,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'contribution_status_id' => 1,
'credit_card_number' => 4444333322221111,
'cvv2' => 123,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 9,
'Y' => 2025,
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Junko',
'billing_middle_name' => '',
'payment_processor_id' => $this->paymentProcessorID,
'currency' => 'USD',
'source' => 'bob sled race',
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
}
catch (Civi\Payment\Exception\PaymentProcessorException $e) {
$error = TRUE;
}
- $this->callAPISuccessGetCount('Contribution', array(
+ $this->callAPISuccessGetCount('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => $error ? 'Failed' : 'Completed',
- 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array(
+ 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [
'return' => 'payment_instrument_id',
'id' => $this->paymentProcessorID,
- )),
- ), 1);
- $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $this->_individualId));
+ ]),
+ ], 1);
+ $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]);
$this->assertTrue(empty($contact['source']));
$mut->assertMailLogEmpty();
$mut->stop();
*/
public function testSubmitCreditCardFee() {
$form = new CRM_Contribute_Form_Contribution();
- $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 0, 'trxn_id' => 'tx', 'fee_amount' => .08));
+ $this->paymentProcessor->setDoDirectPaymentResult(['is_error' => 0, 'trxn_id' => 'tx', 'fee_amount' => .08]);
$form->_mode = 'Live';
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'contribution_status_id' => 1,
'credit_card_number' => 4444333322221111,
'cvv2' => 123,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 9,
'Y' => 2025,
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Junko',
'billing_middle_name' => '',
'payment_processor_id' => $this->paymentProcessorID,
'currency' => 'USD',
'source' => '',
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 'Completed',
- ));
+ ]);
$this->assertEquals('50', $contribution['total_amount']);
$this->assertEquals(.08, $contribution['fee_amount']);
$this->assertEquals(49.92, $contribution['net_amount']);
public function testSubmitCreditCardFullyDeductible() {
$form = new CRM_Contribute_Form_Contribution();
$form->_mode = 'Live';
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'contribution_status_id' => 1,
'credit_card_number' => 4444333322221111,
'cvv2' => 123,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 9,
'Y' => 2025,
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Junko',
'billing_middle_name' => '',
'payment_processor_id' => $this->paymentProcessorID,
'currency' => 'USD',
'source' => '',
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 'Completed',
- ));
+ ]);
$this->assertEquals('50', $contribution['total_amount']);
$this->assertEquals(0, $contribution['non_deductible_amount']);
}
*/
public function testSubmitCreditCardInvalid() {
$form = new CRM_Contribute_Form_Contribution();
- $this->paymentProcessor->setDoDirectPaymentResult(array('is_error' => 1));
+ $this->paymentProcessor->setDoDirectPaymentResult(['is_error' => 1]);
try {
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'payment_processor_id' => $this->paymentProcessorID,
- 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012),
+ 'credit_card_exp_date' => ['M' => 5, 'Y' => 2012],
'credit_card_number' => '411111111111111',
- ), CRM_Core_Action::ADD, 'live');
+ ], CRM_Core_Action::ADD, 'live');
}
catch (\Civi\Payment\Exception\PaymentProcessorException $e) {
- $this->callAPISuccessGetCount('Contribution', array(
+ $this->callAPISuccessGetCount('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 'Failed',
- ), 1);
- $lineItem = $this->callAPISuccessGetSingle('line_item', array());
+ ], 1);
+ $lineItem = $this->callAPISuccessGetSingle('line_item', []);
$this->assertEquals('50.00', $lineItem['unit_price']);
$this->assertEquals('50.00', $lineItem['line_total']);
$this->assertEquals(1, $lineItem['qty']);
$this->assertEquals(1, $lineItem['financial_type_id']);
- $financialItem = $this->callAPISuccessGetSingle('financial_item', array(
+ $financialItem = $this->callAPISuccessGetSingle('financial_item', [
'civicrm_line_item' => $lineItem['id'],
'entity_id' => $lineItem['id'],
- ));
+ ]);
$this->assertEquals('50.00', $financialItem['amount']);
$this->assertEquals(3, $financialItem['status_id']);
return;
*/
public function testSubmitCreditCardWithBillingAddress() {
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'payment_processor_id' => $this->paymentProcessorID,
- 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025),
+ 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
'credit_card_number' => '411111111111111',
'billing_city-5' => 'Vancouver',
- ), CRM_Core_Action::ADD, 'live');
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id'));
+ ], CRM_Core_Action::ADD, 'live');
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'address_id']);
$this->assertNotEmpty($contribution['address_id']);
// CRM-18490 : There is a unwanted test leakage due to below getsingle Api as it only fails in Jenkin
// for now we are only fetching address on based on Address ID (removed filter location_type_id and city)
- $this->callAPISuccessGetSingle('Address', array(
+ $this->callAPISuccessGetSingle('Address', [
'id' => $contribution['address_id'],
- ));
+ ]);
}
/**
public function testSubmitCreditCardWithRecur() {
$form = new CRM_Contribute_Form_Contribution();
$receiveDate = date('Y-m-d H:i:s', strtotime('+1 month'));
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'is_recur' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'payment_processor_id' => $this->paymentProcessorID,
- 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025),
+ 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
'credit_card_number' => '411111111111111',
'billing_city-5' => 'Vancouver',
- ), CRM_Core_Action::ADD, 'live');
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'receive_date'));
+ ], CRM_Core_Action::ADD, 'live');
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'receive_date']);
$this->assertEquals($contribution['receive_date'], $receiveDate);
}
*/
public function testSubmitCreditCardWithNoBillingAddress() {
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'payment_processor_id' => $this->paymentProcessorID,
- 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025),
+ 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
'credit_card_number' => '411111111111111',
- ), CRM_Core_Action::ADD, 'live');
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id'));
+ ], CRM_Core_Action::ADD, 'live');
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'address_id']);
$this->assertEmpty($contribution['address_id']);
- $this->callAPISuccessGetCount('Address', array(
+ $this->callAPISuccessGetCount('Address', [
'city' => 'Vancouver',
'location_type_id' => 5,
- ), 0);
+ ], 0);
}
/**
public function testSubmitEmailReceipt() {
$form = new CRM_Contribute_Form_Contribution();
$mut = new CiviMailUtils($this, TRUE);
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'is_email_receipt' => TRUE,
'from_email_address' => 'test@test.com',
'contribution_status_id' => 1,
- ), CRM_Core_Action::ADD);
- $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
- $mut->checkMailLog(array(
+ ], CRM_Core_Action::ADD);
+ $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1);
+ $mut->checkMailLog([
'<p>Please print this receipt for your records.</p>',
- ));
+ ]);
$mut->stop();
}
'contact_id' => $this->_userId,
'email' => 'testLoggedIn@example.com',
]);
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'is_email_receipt' => TRUE,
'from_email_address' => $email['id'],
'contribution_status_id' => 1,
- ), CRM_Core_Action::ADD);
- $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
- $mut->checkMailLog(array(
+ ], CRM_Core_Action::ADD);
+ $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1);
+ $mut->checkMailLog([
'<p>Please print this receipt for your records.</p>',
'<testloggedin@example.com>',
- ));
+ ]);
$mut->stop();
}
*/
public function testEmailReceiptOnPayLater() {
$donationFT = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Donation', 'id', 'name');
- $paramsSet = array(
+ $paramsSet = [
'title' => 'Price Set' . substr(sha1(rand()), 0, 4),
'is_active' => TRUE,
'financial_type_id' => $donationFT,
'extends' => 2,
- );
+ ];
$paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']);
$priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
$this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title',
'id', $paramsSet['title'], 'Check DB for created priceset'
);
- $paramsField = array(
+ $paramsField = [
'label' => 'Price Field',
'name' => CRM_Utils_String::titleToVar('Price Field'),
'html_type' => 'CheckBox',
- 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'),
- 'option_value' => array('1' => 100, '2' => 200),
- 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'),
- 'option_weight' => array('1' => 1, '2' => 2),
- 'option_amount' => array('1' => 100, '2' => 200),
+ 'option_label' => ['1' => 'Price Field 1', '2' => 'Price Field 2'],
+ 'option_value' => ['1' => 100, '2' => 200],
+ 'option_name' => ['1' => 'Price Field 1', '2' => 'Price Field 2'],
+ 'option_weight' => ['1' => 1, '2' => 2],
+ 'option_amount' => ['1' => 100, '2' => 200],
'is_display_amounts' => 1,
'weight' => 1,
'options_per_line' => 1,
- 'is_active' => array('1' => 1, '2' => 1),
+ 'is_active' => ['1' => 1, '2' => 1],
'price_set_id' => $priceset->id,
'is_enter_qty' => 1,
'financial_type_id' => $donationFT,
- );
+ ];
$priceField = CRM_Price_BAO_PriceField::create($paramsField);
- $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id));
+ $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField->id]);
- $params = array(
+ $params = [
'total_amount' => 100,
'financial_type_id' => $donationFT,
'contact_id' => $this->_individualId,
'from_email_address' => 'test@test.com',
'price_set_id' => $priceSetId,
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'),
- );
+ ];
foreach ($priceFieldValue['values'] as $id => $price) {
if ($price['amount'] == 100) {
- $params['price_' . $priceField->id] = array($id => 1);
+ $params['price_' . $priceField->id] = [$id => 1];
}
}
$form = new CRM_Contribute_Form_Contribution();
$form->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
$form->testSubmit($params, CRM_Core_Action::ADD);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Financial Type: Donation
---------------------------------------------------------
Item Qty Each Total
----------------------------------------------------------
Price Field - Price Field 1 1 $ 100.00 $ 100.00
',
- ));
+ ]);
$mut->stop();
}
* Test that a contribution is assigned against a pledge.
*/
public function testUpdatePledge() {
- $pledge = $this->callAPISuccess('pledge', 'create', array(
+ $pledge = $this->callAPISuccess('pledge', 'create', [
'contact_id' => $this->_individualId,
'pledge_create_date' => date('Ymd'),
'start_date' => date('Ymd'),
'frequency_day' => 15,
'installments' => 2,
'sequential' => 1,
- ));
- $pledgePaymentID = $this->callAPISuccess('pledge_payment', 'getvalue', array(
+ ]);
+ $pledgePaymentID = $this->callAPISuccess('pledge_payment', 'getvalue', [
'pledge_id' => $pledge['id'],
- 'options' => array('limit' => 1),
+ 'options' => ['limit' => 1],
'return' => 'id',
- ));
+ ]);
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'pledge_payment_id' => $pledgePaymentID,
'contribution_status_id' => 1,
- ), CRM_Core_Action::ADD);
- $pledgePayment = $this->callAPISuccess('pledge_payment', 'getsingle', array('id' => $pledgePaymentID));
+ ], CRM_Core_Action::ADD);
+ $pledgePayment = $this->callAPISuccess('pledge_payment', 'getsingle', ['id' => $pledgePaymentID]);
$this->assertNotEmpty($pledgePayment['contribution_id']);
$this->assertEquals($pledgePayment['actual_amount'], 50);
$this->assertEquals(1, $pledgePayment['status_id']);
public function testPremiumUpdate() {
$form = new CRM_Contribute_Form_Contribution();
$mut = new CiviMailUtils($this, TRUE);
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
- 'product_name' => array($this->products[0]['id'], 1),
+ 'product_name' => [$this->products[0]['id'], 1],
'fulfilled_date' => '',
'is_email_receipt' => TRUE,
'from_email_address' => 'test@test.com',
- ), CRM_Core_Action::ADD);
- $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array());
+ ], CRM_Core_Action::ADD);
+ $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', []);
$this->assertEquals('clumsy smurf', $contributionProduct['product_option']);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Premium Information',
'Smurf',
'clumsy smurf',
- ));
+ ]);
$mut->stop();
}
public function testPremiumUpdateCreditCard() {
$form = new CRM_Contribute_Form_Contribution();
$mut = new CiviMailUtils($this, TRUE);
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
- 'product_name' => array($this->products[0]['id'], 1),
+ 'product_name' => [$this->products[0]['id'], 1],
'fulfilled_date' => '',
'is_email_receipt' => TRUE,
'from_email_address' => 'test@test.com',
'payment_processor_id' => $this->paymentProcessorID,
- 'credit_card_exp_date' => array('M' => 5, 'Y' => 2026),
+ 'credit_card_exp_date' => ['M' => 5, 'Y' => 2026],
'credit_card_number' => '411111111111111',
- ), CRM_Core_Action::ADD, 'live');
- $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array());
+ ], CRM_Core_Action::ADD, 'live');
+ $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', []);
$this->assertEquals('clumsy smurf', $contributionProduct['product_option']);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Premium Information',
'Smurf',
'clumsy smurf',
- ));
+ ]);
$mut->stop();
}
*/
public function testSubmitWithNote() {
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
'note' => 'Super cool and interesting stuff',
- ), CRM_Core_Action::ADD);
- $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
- $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution'));
+ ], CRM_Core_Action::ADD);
+ $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1);
+ $note = $this->callAPISuccessGetSingle('note', ['entity_table' => 'civicrm_contribution']);
$this->assertEquals($note['note'], 'Super cool and interesting stuff');
}
public function testSubmitWithNoteCreditCard() {
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
'note' => 'Super cool and interesting stuff',
- ) + $this->getCreditCardParams(),
+ ] + $this->getCreditCardParams(),
CRM_Core_Action::ADD);
- $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
- $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution'));
+ $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1);
+ $note = $this->callAPISuccessGetSingle('note', ['entity_table' => 'civicrm_contribution']);
$this->assertEquals($note['note'], 'Super cool and interesting stuff');
}
*/
public function testEnterNegativeContribution() {
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => -5,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
- ),
+ ],
CRM_Core_Action::ADD);
- $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
+ $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
- ));
+ ]);
$this->assertEquals(-5, $contribution['total_amount']);
}
$this->setCurrencySeparators($thousandSeparator);
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => $this->formatMoneyInput(6100.10),
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
'price_set_id' => 0,
- ), CRM_Core_Action::ADD);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
- $form->testSubmit(array(
+ ], CRM_Core_Action::ADD);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
+ $form->testSubmit([
'total_amount' => $this->formatMoneyInput(5200.20),
'net_amount' => $this->formatMoneyInput(5200.20),
'financial_type_id' => 1,
'contribution_status_id' => 1,
'price_set_id' => 0,
'id' => $contribution['id'],
- ), CRM_Core_Action::UPDATE);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
+ ], CRM_Core_Action::UPDATE);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
$this->assertEquals(5200.20, $contribution['total_amount'], 2);
- $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', array('sequential' => TRUE));
+ $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', ['sequential' => TRUE]);
$this->assertEquals(2, $financialTransactions['count']);
$this->assertEquals(6100.10, $financialTransactions['values'][0]['total_amount']);
$this->assertEquals(-899.90, $financialTransactions['values'][1]['total_amount']);
$this->assertEquals(-899.90, $financialTransactions['values'][1]['net_amount']);
- $lineItem = $this->callAPISuccessGetSingle('LineItem', array());
+ $lineItem = $this->callAPISuccessGetSingle('LineItem', []);
$this->assertEquals(5200.20, $lineItem['line_total']);
}
$this->setCurrencySeparators($thousandSeparator);
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 1200.55,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'check_number' => '123AX',
'contribution_status_id' => 1,
'price_set_id' => 0,
- ), CRM_Core_Action::ADD);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
- $form->testSubmit(array(
+ ], CRM_Core_Action::ADD);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
+ $form->testSubmit([
'total_amount' => 1200.55,
'net_amount' => 1200.55,
'financial_type_id' => 1,
'contribution_status_id' => 1,
'price_set_id' => 0,
'id' => $contribution['id'],
- ), CRM_Core_Action::UPDATE);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
+ ], CRM_Core_Action::UPDATE);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
$this->assertEquals(1200.55, $contribution['total_amount']);
- $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', array('sequential' => TRUE));
+ $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', ['sequential' => TRUE]);
$this->assertEquals(3, $financialTransactions['count']);
list($oldTrxn, $reversedTrxn, $latestTrxn) = $financialTransactions['values'];
$this->assertEquals(1200.55, $latestTrxn['total_amount']);
$this->assertEquals('1011', $latestTrxn['pan_truncation']);
$this->assertEquals(array_search('Credit Card', $this->paymentInstruments), $latestTrxn['payment_instrument_id']);
- $lineItem = $this->callAPISuccessGetSingle('LineItem', array());
+ $lineItem = $this->callAPISuccessGetSingle('LineItem', []);
}
/**
* Credit card specific parameters.
*/
protected function getCreditCardParams() {
- return array(
+ return [
'payment_processor_id' => $this->paymentProcessorID,
- 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012),
+ 'credit_card_exp_date' => ['M' => 5, 'Y' => 2012],
'credit_card_number' => '411111111111111',
- );
+ ];
}
/**
// create a partially paid contribution by using back-office form
$form = new CRM_Contribute_Form_Contribution();
$form->testSubmit(
- array(
+ [
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'check_number' => substr(sha1(rand()), 0, 7),
'billing_city-5' => 'Vancouver',
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'),
- ), CRM_Core_Action::ADD
+ ], CRM_Core_Action::ADD
);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array());
+ $contribution = $this->callAPISuccessGetSingle('Contribution', []);
$this->assertNotEmpty($contribution);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
// pay additional amount by using Credit Card
$form = new CRM_Contribute_Form_AdditionalPayment();
- $form->testSubmit(array(
+ $form->testSubmit([
'contribution_id' => $contribution['id'],
'contact_id' => $this->_individualId,
'total_amount' => 50,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit card', $this->paymentInstruments),
'payment_processor_id' => $this->paymentProcessorID,
- 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025),
+ 'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
'credit_card_number' => '411111111111111',
'cvv2' => 234,
'credit_card_type' => 'Visa',
'billing_postal_code-5' => 1321312,
'billing_country_id-5' => 1228,
'trxn_date' => '2017-04-11 13:05:11',
- ), 'live');
- $contribution = $this->callAPISuccessGetSingle('Contribution', array());
+ ], 'live');
+ $contribution = $this->callAPISuccessGetSingle('Contribution', []);
$this->assertNotEmpty($contribution);
$this->assertEquals('Completed', $contribution['contribution_status']);
}
$this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId);
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => $this->formatMoneyInput(1000.00),
'financial_type_id' => $this->_financialTypeId,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
'price_set_id' => 0,
- ),
+ ],
CRM_Core_Action::ADD
);
$contribution = $this->callAPISuccessGetSingle('Contribution',
- array(
+ [
'contact_id' => $this->_individualId,
- 'return' => array('tax_amount', 'total_amount'),
- )
+ 'return' => ['tax_amount', 'total_amount'],
+ ]
);
$this->assertEquals(1100, $contribution['total_amount']);
$this->assertEquals(100, $contribution['tax_amount']);
- $this->callAPISuccessGetCount('FinancialTrxn', array(), 1);
- $this->callAPISuccessGetCount('FinancialItem', array(), 2);
- $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id']));
+ $this->callAPISuccessGetCount('FinancialTrxn', [], 1);
+ $this->callAPISuccessGetCount('FinancialItem', [], 2);
+ $lineItem = $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id']]);
$this->assertEquals(1000, $lineItem['line_total']);
$this->assertEquals(100, $lineItem['tax_amount']);
// CRM-20423: Upon simple submit of 'Edit Contribution' form ensure that total amount is same
- $form->testSubmit(array(
+ $form->testSubmit([
'id' => $contribution['id'],
'financial_type_id' => 3,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
- ), CRM_Core_Action::UPDATE);
+ ], CRM_Core_Action::UPDATE);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
// Check if total amount is unchanged
$this->assertEquals(1100, $contribution['total_amount']);
}
$this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId);
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 100,
'financial_type_id' => 3,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
'price_set_id' => 0,
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
$contribution = $this->callAPISuccessGetSingle('Contribution',
- array(
+ [
'contact_id' => $this->_individualId,
- 'return' => array('tax_amount', 'total_amount'),
- )
+ 'return' => ['tax_amount', 'total_amount'],
+ ]
);
$this->assertEquals(100, $contribution['total_amount']);
$this->assertEquals(NULL, $contribution['tax_amount']);
- $this->callAPISuccessGetCount('FinancialTrxn', array(), 1);
- $this->callAPISuccessGetCount('FinancialItem', array(), 1);
+ $this->callAPISuccessGetCount('FinancialTrxn', [], 1);
+ $this->callAPISuccessGetCount('FinancialItem', [], 1);
$lineItem = $this->callAPISuccessGetSingle(
'LineItem',
- array(
+ [
'contribution_id' => $contribution['id'],
- 'return' => array('line_total', 'tax_amount'),
- )
+ 'return' => ['line_total', 'tax_amount'],
+ ]
);
$this->assertEquals(100, $lineItem['line_total']);
$this->assertTrue(empty($lineItem['tax_amount']));
$mut = new CiviMailUtils($this, TRUE);
// Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same:
- $form->testSubmit(array(
+ $form->testSubmit([
'id' => $contribution['id'],
'tax_amount' => $contribution['tax_amount'],
'financial_type_id' => $contribution['financial_type_id'],
'contribution_status_id' => 1,
'is_email_receipt' => 1,
'from_email_address' => 'demo@example.com',
- ), CRM_Core_Action::UPDATE);
+ ], CRM_Core_Action::UPDATE);
$contribution = $this->callAPISuccessGetSingle('Contribution',
- array(
+ [
'contribution_id' => 1,
- 'return' => array('tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'),
- )
+ 'return' => ['tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'],
+ ]
);
$this->assertEquals(11000, $contribution['total_amount']);
$this->assertEquals(1000, $contribution['tax_amount']);
$this->assertEquals(11000, $contribution['net_amount']);
- $strings = array(
+ $strings = [
'Total Tax Amount : $ ' . $this->formatMoneyInput(1000.00),
'Total Amount : $ ' . $this->formatMoneyInput(11000.00),
'Date Received: April 21st, 2015',
'Paid By: Check',
'Check Number: 12345',
- );
+ ];
$mut->checkMailLog($strings);
- $this->callAPISuccessGetCount('FinancialTrxn', array(), 3);
- $items = $this->callAPISuccess('FinancialItem', 'get', array('sequential' => 1));
+ $this->callAPISuccessGetCount('FinancialTrxn', [], 3);
+ $items = $this->callAPISuccess('FinancialItem', 'get', ['sequential' => 1]);
$this->assertEquals(2, $items['count']);
$this->assertEquals('Contribution Amount', $items['values'][0]['description']);
$this->assertEquals('Sales Tax', $items['values'][1]['description']);
$mut = new CiviMailUtils($this, TRUE);
// Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same:
- $form->testSubmit(array(
+ $form->testSubmit([
'id' => $contribution['id'],
'total_amount' => $this->formatMoneyInput(20000),
'tax_amount' => $this->formatMoneyInput(2000),
'contribution_status_id' => 1,
'is_email_receipt' => 1,
'from_email_address' => 'demo@example.com',
- ), CRM_Core_Action::UPDATE);
+ ], CRM_Core_Action::UPDATE);
$contribution = $this->callAPISuccessGetSingle('Contribution',
- array(
+ [
'contribution_id' => 1,
- 'return' => array('tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'),
- )
+ 'return' => ['tax_amount', 'total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'payment_instrument_id'],
+ ]
);
$this->assertEquals(22000, $contribution['total_amount']);
$this->assertEquals(2000, $contribution['tax_amount']);
$this->assertEquals(22000, $contribution['net_amount']);
- $strings = array(
+ $strings = [
'Total Tax Amount : $ ' . $this->formatMoneyInput(2000),
'Total Amount : $ ' . $this->formatMoneyInput(22000.00),
'Date Received: April 21st, 2015',
'Paid By: Check',
'Check Number: 12345',
- );
+ ];
$mut->checkMailLog($strings);
- $this->callAPISuccessGetCount('FinancialTrxn', array(), 4);
- $items = $this->callAPISuccess('FinancialItem', 'get', array('sequential' => 1));
+ $this->callAPISuccessGetCount('FinancialTrxn', [], 4);
+ $items = $this->callAPISuccess('FinancialItem', 'get', ['sequential' => 1]);
$this->assertEquals(4, $items['count']);
$this->assertEquals('Contribution Amount', $items['values'][0]['description']);
$this->assertEquals('Sales Tax', $items['values'][1]['description']);
protected function doInitialSubmit() {
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => $this->formatMoneyInput(10000),
'financial_type_id' => $this->_financialTypeId,
'receive_date' => '2015-04-21 00:00:00',
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 1,
'price_set_id' => 0,
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
$contribution = $this->callAPISuccessGetSingle('Contribution',
- array(
+ [
'contribution_id' => 1,
- 'return' => array(
+ 'return' => [
'tax_amount',
'total_amount',
'net_amount',
'financial_type_id',
'receive_date',
'payment_instrument_id',
- ),
- )
+ ],
+ ]
);
$this->assertEquals(11000, $contribution['total_amount']);
$this->assertEquals(1000, $contribution['tax_amount']);
$this->assertEquals(11000, $contribution['net_amount']);
- return array($form, $contribution);
+ return [$form, $contribution];
}
/**
public function testCardTypeAndPanTruncation() {
$form = new CRM_Contribute_Form_Contribution();
$form->testSubmit(
- array(
+ [
'total_amount' => 100,
'financial_type_id' => 3,
'contact_id' => $this->_individualId,
'credit_card_type' => 'Visa',
'pan_truncation' => 4567,
'price_set_id' => 0,
- ),
+ ],
CRM_Core_Action::ADD
);
$contribution = $this->callAPISuccessGetSingle('Contribution',
- array(
+ [
'contact_id' => $this->_individualId,
- 'return' => array('id'),
- )
+ 'return' => ['id'],
+ ]
);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('card_type_id.label', 'pan_truncation'),
- )
+ 'return' => ['card_type_id.label', 'pan_truncation'],
+ ]
);
$this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa');
$this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 4567);
*/
public function testContributionBasePreProcess() {
//Create contribution page with only pay later enabled.
- $params = array(
+ $params = [
'title' => "Test Contribution Page",
'financial_type_id' => 1,
'currency' => 'NZD',
'is_email_receipt' => TRUE,
'receipt_from_email' => 'yourconscience@donate.com',
'receipt_from_name' => 'Ego Freud',
- );
+ ];
$page1 = $this->callAPISuccess("contribution_page", 'create', $params);
$form = new CRM_Contribute_Form_Contribution();
$form->_mode = 'Live';
$form->testSubmit(
- array(
+ [
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'credit_card_number' => 4444333322221111,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
'cvv2' => 123,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 9,
'Y' => date('Y', strtotime('+5 years')),
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Junko',
'billing_middle_name' => '',
'payment_processor_id' => $this->paymentProcessorID,
'currency' => 'USD',
'source' => 'bob sled race',
- ),
+ ],
CRM_Core_Action::ADD
);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualId));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('card_type_id', 'pan_truncation'),
- )
+ 'return' => ['card_type_id', 'pan_truncation'],
+ ]
);
$this->assertEquals($visaID, $financialTrxn['card_type_id']);
$this->assertEquals(1111, $financialTrxn['pan_truncation']);
$contactID2 = $this->organizationCreate();
// create membership types
- $membershipTypeOne = civicrm_api3('membership_type', 'create', array(
+ $membershipTypeOne = civicrm_api3('membership_type', 'create', [
'domain_id' => 1,
'name' => "One",
'member_of_contact_id' => $contactID1,
'weight' => 50,
'is_active' => 1,
'visibility' => "Public",
- ));
+ ]);
- $membershipTypeTwo = civicrm_api3('membership_type', 'create', array(
+ $membershipTypeTwo = civicrm_api3('membership_type', 'create', [
'domain_id' => 1,
'name' => "Two",
'member_of_contact_id' => $contactID2,
'weight' => 51,
'is_active' => 1,
'visibility' => "Public",
- ));
+ ]);
//create custom Fields
- $membershipCustomFieldsGroup = civicrm_api3('CustomGroup', 'create', array(
+ $membershipCustomFieldsGroup = civicrm_api3('CustomGroup', 'create', [
'title' => "Custom Fields on Membership",
'extends' => "Membership",
- ));
+ ]);
- $membershipCustomField = civicrm_api3('CustomField', 'create', array(
+ $membershipCustomField = civicrm_api3('CustomField', 'create', [
"custom_group_id" => $membershipCustomFieldsGroup['id'],
"name" => "my_membership_custom_field",
"label" => "Membership Custom Field",
"is_active" => "1",
"is_view" => "0",
"text_length" => "255",
- ));
+ ]);
// create profile
- $membershipCustomFieldsProfile = civicrm_api3('UFGroup', 'create', array(
+ $membershipCustomFieldsProfile = civicrm_api3('UFGroup', 'create', [
"is_active" => "1",
"group_type" => "Membership,Individual",
"title" => "Membership Custom Fields",
"is_edit_link" => "0",
"is_uf_link" => "0",
"is_update_dupe" => "0",
- ));
+ ]);
// add custom fields to profile
- $membershipCustomFieldsProfileFields = civicrm_api3('UFField', 'create', array(
+ $membershipCustomFieldsProfileFields = civicrm_api3('UFField', 'create', [
"uf_group_id" => $membershipCustomFieldsProfile['id'],
"field_name" => "custom_" . $membershipCustomField['id'],
"is_active" => "1",
"is_searchable" => "0",
"label" => "custom text field on membership",
"field_type" => "Membership",
- ));
+ ]);
- $contribPage = civicrm_api3('ContributionPage', 'create', array(
+ $contribPage = civicrm_api3('ContributionPage', 'create', [
"title" => "Membership",
"financial_type_id" => 1,
'financial_account_id' => 1,
'is_allow_other_amount' => 1,
'min_amount' => 10,
'max_amount' => 1000,
- ));
+ ]);
$contribPage1 = $contribPage['id'];
//create price set with two options for the two different memberships
- $priceSet = civicrm_api3('PriceSet', 'create', array(
+ $priceSet = civicrm_api3('PriceSet', 'create', [
'title' => "Two Membership Type Checkbox",
'extends' => "CiviMember",
'is_active' => 1,
"financial_type_id" => "1",
"is_quick_config" => "0",
"is_reserved" => "0",
- "entity" => array("civicrm_contribution_page" => array($contribPage1)),
- ));
+ "entity" => ["civicrm_contribution_page" => [$contribPage1]],
+ ]);
- $priceField = civicrm_api3('PriceField', 'create', array(
+ $priceField = civicrm_api3('PriceField', 'create', [
"price_set_id" => $priceSet['id'],
"name" => "mt",
"label" => "Membership Types",
"is_active" => "1",
"is_required" => "0",
"visibility_id" => "1",
- ));
+ ]);
- $priceFieldOption1 = civicrm_api3('PriceFieldValue', 'create', array(
+ $priceFieldOption1 = civicrm_api3('PriceFieldValue', 'create', [
"price_field_id" => $priceField['id'],
"name" => "membership_type_one",
"label" => "Membership Type One",
"financial_type_id" => "1",
"non_deductible_amount" => "0.00",
"contribution_type_id" => "2",
- ));
+ ]);
- $priceFieldOption2 = civicrm_api3('PriceFieldValue', 'create', array(
+ $priceFieldOption2 = civicrm_api3('PriceFieldValue', 'create', [
"price_field_id" => $priceField['id'],
"name" => "membership_type_two",
"label" => "Membership Type Two",
"financial_type_id" => "1",
"non_deductible_amount" => "0.00",
"contribution_type_id" => "2",
- ));
+ ]);
// assign profile with custom fields to contribution page
- $profile = civicrm_api3('UFJoin', 'create', array(
+ $profile = civicrm_api3('UFJoin', 'create', [
'module' => "CiviContribute",
'weight' => "1",
'uf_group_id' => $membershipCustomFieldsProfile['id'],
"entity_table" => "civicrm_contribution_page",
"entity_id" => $contribPage1,
- ));
+ ]);
$form = new CRM_Contribute_Form_Contribution_Confirm();
- $form->_params = array(
+ $form->_params = [
'id' => $contribPage1,
"qfKey" => "donotcare",
"custom_{$membershipCustomField['id']}" => "Hello",
"email-5" => "admin@example.com",
"priceSetId" => $priceSet['id'],
'price_set_id' => $priceSet['id'],
- "price_" . $priceField['id'] => array($priceFieldOption1['id'] => 1, $priceFieldOption2['id'] => 1),
+ "price_" . $priceField['id'] => [$priceFieldOption1['id'] => 1, $priceFieldOption2['id'] => 1],
"invoiceID" => "9a6f7b49358dc31c3604e463b225c5be",
"email" => "admin@example.com",
"currencyID" => "USD",
'tax_amount' => 0.00,
'is_pay_later' => 1,
'is_quick_config' => 1,
- );
+ ];
$form->submit($form->_params);
- $membership1 = civicrm_api3('Membership', 'getsingle', array(
+ $membership1 = civicrm_api3('Membership', 'getsingle', [
'contact_id' => $contactID,
'membership_type_id' => $membershipTypeOne['id'],
- ));
+ ]);
$this->assertEquals("Hello", $membership1["custom_{$membershipCustomField['id']}"]);
- $membership2 = civicrm_api3('Membership', 'getsingle', array(
+ $membership2 = civicrm_api3('Membership', 'getsingle', [
'contact_id' => $contactID,
'membership_type_id' => $membershipTypeTwo['id'],
- ));
+ ]);
$this->assertEquals("Hello", $membership2["custom_{$membershipCustomField['id']}"]);
}
$form->testProcessContribution($batchEntry);
// fetch created contributions
- $entities = $this->callAPISuccess('EntityBatch', 'get', array('batch_id' => $batchID));
+ $entities = $this->callAPISuccess('EntityBatch', 'get', ['batch_id' => $batchID]);
$ids = [];
foreach ($entities['values'] as $value) {
$ids[] = $value['entity_id'];
$useCases = [
// Case 1: Search for ONLY those contributions which are created from batch
[
- 'form_value' => array('contribution_batch_id' => 'IS NOT NULL'),
+ 'form_value' => ['contribution_batch_id' => 'IS NOT NULL'],
'expected_count' => 2,
- 'expected_contribution' => array($batchContriID1, $batchContriID2),
+ 'expected_contribution' => [$batchContriID1, $batchContriID2],
'expected_qill' => 'Batch Name Not Null',
],
// Case 2: Search for ONLY those contributions which are NOT created from batch
[
- 'form_value' => array('contribution_batch_id' => 'IS NULL'),
+ 'form_value' => ['contribution_batch_id' => 'IS NULL'],
'expected_count' => 1,
- 'expected_contribution' => array($nonBatchContriID),
+ 'expected_contribution' => [$nonBatchContriID],
'expected_qill' => 'Batch Name Is Null',
],
// Case 3: Search for ONLY those contributions which are created from batch ID - $batchID
[
- 'form_value' => array('contribution_batch_id' => $batchID),
+ 'form_value' => ['contribution_batch_id' => $batchID],
'expected_count' => 2,
- 'expected_contribution' => array($batchContriID1, $batchContriID2),
+ 'expected_contribution' => [$batchContriID1, $batchContriID2],
'expected_qill' => 'Batch Name = ' . $batchTitle,
],
];
foreach ($useCases as $case) {
$fv = $case['form_value'];
- CRM_Contact_BAO_Query::processSpecialFormValue($fv, array('contribution_batch_id'));
+ CRM_Contact_BAO_Query::processSpecialFormValue($fv, ['contribution_batch_id']);
$query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($fv));
list($select, $from, $where) = $query->query();
*/
public function testCardTypeFilter() {
$this->quickCleanup($this->_tablesToTruncate);
- $contactID1 = $this->individualCreate(array(), 1);
- $contactID2 = $this->individualCreate(array(), 2);
- $Contribution1 = $this->callAPISuccess('Contribution', 'create', array(
+ $contactID1 = $this->individualCreate([], 1);
+ $contactID2 = $this->individualCreate([], 2);
+ $Contribution1 = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => 1,
'total_amount' => 100,
'receive_date' => date('Ymd'),
'payment_instrument' => 1,
'contribution_status_id' => 1,
'contact_id' => $contactID1,
- ));
- $params = array(
+ ]);
+ $params = [
'to_financial_account_id' => 1,
'status_id' => 1,
'contribution_id' => $Contribution1['id'],
'payment_instrument_id' => 1,
'card_type_id' => 1,
'total_amount' => 100,
- );
+ ];
CRM_Core_BAO_FinancialTrxn::create($params);
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => 1,
'total_amount' => 150,
'receive_date' => date('Ymd'),
'payment_instrument' => 1,
'contribution_status_id' => 1,
'contact_id' => $contactID1,
- ));
- $Contribution3 = $this->callAPISuccess('Contribution', 'create', array(
+ ]);
+ $Contribution3 = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => 1,
'total_amount' => 200,
'receive_date' => date('Ymd'),
'payment_instrument' => 1,
'contribution_status_id' => 1,
'contact_id' => $contactID2,
- ));
- $params = array(
+ ]);
+ $params = [
'to_financial_account_id' => 1,
'status_id' => 1,
'contribution_id' => $Contribution3['id'],
'payment_instrument_id' => 1,
'card_type_id' => 2,
'total_amount' => 200,
- );
+ ];
CRM_Core_BAO_FinancialTrxn::create($params);
- $useCases = array(
+ $useCases = [
// Case 1: Search for ONLY those contributions which have card type
- array(
- 'form_value' => array('financial_trxn_card_type_id' => 'IS NOT NULL'),
+ [
+ 'form_value' => ['financial_trxn_card_type_id' => 'IS NOT NULL'],
'expected_count' => 2,
- 'expected_contribution' => array($Contribution1['id'], $Contribution3['id']),
+ 'expected_contribution' => [$Contribution1['id'], $Contribution3['id']],
'expected_qill' => 'Card Type Not Null',
- ),
+ ],
// Case 2: Search for ONLY those contributions which have Card Type as Visa
- array(
- 'form_value' => array('financial_trxn_card_type_id' => array(1)),
+ [
+ 'form_value' => ['financial_trxn_card_type_id' => [1]],
'expected_count' => 1,
- 'expected_contribution' => array($Contribution1['id']),
+ 'expected_contribution' => [$Contribution1['id']],
'expected_qill' => 'Card Type In Visa',
- ),
+ ],
// Case 3: Search for ONLY those contributions which have Card Type as Amex
- array(
- 'form_value' => array('financial_trxn_card_type_id' => array(3)),
+ [
+ 'form_value' => ['financial_trxn_card_type_id' => [3]],
'expected_count' => 0,
- 'expected_contribution' => array(),
+ 'expected_contribution' => [],
'expected_qill' => 'Card Type In Amex',
- ),
+ ],
// Case 4: Search for ONLY those contributions which have Card Type as Visa or MasterCard
- array(
- 'form_value' => array('financial_trxn_card_type_id' => array(1, 2)),
+ [
+ 'form_value' => ['financial_trxn_card_type_id' => [1, 2]],
'expected_count' => 2,
- 'expected_contribution' => array($Contribution1['id'], $Contribution3['id']),
+ 'expected_contribution' => [$Contribution1['id'], $Contribution3['id']],
'expected_qill' => 'Card Type In Visa, MasterCard',
- ),
- );
+ ],
+ ];
foreach ($useCases as $case) {
$fv = $case['form_value'];
- CRM_Contact_BAO_Query::processSpecialFormValue($fv, array('financial_trxn_card_type_id'));
+ CRM_Contact_BAO_Query::processSpecialFormValue($fv, ['financial_trxn_card_type_id']);
$query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($fv));
list($select, $from, $where) = $query->query();
*/
public function testCardNumberFilter() {
$this->quickCleanup($this->_tablesToTruncate);
- $contactID1 = $this->individualCreate(array(), 1);
- $contactID2 = $this->individualCreate(array(), 2);
- $Contribution1 = $this->callAPISuccess('Contribution', 'create', array(
+ $contactID1 = $this->individualCreate([], 1);
+ $contactID2 = $this->individualCreate([], 2);
+ $Contribution1 = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => 1,
'total_amount' => 100,
'receive_date' => date('Ymd'),
'payment_instrument' => 1,
'contribution_status_id' => 1,
'contact_id' => $contactID1,
- ));
- $params = array(
+ ]);
+ $params = [
'to_financial_account_id' => 1,
'status_id' => 1,
'contribution_id' => $Contribution1['id'],
'card_type_id' => 1,
'total_amount' => 100,
'pan_truncation' => 1234,
- );
+ ];
CRM_Core_BAO_FinancialTrxn::create($params);
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => 1,
'total_amount' => 150,
'receive_date' => date('Ymd'),
'payment_instrument' => 1,
'contribution_status_id' => 1,
'contact_id' => $contactID1,
- ));
- $Contribution3 = $this->callAPISuccess('Contribution', 'create', array(
+ ]);
+ $Contribution3 = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => 1,
'total_amount' => 200,
'receive_date' => date('Ymd'),
'payment_instrument' => 1,
'contribution_status_id' => 1,
'contact_id' => $contactID2,
- ));
- $params = array(
+ ]);
+ $params = [
'to_financial_account_id' => 1,
'status_id' => 1,
'contribution_id' => $Contribution3['id'],
'card_type_id' => 2,
'total_amount' => 200,
'pan_truncation' => 5678,
- );
+ ];
CRM_Core_BAO_FinancialTrxn::create($params);
- $useCases = array(
+ $useCases = [
// Case 1: Search for ONLY those contributions which have card number
- array(
- 'form_value' => array('financial_trxn_pan_truncation' => 'IS NOT NULL'),
+ [
+ 'form_value' => ['financial_trxn_pan_truncation' => 'IS NOT NULL'],
'expected_count' => 2,
- 'expected_contribution' => array($Contribution1['id'], $Contribution3['id']),
+ 'expected_contribution' => [$Contribution1['id'], $Contribution3['id']],
'expected_qill' => 'Card Number Not Null',
- ),
+ ],
// Case 2: Search for ONLY those contributions which have Card Number as 1234
- array(
- 'form_value' => array('financial_trxn_pan_truncation' => 1234),
+ [
+ 'form_value' => ['financial_trxn_pan_truncation' => 1234],
'expected_count' => 1,
- 'expected_contribution' => array($Contribution1['id']),
+ 'expected_contribution' => [$Contribution1['id']],
'expected_qill' => 'Card Number Like %1234%',
- ),
+ ],
// Case 3: Search for ONLY those contributions which have Card Number as 8888
- array(
- 'form_value' => array('financial_trxn_pan_truncation' => 8888),
+ [
+ 'form_value' => ['financial_trxn_pan_truncation' => 8888],
'expected_count' => 0,
- 'expected_contribution' => array(),
+ 'expected_contribution' => [],
'expected_qill' => 'Card Number Like %8888%',
- ),
- );
+ ],
+ ];
foreach ($useCases as $case) {
$fv = $case['form_value'];
- CRM_Contact_BAO_Query::processSpecialFormValue($fv, array('financial_trxn_pan_truncation'));
+ CRM_Contact_BAO_Query::processSpecialFormValue($fv, ['financial_trxn_pan_truncation']);
$query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($fv));
list($select, $from, $where) = $query->query();
* invoice pdf for pending and completed contributions
*/
public function testInvoiceForDueDate() {
- $contactIds = array();
- $params = array(
+ $contactIds = [];
+ $params = [
'output' => 'pdf_invoice',
'forPage' => 1,
- );
+ ];
$this->_individualId = $this->individualCreate();
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_individualId,
'total_amount' => 100,
'financial_type_id' => 'Donation',
- );
+ ];
$result = $this->callAPISuccess('Contribution', 'create', $contributionParams);
$contributionParams['contribution_status_id'] = 2;
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
$contribution3 = $this->callAPISuccess('Contribution', 'create', $contributionParams);
- $this->callAPISuccess('Payment', 'create', array('total_amount' => 8, 'contribution_id' => $contribution3['id']));
+ $this->callAPISuccess('Payment', 'create', ['total_amount' => 8, 'contribution_id' => $contribution3['id']]);
- $this->callAPISuccess('Contribution', 'create', array('id' => $contribution3['id'], 'is_pay_later' => 0));
+ $this->callAPISuccess('Contribution', 'create', ['id' => $contribution3['id'], 'is_pay_later' => 0]);
- $contributionIDs = array(
- array($result['id']),
- array($contribution['id']),
- array($contribution3['id']),
- );
+ $contributionIDs = [
+ [$result['id']],
+ [$contribution['id']],
+ [$contribution3['id']],
+ ];
$contactIds[] = $this->_individualId;
foreach ($contributionIDs as $contributionID) {
protected function setUp() {
parent::setUp();
- $this->_individualId = $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins'));
+ $this->_individualId = $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']);
$this->_docTypes = CRM_Core_SelectValues::documentApplicationType();
}
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
- $this->quickCleanup(array('civicrm_uf_match'));
+ $this->quickCleanup(['civicrm_uf_match']);
CRM_Utils_Hook::singleton()->reset();
}
public function testBuildContributionArray() {
$this->_individualId = $this->individualCreate();
- $customGroup = $this->callAPISuccess('CustomGroup', 'create', array(
+ $customGroup = $this->callAPISuccess('CustomGroup', 'create', [
'title' => 'Test Custom Set for Contribution',
'extends' => 'Contribution',
'is_active' => TRUE,
- ));
- $params = array(
+ ]);
+ $params = [
'custom_group_id' => $customGroup['id'],
'label' => 'Text field',
'html_type' => 'Text',
'data_type' => 'String',
'weight' => 1,
'is_active' => 1,
- );
+ ];
$customField = $this->callAPISuccess('CustomField', 'create', $params);
$customFieldKey = 'custom_' . $customField['id'];
$campaignTitle = 'Test Campaign ' . substr(sha1(rand()), 0, 7);
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'total_amount' => 6,
- 'campaign_id' => $this->campaignCreate(array('title' => $campaignTitle), FALSE),
+ 'campaign_id' => $this->campaignCreate(['title' => $campaignTitle], FALSE),
'financial_type_id' => 'Donation',
$customFieldKey => 'Text_' . substr(sha1(rand()), 0, 7),
- );
- $contributionIDs = $returnProperties = array();
+ ];
+ $contributionIDs = $returnProperties = [];
$result = $this->callAPISuccess('Contribution', 'create', $params);
$contributionIDs[] = $result['id'];
- $this->hookClass->setHook('civicrm_tokenValues', array($this, 'hookTokenValues'));
+ $this->hookClass->setHook('civicrm_tokenValues', [$this, 'hookTokenValues']);
// assume that there are two token {contribution.financial_type} and
// {contribution.custom_N} in message content
- $messageToken = array(
- 'contribution' => array(
+ $messageToken = [
+ 'contribution' => [
'financial_type',
'payment_instrument',
'campaign',
$customFieldKey,
- ),
- );
+ ],
+ ];
list($contributions, $contacts) = CRM_Contribute_Form_Task_PDFLetterCommon::buildContributionArray('contact_id', $contributionIDs, $returnProperties, TRUE, TRUE, $messageToken, 'test', '**', FALSE);
public function testPostProcess() {
$this->createLoggedInUser();
$this->_individualId = $this->individualCreate();
- foreach (array('docx', 'odt') as $docType) {
- $formValues = array(
+ foreach (['docx', 'odt'] as $docType) {
+ $formValues = [
'is_unit_test' => TRUE,
'group_by' => NULL,
- 'document_file' => array(
+ 'document_file' => [
'name' => __DIR__ . "/sample_documents/Template.$docType",
'type' => $this->_docTypes[$docType],
- ),
- );
+ ],
+ ];
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_individualId,
'total_amount' => 100,
'financial_type_id' => 'Donation',
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
$contributionId = $contribution['id'];
$form = new CRM_Contribute_Form_Task_PDFLetter();
- $form->setContributionIds(array($contributionId));
+ $form->setContributionIds([$contributionId]);
$format = Civi::settings()->get('dateformatFull');
$date = CRM_Utils_Date::getToday();
$displayDate = CRM_Utils_Date::customFormat($date, $format);
$html = CRM_Contribute_Form_Task_PDFLetterCommon::postProcess($form, $formValues);
- $expectedValues = array(
+ $expectedValues = [
'Hello Anthony Collins',
'$ 100.00',
$displayDate,
'Donation',
- );
+ ];
foreach ($expectedValues as $val) {
$this->assertTrue(strpos($html[$contributionId], $val) !== 0);
*/
public function testPostProcessGroupByContact() {
$this->createLoggedInUser();
- $this->hookClass->setHook('civicrm_tokenValues', array($this, 'hook_aggregateTokenValues'));
- $this->hookClass->setHook('civicrm_tokens', array($this, 'hook_tokens'));
+ $this->hookClass->setHook('civicrm_tokenValues', [$this, 'hook_aggregateTokenValues']);
+ $this->hookClass->setHook('civicrm_tokens', [$this, 'hook_tokens']);
$this->mut = new CiviMailUtils($this, TRUE);
$this->_individualId = $this->individualCreate();
$this->_individualId2 = $this->individualCreate();
$htmlMessage = "{aggregate.rendered_token}";
- $formValues = array(
+ $formValues = [
'is_unit_test' => TRUE,
'group_by' => 'contact_id',
'html_message' => $htmlMessage,
'email_options' => 'both',
'subject' => 'Testy test test',
'from' => 'info@example.com',
- );
+ ];
- $contributionIDs = array();
- $contribution = $this->callAPISuccess('Contribution', 'create', array(
+ $contributionIDs = [];
+ $contribution = $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $this->_individualId,
'total_amount' => 100,
'financial_type_id' => 'Donation',
'receive_date' => '2016-12-25',
- ));
+ ]);
$contributionIDs[] = $contribution['id'];
- $contribution = $this->callAPISuccess('Contribution', 'create', array(
+ $contribution = $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $this->_individualId2,
'total_amount' => 10,
'financial_type_id' => 'Donation',
'receive_date' => '2016-12-25',
- ));
+ ]);
$contributionIDs[] = $contribution['id'];
- $contribution = $this->callAPISuccess('Contribution', 'create', array(
+ $contribution = $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $this->_individualId2,
'total_amount' => 1,
'financial_type_id' => 'Donation',
'receive_date' => '2016-12-25',
- ));
+ ]);
$contributionIDs[] = $contribution['id'];
$form = new CRM_Contribute_Form_Task_PDFLetter();
</tbody>
</table>", $html[2]);
- $activities = $this->callAPISuccess('Activity', 'get', array('activity_type_id' => 'Print PDF Letter', 'sequential' => 1));
+ $activities = $this->callAPISuccess('Activity', 'get', ['activity_type_id' => 'Print PDF Letter', 'sequential' => 1]);
$this->assertEquals(2, $activities['count']);
$this->assertEquals($html[1], $activities['values'][0]['details']);
$this->assertEquals($html[2], $activities['values'][1]['details']);
*/
public function hook_tokens(&$tokens) {
$this->hookTokensCalled++;
- $tokens['aggregate'] = array('rendered_token' => 'rendered_token');
+ $tokens['aggregate'] = ['rendered_token' => 'rendered_token'];
}
/**
* @param array $tokens
* @param null $context
*/
- public function hook_aggregateTokenValues(&$values, $contactIDs, $job = NULL, $tokens = array(), $context = NULL) {
+ public function hook_aggregateTokenValues(&$values, $contactIDs, $job = NULL, $tokens = [], $context = NULL) {
foreach ($contactIDs as $contactID) {
CRM_Core_Smarty::singleton()->assign('messageContactID', $contactID);
$values[$contactID]['aggregate.rendered_token'] = CRM_Core_Smarty::singleton()
$form = new CRM_Contribute_Form_Task_Status();
// create a pending contribution
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_individualId,
'total_amount' => 100,
'financial_type_id' => 'Donation',
'contribution_status_id' => 2,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
$contributionId = $contribution['id'];
- $form->setContributionIds(array($contributionId));
+ $form->setContributionIds([$contributionId]);
$form->buildQuickForm();
- $params = array(
+ $params = [
"contribution_status_id" => 1,
"trxn_id_{$contributionId}" => NULL,
"check_number_{$contributionId}" => NULL,
"fee_amount_{$contributionId}" => 0,
"trxn_date_{$contributionId}" => date('m/d/Y'),
"payment_instrument_id_{$contributionId}" => 4,
- );
+ ];
CRM_Contribute_Form_Task_Status::processForm($form, $params);
- $contribution = $this->callAPISuccess('Contribution', 'get', array('id' => $contributionId));
+ $contribution = $this->callAPISuccess('Contribution', 'get', ['id' => $contributionId]);
$updatedContribution = $contribution['values'][1];
$this->assertEquals('', $updatedContribution['contribution_source']);
* executes without any error after sorting the search result.
*/
public function testPreProcessCommonAfterSorting() {
- $fields = array(
+ $fields = [
'source' => 'contribution_source',
'status' => 'contribution_status',
'financialTypes' => 'financial_type',
- );
- $financialTypes = array('Member Dues', 'Event Fee', 'Donation');
- $status = array('Completed', 'Partially paid', 'Pending');
- $source = array('test source text', 'check source text', 'source text');
+ ];
+ $financialTypes = ['Member Dues', 'Event Fee', 'Donation'];
+ $status = ['Completed', 'Partially paid', 'Pending'];
+ $source = ['test source text', 'check source text', 'source text'];
$this->_individualId = $this->individualCreate();
for ($i = 0; $i < 3; $i++) {
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_individualId,
'total_amount' => 100,
'source' => $source[$i],
'financial_type_id' => $financialTypes[$i],
'contribution_status_id' => $status[$i],
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
$contributionIds[] = $contribution['id'];
}
// Generate expected sorted array.
- $expectedValues = array();
+ $expectedValues = [];
foreach ($fields as $key => $fld) {
$sortedFields = array_combine($$key, $contributionIds);
ksort($sortedFields);
* @group headless
*/
class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase {
- protected $_tablesToTruncate = array();
+ protected $_tablesToTruncate = [];
/**
* Setup function.
*/
public function testImportParserWithSoftCreditsByExternalIdentifier($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
- $contact1Params = array(
+ $contact1Params = [
'first_name' => 'Contact',
'last_name' => 'One',
'external_identifier' => 'ext-1',
'contact_type' => 'Individual',
- );
- $contact2Params = array(
+ ];
+ $contact2Params = [
'first_name' => 'Contact',
'last_name' => 'Two',
'external_identifier' => 'ext-2',
'contact_type' => 'Individual',
- );
+ ];
$contact1Id = $this->individualCreate($contact1Params);
$contact2Id = $this->individualCreate($contact2Params);
- $values = array(
+ $values = [
"total_amount" => $this->formatMoneyInput(1230.99),
"financial_type" => "Donation",
"external_identifier" => "ext-1",
"soft_credit" => "ext-2",
- );
- $mapperSoftCredit = array(NULL, NULL, NULL, "external_identifier");
- $mapperSoftCreditType = array(NULL, NULL, NULL, "1");
+ ];
+ $mapperSoftCredit = [NULL, NULL, NULL, "external_identifier"];
+ $mapperSoftCreditType = [NULL, NULL, NULL, "1"];
$this->runImport($values, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Contribute_Import_Parser::SOFT_CREDIT, $mapperSoftCredit, NULL, $mapperSoftCreditType);
- $params = array(
+ $params = [
"contact_id" => $contact1Id,
- );
- $values = array();
+ ];
+ $values = [];
$contributionsOfMainContact = CRM_Contribute_BAO_Contribution::retrieve($params, $values, $values);
$this->assertEquals(1230.99, $contributionsOfMainContact->total_amount);
$this->assertEquals(1230.99, $contributionsOfMainContact->net_amount);
*/
class CRM_Contribute_Page_AjaxTest extends CiviUnitTestCase {
- protected $_params = array();
+ protected $_params = [];
public function setUp() {
parent::setUp();
- $this->_fields = array('amount', 'sct_label');
+ $this->_fields = ['amount', 'sct_label'];
- $this->_params = array(
+ $this->_params = [
'page' => 1,
'rp' => 50,
'offset' => 0,
'rowCount' => 50,
'sort' => NULL,
'is_unit_test' => TRUE,
- );
- $softContactParams = array(
+ ];
+ $softContactParams = [
'first_name' => 'soft',
'last_name' => 'Contact',
- );
+ ];
$this->_softContactId = $this->individualCreate($softContactParams);
//create three sample contacts
- foreach (array(0, 1, 2) as $seq) {
- $this->_primaryContacts[] = $this->individualCreate(array(), $seq);
+ foreach ([0, 1, 2] as $seq) {
+ $this->_primaryContacts[] = $this->individualCreate([], $seq);
}
}
* Test retrieve Soft Contribution through AJAX
*/
public function testGetSoftContributionSelector() {
- $softTypes = array(3, 2, 5);
- $amounts = array('100', '600', '150');
+ $softTypes = [3, 2, 5];
+ $amounts = ['100', '600', '150'];
// create sample soft contribution for contact
foreach ($this->_primaryContacts as $seq => $contactId) {
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $contactId,
'receive_date' => date('Ymd'),
'total_amount' => $amounts[$seq],
'financial_type_id' => 1,
'non_deductible_amount' => '10',
'contribution_status_id' => 1,
- 'soft_credit' => array(
- '1' => array(
+ 'soft_credit' => [
+ '1' => [
'contact_id' => $this->_softContactId,
'amount' => $amounts[$seq],
'soft_credit_type_id' => $softTypes[$seq],
- ),
- ),
- ));
+ ],
+ ],
+ ]);
}
$_GET = array_merge($this->_params,
- array(
+ [
'cid' => $this->_softContactId,
'context' => 'contribution',
- )
+ ]
);
$softCreditList = CRM_Contribute_Page_AJAX::getSoftContributionRows();
foreach ($this->_fields as $columnName) {
- $_GET['columns'][] = array(
+ $_GET['columns'][] = [
'data' => $columnName,
- );
+ ];
}
// get the results in descending order
- $_GET['order'] = array(
- '0' => array(
+ $_GET['order'] = [
+ '0' => [
'column' => 0,
'dir' => 'desc',
- ),
- );
+ ],
+ ];
$amountSortedList = CRM_Contribute_Page_AJAX::getSoftContributionRows();
$this->assertEquals(3, $softCreditList['recordsTotal']);
*/
public function testGetSoftContributionForMembership() {
//Check soft credit for membership
- $memParams = array(
+ $memParams = [
'contribution_contact_id' => $this->_primaryContacts[0],
'contact_id' => $this->_softContactId,
'contribution_status_id' => 1,
'status_id' => 1,
'total_amount' => 100,
'receive_date' => '2018-06-08',
- 'soft_credit' => array(
+ 'soft_credit' => [
'soft_credit_type_id' => 11,
'contact_id' => $this->_softContactId,
- ),
- );
+ ],
+ ];
$_GET = array_merge($this->_params,
- array(
+ [
'cid' => $this->_softContactId,
'context' => 'membership',
'entityID' => $this->contactMembershipCreate($memParams),
- )
+ ]
);
$softCreditList = CRM_Contribute_Page_AJAX::getSoftContributionRows();
* CRM-20866 - Soft credit appearance inconsistent in contribution search
*/
public function testSoftCreditFieldsSelected() {
- $queryParams = array(array('contribution_or_softcredits', '=', 'both_related', 0, 0));
+ $queryParams = [['contribution_or_softcredits', '=', 'both_related', 0, 0]];
$searchSelector = new CRM_Contribute_Selector_Search($queryParams, CRM_Core_Action::VIEW);
list($select, $from, $where, $having) = $searchSelector->getQuery()->query();
* CRM-20866 - Soft credit appearance inconsistent in contribution search
*/
public function testSoftCreditFieldNotSelected() {
- $queryParams = array(array('contribution_or_softcredits', '=', 'only_contribs', 0, 0));
+ $queryParams = [['contribution_or_softcredits', '=', 'only_contribs', 0, 0]];
$searchSelector = new CRM_Contribute_Selector_Search($queryParams, CRM_Core_Action::VIEW);
list($select, $from, $where, $having) = $searchSelector->getQuery()->query();
$this->mut = new CiviMailUtils($this, TRUE);
- $this->fixtures['rolling_membership_type'] = array(
+ $this->fixtures['rolling_membership_type'] = [
'period_type' => 'rolling',
'duration_unit' => 'month',
'duration_interval' => '3',
'is_active' => 1,
'domain_id' => 1,
'financial_type_id' => 2,
- );
+ ];
- $this->fixtures['rolling_membership'] = array(
- 'membership_type_id' => array(
+ $this->fixtures['rolling_membership'] = [
+ 'membership_type_id' => [
'period_type' => 'rolling',
'duration_unit' => 'month',
'duration_interval' => '3',
'is_active' => 1,
- ),
+ ],
'join_date' => '20120315',
'start_date' => '20120315',
'end_date' => '20120615',
'is_override' => 0,
- );
+ ];
- $this->fixtures['rolling_membership_past'] = array(
- 'membership_type_id' => array(
+ $this->fixtures['rolling_membership_past'] = [
+ 'membership_type_id' => [
'period_type' => 'rolling',
'duration_unit' => 'month',
'duration_interval' => '3',
'is_active' => 1,
- ),
+ ],
'join_date' => '20100310',
'start_date' => '20100310',
'end_date' => '20100610',
'is_override' => 'NULL',
- );
- $this->fixtures['participant'] = array(
- 'event_id' => array(
+ ];
+ $this->fixtures['participant'] = [
+ 'event_id' => [
'is_active' => 1,
'is_template' => 0,
'title' => 'Example Event',
'start_date' => '20120315',
'end_date' => '20120615',
- ),
+ ],
// Attendee.
'role_id' => '1',
// No-show.
'status_id' => '8',
- );
+ ];
- $this->fixtures['phonecall'] = array(
+ $this->fixtures['phonecall'] = [
'status_id' => 1,
'activity_type_id' => 2,
'activity_date_time' => '20120615100000',
'is_current_revision' => 1,
'is_deleted' => 0,
- );
- $this->fixtures['contact'] = array(
+ ];
+ $this->fixtures['contact'] = [
'is_deceased' => 0,
'contact_type' => 'Individual',
'email' => 'test-member@example.com',
'gender_id' => 'Female',
'first_name' => 'Churmondleia',
'last_name' => 'Ōtākou',
- );
- $this->fixtures['contact_2'] = array(
+ ];
+ $this->fixtures['contact_2'] = [
'is_deceased' => 0,
'contact_type' => 'Individual',
'email' => 'test-contact-2@example.com',
'gender_id' => 'Male',
'first_name' => 'Fabble',
'last_name' => 'Fi',
- );
- $this->fixtures['contact_birthdate'] = array(
+ ];
+ $this->fixtures['contact_birthdate'] = [
'is_deceased' => 0,
'contact_type' => 'Individual',
'email' => 'test-bday@example.com',
'birth_date' => '20050707',
- );
- $this->fixtures['sched_activity_1day'] = array(
+ ];
+ $this->fixtures['sched_activity_1day'] = [
'name' => 'One_Day_Phone_Call_Notice',
'title' => 'One Day Phone Call Notice',
'limit_to' => '1',
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => '1-Day (non-repeating) (about {activity.activity_type})',
- );
- $this->fixtures['sched_activity_1day_r'] = array(
+ ];
+ $this->fixtures['sched_activity_1day_r'] = [
'name' => 'One_Day_Phone_Call_Notice_R',
'title' => 'One Day Phone Call Notice R',
'limit_to' => 1,
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => '1-Day (repeating) (about {activity.activity_type})',
- );
- $this->fixtures['sched_activity_1day_r_on_abs_date'] = array(
+ ];
+ $this->fixtures['sched_activity_1day_r_on_abs_date'] = [
'name' => 'One_Day_Phone_Call_Notice_R',
'title' => 'One Day Phone Call Notice R',
'limit_to' => 1,
'start_action_offset' => '',
'start_action_unit' => '',
'subject' => '1-Day (repeating) (about {activity.activity_type})',
- );
- $this->fixtures['sched_eventname_1day_on_abs_date'] = array(
+ ];
+ $this->fixtures['sched_eventname_1day_on_abs_date'] = [
'name' => 'sched_eventname_1day_on_abs_date',
'title' => 'sched_eventname_1day_on_abs_date',
'limit_to' => 1,
'start_action_offset' => NULL,
'start_action_unit' => NULL,
'subject' => 'sched_eventname_1day_on_abs_date',
- );
- $this->fixtures['sched_membership_join_2week'] = array(
+ ];
+ $this->fixtures['sched_membership_join_2week'] = [
'name' => 'sched_membership_join_2week',
'title' => 'sched_membership_join_2week',
'absolute_date' => '',
'start_action_offset' => '2',
'start_action_unit' => 'week',
'subject' => 'subject sched_membership_join_2week (joined {membership.join_date})',
- );
- $this->fixtures['sched_membership_start_1week'] = array(
+ ];
+ $this->fixtures['sched_membership_start_1week'] = [
'name' => 'sched_membership_start_1week',
'title' => 'sched_membership_start_1week',
'absolute_date' => '',
'start_action_offset' => '1',
'start_action_unit' => 'week',
'subject' => 'subject sched_membership_start_1week (joined {membership.start_date})',
- );
- $this->fixtures['sched_membership_end_2week'] = array(
+ ];
+ $this->fixtures['sched_membership_end_2week'] = [
'name' => 'sched_membership_end_2week',
'title' => 'sched_membership_end_2week',
'absolute_date' => '',
'start_action_offset' => '2',
'start_action_unit' => 'week',
'subject' => 'subject sched_membership_end_2week',
- );
- $this->fixtures['sched_on_membership_end_date'] = array(
+ ];
+ $this->fixtures['sched_on_membership_end_date'] = [
'name' => 'sched_on_membership_end_date',
'title' => 'sched_on_membership_end_date',
'body_html' => '<p>Your membership expired today</p>',
'start_action_offset' => '0',
'start_action_unit' => 'hour',
'subject' => 'subject send reminder on membership_end_date',
- );
- $this->fixtures['sched_after_1day_membership_end_date'] = array(
+ ];
+ $this->fixtures['sched_after_1day_membership_end_date'] = [
'name' => 'sched_after_1day_membership_end_date',
'title' => 'sched_after_1day_membership_end_date',
'body_html' => '<p>Your membership expired yesterday</p>',
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => 'subject send reminder on membership_end_date',
- );
+ ];
- $this->fixtures['sched_membership_end_2month'] = array(
+ $this->fixtures['sched_membership_end_2month'] = [
'name' => 'sched_membership_end_2month',
'title' => 'sched_membership_end_2month',
'absolute_date' => '',
'start_action_offset' => '2',
'start_action_unit' => 'month',
'subject' => 'subject sched_membership_end_2month',
- );
+ ];
- $this->fixtures['sched_membership_absolute_date'] = array(
+ $this->fixtures['sched_membership_absolute_date'] = [
'name' => 'sched_membership_absolute_date',
'title' => 'sched_membership_absolute_date',
'absolute_date' => CRM_Utils_Date::processDate('20120614100000'),
'start_action_offset' => '',
'start_action_unit' => '',
'subject' => 'subject sched_membership_absolute_date',
- );
+ ];
- $this->fixtures['sched_contact_bday_yesterday'] = array(
+ $this->fixtures['sched_contact_bday_yesterday'] = [
'name' => 'sched_contact_bday_yesterday',
'title' => 'sched_contact_bday_yesterday',
'absolute_date' => '',
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => 'subject sched_contact_bday_yesterday',
- );
+ ];
- $this->fixtures['sched_contact_bday_anniv'] = array(
+ $this->fixtures['sched_contact_bday_anniv'] = [
'name' => 'sched_contact_bday_anniv',
'title' => 'sched_contact_bday_anniv',
'absolute_date' => '',
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => 'subject sched_contact_bday_anniv',
- );
+ ];
- $this->fixtures['sched_contact_grad_tomorrow'] = array(
+ $this->fixtures['sched_contact_grad_tomorrow'] = [
'name' => 'sched_contact_grad_tomorrow',
'title' => 'sched_contact_grad_tomorrow',
'absolute_date' => '',
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => 'subject sched_contact_grad_tomorrow',
- );
+ ];
- $this->fixtures['sched_contact_grad_anniv'] = array(
+ $this->fixtures['sched_contact_grad_anniv'] = [
'name' => 'sched_contact_grad_anniv',
'title' => 'sched_contact_grad_anniv',
'absolute_date' => '',
'start_action_offset' => '1',
'start_action_unit' => 'week',
'subject' => 'subject sched_contact_grad_anniv',
- );
+ ];
- $this->fixtures['sched_contact_created_yesterday'] = array(
+ $this->fixtures['sched_contact_created_yesterday'] = [
'name' => 'sched_contact_created_yesterday',
'title' => 'sched_contact_created_yesterday',
'absolute_date' => '',
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => 'subject sched_contact_created_yesterday',
- );
+ ];
- $this->fixtures['sched_contact_mod_anniv'] = array(
+ $this->fixtures['sched_contact_mod_anniv'] = [
'name' => 'sched_contact_mod_anniv',
'title' => 'sched_contact_mod_anniv',
'absolute_date' => '',
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => 'subject sched_contact_mod_anniv',
- );
+ ];
- $this->fixtures['sched_eventtype_start_1week_before'] = array(
+ $this->fixtures['sched_eventtype_start_1week_before'] = [
'name' => 'sched_eventtype_start_1week_before',
'title' => 'sched_eventtype_start_1week_before',
'absolute_date' => '',
'start_action_offset' => '1',
'start_action_unit' => 'week',
'subject' => 'subject sched_eventtype_start_1week_before ({event.title})',
- );
- $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks'] = array(
+ ];
+ $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks'] = [
'name' => 'sched_eventtype_end_2month_repeat_twice_2_weeks',
'title' => 'sched_eventtype_end_2month_repeat_twice_2_weeks',
'absolute_date' => '',
'start_action_offset' => '2',
'start_action_unit' => 'month',
'subject' => 'subject sched_eventtype_end_2month_repeat_twice_2_weeks {event.title}',
- );
+ ];
- $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'] = array(
+ $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'] = [
'name' => 'sched_membership_end_2month',
'title' => 'sched_membership_end_2month',
'absolute_date' => '',
'start_action_offset' => '2',
'start_action_unit' => 'month',
'subject' => 'subject sched_membership_end_2month',
- );
- $this->fixtures['sched_membership_end_limit_to_none'] = array(
+ ];
+ $this->fixtures['sched_membership_end_limit_to_none'] = [
'name' => 'limit to none',
'title' => 'limit to none',
'absolute_date' => '',
'start_action_offset' => '2',
'start_action_unit' => 'month',
'subject' => 'limit to none',
- );
- $this->fixtures['sched_on_membership_end_date_repeat_interval'] = array(
+ ];
+ $this->fixtures['sched_on_membership_end_date_repeat_interval'] = [
'name' => 'sched_on_membership_end_date',
'title' => 'sched_on_membership_end_date',
'body_html' => '<p>Your membership expired 1 unit ago</p>',
'start_action_offset' => '0',
'start_action_unit' => 'hour',
'subject' => 'subject send reminder every unit after membership_end_date',
- );
+ ];
- $customGroup = $this->callAPISuccess('CustomGroup', 'create', array(
+ $customGroup = $this->callAPISuccess('CustomGroup', 'create', [
'title' => ts('Test Contact Custom group'),
'name' => 'test_contact_cg',
'extends' => 'Contact',
'is_active' => 1,
'collapse_adv_display' => 0,
'collapse_display' => 0,
- ));
- $customField = $this->callAPISuccess('CustomField', 'create', array(
+ ]);
+ $customField = $this->callAPISuccess('CustomField', 'create', [
'label' => 'Test Text',
'data_type' => 'String',
'html_type' => 'Text',
'custom_group_id' => $customGroup['id'],
- ));
- $this->fixtures['contact_custom_token'] = array(
+ ]);
+ $this->fixtures['contact_custom_token'] = [
'id' => $customField['id'],
'token' => sprintf('{contact.custom_%s}', $customField['id']),
'name' => sprintf('custom_%s', $customField['id']),
'value' => 'text ' . substr(sha1(rand()), 0, 7),
- );
+ ];
$this->_setUp();
}
$this->mut->clearMessages();
$this->mut->stop();
unset($this->mut);
- $this->quickCleanup(array(
+ $this->quickCleanup([
'civicrm_action_schedule',
'civicrm_action_log',
'civicrm_membership',
'civicrm_participant',
'civicrm_event',
'civicrm_email',
- ));
- $this->callAPISuccess('CustomField', 'delete', array('id' => $this->fixtures['contact_custom_token']['id']));
- $this->callAPISuccess('CustomGroup', 'delete', array(
+ ]);
+ $this->callAPISuccess('CustomField', 'delete', ['id' => $this->fixtures['contact_custom_token']['id']]);
+ $this->callAPISuccess('CustomGroup', 'delete', [
'id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'test_contact_cg', 'id', 'name'),
- ));
+ ]);
$this->_tearDown();
}
public function mailerExamples() {
- $cases = array();
+ $cases = [];
// Some tokens - short as subject has 128char limit in DB.
- $someTokensTmpl = implode(';;', array(
+ $someTokensTmpl = implode(';;', [
// basic contact token
'{contact.display_name}',
// funny legacy contact token
'{domain.name}',
// action-scheduler token
'{activity.activity_type}',
- ));
+ ]);
// Further tokens can be tested in the body text/html.
- $manyTokensTmpl = implode(';;', array(
+ $manyTokensTmpl = implode(';;', [
$someTokensTmpl,
'{contact.email_greeting}',
$this->fixture['contact_custom_token']['token'],
- ));
+ ]);
// Note: The behavior of domain-tokens on a scheduled reminder is undefined. All we
// can really do is check that it has something.
$someTokensExpected = 'Churmondleia Ōtākou;;Female;;Female;;[a-zA-Z0-9 ]+;;Phone Call';
$manyTokensExpected = sprintf('%s;;Dear Churmondleia;;%s', $someTokensExpected, $this->fixture['contact_custom_token']['value']);
// In this example, we use a lot of tokens cutting across multiple components.
- $cases[0] = array(
+ $cases[0] = [
// Schedule definition.
- array(
+ [
'subject' => "subj $someTokensTmpl",
'body_html' => "html $manyTokensTmpl",
'body_text' => "text $manyTokensTmpl",
- ),
+ ],
// Assertions (regex).
- array(
+ [
'from_name' => "/^FIXME\$/",
'from_email' => "/^info@EXAMPLE.ORG\$/",
'subject' => "/^subj $someTokensExpected\$/",
'body_html' => "/^html $manyTokensExpected\$/",
'body_text' => "/^text $manyTokensExpected\$/",
- ),
- );
+ ],
+ ];
// In this example, we customize the from address.
- $cases[1] = array(
+ $cases[1] = [
// Schedule definition.
- array(
+ [
'from_name' => 'Bob',
'from_email' => 'bob@example.org',
- ),
+ ],
// Assertions (regex).
- array(
+ [
'from_name' => "/^Bob\$/",
'from_email' => "/^bob@example.org\$/",
- ),
- );
+ ],
+ ];
// In this example, we autoconvert HTML to text
- $cases[2] = array(
+ $cases[2] = [
// Schedule definition.
- array(
+ [
'body_html' => '<p>Hello & stuff.</p>',
'body_text' => '',
- ),
+ ],
// Assertions (regex).
- array(
+ [
'body_html' => '/^' . preg_quote('<p>Hello & stuff.</p>', '/') . '/',
'body_text' => '/^' . preg_quote('Hello & stuff.', '/') . '/',
- ),
- );
+ ],
+ ];
// In this example, we autoconvert HTML to text
- $cases[3] = array(
+ $cases[3] = [
// Schedule definition.
- array(
+ [
'body_html' => '',
'body_text' => 'Hello world',
- ),
+ ],
// Assertions (regex).
- array(
+ [
'body_html' => '/^--UNDEFINED--$/',
'body_text' => '/^Hello world$/',
- ),
- );
+ ],
+ ];
return $cases;
}
$this->assertTrue(is_numeric($activity->id));
$contact = $this->callAPISuccess('contact', 'create', array_merge(
$this->fixtures['contact'],
- array(
+ [
$this->fixtures['contact_custom_token']['name'] => $this->fixtures['contact_custom_token']['value'],
- )
+ ]
));
$activity->save();
$activityContact->save();
CRM_Utils_Time::setTime('2012-06-14 15:00:00');
- $this->callAPISuccess('job', 'send_reminder', array());
- $this->mut->assertRecipients(array(array('test-member@example.com')));
+ $this->callAPISuccess('job', 'send_reminder', []);
+ $this->mut->assertRecipients([['test-member@example.com']]);
foreach ($this->mut->getAllMessages('ezc') as $message) {
/** @var ezcMail $message */
- $messageArray = array();
+ $messageArray = [];
$messageArray['subject'] = $message->subject;
$messageArray['from_name'] = $message->from->name;
$messageArray['from_email'] = $message->from->email;
foreach ($patterns as $field => $pattern) {
$this->assertRegExp($pattern, $messageArray[$field],
- "Check that '$field'' matches regex. " . print_r(array('expected' => $patterns, 'actual' => $messageArray), 1));
+ "Check that '$field'' matches regex. " . print_r(['expected' => $patterns, 'actual' => $messageArray], 1));
}
}
$this->mut->clearMessages();
$activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source);
$activityContact->save();
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 24-hour mark, no email
'time' => '2012-06-14 04:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- array(
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ [
// After the 24-hour mark, an email
'time' => '2012-06-14 15:00:00',
- 'recipients' => array(array('test-member@example.com')),
- 'subjects' => array('1-Day (non-repeating) (about Phone Call)'),
- ),
- array(
+ 'recipients' => [['test-member@example.com']],
+ 'subjects' => ['1-Day (non-repeating) (about Phone Call)'],
+ ],
+ [
// Run cron again; message already sent
'time' => '',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
$activityDAO = new CRM_Activity_DAO_Activity();
$activityDAO->source_record_id = $activity->id;
$activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source);
$activityContact->save();
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 24-hour mark, no email
'time' => '012-06-14 04:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- array(
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ [
// After the 24-hour mark, an email
'time' => '2012-06-14 15:00:00',
- 'recipients' => array(array('test-member@example.com')),
- 'subjects' => array('1-Day (repeating) (about Phone Call)'),
- ),
- array(
+ 'recipients' => [['test-member@example.com']],
+ 'subjects' => ['1-Day (repeating) (about Phone Call)'],
+ ],
+ [
// Run cron 4 hours later; first message already sent
'time' => '2012-06-14 20:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- array(
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ [
// Run cron 6 hours later; send second message.
'time' => '2012-06-14 21:00:01',
- 'recipients' => array(array('test-member@example.com')),
- 'subjects' => array('1-Day (repeating) (about Phone Call)'),
- ),
- ));
+ 'recipients' => [['test-member@example.com']],
+ 'subjects' => ['1-Day (repeating) (about Phone Call)'],
+ ],
+ ]);
}
public function testActivityDateTimeMatchRepeatableScheduleOnAbsDate() {
$activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source);
$activityContact->save();
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 24-hour mark, no email
'time' => '2012-06-13 04:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- array(
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ [
// On absolute date set on 2012-06-14
'time' => '2012-06-14 00:00:00',
- 'recipients' => array(array('test-member@example.com')),
- 'subjects' => array('1-Day (repeating) (about Phone Call)'),
- ),
- array(
+ 'recipients' => [['test-member@example.com']],
+ 'subjects' => ['1-Day (repeating) (about Phone Call)'],
+ ],
+ [
// Run cron 4 hours later; first message already sent
'time' => '2012-06-14 04:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- array(
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ [
// Run cron 6 hours later; send second message.
'time' => '2012-06-14 06:00:01',
- 'recipients' => array(array('test-member@example.com')),
- 'subjects' => array('1-Day (repeating) (about Phone Call)'),
- ),
- ));
+ 'recipients' => [['test-member@example.com']],
+ 'subjects' => ['1-Day (repeating) (about Phone Call)'],
+ ],
+ ]);
}
public function testEventNameWithAbsoluteDateAndNothingElse() {
- $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], array('status_id' => 1)));
- $this->callAPISuccess('Email', 'create', array(
+ $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], ['status_id' => 1]));
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $participant->contact_id,
'email' => 'test-event@example.com',
- ));
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $participant->contact_id)));
+ ]);
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $participant->contact_id]));
$actionSchedule = $this->fixtures['sched_eventname_1day_on_abs_date'];
$actionSchedule['entity_value'] = $participant->event_id;
$this->callAPISuccess('action_schedule', 'create', $actionSchedule);
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 24-hour mark, no email
'time' => '2012-06-13 04:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- array(
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ [
// On absolute date set on 2012-06-14
'time' => '2012-06-14 00:00:00',
- 'recipients' => array(array('test-event@example.com')),
- 'subjects' => array('sched_eventname_1day_on_abs_date'),
- ),
- array(
+ 'recipients' => [['test-event@example.com']],
+ 'subjects' => ['sched_eventname_1day_on_abs_date'],
+ ],
+ [
// Run cron 4 hours later; first message already sent
'time' => '2012-06-14 04:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- ));
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ ]);
}
/**
* an email should be sent.
*/
public function testMembershipDateMatch() {
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 1)));
+ $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 1]));
$this->assertTrue(is_numeric($membership->id));
- $result = $this->callAPISuccess('Email', 'create', array(
+ $result = $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'test-member@example.com',
'location_type_id' => 1,
'is_primary' => 1,
- ));
+ ]);
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id)));
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
$actionSchedule = $this->fixtures['sched_membership_join_2week'];
$actionSchedule['entity_value'] = $membership->membership_type_id;
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
$this->assertTrue(is_numeric($actionScheduleDao->id));
// start_date=2012-03-15 ; schedule is 2 weeks after join_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 2-week mark, no email.
'time' => '2012-03-28 01:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- array(
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ [
// After the 2-week mark, send an email.
'time' => '2012-03-29 01:00:00',
- 'recipients' => array(array('test-member@example.com')),
- 'subjects' => array('subject sched_membership_join_2week (joined March 15th, 2012)'),
- ),
- ));
+ 'recipients' => [['test-member@example.com']],
+ 'subjects' => ['subject sched_membership_join_2week (joined March 15th, 2012)'],
+ ],
+ ]);
$actionSchedule = $this->fixtures['sched_membership_start_1week'];
$actionSchedule['entity_value'] = $membership->membership_type_id;
$this->assertTrue(is_numeric($actionScheduleDao->id));
// start_date=2012-03-15 ; schedule is 1 weeks after start_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 2-week mark, no email.
'time' => '2012-03-21 01:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- array(
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ [
// After the 2-week mark, send an email.
'time' => '2012-03-22 01:00:00',
- 'recipients' => array(array('test-member@example.com')),
- 'subjects' => array('subject sched_membership_start_1week (joined March 15th, 2012)'),
- ),
- ));
+ 'recipients' => [['test-member@example.com']],
+ 'subjects' => ['subject sched_membership_start_1week (joined March 15th, 2012)'],
+ ],
+ ]);
}
/**
*/
public function testScheduleReminderWithParentGroup() {
// Contact A with birth-date at '07-07-2005' and gender - Male, later got added in smart group
- $contactID1 = $this->individualCreate(array('birth_date' => '20050707', 'gender_id' => 1, 'email' => 'abc@test.com'));
+ $contactID1 = $this->individualCreate(['birth_date' => '20050707', 'gender_id' => 1, 'email' => 'abc@test.com']);
// Contact B with birth-date at '07-07-2005', later got added in regular group
- $contactID2 = $this->individualCreate(array('birth_date' => '20050707', 'email' => 'def@test.com'), 1);
+ $contactID2 = $this->individualCreate(['birth_date' => '20050707', 'email' => 'def@test.com'], 1);
// Contact C with birth-date at '07-07-2005', but not included in any group
- $contactID3 = $this->individualCreate(array('birth_date' => '20050707', 'email' => 'ghi@test.com'), 2);
+ $contactID3 = $this->individualCreate(['birth_date' => '20050707', 'email' => 'ghi@test.com'], 2);
// create regular group and add Contact B to it
$groupID = $this->groupCreate();
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID,
'contact_id' => $contactID2,
- ));
+ ]);
// create smart group which will contain all Male contacts
- $smartGroupParams = array('formValues' => array('gender_id' => 1));
+ $smartGroupParams = ['formValues' => ['gender_id' => 1]];
$smartGroupID = $this->smartGroupCreate(
$smartGroupParams,
- array(
+ [
'name' => 'new_smart_group',
'title' => 'New Smart Group',
- 'parents' => array($groupID => 1),
- )
+ 'parents' => [$groupID => 1],
+ ]
);
- $actionScheduleParams = array(
+ $actionScheduleParams = [
'name' => 'sched_contact_bday_yesterday',
'title' => 'sched_contact_bday_yesterday',
'absolute_date' => '',
'start_action_offset' => '1',
'start_action_unit' => 'day',
'subject' => 'subject sched_contact_bday_yesterday',
- );
+ ];
// Create schedule reminder where parent group ($groupID) is selectd to limit recipients,
// which contain a individual contact - $contactID2 and is parent to smart group.
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionScheduleParams);
$this->assertTrue(is_numeric($actionScheduleDao->id));
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// On the birthday, no email.
'time' => '2005-07-07 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// The next day, send an email.
'time' => '2005-07-08 20:00:00',
- 'recipients' => array(
- array(
+ 'recipients' => [
+ [
'def@test.com',
- ),
- array(
+ ],
+ [
'abc@test.com',
- ),
- ),
- ),
- ));
+ ],
+ ],
+ ],
+ ]);
$this->groupDelete($smartGroupID);
$this->groupDelete($groupID);
}
public function testMembershipJoinDateNonMatch() {
$membership = $this->createTestObject('CRM_Member_DAO_Membership', $this->fixtures['rolling_membership']);
$this->assertTrue(is_numeric($membership->id));
- $result = $this->callAPISuccess('Email', 'create', array(
+ $result = $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'location_type_id' => 1,
'email' => 'test-member@example.com',
- ));
+ ]);
// Add an alternative membership type, and only send messages for that type
- $extraMembershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', array());
+ $extraMembershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', []);
$this->assertTrue(is_numeric($extraMembershipType->id));
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($this->fixtures['sched_membership_join_2week']);
$this->assertTrue(is_numeric($actionScheduleDao->id));
$actionScheduleDao->save();
// start_date=2012-03-15 ; schedule is 2 weeks after start_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// After the 2-week mark, don't send email because we have different membership type.
'time' => '2012-03-29 01:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
/**
*/
public function testMembershipEndDateRepeat() {
// creates membership with end_date = 20120615
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2)));
- $result = $this->callAPISuccess('Email', 'create', array(
+ $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2]));
+ $result = $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'test-member@example.com',
- ));
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id)));
+ ]);
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
$actionSchedule = $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'];
$actionSchedule['entity_value'] = $membership->membership_type_id;
$this->callAPISuccess('action_schedule', 'create', $actionSchedule);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// After the 1-month mark, no email
'time' => '2012-07-15 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After the 2-month mark, send an email.
'time' => '2012-08-15 01:00:00',
- 'recipients' => array(array('test-member@example.com')),
- ),
- array(
+ 'recipients' => [['test-member@example.com']],
+ ],
+ [
// 4 weeks after first email send first repeat
'time' => '2012-09-12 01:00:00',
- 'recipients' => array(array('test-member@example.com')),
- ),
- array(
+ 'recipients' => [['test-member@example.com']],
+ ],
+ [
// 1 week after first repeat send nothing
// There was a bug where the first repeat went out and then
// it would keep going out every cron run. This is to check that's
// not happening.
'time' => '2012-09-19 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// 4 weeks after first repeat send second repeat
'time' => '2012-10-10 01:00:00',
- 'recipients' => array(array('test-member@example.com')),
- ),
- array(
+ 'recipients' => [['test-member@example.com']],
+ ],
+ [
// 4 months after membership end, send nothing
'time' => '2012-10-15 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// 5 months after membership end, send nothing
'time' => '2012-11-15 01:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
/**
*/
public function testMembershipEndDateRepeatChangedEndDate_CRM_15376() {
// creates membership with end_date = 20120615
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2)));
- $this->callAPISuccess('Email', 'create', array(
+ $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2]));
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'test-member@example.com',
- ));
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id)));
+ ]);
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
$actionSchedule = $this->fixtures['sched_membership_end_2month_repeat_twice_4_weeks'];
$actionSchedule['entity_value'] = $membership->membership_type_id;
$this->callAPISuccess('action_schedule', 'create', $actionSchedule);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// After the 2-week mark, send an email.
'time' => '2012-08-15 01:00:00',
- 'recipients' => array(array('test-member@example.com')),
- ),
- ));
+ 'recipients' => [['test-member@example.com']],
+ ],
+ ]);
// Extend membership - reminder should NOT go out.
- $this->callAPISuccess('membership', 'create', array('id' => $membership->id, 'end_date' => '2014-01-01'));
- $this->assertCronRuns(array(
- array(
+ $this->callAPISuccess('membership', 'create', ['id' => $membership->id, 'end_date' => '2014-01-01']);
+ $this->assertCronRuns([
+ [
// After the 2-week mark, send an email.
'time' => '2012-09-12 01:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
/**
*/
public function testMembershipEndDateMatch() {
// creates membership with end_date = 20120615
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2)));
+ $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2]));
$this->assertTrue(is_numeric($membership->id));
- $this->callAPISuccess('Email', 'create', array(
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'test-member@example.com',
- ));
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id)));
+ ]);
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
$actionSchedule = $this->fixtures['sched_membership_end_2week'];
$actionSchedule['entity_value'] = $membership->membership_type_id;
$this->assertTrue(is_numeric($actionScheduleDao->id));
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 2-week mark, no email.
'time' => '2012-05-31 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After the 2-week mark, send an email.
'time' => '2012-06-01 01:00:00',
- 'recipients' => array(array('test-member@example.com')),
- ),
- array(
+ 'recipients' => [['test-member@example.com']],
+ ],
+ [
// After the email is sent, another one is not sent
'time' => '2012-06-01 02:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
// Now suppose user has renewed for rolling membership after 3 months, so upcoming assertion is written
// to ensure that new reminder is sent 2 week before the new end_date i.e. '2012-09-15'
//change the email id of chosen membership contact to assert
//recipient of not the previously sent mail but the new one
- $result = $this->callAPISuccess('Email', 'create', array(
+ $result = $this->callAPISuccess('Email', 'create', [
'is_primary' => 1,
'contact_id' => $membership->contact_id,
'email' => 'member2@example.com',
- ));
+ ]);
$this->assertAPISuccess($result);
// end_date=2012-09-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 2-week mark, no email
'time' => '2012-08-31 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After the 2-week mark, send an email
'time' => '2012-09-01 01:00:00',
- 'recipients' => array(array('member2@example.com')),
- ),
- array(
+ 'recipients' => [['member2@example.com']],
+ ],
+ [
// After the email is sent, another one is not sent
'time' => '2012-09-01 02:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
$membership->end_date = '2012-12-15';
$membership->save();
// end_date=2012-12-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 2-week mark, no email
'time' => '2012-11-30 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After the 2-week mark, send an email
'time' => '2012-12-01 01:00:00',
- 'recipients' => array(array('member2@example.com')),
- ),
- array(
+ 'recipients' => [['member2@example.com']],
+ ],
+ [
// After the email is sent, another one is not sent
'time' => '2012-12-01 02:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
public function createMembershipAndContact($contactFixture, $membershipTypeId) {
$result = $this->callAPISuccess('contact', 'create', $contactFixture);
$contact = $result['values'][$result['id']];
- $params = array(
+ $params = [
'status_id' => 2,
'contact_id' => $contact['id'],
'membership_type_id' => $membershipTypeId,
'owner_membership_id' => 'NULL',
- );
+ ];
$params = array_merge($this->fixtures['rolling_membership'], $params);
$membership = $this->createTestObject('CRM_Member_DAO_Membership', $params);
$this->assertTrue(is_numeric($membership->id));
$this->assertTrue(is_numeric($actionScheduleDao->id));
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 2-week mark, no email.
'time' => '2012-05-31 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After the 2-week mark, send emails.
'time' => '2012-06-01 01:00:00',
- 'recipients' => array(
- array('test-member@example.com'),
- array('test-contact-2@example.com'),
- ),
- ),
- array(
+ 'recipients' => [
+ ['test-member@example.com'],
+ ['test-contact-2@example.com'],
+ ],
+ ],
+ [
// After the email is sent, another one is not sent
'time' => '2012-06-01 02:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
// Now suppose user has renewed for rolling membership after 3 months, so upcoming assertion is written
// to ensure that new reminder is sent 2 week before the new end_date i.e. '2012-09-15'
$membershipTwo->save();
// end_date=2012-09-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 2-week mark, no email
'time' => '2012-08-31 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After the 2-week mark, send an email
'time' => '2012-09-01 01:00:00',
- 'recipients' => array(
- array('test-member@example.com'),
- array('test-contact-2@example.com'),
- ),
- ),
- array(
+ 'recipients' => [
+ ['test-member@example.com'],
+ ['test-contact-2@example.com'],
+ ],
+ ],
+ [
// After the email is sent, another one is not sent
'time' => '2012-06-01 02:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
/**
*/
public function testMembershipEndDateNoMatch() {
// creates membership with end_date = 20120615
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 3)));
+ $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 3]));
$this->assertTrue(is_numeric($membership->id));
- $result = $this->callAPISuccess('Email', 'create', array(
+ $result = $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'test-member@example.com',
- ));
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id)));
+ ]);
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
$actionSchedule = $this->fixtures['sched_membership_end_2month'];
$actionSchedule['entity_value'] = $membership->membership_type_id;
$this->assertTrue(is_numeric($actionScheduleDao->id));
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 2-week mark, no email.
'time' => '2012-05-31 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After the 2-week mark, no email
'time' => '2013-05-01 01:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
public function testContactBirthDateNoAnniv() {
$actionSchedule = $this->fixtures['sched_contact_bday_yesterday'];
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
$this->assertTrue(is_numeric($actionScheduleDao->id));
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// On the birthday, no email.
'time' => '2005-07-07 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// The next day, send an email.
'time' => '2005-07-08 20:00:00',
- 'recipients' => array(array('test-bday@example.com')),
- ),
- ));
+ 'recipients' => [['test-bday@example.com']],
+ ],
+ ]);
}
public function testContactBirthDateAnniversary() {
$actionSchedule = $this->fixtures['sched_contact_bday_anniv'];
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
$this->assertTrue(is_numeric($actionScheduleDao->id));
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// On some random day, no email.
'time' => '2014-03-07 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// On the eve of their 9th birthday, send an email.
'time' => '2014-07-06 20:00:00',
- 'recipients' => array(array('test-bday@example.com')),
- ),
- ));
+ 'recipients' => [['test-bday@example.com']],
+ ],
+ ]);
}
public function testContactCustomDateNoAnniv() {
- $group = array(
+ $group = [
'title' => 'Test_Group',
'name' => 'test_group',
- 'extends' => array('Individual'),
+ 'extends' => ['Individual'],
'style' => 'Inline',
'is_multiple' => FALSE,
'is_active' => 1,
- );
+ ];
$createGroup = $this->callAPISuccess('custom_group', 'create', $group);
- $field = array(
+ $field = [
'label' => 'Graduation',
'data_type' => 'Date',
'html_type' => 'Select Date',
'custom_group_id' => $createGroup['id'],
- );
+ ];
$createField = $this->callAPISuccess('custom_field', 'create', $field);
$contactParams = $this->fixtures['contact'];
$contactParams["custom_{$createField['id']}"] = '2013-12-16';
$actionSchedule['entity_value'] = "custom_{$createField['id']}";
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
$this->assertTrue(is_numeric($actionScheduleDao->id));
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// On some random day, no email.
'time' => '2014-03-07 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// On the eve of their graduation, send an email.
'time' => '2013-12-15 20:00:00',
- 'recipients' => array(array('test-member@example.com')),
- ),
- ));
- $this->callAPISuccess('custom_group', 'delete', array('id' => $createGroup['id']));
+ 'recipients' => [['test-member@example.com']],
+ ],
+ ]);
+ $this->callAPISuccess('custom_group', 'delete', ['id' => $createGroup['id']]);
}
public function testContactCreatedNoAnniv() {
$actionSchedule = $this->fixtures['sched_contact_created_yesterday'];
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
$this->assertTrue(is_numeric($actionScheduleDao->id));
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// On the date created, no email.
'time' => $contact['values'][$contact['id']]['created_date'],
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// The next day, send an email.
'time' => date('Y-m-d H:i:s', strtotime($contact['values'][$contact['id']]['created_date'] . ' +1 day')),
- 'recipients' => array(array('test-bday@example.com')),
- ),
- ));
+ 'recipients' => [['test-bday@example.com']],
+ ],
+ ]);
}
public function testContactModifiedAnniversary() {
$contact = $this->callAPISuccess('Contact', 'create', $this->fixtures['contact_birthdate']);
$this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id'];
- $modifiedDate = $this->callAPISuccess('Contact', 'getvalue', array('id' => $contact['id'], 'return' => 'modified_date'));
+ $modifiedDate = $this->callAPISuccess('Contact', 'getvalue', ['id' => $contact['id'], 'return' => 'modified_date']);
$actionSchedule = $this->fixtures['sched_contact_mod_anniv'];
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
$this->assertTrue(is_numeric($actionScheduleDao->id));
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// On some random day, no email.
'time' => date('Y-m-d H:i:s', strtotime($contact['values'][$contact['id']]['modified_date'] . ' -60 days')),
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// On the eve of 3 years after they were modified, send an email.
'time' => date('Y-m-d H:i:s', strtotime($modifiedDate . ' +3 years -1 day')),
- 'recipients' => array(array('test-bday@example.com')),
- ),
- ));
+ 'recipients' => [['test-bday@example.com']],
+ ],
+ ]);
}
/**
*/
public function testMembershipLimitToNone() {
// creates membership with end_date = 20120615
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2)));
+ $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2]));
$this->assertTrue(is_numeric($membership->id));
- $result = $this->callAPISuccess('Email', 'create', array(
+ $result = $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'member@example.com',
- ));
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id)));
- $this->callAPISuccess('contact', 'create', array('email' => 'b@c.com', 'contact_type' => 'Individual'));
+ ]);
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
+ $this->callAPISuccess('contact', 'create', ['email' => 'b@c.com', 'contact_type' => 'Individual']);
$this->assertAPISuccess($result);
$this->assertTrue(is_numeric($actionScheduleDao->id));
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 2-week mark, no email.
'time' => '2012-05-31 01:00:00',
// 'time' => '2012-06-01 01:00:00', // FIXME: Is this the right boundary?
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
public function testMembership_referenceDate() {
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2)));
+ $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2]));
$this->assertTrue(is_numeric($membership->id));
- $result = $this->callAPISuccess('Email', 'create', array(
+ $result = $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'member@example.com',
- ));
+ ]);
- $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id)));
+ $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
$this->assertAPISuccess($result);
$actionSchedule = $this->fixtures['sched_membership_join_2week'];
$this->assertTrue(is_numeric($actionScheduleDao->id));
// start_date=2012-03-15 ; schedule is 2 weeks after start_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// After the 2-week mark, send an email
'time' => '2012-03-29 01:00:00',
- 'recipients' => array(array('member@example.com')),
- ),
- array(
+ 'recipients' => [['member@example.com']],
+ ],
+ [
// After the 2-week 1day mark, don't send an email
'time' => '2012-03-30 01:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
//check if reference date is set to membership's join date
//as per the action_start_date chosen for current schedule reminder
$membership->join_date = '2012-03-29';
$membership->save();
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// After the 13 days of the changed join date 2012-03-29, don't send an email
'time' => '2012-04-11 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After the 2-week of the changed join date 2012-03-29, send an email
'time' => '2012-04-12 01:00:00',
- 'recipients' => array(array('member@example.com')),
- ),
- ));
- $this->assertCronRuns(array(
- array(
+ 'recipients' => [['member@example.com']],
+ ],
+ ]);
+ $this->assertCronRuns([
+ [
// It should not re-send on the same day
'time' => '2012-04-12 01:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
public function testMembershipOnMultipleReminder() {
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2)));
+ $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 2]));
$this->assertTrue(is_numeric($membership->id));
- $result = $this->callAPISuccess('Email', 'create', array(
+ $result = $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'member@example.com',
- ));
- $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id)));
+ ]);
+ $result = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
$this->assertAPISuccess($result);
// Send email 2 weeks before end_date
// Send email 1 day after end_date/grace period
$actionScheduleAfter = $this->fixtures['sched_after_1day_membership_end_date'];
$actionScheduleBefore['entity_value'] = $actionScheduleOn['entity_value'] = $actionScheduleAfter['entity_value'] = $membership->membership_type_id;
- foreach (array('actionScheduleBefore', 'actionScheduleOn', 'actionScheduleAfter') as $value) {
+ foreach (['actionScheduleBefore', 'actionScheduleOn', 'actionScheduleAfter'] as $value) {
$$value = CRM_Core_BAO_ActionSchedule::add($$value);
$this->assertTrue(is_numeric($$value->id));
}
$this->assertCronRuns(
- array(
- array(
+ [
+ [
// 1day 2weeks before membership end date(MED), don't send mail
'time' => '2012-05-31 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// 2 weeks before MED, send an email
'time' => '2012-06-01 01:00:00',
- 'recipients' => array(array('member@example.com')),
- ),
- array(
+ 'recipients' => [['member@example.com']],
+ ],
+ [
// 1day before MED, don't send mail
'time' => '2012-06-14 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// On MED, send an email
'time' => '2012-06-15 00:00:00',
- 'recipients' => array(array('member@example.com')),
- ),
- array(
+ 'recipients' => [['member@example.com']],
+ ],
+ [
// After 1day of MED, send an email
'time' => '2012-06-16 01:00:00',
- 'recipients' => array(array('member@example.com')),
- ),
- array(
+ 'recipients' => [['member@example.com']],
+ ],
+ [
// After 1day 1min of MED, don't send an email
'time' => '2012-06-17 00:01:00',
- 'recipients' => array(),
- ),
- )
+ 'recipients' => [],
+ ],
+ ]
);
// Assert the timestamp as of when the emails of respective three reminders as configured
$membership->end_date = '2012-06-20';
$membership->save();
- $result = $this->callAPISuccess('Contact', 'get', array('id' => $membership->contact_id));
+ $result = $this->callAPISuccess('Contact', 'get', ['id' => $membership->contact_id]);
$this->assertCronRuns(
- array(
- array(
+ [
+ [
// 1day 2weeks before membership end date(MED), don't send mail
'time' => '2012-06-05 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// 2 weeks before MED, send an email
'time' => '2012-06-06 01:00:00',
- 'recipients' => array(array('member@example.com')),
- ),
- array(
+ 'recipients' => [['member@example.com']],
+ ],
+ [
// 1day before MED, don't send mail
'time' => '2012-06-19 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// On MED, send an email
'time' => '2012-06-20 00:00:00',
- 'recipients' => array(array('member@example.com')),
- ),
- array(
+ 'recipients' => [['member@example.com']],
+ ],
+ [
// After 1day of MED, send an email
'time' => '2012-06-21 01:00:00',
- 'recipients' => array(array('member@example.com')),
- ),
- array(
+ 'recipients' => [['member@example.com']],
+ ],
+ [
// After 1day 1min of MED, don't send an email
'time' => '2012-07-21 00:01:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
public function testContactCustomDate_Anniv() {
- $group = array(
+ $group = [
'title' => 'Test_Group now',
'name' => 'test_group_now',
- 'extends' => array('Individual'),
+ 'extends' => ['Individual'],
'style' => 'Inline',
'is_multiple' => FALSE,
'is_active' => 1,
- );
+ ];
$createGroup = $this->callAPISuccess('custom_group', 'create', $group);
- $field = array(
+ $field = [
'label' => 'Graduation',
'data_type' => 'Date',
'html_type' => 'Select Date',
'custom_group_id' => $createGroup['id'],
- );
+ ];
$createField = $this->callAPISuccess('custom_field', 'create', $field);
$contactParams = $this->fixtures['contact'];
$actionSchedule['entity_value'] = "custom_{$createField['id']}";
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
$this->assertTrue(is_numeric($actionScheduleDao->id));
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// On some random day, no email.
'time' => '2014-03-07 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// A week after their 5th anniversary of graduation, send an email.
'time' => '2018-12-23 20:00:00',
- 'recipients' => array(array('test-member@example.com')),
- ),
- ));
- $this->callAPISuccess('custom_group', 'delete', array('id' => $createGroup['id']));
+ 'recipients' => [['test-member@example.com']],
+ ],
+ ]);
+ $this->callAPISuccess('custom_group', 'delete', ['id' => $createGroup['id']]);
}
/**
*/
public function testEventTypeRegistrationDate() {
//Create contact
- $contactParams = array(
+ $contactParams = [
'email' => 'test-event@example.com',
- );
+ ];
$contact = $this->individualCreate($contactParams);
//Add it as a participant to an event ending registration - 7 days from now.
- $params = array(
+ $params = [
'start_date' => date('Ymd', strtotime('-5 day')),
'end_date' => date('Ymd', strtotime('+7 day')),
'registration_start_date' => date('Ymd', strtotime('-5 day')),
'registration_end_date' => date('Ymd', strtotime('+7 day')),
- );
+ ];
$event = $this->eventCreate($params);
- $this->participantCreate(array('contact_id' => $contact, 'event_id' => $event['id']));
+ $this->participantCreate(['contact_id' => $contact, 'event_id' => $event['id']]);
//Create a scheduled reminder to send email 7 days before registration date.
$actionSchedule = $this->fixtures['sched_eventtype_start_1week_before'];
$actionSchedule['start_action_unit'] = 'day';
$actionSchedule['start_action_date'] = 'registration_end_date';
$actionSchedule['entity_value'] = $event['values'][$event['id']]['event_type_id'];
- $actionSchedule['entity_status'] = $this->callAPISuccessGetValue('ParticipantStatusType', array(
+ $actionSchedule['entity_status'] = $this->callAPISuccessGetValue('ParticipantStatusType', [
'return' => "id",
'name' => "Attended",
- ));
+ ]);
$actionSched = $this->callAPISuccess('action_schedule', 'create', $actionSchedule);
//Run the cron and verify if an email was sent.
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
'time' => date('Y-m-d'),
- 'recipients' => array(array('test-event@example.com')),
- ),
- ));
+ 'recipients' => [['test-event@example.com']],
+ ],
+ ]);
//Create contact 2
- $contactParams = array(
+ $contactParams = [
'email' => 'test-event2@example.com',
- );
+ ];
$contact2 = $this->individualCreate($contactParams);
//Create an event with registration end date = 2 week from now.
$params['end_date'] = date('Ymd', strtotime('+2 week'));
$params['registration_end_date'] = date('Ymd', strtotime('+2 week'));
$event2 = $this->eventCreate($params);
- $this->participantCreate(array('contact_id' => $contact2, 'event_id' => $event2['id']));
+ $this->participantCreate(['contact_id' => $contact2, 'event_id' => $event2['id']]);
//Assert there is no reminder sent to the contact.
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
'time' => date('Y-m-d'),
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
//Modify the sched reminder to be sent 2 week from registration end date.
- $this->callAPISuccess('action_schedule', 'create', array(
+ $this->callAPISuccess('action_schedule', 'create', [
'id' => $actionSched['id'],
'start_action_offset' => 2,
'start_action_unit' => 'week',
- ));
+ ]);
//Contact should receive the reminder now.
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
'time' => date('Y-m-d'),
- 'recipients' => array(array('test-event2@example.com')),
- ),
- ));
+ 'recipients' => [['test-event2@example.com']],
+ ],
+ ]);
}
/**
*/
public function testEventTypeStartDate() {
// Create event+participant with start_date = 20120315, end_date = 20120615.
- $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], array('status_id' => 2)));
- $this->callAPISuccess('Email', 'create', array(
+ $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], ['status_id' => 2]));
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $participant->contact_id,
'email' => 'test-event@example.com',
- ));
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $participant->contact_id)));
+ ]);
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $participant->contact_id]));
$actionSchedule = $this->fixtures['sched_eventtype_start_1week_before'];
$actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id');
//echo "CREATED\n"; ob_flush(); sleep(20);
// end_date=2012-06-15 ; schedule is 2 weeks before end_date
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// 2 weeks before
'time' => '2012-03-02 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// 1 week before
'time' => '2012-03-08 01:00:00',
- 'recipients' => array(array('test-event@example.com')),
- ),
- array(
+ 'recipients' => [['test-event@example.com']],
+ ],
+ [
// And then nothing else
'time' => '2012-03-16 01:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
public function testEventTypeEndDateRepeat() {
// Create event+participant with start_date = 20120315, end_date = 20120615.
- $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], array('status_id' => 2)));
- $this->callAPISuccess('Email', 'create', array(
+ $participant = $this->createTestObject('CRM_Event_DAO_Participant', array_merge($this->fixtures['participant'], ['status_id' => 2]));
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $participant->contact_id,
'email' => 'test-event@example.com',
- ));
- $c = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $participant->contact_id)));
+ ]);
+ $c = $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $participant->contact_id]));
$actionSchedule = $this->fixtures['sched_eventtype_end_2month_repeat_twice_2_weeks'];
$actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id');
$this->callAPISuccess('action_schedule', 'create', $actionSchedule);
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Almost 2 months.
'time' => '2012-08-13 01:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After the 2-month mark, send an email.
'time' => '2012-08-16 01:00:00',
- 'recipients' => array(array('test-event@example.com')),
- ),
- array(
+ 'recipients' => [['test-event@example.com']],
+ ],
+ [
// After 2 months and 1 week, don't repeat yet.
'time' => '2012-08-23 02:00:00',
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
// After 2 months and 2 weeks
'time' => '2012-08-30 02:00:00',
- 'recipients' => array(array('test-event@example.com')),
- ),
- array(
+ 'recipients' => [['test-event@example.com']],
+ ],
+ [
// After 2 months and 4 week
'time' => '2012-09-13 02:00:00',
- 'recipients' => array(array('test-event@example.com')),
- ),
- array(
+ 'recipients' => [['test-event@example.com']],
+ ],
+ [
// After 2 months and 6 weeks
'time' => '2012-09-27 01:00:00',
- 'recipients' => array(),
- ),
- ));
+ 'recipients' => [],
+ ],
+ ]);
}
// TODO // function testMembershipEndDate_NonMatch() { }
public function assertCronRuns($cronRuns) {
foreach ($cronRuns as $cronRun) {
CRM_Utils_Time::setTime($cronRun['time']);
- $this->callAPISuccess('job', 'send_reminder', array());
+ $this->callAPISuccess('job', 'send_reminder', []);
$this->mut->assertRecipients($cronRun['recipients']);
if (array_key_exists('subjects', $cronRun)) {
$this->mut->assertSubjects($cronRun['subjects']);
* This method is called before a test is executed.
*/
protected function _setUp() {
- $this->_testObjects = array();
+ $this->_testObjects = [];
}
/**
*
* @return array|NULL|object
*/
- public function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE) {
+ public function createTestObject($daoName, $params = [], $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));
+ $this->registerTestObjects([$objects]);
}
return $objects;
}
// and the "automatic/secondary records"
foreach ($this->_testObjects as $daoName => $daoIds) {
foreach ($daoIds as $daoId) {
- CRM_Core_DAO::deleteTestObjects($daoName, array('id' => $daoId));
+ CRM_Core_DAO::deleteTestObjects($daoName, ['id' => $daoId]);
}
}
- $this->_testObjects = array();
+ $this->_testObjects = [];
}
/**
* CRM-17028
*/
public function testRepetitionFrequencyUnit() {
- $membershipTypeParams = array(
+ $membershipTypeParams = [
'duration_interval' => '1',
'duration_unit' => 'year',
'is_active' => 1,
'period_type' => 'rolling',
- );
+ ];
$membershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', $membershipTypeParams);
- $interval_units = array('hour', 'day', 'week', 'month', 'year');
+ $interval_units = ['hour', 'day', 'week', 'month', 'year'];
foreach ($interval_units as $interval_unit) {
$membershipEndDate = DateTime::createFromFormat('Y-m-d H:i:s', "2013-03-15 00:00:00");
- $contactParams = array(
+ $contactParams = [
'contact_type' => 'Individual',
'first_name' => 'Test',
'last_name' => "Interval $interval_unit",
'is_deceased' => 0,
- );
+ ];
$contact = $this->createTestObject('CRM_Contact_DAO_Contact', $contactParams);
$this->assertTrue(is_numeric($contact->id));
- $emailParams = array(
+ $emailParams = [
'contact_id' => $contact->id,
'is_primary' => 1,
'email' => "test-member-{$interval_unit}@example.com",
'location_type_id' => 1,
- );
+ ];
$email = $this->createTestObject('CRM_Core_DAO_Email', $emailParams);
$this->assertTrue(is_numeric($email->id));
- $membershipParams = array(
+ $membershipParams = [
'membership_type_id' => $membershipType->id,
'contact_id' => $contact->id,
'join_date' => '20120315',
'end_date' => '20130315',
'is_override' => 0,
'status_id' => 2,
- );
+ ];
$membershipParams['status-id'] = 1;
$membership = $this->createTestObject('CRM_Member_DAO_Membership', $membershipParams);
$actionScheduleParams = $this->fixtures['sched_on_membership_end_date_repeat_interval'];
$beforeEndDate = $this->createModifiedDateTime($membershipEndDate, '-1 day');
$beforeFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+1 $interval_unit");
$afterFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+2 $interval_unit");
- $cronRuns = array(
- array(
+ $cronRuns = [
+ [
'time' => $beforeEndDate->format('Y-m-d H:i:s'),
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
'time' => $membershipEndDate->format('Y-m-d H:i:s'),
- 'recipients' => array(array("test-member-{$interval_unit}@example.com")),
- ),
- array(
+ 'recipients' => [["test-member-{$interval_unit}@example.com"]],
+ ],
+ [
'time' => $beforeFirstUnit->format('Y-m-d H:i:s'),
- 'recipients' => array(),
- ),
- array(
+ 'recipients' => [],
+ ],
+ [
'time' => $afterFirstUnit->format('Y-m-d H:i:s'),
- 'recipients' => array(array("test-member-{$interval_unit}@example.com")),
- ),
- );
+ 'recipients' => [["test-member-{$interval_unit}@example.com"]],
+ ],
+ ];
$this->assertCronRuns($cronRuns);
$actionSchedule->delete();
$membership->delete();
}
public function testMembershipScheduleWithAbsoluteDate() {
- $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 1)));
+ $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], ['status_id' => 1]));
$this->assertTrue(is_numeric($membership->id));
- $result = $this->callAPISuccess('Email', 'create', array(
+ $result = $this->callAPISuccess('Email', 'create', [
'contact_id' => $membership->contact_id,
'email' => 'test-member@example.com',
'location_type_id' => 1,
'is_primary' => 1,
- ));
+ ]);
- $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id)));
+ $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], ['contact_id' => $membership->contact_id]));
$actionSchedule = $this->fixtures['sched_membership_absolute_date'];
$actionSchedule['entity_value'] = $membership->membership_type_id;
$actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule);
$this->assertTrue(is_numeric($actionScheduleDao->id));
- $this->assertCronRuns(array(
- array(
+ $this->assertCronRuns([
+ [
// Before the 24-hour mark, no email
'time' => '2012-06-13 04:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- array(
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ [
// On absolute date set on 2012-06-14
'time' => '2012-06-14 00:00:00',
- 'recipients' => array(array('test-member@example.com')),
- 'subjects' => array('subject sched_membership_absolute_date'),
- ),
- array(
+ 'recipients' => [['test-member@example.com']],
+ 'subjects' => ['subject sched_membership_absolute_date'],
+ ],
+ [
// Run cron 4 hours later; first message already sent
'time' => '2012-06-14 04:00:00',
- 'recipients' => array(),
- 'subjects' => array(),
- ),
- ));
+ 'recipients' => [],
+ 'subjects' => [],
+ ],
+ ]);
}
}
public function setUp() {
parent::setUp();
- $this->quickCleanup(array('civicrm_contact', 'civicrm_address'));
+ $this->quickCleanup(['civicrm_contact', 'civicrm_address']);
}
/**
public function testCreate() {
$contactId = $this->individualCreate();
- $params = array();
- $params['address']['1'] = array(
+ $params = [];
+ $params['address']['1'] = [
'street_address' => 'Oberoi Garden',
'supplemental_address_1' => 'Attn: Accounting',
'supplemental_address_2' => 'Powai',
'location_type_id' => '1',
'is_primary' => '1',
'is_billing' => '0',
- );
+ ];
$params['contact_id'] = $contactId;
// Now call add() to modify an existing address
- $params = array();
- $params['address']['1'] = array(
+ $params = [];
+ $params['address']['1'] = [
'id' => $addressId,
'street_address' => '120 Terminal Road',
'supplemental_address_1' => 'A-wing:3037',
'location_type_id' => '1',
'is_primary' => '1',
'is_billing' => '0',
- );
+ ];
$params['contact_id'] = $contactId;
$block = CRM_Core_BAO_Address::create($params, $fixAddress, $entity = NULL);
public function testAdd() {
$contactId = $this->individualCreate();
- $fixParams = array(
+ $fixParams = [
'street_address' => 'E 906N Pine Pl W',
'supplemental_address_1' => 'Editorial Dept',
'supplemental_address_2' => '',
'is_primary' => '1',
'is_billing' => '0',
'contact_id' => $contactId,
- );
+ ];
$addAddress = CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
public function testallAddress() {
$contactId = $this->individualCreate();
- $fixParams = array(
+ $fixParams = [
'street_address' => 'E 906N Pine Pl W',
'supplemental_address_1' => 'Editorial Dept',
'supplemental_address_2' => '',
'is_primary' => '1',
'is_billing' => '0',
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
$addParams = $this->assertDBNotNull('CRM_Core_DAO_Address', $contactId, 'id', 'contact_id',
'Database check for created contact address.'
);
- $fixParams = array(
+ $fixParams = [
'street_address' => 'SW 719B Beech Dr NW',
'supplemental_address_1' => 'C/o OPDC',
'supplemental_address_2' => '',
'is_primary' => '',
'is_billing' => '1',
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
public function testnullallAddress() {
$contactId = $this->individualCreate();
- $fixParams = array(
+ $fixParams = [
'street_address' => 'E 906N Pine Pl W',
'supplemental_address_1' => 'Editorial Dept',
'supplemental_address_2' => '',
'is_primary' => '1',
'is_billing' => '0',
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Address::add($fixParams, $fixAddress = TRUE);
public function testGetValues() {
$contactId = $this->individualCreate();
- $params = array();
- $params['address']['1'] = array(
+ $params = [];
+ $params['address']['1'] = [
'street_address' => 'Oberoi Garden',
'supplemental_address_1' => 'Attn: Accounting',
'supplemental_address_2' => 'Powai',
'location_type_id' => '1',
'is_primary' => '1',
'is_billing' => '0',
- );
+ ];
$params['contact_id'] = $contactId;
'Database check for created address.'
);
- $entityBlock = array('contact_id' => $contactId);
+ $entityBlock = ['contact_id' => $contactId];
$address = CRM_Core_BAO_Address::getValues($entityBlock);
$this->assertEquals($address[1]['id'], $addressId);
$this->assertEquals($address[1]['contact_id'], $contactId);
$contactId = $this->individualCreate();
$street_address = "54 Excelsior Ave.";
- $params = array(
+ $params = [
'contact_id' => $contactId,
'street_address' => $street_address,
'location_type_id' => 1,
- );
+ ];
$result = civicrm_api3('Address', 'create', $params);
$value = array_pop($result['values']);
}
public function supportedAddressParsingLocales() {
- return array(
- array('en_US'),
- array('en_CA'),
- array('fr_CA'),
- );
+ return [
+ ['en_US'],
+ ['en_CA'],
+ ['fr_CA'],
+ ];
}
/**
}
public function sampleOFUnsupportedAddressParsingLocales() {
- return array(
- array('en_GB'),
- array('af_ZA'),
- array('da_DK'),
- );
+ return [
+ ['en_GB'],
+ ['af_ZA'],
+ ['da_DK'],
+ ];
}
/**
* Also, Contact C's address' master_id should be Contact A's address id.
*/
public function testSharedAddressChaining1() {
- $contactIdA = $this->individualCreate(array(), 0);
- $contactIdB = $this->individualCreate(array(), 1);
- $contactIdC = $this->individualCreate(array(), 2);
+ $contactIdA = $this->individualCreate([], 0);
+ $contactIdB = $this->individualCreate([], 1);
+ $contactIdC = $this->individualCreate([], 2);
- $addressParamsA = array(
+ $addressParamsA = [
'street_address' => '123 Fake St.',
'location_type_id' => '1',
'is_primary' => '1',
'contact_id' => $contactIdA,
- );
+ ];
$addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
- $addressParamsB = array(
+ $addressParamsB = [
'street_address' => '123 Fake St.',
'location_type_id' => '1',
'is_primary' => '1',
'master_id' => $addAddressA->id,
'contact_id' => $contactIdB,
- );
+ ];
$addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE);
- $addressParamsC = array(
+ $addressParamsC = [
'street_address' => '123 Fake St.',
'location_type_id' => '1',
'is_primary' => '1',
'master_id' => $addAddressB->id,
'contact_id' => $contactIdC,
- );
+ ];
$addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE);
- $updatedAddressParamsA = array(
+ $updatedAddressParamsA = [
'id' => $addAddressA->id,
'street_address' => '1313 New Address Lane',
'location_type_id' => '1',
'is_primary' => '1',
'contact_id' => $contactIdA,
- );
+ ];
$updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE);
// CRM-21214 - Has Address C been updated with Address A's new values?
* Also, Contact C's address' master_id should be Contact B's address id.
*/
public function testSharedAddressChaining2() {
- $contactIdA = $this->individualCreate(array(), 0);
- $contactIdB = $this->individualCreate(array(), 1);
- $contactIdC = $this->individualCreate(array(), 2);
+ $contactIdA = $this->individualCreate([], 0);
+ $contactIdB = $this->individualCreate([], 1);
+ $contactIdC = $this->individualCreate([], 2);
- $addressParamsA = array(
+ $addressParamsA = [
'street_address' => '123 Fake St.',
'location_type_id' => '1',
'is_primary' => '1',
'contact_id' => $contactIdA,
- );
+ ];
$addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
- $addressParamsB = array(
+ $addressParamsB = [
'street_address' => '123 Fake St.',
'location_type_id' => '1',
'is_primary' => '1',
'contact_id' => $contactIdB,
- );
+ ];
$addAddressB = CRM_Core_BAO_Address::add($addressParamsB, FALSE);
- $addressParamsC = array(
+ $addressParamsC = [
'street_address' => '123 Fake St.',
'location_type_id' => '1',
'is_primary' => '1',
'master_id' => $addAddressA->id,
'contact_id' => $contactIdC,
- );
+ ];
$addAddressC = CRM_Core_BAO_Address::add($addressParamsC, FALSE);
- $updatedAddressParamsA = array(
+ $updatedAddressParamsA = [
'id' => $addAddressA->id,
'street_address' => '123 Fake St.',
'location_type_id' => '1',
'is_primary' => '1',
'master_id' => $addAddressB->id,
'contact_id' => $contactIdA,
- );
+ ];
$updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE);
- $updatedAddressParamsB = array(
+ $updatedAddressParamsB = [
'id' => $addAddressB->id,
'street_address' => '1313 New Address Lane',
'location_type_id' => '1',
'is_primary' => '1',
'contact_id' => $contactIdB,
- );
+ ];
$updatedAddressB = CRM_Core_BAO_Address::add($updatedAddressParamsB, FALSE);
// CRM-21214 - Has Address C been updated with Address B's new values?
* An error should be given, and master_id should remain the same.
*/
public function testSharedAddressChaining3() {
- $contactIdA = $this->individualCreate(array(), 0);
+ $contactIdA = $this->individualCreate([], 0);
- $addressParamsA = array(
+ $addressParamsA = [
'street_address' => '123 Fake St.',
'location_type_id' => '1',
'is_primary' => '1',
'contact_id' => $contactIdA,
- );
+ ];
$addAddressA = CRM_Core_BAO_Address::add($addressParamsA, FALSE);
- $updatedAddressParamsA = array(
+ $updatedAddressParamsA = [
'id' => $addAddressA->id,
'street_address' => '123 Fake St.',
'location_type_id' => '1',
'is_primary' => '1',
'master_id' => $addAddressA->id,
'contact_id' => $contactIdA,
- );
+ ];
$updatedAddressA = CRM_Core_BAO_Address::add($updatedAddressParamsA, FALSE);
// CRM-21214 - AdressA shouldn't be master of itself.
$ex = [];
- $ex[] = [array('abc' => 'def')];
+ $ex[] = [['abc' => 'def']];
$ex[] = [0];
$ex[] = ['hello world'];
$ex[] = ['Scarabée'];
class CRM_Core_BAO_ConfigSettingTest extends CiviUnitTestCase {
public function testToggleComponent() {
- $origNames = array();
+ $origNames = [];
foreach (CRM_Core_Component::getEnabledComponents() as $c) {
$origNames[] = $c->name;
}
$enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
$this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
- $newNames = array();
+ $newNames = [];
foreach (CRM_Core_Component::getEnabledComponents() as $c) {
$newNames[] = $c->name;
}
*/
public function testGetTree() {
$customGroup = $this->CustomGroupCreate();
- $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+ $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
$result = CRM_Core_BAO_CustomGroup::getTree('Individual', NULL, $customGroup['id']);
$this->assertEquals('Custom Field', $result[$customGroup['id']]['fields'][$customField['id']]['label']);
$this->customGroupDelete($customGroup['id']);
* inconsistency.
*/
public function testGetTreeContactSubType() {
- $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization'));
- $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank')));
- $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
- $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank'));
+ $contactType = $this->callAPISuccess('ContactType', 'create', ['name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization']);
+ $customGroup = $this->CustomGroupCreate(['extends' => 'Organization', 'extends_entity_column_value' => ['Big_Bank']]);
+ $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
+ $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, ['Big_Bank']);
$this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
$result = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, CRM_Core_DAO::VALUE_SEPARATOR . 'Big_Bank' . CRM_Core_DAO::VALUE_SEPARATOR);
$this->assertEquals($result1, $result);
$result = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, 'Big_Bank');
$this->assertEquals($result1, $result);
try {
- CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Small Kind Bank'));
+ CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, ['Small Kind Bank']);
}
catch (CRM_Core_Exception $e) {
$this->customGroupDelete($customGroup['id']);
- $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id']));
+ $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType['id']]);
return;
}
$this->fail('There is no such thing as a small kind bank');
* Test calling getTree for a custom field extending a renamed contact type.
*/
public function testGetTreeContactSubTypeForNameChangedContactType() {
- $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization'));
+ $contactType = $this->callAPISuccess('ContactType', 'create', ['name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization']);
CRM_Core_DAO::executeQuery('UPDATE civicrm_contact_type SET label = "boo" WHERE name = "Organization"');
- $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank')));
- $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
- $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank'));
+ $customGroup = $this->CustomGroupCreate(['extends' => 'Organization', 'extends_entity_column_value' => ['Big_Bank']]);
+ $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
+ $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, ['Big_Bank']);
$this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
$this->customGroupDelete($customGroup['id']);
- $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id']));
+ $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType['id']]);
}
/**
* Test calling getTree for a custom field extending a disabled contact type.
*/
public function testGetTreeContactSubTypeForDisabledChangedContactType() {
- $contactType = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization'));
- $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank')));
- $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
- $this->callAPISuccess('ContactType', 'create', array('id' => $contactType['id'], 'is_active' => 0));
- $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, array('Big_Bank'));
+ $contactType = $this->callAPISuccess('ContactType', 'create', ['name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization']);
+ $customGroup = $this->CustomGroupCreate(['extends' => 'Organization', 'extends_entity_column_value' => ['Big_Bank']]);
+ $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
+ $this->callAPISuccess('ContactType', 'create', ['id' => $contactType['id'], 'is_active' => 0]);
+ $result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, ['Big_Bank']);
$this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
$this->customGroupDelete($customGroup['id']);
- $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType['id']));
+ $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType['id']]);
}
/**
* Test calling GetTree for a custom field extending multiple subTypes.
*/
public function testGetTreetContactSubTypeForMultipleSubTypes() {
- $contactType1 = $this->callAPISuccess('ContactType', 'create', array('name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization'));
- $contactType2 = $this->callAPISuccess('ContactType', 'create', array('name' => 'Small Bank', 'label' => 'smallee', 'parent_id' => 'Organization'));
- $customGroup = $this->CustomGroupCreate(array('extends' => 'Organization', 'extends_entity_column_value' => array('Big_Bank', 'Small_Bank')));
- $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+ $contactType1 = $this->callAPISuccess('ContactType', 'create', ['name' => 'Big Bank', 'label' => 'biggee', 'parent_id' => 'Organization']);
+ $contactType2 = $this->callAPISuccess('ContactType', 'create', ['name' => 'Small Bank', 'label' => 'smallee', 'parent_id' => 'Organization']);
+ $customGroup = $this->CustomGroupCreate(['extends' => 'Organization', 'extends_entity_column_value' => ['Big_Bank', 'Small_Bank']]);
+ $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
$result1 = CRM_Core_BAO_CustomGroup::getTree('Organization', NULL, NULL, NULL, CRM_Core_DAO::VALUE_SEPARATOR . 'Big_Bank' . CRM_Core_DAO::VALUE_SEPARATOR . 'Small_Bank' . CRM_Core_DAO::VALUE_SEPARATOR);
$this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
$this->customGroupDelete($customGroup['id']);
- $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType1['id']));
- $this->callAPISuccess('ContactType', 'delete', array('id' => $contactType2['id']));
+ $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType1['id']]);
+ $this->callAPISuccess('ContactType', 'delete', ['id' => $contactType2['id']]);
}
/**
* Test calling GetTree for a custom field that extends a non numerical Event Type.
*/
public function testGetTreeEventSubTypeAlphabetical() {
- $eventType = $this->callAPISuccess('OptionValue', 'Create', array('option_group_id' => 'event_type', 'value' => 'meeting', 'label' => 'Meeting'));
- $customGroup = $this->CustomGroupCreate(array('extends' => 'Event', 'extends_entity_column_value' => array('Meeting')));
- $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+ $eventType = $this->callAPISuccess('OptionValue', 'Create', ['option_group_id' => 'event_type', 'value' => 'meeting', 'label' => 'Meeting']);
+ $customGroup = $this->CustomGroupCreate(['extends' => 'Event', 'extends_entity_column_value' => ['Meeting']]);
+ $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
$result1 = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, NULL, NULL, CRM_Core_DAO::VALUE_SEPARATOR . 'meeting' . CRM_Core_DAO::VALUE_SEPARATOR);
$this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
$this->customGroupDelete($customGroup['id']);
- $this->callAPISuccess('OptionValue', 'delete', array('id' => $eventType['id']));
+ $this->callAPISuccess('OptionValue', 'delete', ['id' => $eventType['id']]);
}
/**
$sep = CRM_Core_DAO::VALUE_SEPARATOR;
$this->campaignCreate();
$this->campaignCreate();
- $customGroup = $this->CustomGroupCreate(array(
+ $customGroup = $this->CustomGroupCreate([
'extends' => 'Campaign',
'extends_entity_column_value' => "{$sep}1{$sep}2{$sep}",
- ));
- $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+ ]);
+ $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
$result1 = CRM_Core_BAO_CustomGroup::getTree('Campaign', NULL, NULL, NULL, '\ 11\ 12\ 1');
$this->assertEquals('Custom Field', $result1[$customGroup['id']]['fields'][$customField['id']]['label']);
$this->customGroupDelete($customGroup['id']);
* Test calling getTree with contact subtype data.
*/
public function testGetTreeActivitySubType() {
- $customGroup = $this->CustomGroupCreate(array('extends' => 'Activity', 'extends_entity_column_value' => 1));
- $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
+ $customGroup = $this->CustomGroupCreate(['extends' => 'Activity', 'extends_entity_column_value' => 1]);
+ $customField = $this->customFieldCreate(['custom_group_id' => $customGroup['id']]);
$result = CRM_Core_BAO_CustomGroup::getTree('Activity', NULL, NULL, NULL, 1);
$this->assertEquals('Custom Field', $result[$customGroup['id']]['fields'][$customField['id']]['label']);
$this->customGroupDelete($customGroup['id']);
* Test retrieve() with Empty Params.
*/
public function testRetrieveEmptyParams() {
- $params = array();
+ $params = [];
$customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults);
$this->assertNull($customGroup, 'Check that no custom Group is retreived');
}
* Test retrieve() with Inalid Params
*/
public function testRetrieveInvalidParams() {
- $params = array('id' => 99);
+ $params = ['id' => 99];
$customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults);
$this->assertNull($customGroup, 'Check that no custom Group is retreived');
}
*/
public function testRetrieve() {
$customGroupTitle = 'Custom Group';
- $groupParams = array(
+ $groupParams = [
'title' => $customGroupTitle,
'name' => 'My_Custom_Group',
'style' => 'Tab',
'is_active' => 1,
'collapse_display' => 1,
'weight' => 2,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
*/
public function testSetIsActive() {
$customGroupTitle = 'My Custom Group';
- $groupParams = array(
+ $groupParams = [
'title' => $customGroupTitle,
'name' => 'my_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'is_active' => 0,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
$customGroupId = $customGroup['id'];
* Test getGroupDetail() with Empty Params
*/
public function testGetGroupDetailEmptyParams() {
- $customGroupId = array();
+ $customGroupId = [];
$customGroup = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId);
$this->assertTrue(empty($customGroup), 'Check that no custom Group details is retreived');
}
*/
public function testGetGroupDetail() {
$customGroupTitle = 'My Custom Group';
- $groupParams = array(
+ $groupParams = [
'title' => $customGroupTitle,
'name' => 'My_Custom_Group',
'extends' => 'Individual',
'help_post' => 'Custom Group Help Post',
'is_active' => 1,
'collapse_display' => 1,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
$customGroupId = $customGroup['id'];
- $fieldParams = array(
+ $fieldParams = [
'custom_group_id' => $customGroupId,
'label' => 'Test Custom Field',
'html_type' => 'Text',
'is_required' => 1,
'is_searchable' => 0,
'is_active' => 1,
- );
+ ];
$customField = $this->customFieldCreate($fieldParams);
$customFieldId = $customField['id'];
*/
public function testGetTitle() {
$customGroupTitle = 'Custom Group';
- $groupParams = array(
+ $groupParams = [
'title' => $customGroupTitle,
'name' => 'my_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'is_active' => 0,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
$customGroupId = $customGroup['id'];
*/
public function testDeleteGroup() {
$customGroupTitle = 'My Custom Group';
- $groupParams = array(
+ $groupParams = [
'title' => $customGroupTitle,
'name' => 'my_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'is_active' => 1,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
$groupObject = new CRM_Core_BAO_CustomGroup();
* Test createTable()
*/
public function testCreateTable() {
- $groupParams = array(
+ $groupParams = [
'title' => 'My Custom Group',
'name' => 'my_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'is_active' => 1,
'version' => 3,
- );
+ ];
$customGroupBAO = new CRM_Core_BAO_CustomGroup();
$customGroupBAO->copyValues($groupParams);
* Test checkCustomField()
*/
public function testCheckCustomField() {
- $groupParams = array(
+ $groupParams = [
'title' => 'My Custom Group',
'name' => 'my_custom_group',
'extends' => 'Individual',
'help_post' => 'Custom Group Help Post',
'is_active' => 1,
'collapse_display' => 1,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
$this->assertNotNull($customGroup['id'], 'pre-requisite group not created successfully');
$customGroupId = $customGroup['id'];
$customFieldLabel = 'Test Custom Field';
- $fieldParams = array(
+ $fieldParams = [
'custom_group_id' => $customGroupId,
'label' => $customFieldLabel,
'html_type' => 'Text',
'is_required' => 1,
'is_searchable' => 0,
'is_active' => 1,
- );
+ ];
$customField = $this->customFieldCreate($fieldParams);
$customField = $customField['values'][$customField['id']];
$this->assertEquals($customFieldLabel, $dbCustomFieldLabel);
//check the custom field type.
- $params = array('Individual');
+ $params = ['Individual'];
$usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params);
$this->assertEquals(FALSE, $usedFor);
- $params = array('Contribution', 'Membership', 'Participant');
+ $params = ['Contribution', 'Membership', 'Participant'];
$usedFor = CRM_Core_BAO_CustomGroup::checkCustomField($customFieldId, $params);
$this->assertEquals(TRUE, $usedFor);
public function testGetActiveGroups() {
$contactId = $this->individualCreate();
$customGroupTitle = 'Custom Group';
- $groupParams = array(
+ $groupParams = [
'title' => $customGroupTitle,
'name' => 'test_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'weight' => 10,
'is_active' => 1,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
$activeGroup = CRM_Core_BAO_CustomGroup::getActiveGroups('Individual', 'civicrm/contact/view/cd', $contactId);
* Test create()
*/
public function testCreate() {
- $params = array(
+ $params = [
'title' => 'Test_Group_1',
'name' => 'test_group_1',
- 'extends' => array(0 => 'Individual', 1 => array()),
+ 'extends' => [0 => 'Individual', 1 => []],
'weight' => 4,
'collapse_display' => 1,
'style' => 'Inline',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
'version' => 3,
- );
+ ];
$customGroup = CRM_Core_BAO_CustomGroup::create($params);
$dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroup->id, 'title', 'id',
* Test create() given a table_name
*/
public function testCreateTableName() {
- $params = array(
+ $params = [
'title' => 'Test_Group_2',
'name' => 'test_group_2',
'table_name' => 'test_otherTableName',
- 'extends' => array(0 => 'Individual', 1 => array()),
+ 'extends' => [0 => 'Individual', 1 => []],
'weight' => 4,
'collapse_display' => 1,
'style' => 'Inline',
'help_pre' => 'This is Pre Help For Test Group 1',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
- );
+ ];
$customGroup = CRM_Core_BAO_CustomGroup::create($params);
$dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroup->id, 'title', 'id',
*/
public function testIsGroupEmpty() {
$customGroupTitle = 'Test Custom Group';
- $groupParams = array(
+ $groupParams = [
'title' => $customGroupTitle,
'name' => 'test_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'weight' => 10,
'is_active' => 1,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
$customGroupId = $customGroup['id'];
* Test getGroupTitles() with Invalid Params()
*/
public function testGetGroupTitlesWithInvalidParams() {
- $params = array(99);
+ $params = [99];
$groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($params);
$this->assertTrue(empty($groupTitles), 'Check that no titles are received');
}
* Test getGroupTitles()
*/
public function testGetGroupTitles() {
- $groupParams = array(
+ $groupParams = [
'title' => 'Test Group',
'name' => 'test_custom_group',
'style' => 'Tab',
'extends' => 'Individual',
'weight' => 10,
'is_active' => 1,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
- $fieldParams = array(
+ $fieldParams = [
'label' => 'Custom Field',
'html_type' => 'Text',
'data_type' => 'String',
'is_searchable' => 0,
'is_active' => 1,
'custom_group_id' => $customGroup['id'],
- );
+ ];
$customField = $this->customFieldCreate($fieldParams);
$customFieldId = $customField['id'];
- $params = array($customFieldId);
+ $params = [$customFieldId];
$groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($params);
*/
public function testExtractGetParamsReturnsDates() {
// Create a custom group to contain the custom field.
- $groupParams = array(
+ $groupParams = [
'title' => 'My Custom Group',
'name' => 'my_custom_group',
'extends' => 'Individual',
'is_active' => 1,
'collapse_display' => 1,
- );
+ ];
$customGroup = $this->customGroupCreate($groupParams);
$customGroupId = $customGroup['id'];
// Create teh custom field.
- $fieldParams = array(
+ $fieldParams = [
'custom_group_id' => $customGroupId,
'label' => 'My Custom Date Field',
'html_type' => 'Select Date',
'is_searchable' => 0,
'is_active' => 1,
'default_value' => '',
- );
+ ];
$customField = $this->customFieldCreate($fieldParams);
$customFieldId = $customField['id'];
* @throws \Exception
*/
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contact',
- );
+ ];
$this->quickCleanup($tablesToTruncate, TRUE);
parent::tearDown();
}
*/
public function testSearchCustomDataDateRelative() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest');
- $dateCustomField = $this->customFieldCreate(array(
+ $dateCustomField = $this->customFieldCreate([
'custom_group_id' => $ids['custom_group_id'],
'label' => 'date field',
'data_type' => 'Date',
'html_type' => 'Select Date',
'default_value' => NULL,
- ));
+ ]);
$dateCustomFieldName = 'custom_' . $dateCustomField['id'];
- $formValues = array(
+ $formValues = [
$dateCustomFieldName . '_relative' => 'this.year',
$dateCustomFieldName . '_from' => '',
$dateCustomFieldName . '_to' => '',
- );
+ ];
// Assigning the relevant form value to be within a custom key is normally done in
// build field params. It would be better if it were all done in convertFormValues
// but for now we just imitate it.
*/
public function testSearchCustomDataDateFromTo() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest');
- $dateCustomField = $this->customFieldCreate(array(
+ $dateCustomField = $this->customFieldCreate([
'custom_group_id' => $ids['custom_group_id'],
'label' => 'date field',
'data_type' => 'Date',
'html_type' => 'Select Date',
'default_value' => NULL,
- ));
+ ]);
$dateCustomFieldName = 'custom_' . $dateCustomField['id'];
// Assigning the relevant form value to be within a custom key is normally done in
// build field params. It would be better if it were all done in convertFormValues
// but for now we just imitate it.
- $formValues = array(
+ $formValues = [
$dateCustomFieldName . '_from' => '2014-06-06',
$dateCustomFieldName . '_to' => '2015-06-06',
- );
+ ];
$params[$dateCustomField['id']] = CRM_Contact_BAO_Query::convertFormValues($formValues);
$queryObj = new CRM_Core_BAO_CustomQuery($params);
*/
public function testSearchCustomDataFromTo() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest');
- $datas = array(
+ $datas = [
'Int' => 2,
'Float' => 12.123,
'Money' => 91.21,
- );
+ ];
foreach ($datas as $type => $data) {
$customField = $this->customFieldCreate(
- array(
+ [
'custom_group_id' => $ids['custom_group_id'],
'label' => "$type field",
'data_type' => $type,
'html_type' => 'Text',
'default_value' => NULL,
- )
+ ]
);
$customFieldName = 'custom_' . $customField['id'];
// Assigning the relevant form value to be within a custom key is normally done in
// but for now we just imitate it.
$from = $data - 1;
$to = $data;
- $formValues = array(
+ $formValues = [
$customFieldName . '_from' => $from,
$customFieldName . '_to' => $to,
- );
+ ];
- $params = array($customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues));
+ $params = [$customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues)];
$queryObj = new CRM_Core_BAO_CustomQuery($params);
$queryObj->Query();
$this->assertEquals(
*/
public function testSearchCustomDataFromAndTo() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest');
- $datas = array(
+ $datas = [
'Date' => '2015-06-06',
'Int' => 2,
'Float' => 12.123,
'Money' => 91.21,
- );
+ ];
foreach ($datas as $type => $data) {
$isDate = ($type === 'Date');
$customField = $this->customFieldCreate(
- array(
+ [
'custom_group_id' => $ids['custom_group_id'],
'label' => "$type field",
'data_type' => $type,
'html_type' => ($isDate) ? 'Select Date' : 'Text',
'default_value' => NULL,
- )
+ ]
);
$customFieldName = 'custom_' . $customField['id'];
// but for now we just imitate it.
//Scenrio 2 : TO date filter
- $formValues = array(
+ $formValues = [
$customFieldName . '_to' => $data,
- );
+ ];
- $params = array($customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues));
+ $params = [$customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues)];
$queryObj = new CRM_Core_BAO_CustomQuery($params);
$queryObj->Query();
$wierdStringThatMeansGreaterEquals = chr(226) . chr(137) . chr(164);
);
//Scenrio 2 : FROM date filter
- $formValues = array(
+ $formValues = [
$customFieldName . '_from' => $data,
- );
+ ];
- $params = array($customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues));
+ $params = [$customField['id'] => CRM_Contact_BAO_Query::convertFormValues($formValues)];
$queryObj = new CRM_Core_BAO_CustomQuery($params);
$queryObj->Query();
$wierdStringThatMeansLessThanEquals = chr(226) . chr(137) . chr(165);
*/
public function testSearchCustomDataDateEquals() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTestTest');
- $dateCustomField = $this->customFieldCreate(array(
+ $dateCustomField = $this->customFieldCreate([
'custom_group_id' => $ids['custom_group_id'],
'label' => 'date field',
'data_type' => 'Date',
'html_type' => 'Select Date',
'default_value' => NULL,
- ));
+ ]);
$dateCustomFieldName = 'custom_' . $dateCustomField['id'];
- $this->individualCreate(array($dateCustomFieldName => "2015-01-01"));
+ $this->individualCreate([$dateCustomFieldName => "2015-01-01"]);
// Assigning the relevant form value to be within a custom key is normally done in
// build field params. It would be better if it were all done in convertFormValues
// but for now we just imitate it.
- $formValues = array($dateCustomFieldName => '2015-06-06');
+ $formValues = [$dateCustomFieldName => '2015-06-06'];
$params[$dateCustomField['id']] = CRM_Contact_BAO_Query::convertFormValues($formValues);
$queryObj = new CRM_Core_BAO_CustomQuery($params);
$queryObj->Query();
public function testCustomGroupMultipleSingle() {
$contactID = $this->individualCreate();
- $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
- $fields = array(
+ $customGroup = $this->customGroupCreate(['is_multiple' => 1]);
+ $fields = [
'custom_group_id' => $customGroup['id'],
'dataType' => 'String',
'htmlType' => 'Text',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params = array(
+ $params = [
'entityID' => $contactID,
"custom_{$customField['id']}_-1" => 'First String',
- );
+ ];
CRM_Core_BAO_CustomValueTable::setValues($params);
- $newParams = array(
+ $newParams = [
'entityID' => $contactID,
"custom_{$customField['id']}" => 1,
- );
+ ];
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
$this->assertEquals($params["custom_{$customField['id']}_-1"], $result["custom_{$customField['id']}_1"]);
$this->assertEquals($params['entityID'], $result['entityID']);
- $updateParams = array(
+ $updateParams = [
'id' => 1,
'entityID' => $contactID,
"custom_{$customField['id']}" => 2,
- );
+ ];
CRM_Core_BAO_CustomValueTable::setValues($updateParams);
- $criteria = array(
+ $criteria = [
'id' => 1,
'entityID' => $contactID,
- );
+ ];
$result = CRM_Core_BAO_CustomValueTable::getValues($criteria);
$this->assertEquals(2, $result["custom_{$customField['id']}_1"]);
public function testCustomGroupMultipleDouble() {
$contactID = $this->individualCreate();
- $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
- $fields = array(
+ $customGroup = $this->customGroupCreate(['is_multiple' => 1]);
+ $fields = [
'custom_group_id' => $customGroup['id'],
'dataType' => 'String',
'htmlType' => 'Text',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params = array(
+ $params = [
'entityID' => $contactID,
"custom_{$customField['id']}_-1" => 'First String',
"custom_{$customField['id']}_-2" => 'Second String',
- );
+ ];
CRM_Core_BAO_CustomValueTable::setValues($params);
- $newParams = array(
+ $newParams = [
'entityID' => $contactID,
"custom_{$customField['id']}" => 1,
- );
+ ];
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
$this->assertEquals($params["custom_{$customField['id']}_-1"], $result["custom_{$customField['id']}_1"]);
public function testCustomGroupMultipleUpdate() {
$contactID = $this->individualCreate();
- $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
- $fields = array(
+ $customGroup = $this->customGroupCreate(['is_multiple' => 1]);
+ $fields = [
'custom_group_id' => $customGroup['id'],
'dataType' => 'String',
'htmlType' => 'Text',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params = array(
+ $params = [
'entityID' => $contactID,
"custom_{$customField['id']}_-1" => 'First String',
"custom_{$customField['id']}_-2" => 'Second String',
"custom_{$customField['id']}_-3" => 'Third String',
- );
+ ];
CRM_Core_BAO_CustomValueTable::setValues($params);
- $newParams = array(
+ $newParams = [
'entityID' => $contactID,
"custom_{$customField['id']}_1" => 'Updated First String',
"custom_{$customField['id']}_3" => 'Updated Third String',
- );
+ ];
CRM_Core_BAO_CustomValueTable::setValues($newParams);
- $getParams = array(
+ $getParams = [
'entityID' => $contactID,
"custom_{$customField['id']}" => 1,
- );
+ ];
$result = CRM_Core_BAO_CustomValueTable::getValues($getParams);
$this->assertEquals($newParams["custom_{$customField['id']}_1"], $result["custom_{$customField['id']}_1"]);
public function testCustomGroupMultipleOldFormat() {
$contactID = $this->individualCreate();
- $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
- $fields = array(
+ $customGroup = $this->customGroupCreate(['is_multiple' => 1]);
+ $fields = [
'custom_group_id' => $customGroup['id'],
'dataType' => 'String',
'htmlType' => 'Text',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params = array(
+ $params = [
'entityID' => $contactID,
"custom_{$customField['id']}" => 'First String',
- );
+ ];
CRM_Core_BAO_CustomValueTable::setValues($params);
- $newParams = array(
+ $newParams = [
'entityID' => $contactID,
"custom_{$customField['id']}" => 1,
- );
+ ];
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
$this->assertEquals($params["custom_{$customField['id']}"], $result["custom_{$customField['id']}_1"]);
* Test setValues() and GetValues() methods with custom Date field
*/
public function testSetGetValuesDate() {
- $params = array();
+ $params = [];
$contactID = $this->individualCreate();
//create Custom Group
- $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
+ $customGroup = $this->customGroupCreate(['is_multiple' => 1]);
//create Custom Field of data type Date
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'Date',
'html_type' => 'Select Date',
'default_value' => '',
- );
+ ];
$customField = $this->customFieldCreate($fields);
// Retrieve the field ID for sample custom field 'test_Date'
- $params = array('label' => 'test_Date');
- $field = array();
+ $params = ['label' => 'test_Date'];
+ $field = [];
CRM_Core_BAO_CustomField::retrieve($params, $field);
$fieldID = $customField['id'];
// Set test_Date to a valid date value
$date = '20080608000000';
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => $date,
- );
+ ];
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
$this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).');
// Check that the date value is stored
- $values = array();
- $params = array(
+ $values = [];
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => 1,
- );
+ ];
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).');
// Now set test_Date to an invalid date value and try to reset
$badDate = '20080631000000';
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => $badDate,
- );
+ ];
CRM_Core_TemporaryErrorScope::useException();
$message = NULL;
// Check that an exception has been thrown
$this->assertNotNull($message, 'Verify than an exception is thrown when bad date is passed');
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => 1,
- );
+ ];
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values['custom_' . $fieldID . '_1'],
CRM_Utils_Date::mysqlToIso($date),
);
// Test setting test_Date to null
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => NULL,
- );
+ ];
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
// Check that the date value is empty
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => 1,
- );
+ ];
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).');
public function testSetGetValuesYesNoRadio() {
$contactID = $this->individualCreate();
- $customGroup = $this->customGroupCreate(array('is_multiple' => 1));
+ $customGroup = $this->customGroupCreate(['is_multiple' => 1]);
//create Custom Field of type YesNo(Boolean) Radio
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'Boolean',
'html_type' => 'Radio',
'default_value' => '',
- );
+ ];
$customField = $this->customFieldCreate($fields);
// Retrieve the field ID for sample custom field 'test_Boolean'
- $params = array('label' => 'test_Boolean');
- $field = array();
+ $params = ['label' => 'test_Boolean'];
+ $field = [];
//get field Id
CRM_Core_BAO_CustomField::retrieve($params, $field);
// valid boolean value '1' for Boolean Radio
$yesNo = '1';
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => $yesNo,
- );
+ ];
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
$this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).');
// Check that the YesNo radio value is stored
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => 1,
- );
+ ];
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).');
// Now set YesNo radio to an invalid boolean value and try to reset
$badYesNo = '20';
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => $badYesNo,
- );
+ ];
CRM_Core_TemporaryErrorScope::useException();
$message = NULL;
// Check that an exception has been thrown
$this->assertNotNull($message, 'Verify than an exception is thrown when bad boolean is passed');
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $fieldID => 1,
- );
+ ];
$values = CRM_Core_BAO_CustomValueTable::getValues($params);
$this->assertEquals($values["custom_{$fieldID}_1"], $yesNo,
* Test store function for country.
*/
public function testStoreCountry() {
- $params = array();
+ $params = [];
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'Country',
'html_type' => 'Select Country',
'default_value' => '',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params[] = array(
- $customField['id'] => array(
+ $params[] = [
+ $customField['id'] => [
'value' => 1228,
'type' => 'Country',
'custom_field_id' => $customField['id'],
'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
'column_name' => $customField['values'][$customField['id']]['column_name'],
'file_id' => '',
- ),
- );
+ ],
+ ];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
*/
public function testStoreFile() {
$contactID = $this->individualCreate();
- $file = $this->callAPISuccess('File', 'create', array('uri' => 'dummy_data'));
+ $file = $this->callAPISuccess('File', 'create', ['uri' => 'dummy_data']);
$customGroup = $this->customGroupCreate();
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'File',
'html_type' => 'File',
'default_value' => '',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params[] = array(
- $customField['id'] => array(
+ $params[] = [
+ $customField['id'] => [
'value' => 'i/contact_house.png',
'type' => 'File',
'custom_field_id' => $customField['id'],
'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
'column_name' => $customField['values'][$customField['id']]['column_name'],
'file_id' => $file['id'],
- ),
- );
+ ],
+ ];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
public function testStoreStateProvince() {
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'StateProvince',
'html_type' => 'Select State/Province',
'default_value' => '',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params[] = array(
- $customField['id'] => array(
+ $params[] = [
+ $customField['id'] => [
'value' => 1029,
'type' => 'StateProvince',
'custom_field_id' => $customField['id'],
'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
'column_name' => $customField['values'][$customField['id']]['column_name'],
'file_id' => 1,
- ),
- );
+ ],
+ ];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
* Test store function for date.
*/
public function testStoreDate() {
- $params = array();
+ $params = [];
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'Date',
'html_type' => 'Select Date',
'default_value' => '',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params[] = array(
- $customField['id'] => array(
+ $params[] = [
+ $customField['id'] => [
'value' => '20080608000000',
'type' => 'Date',
'custom_field_id' => $customField['id'],
'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
'column_name' => $customField['values'][$customField['id']]['column_name'],
'file_id' => '',
- ),
- );
+ ],
+ ];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
* Test store function for rich text editor.
*/
public function testStoreRichTextEditor() {
- $params = array();
+ $params = [];
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'html_type' => 'RichTextEditor',
'data_type' => 'Memo',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params[] = array(
- $customField['id'] => array(
+ $params[] = [
+ $customField['id'] => [
'value' => '<p><strong>This is a <u>test</u></p>',
'type' => 'Memo',
'custom_field_id' => $customField['id'],
'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
'column_name' => $customField['values'][$customField['id']]['column_name'],
'file_id' => '',
- ),
- );
+ ],
+ ];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
*/
public function testGetEntityValues() {
- $params = array();
+ $params = [];
$contactID = $this->individualCreate();
- $customGroup = $this->customGroupCreate(array('extends' => 'Individual'));
- $fields = array(
+ $customGroup = $this->customGroupCreate(['extends' => 'Individual']);
+ $fields = [
'custom_group_id' => $customGroup['id'],
'html_type' => 'RichTextEditor',
'data_type' => 'Memo',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params[] = array(
- $customField['id'] => array(
+ $params[] = [
+ $customField['id'] => [
'value' => '<p><strong>This is a <u>test</u></p>',
'type' => 'Memo',
'custom_field_id' => $customField['id'],
'table_name' => $customGroup['values'][$customGroup['id']]['table_name'],
'column_name' => $customField['values'][$customField['id']]['column_name'],
'file_id' => '',
- ),
- );
+ ],
+ ];
CRM_Core_BAO_CustomValueTable::store($params, 'civicrm_contact', $contactID);
}
public function testCustomGroupMultiple() {
- $params = array();
+ $params = [];
$contactID = $this->individualCreate();
$customGroup = $this->customGroupCreate();
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'String',
'html_type' => 'Text',
- );
+ ];
$customField = $this->customFieldCreate($fields);
- $params = array(
+ $params = [
'entityID' => $contactID,
'custom_' . $customField['id'] . '_-1' => 'First String',
- );
+ ];
$error = CRM_Core_BAO_CustomValueTable::setValues($params);
- $newParams = array(
+ $newParams = [
'entityID' => $contactID,
'custom_' . $customField['id'] => 1,
- );
+ ];
$result = CRM_Core_BAO_CustomValueTable::getValues($newParams);
$this->assertEquals($params['custom_' . $customField['id'] . '_-1'], $result['custom_' . $customField['id']]);
public function testTypeCheckWithValidInput() {
- $values = array(
+ $values = [
'Memo' => 'Test1',
'String' => 'Test',
'Int' => 1,
'StateProvince' => 'California',
'Country' => 'US',
'Link' => 'http://civicrm.org',
- );
+ ];
foreach ($values as $type => $value) {
$valid = CRM_Core_BAO_CustomValue::typecheck($type, $value);
if ($type == 'Date') {
}
public function testTypeCheckWithInvalidInput() {
- $values = array('check1' => 'chk');
+ $values = ['check1' => 'chk'];
foreach ($values as $type => $value) {
$valid = CRM_Core_BAO_CustomValue::typecheck($type, $value);
$this->assertEquals($valid, NULL, 'Checking invalid type for returned CustomField Type.');
}
public function testTypeCheckWithWrongInput() {
- $values = array(
+ $values = [
'String' => 1,
'Boolean' => 'US',
- );
+ ];
foreach ($values as $type => $value) {
$valid = CRM_Core_BAO_CustomValue::typecheck($type, $value);
$this->assertEquals($valid, NULL, 'Checking type ' . $type . ' for returned CustomField Type.');
}
public function testTypeToFieldWithValidInput() {
- $values = array(
+ $values = [
'String' => 'char_data',
'File' => 'char_data',
'Boolean' => 'int_data',
'Money' => 'decimal_data',
'Date' => 'date_data',
'Link' => 'char_data',
- );
+ ];
foreach ($values as $type => $value) {
$valid = CRM_Core_BAO_CustomValue::typeToField($type);
}
public function testTypeToFieldWithWrongInput() {
- $values = array(
+ $values = [
'String' => 'memo_data',
'File' => 'date_data',
'Boolean' => 'char_data',
- );
+ ];
foreach ($values as $type => $value) {
$valid = CRM_Core_BAO_CustomValue::typeToField($type);
$this->assertNotEquals($valid, $value, 'Checking type ' . $type . ' for returned CustomField Type.');
}
public function fixCustomFieldValue() {
- $customGroup = $this->customGroupCreate(array('extends' => 'Individual'));
+ $customGroup = $this->customGroupCreate(['extends' => 'Individual']);
- $fields = array(
+ $fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'Memo',
'html_type' => 'TextArea',
'default_value' => '',
- );
+ ];
$customField = $this->customFieldCreate($fields);
$custom = 'custom_' . $customField['id'];
- $params = array(
+ $params = [
'email' => 'abc@webaccess.co.in',
$custom => 'note',
- );
+ ];
CRM_Core_BAO_CustomValue::fixCustomFieldValue($params);
$this->assertEquals($params[$custom], '%note%', 'Checking the returned value of type Memo.');
}
public function testFixCustomFieldValueWithEmptyParams() {
- $params = array();
+ $params = [];
$result = CRM_Core_BAO_CustomValue::fixCustomFieldValue($params);
$this->assertEquals($result, NULL, 'Checking the returned value of type Memo.');
}
}
public function parseUrlTestData() {
- return array(
- array('https://foo.bar', 'https://foo.bar'),
- array('civicrm/path?reset=1&unit=test', CRM_Utils_System::url('civicrm/path', 'reset=1&unit=test', FALSE, NULL, FALSE)),
- );
+ return [
+ ['https://foo.bar', 'https://foo.bar'],
+ ['civicrm/path?reset=1&unit=test', CRM_Utils_System::url('civicrm/path', 'reset=1&unit=test', FALSE, NULL, FALSE)],
+ ];
}
}
public function setUp() {
parent::setUp();
- $this->quickCleanup(array('civicrm_contact', 'civicrm_email'));
+ $this->quickCleanup(['civicrm_contact', 'civicrm_email']);
}
/**
public function testAdd() {
$contactId = $this->individualCreate();
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'email' => 'jane.doe@example.com',
'is_primary' => 1,
'location_type_id' => 1,
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Email::add($params);
// Now call add() to modify an existing email address
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'id' => $emailId,
'contact_id' => $contactId,
'is_bulkmail' => 1,
'on_hold' => 1,
- );
+ ];
CRM_Core_BAO_Email::add($params);
public function testHoldEmail() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'email' => 'jane.doe@example.com',
'is_primary' => 1,
'location_type_id' => 1,
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Email::add($params);
);
// Now call add() to update on_hold=1 ("On Hold Bounce") and check record state
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'id' => $emailId,
'contact_id' => $contactId,
'on_hold' => 1,
- );
+ ];
CRM_Core_BAO_Email::add($params);
);
// Now call add() to update on_hold=2 ("On Hold Opt-out") and check record state
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'id' => $emailId,
'contact_id' => $contactId,
'on_hold' => 2,
- );
+ ];
CRM_Core_BAO_Email::add($params);
);
// Now call add() with on_hold=null (not on hold) and verify that reset_date is set.
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'id' => $emailId,
'contact_id' => $contactId,
'on_hold' => 'null',
- );
+ ];
CRM_Core_BAO_Email::add($params);
$this->assertDBCompareValue('CRM_Core_DAO_Email', $emailId, 'on_hold', 'id', 0,
* AllEmails() method - get all emails for our contact, with primary email first
*/
public function testAllEmails() {
- $contactParams = array(
+ $contactParams = [
'first_name' => 'Alan',
'last_name' => 'Smith',
'email' => 'alan.smith1@example.com',
- 'api.email.create.0' => array('email' => 'alan.smith2@example.com', 'location_type_id' => 'Home'),
- 'api.email.create.1' => array('email' => 'alan.smith3@example.com', 'location_type_id' => 'Main'),
- );
+ 'api.email.create.0' => ['email' => 'alan.smith2@example.com', 'location_type_id' => 'Home'],
+ 'api.email.create.1' => ['email' => 'alan.smith3@example.com', 'location_type_id' => 'Main'],
+ ];
$contactId = $this->individualCreate($contactParams);
public function testCreate() {
$contactId = $this->individualCreate();
$financialTypeId = 1;
- $this->contributionCreate(array(
+ $this->contributionCreate([
'contact_id' => $contactId,
'financial_type_id' => $financialTypeId,
- ));
- $params = array(
+ ]);
+ $params = [
'contribution_id' => $financialTypeId,
'to_financial_account_id' => 1,
'trxn_date' => 20091021184930,
'currency' => 'USD',
'payment_processor' => 'Dummy',
'trxn_id' => 'test_01014000',
- );
+ ];
$FinancialTrxn = CRM_Core_BAO_FinancialTrxn::create($params);
$result = $this->assertDBNotNull('CRM_Core_BAO_FinancialTrxn', $FinancialTrxn->id,
public function testGetTotalPayments() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'trxn_id' => '22ereerwwe4444yy',
'invoice_id' => '86ed39e9e9yy6ef6541621ce0eafe7eb81',
'thankyou_date' => '20080522',
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params);
$contribution = $contribution['values'][$contribution['id']];
$cmp = bccomp($total, $paid, 5);
// If paid amount is greater or equal to total amount
if ($cmp == 0 || $cmp == -1) {
- civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id']));
+ civicrm_api3('Contribution', 'completetransaction', ['id' => $contribution['id']]);
}
$totalPaymentAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribution['id']);
* Test for createDeferredTrxn().
*/
public function testCreateDeferredTrxn() {
- Civi::settings()->set('contribution_invoice_settings', array('deferred_revenue_enabled' => '1'));
+ Civi::settings()->set('contribution_invoice_settings', ['deferred_revenue_enabled' => '1']);
$cid = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $cid,
'receive_date' => '2016-01-20',
'total_amount' => 622,
'financial_type_id' => 4,
- 'line_items' => array(
- array(
- 'line_item' => array(
- array(
+ 'line_items' => [
+ [
+ 'line_item' => [
+ [
'entity_table' => 'civicrm_contribution',
'price_field_id' => 8,
'price_field_value_id' => 16,
'unit_price' => 100,
'line_total' => 100,
'financial_type_id' => 4,
- ),
- ),
- 'params' => array(),
- ),
- ),
- );
+ ],
+ ],
+ 'params' => [],
+ ],
+ ],
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params);
$lineItems[1] = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']);
$lineItemId = key($lineItems[1]);
$lineItems[1][$lineItemId]['financial_item_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_item WHERE entity_table = 'civicrm_line_item' AND entity_id = {$lineItemId}");
// Get financial trxns for contribution
- $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622));
+ $trxn = $this->callAPISuccess("FinancialTrxn", "get", ['total_amount' => 622]);
$this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime('2016-01-20')));
$contributionObj = $this->getContributionObject($contribution['id']);
$contributionObj->revenue_recognition_date = date('Ymd', strtotime("+1 month"));
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn($lineItems, $contributionObj);
- $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622, 'id' => array("NOT IN" => array($trxn['id']))));
+ $trxn = $this->callAPISuccess("FinancialTrxn", "get", ['total_amount' => 622, 'id' => ["NOT IN" => [$trxn['id']]]]);
$this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime("+1 month")));
}
*/
public function testUpdateCreditCardDetailsUsingContributionAPI() {
$cid = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $cid,
'receive_date' => '2016-01-20',
'total_amount' => 100,
'financial_type_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('card_type_id', 'pan_truncation'),
- )
+ 'return' => ['card_type_id', 'pan_truncation'],
+ ]
);
$this->assertEquals(CRM_Utils_Array::value('card_type_id', $financialTrxn), NULL);
$this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), NULL);
- $params = array(
+ $params = [
'card_type_id' => 2,
'pan_truncation' => 4567,
'id' => $contribution['id'],
- );
+ ];
$this->callAPISuccess("Contribution", "create", $params);
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('card_type_id', 'pan_truncation'),
- )
+ 'return' => ['card_type_id', 'pan_truncation'],
+ ]
);
$this->assertEquals($financialTrxn['card_type_id'], 2);
$this->assertEquals($financialTrxn['pan_truncation'], 4567);
*/
public function testUpdateCreditCardDetails() {
$cid = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $cid,
'receive_date' => '2016-01-20',
'total_amount' => 100,
'financial_type_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('card_type_id', 'pan_truncation'),
- )
+ 'return' => ['card_type_id', 'pan_truncation'],
+ ]
);
$this->assertEquals(CRM_Utils_Array::value('card_type_id', $financialTrxn), NULL);
$this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), NULL);
CRM_Core_BAO_FinancialTrxn::updateCreditCardDetails($contribution['id'], 4567, 2);
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('card_type_id', 'pan_truncation'),
- )
+ 'return' => ['card_type_id', 'pan_truncation'],
+ ]
);
$this->assertEquals($financialTrxn['card_type_id'], 2);
$this->assertEquals($financialTrxn['pan_truncation'], 4567);
public function testGetPartialPaymentWithType() {
//create the contribution that isn't paid yet
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'total_amount' => 300.00,
'fee_amount' => 0.00,
'net_amount' => 300.00,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params)['values'][7];
//make a payment one cent short
- $params = array(
+ $params = [
'contribution_id' => $contribution['id'],
'total_amount' => 299.99,
- );
+ ];
$this->callAPISuccess('Payment', 'create', $params);
//amount owed should be one cent
$amountOwed = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($contribution['id'], 'contribution')['amount_owed'];
public function testAdd() {
$contactId = $this->individualCreate();
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'name' => 'jane.doe',
'provider_id' => 1,
'is_primary' => 1,
'location_type_id' => 1,
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_IM::add($params);
// Now call add() to modify an existing IM
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'id' => $imId,
'contact_id' => $contactId,
'provider_id' => 3,
'name' => 'doe.jane',
- );
+ ];
CRM_Core_BAO_IM::add($params);
public function setUp() {
parent::setUp();
- $this->quickCleanup(array(
+ $this->quickCleanup([
'civicrm_contact',
'civicrm_address',
'civicrm_loc_block',
'civicrm_email',
'civicrm_phone',
'civicrm_im',
- ));
+ ]);
}
/**
* This method is called after a test is executed.
*/
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contact',
'civicrm_openid',
'civicrm_loc_block',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
}
public function testCreateWithMissingParams() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'street_address' => 'Saint Helier St',
- );
+ ];
CRM_Core_BAO_Location::create($params);
//create various element of location block
//like address, phone, email, openid, im.
- $params = array(
- 'address' => array(
- '1' => array(
+ $params = [
+ 'address' => [
+ '1' => [
'street_address' => 'Saint Helier St',
'supplemental_address_1' => 'Hallmark Ct',
'supplemental_address_2' => 'Jersey Village',
'geo_code_2' => '-105.00973',
'is_primary' => 1,
'location_type_id' => 1,
- ),
- ),
- 'email' => array(
- '1' => array(
+ ],
+ ],
+ 'email' => [
+ '1' => [
'email' => 'john.smith@example.org',
'is_primary' => 1,
'location_type_id' => 1,
- ),
- ),
- 'phone' => array(
- '1' => array(
+ ],
+ ],
+ 'phone' => [
+ '1' => [
'phone_type_id' => 1,
'phone' => '303443689',
'is_primary' => 1,
'location_type_id' => 1,
- ),
- '2' => array(
+ ],
+ '2' => [
'phone_type_id' => 2,
'phone' => '9833910234',
'location_type_id' => 1,
- ),
- ),
- 'openid' => array(
- '1' => array(
+ ],
+ ],
+ 'openid' => [
+ '1' => [
'openid' => 'http://civicrm.org/',
'location_type_id' => 1,
'is_primary' => 1,
- ),
- ),
- 'im' => array(
- '1' => array(
+ ],
+ ],
+ 'im' => [
+ '1' => [
'name' => 'jane.doe',
'provider_id' => 1,
'location_type_id' => 1,
'is_primary' => 1,
- ),
- ),
- );
+ ],
+ ],
+ ];
$params['contact_id'] = $contactId;
$locBlockId = CRM_Utils_Array::value('id', $location);
//Now check DB for contact
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'street_address' => 'Saint Helier St',
'supplemental_address_1' => 'Hallmark Ct',
'supplemental_address_2' => 'Jersey Village',
'state_province_id' => 1029,
'geo_code_1' => '18.219023',
'geo_code_2' => '-105.00973',
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
- $compareParams = array('email' => 'john.smith@example.org');
+ $compareParams = ['email' => 'john.smith@example.org'];
$this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
- $compareParams = array('openid' => 'http://civicrm.org/');
+ $compareParams = ['openid' => 'http://civicrm.org/'];
$this->assertDBCompareValues('CRM_Core_DAO_OpenID', $searchParams, $compareParams);
- $compareParams = array(
+ $compareParams = [
'name' => 'jane.doe',
'provider_id' => 1,
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams);
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'is_primary' => 1,
'phone_type_id' => 1,
- );
- $compareParams = array('phone' => '303443689');
+ ];
+ $compareParams = ['phone' => '303443689'];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
- $searchParams = array(
+ $searchParams = [
'contact_id' => $contactId,
'location_type_id' => 1,
'phone_type_id' => 2,
- );
- $compareParams = array('phone' => '9833910234');
+ ];
+ $compareParams = ['phone' => '9833910234'];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
//delete the location block
public function testCreateWithLocBlock() {
$this->_contactId = $this->individualCreate();
$event = $this->eventCreate();
- $params = array(
- 'address' => array(
- '1' => array(
+ $params = [
+ 'address' => [
+ '1' => [
'street_address' => 'Saint Helier St',
'supplemental_address_1' => 'Hallmark Ct',
'supplemental_address_2' => 'Jersey Village',
'geo_code_2' => '-105.00973',
'is_primary' => 1,
'location_type_id' => 1,
- ),
- ),
- 'email' => array(
- '1' => array(
+ ],
+ ],
+ 'email' => [
+ '1' => [
'email' => 'john.smith@example.org',
'is_primary' => 1,
'location_type_id' => 1,
- ),
- ),
- 'phone' => array(
- '1' => array(
+ ],
+ ],
+ 'phone' => [
+ '1' => [
'phone_type_id' => 1,
'phone' => '303443689',
'is_primary' => 1,
'location_type_id' => 1,
- ),
- '2' => array(
+ ],
+ '2' => [
'phone_type_id' => 2,
'phone' => '9833910234',
'location_type_id' => 1,
- ),
- ),
- 'im' => array(
- '1' => array(
+ ],
+ ],
+ 'im' => [
+ '1' => [
'name' => 'jane.doe',
'provider_id' => 1,
'location_type_id' => 1,
'is_primary' => 1,
- ),
- ),
- );
+ ],
+ ],
+ ];
$params['entity_id'] = $event['id'];
$params['entity_table'] = 'civicrm_event';
$locBlockId = CRM_Utils_Array::value('id', $location);
//update event record with location block id
- $eventParams = array(
+ $eventParams = [
'id' => $event['id'],
'loc_block_id' => $locBlockId,
- );
+ ];
CRM_Event_BAO_Event::add($eventParams);
$locBlockId,
'Checking database for the record.'
);
- $locElementIds = array();
- $locParams = array('id' => $locBlockId);
+ $locElementIds = [];
+ $locParams = ['id' => $locBlockId];
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_LocBlock',
$locParams,
$locElementIds
);
//Now check DB for location elements.
- $searchParams = array(
+ $searchParams = [
'id' => CRM_Utils_Array::value('address_id', $locElementIds),
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'street_address' => 'Saint Helier St',
'supplemental_address_1' => 'Hallmark Ct',
'supplemental_address_2' => 'Jersey Village',
'state_province_id' => 1029,
'geo_code_1' => '18.219023',
'geo_code_2' => '-105.00973',
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_Address', $searchParams, $compareParams);
- $searchParams = array(
+ $searchParams = [
'id' => CRM_Utils_Array::value('email_id', $locElementIds),
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array('email' => 'john.smith@example.org');
+ ];
+ $compareParams = ['email' => 'john.smith@example.org'];
$this->assertDBCompareValues('CRM_Core_DAO_Email', $searchParams, $compareParams);
- $searchParams = array(
+ $searchParams = [
'id' => CRM_Utils_Array::value('phone_id', $locElementIds),
'location_type_id' => 1,
'is_primary' => 1,
'phone_type_id' => 1,
- );
- $compareParams = array('phone' => '303443689');
+ ];
+ $compareParams = ['phone' => '303443689'];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
- $searchParams = array(
+ $searchParams = [
'id' => CRM_Utils_Array::value('phone_2_id', $locElementIds),
'location_type_id' => 1,
'phone_type_id' => 2,
- );
- $compareParams = array('phone' => '9833910234');
+ ];
+ $compareParams = ['phone' => '9833910234'];
$this->assertDBCompareValues('CRM_Core_DAO_Phone', $searchParams, $compareParams);
- $searchParams = array(
+ $searchParams = [
'id' => CRM_Utils_Array::value('im_id', $locElementIds),
'location_type_id' => 1,
'is_primary' => 1,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'name' => 'jane.doe',
'provider_id' => 1,
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_IM', $searchParams, $compareParams);
// Cleanup.
$this->_contactId = $this->individualCreate();
//create test event record.
$event = $this->eventCreate();
- $params['location'][1] = array(
+ $params['location'][1] = [
'location_type_id' => 1,
'is_primary' => 1,
- 'address' => array(
+ 'address' => [
'street_address' => 'Saint Helier St',
'supplemental_address_1' => 'Hallmark Ct',
'supplemental_address_2' => 'Jersey Village',
'state_province_id' => 1029,
'geo_code_1' => '18.219023',
'geo_code_2' => '-105.00973',
- ),
- 'email' => array(
- '1' => array('email' => 'john.smith@example.org'),
- ),
- 'phone' => array(
- '1' => array(
+ ],
+ 'email' => [
+ '1' => ['email' => 'john.smith@example.org'],
+ ],
+ 'phone' => [
+ '1' => [
'phone_type_id' => 1,
'phone' => '303443689',
- ),
- '2' => array(
+ ],
+ '2' => [
'phone_type_id' => 2,
'phone' => '9833910234',
- ),
- ),
- 'im' => array(
- '1' => array(
+ ],
+ ],
+ 'im' => [
+ '1' => [
'name' => 'jane.doe',
'provider_id' => 1,
- ),
- ),
- );
+ ],
+ ],
+ ];
$params['entity_id'] = $event['id'];
$params['entity_table'] = 'civicrm_event';
$location = CRM_Core_BAO_Location::create($params, NULL, TRUE);
$locBlockId = CRM_Utils_Array::value('id', $location);
//update event record with location block id
- $eventParams = array(
+ $eventParams = [
'id' => $event['id'],
'loc_block_id' => $locBlockId,
- );
+ ];
CRM_Event_BAO_Event::add($eventParams);
//delete the location block
//create various element of location block
//like address, phone, email, openid, im.
- $params = array(
- 'address' => array(
- '1' => array(
+ $params = [
+ 'address' => [
+ '1' => [
'street_address' => 'Saint Helier St',
'supplemental_address_1' => 'Hallmark Ct',
'supplemental_address_2' => 'Jersey Village',
'geo_code_2' => '-105.00973',
'is_primary' => 1,
'location_type_id' => 1,
- ),
- ),
- 'email' => array(
- '1' => array(
+ ],
+ ],
+ 'email' => [
+ '1' => [
'email' => 'john.smith@example.org',
'is_primary' => 1,
'location_type_id' => 1,
- ),
- ),
- 'phone' => array(
- '1' => array(
+ ],
+ ],
+ 'phone' => [
+ '1' => [
'phone_type_id' => 1,
'phone' => '303443689',
'is_primary' => 1,
'location_type_id' => 1,
- ),
- '2' => array(
+ ],
+ '2' => [
'phone_type_id' => 2,
'phone' => '9833910234',
'location_type_id' => 1,
- ),
- ),
- 'openid' => array(
- '1' => array(
+ ],
+ ],
+ 'openid' => [
+ '1' => [
'openid' => 'http://civicrm.org/',
'location_type_id' => 1,
'is_primary' => 1,
- ),
- ),
- 'im' => array(
- '1' => array(
+ ],
+ ],
+ 'im' => [
+ '1' => [
'name' => 'jane.doe',
'provider_id' => 1,
'location_type_id' => 1,
'is_primary' => 1,
- ),
- ),
- );
+ ],
+ ],
+ ];
$params['contact_id'] = $contactId;
-<?php\r
-/* vim: set shiftwidth=2 tabstop=2 softtabstop=2: */\r
-\r
-/**\r
- * Class CRM_Core_BAO_MessageTemplateTest\r
- * @group headless\r
- */\r
-class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase {\r
-\r
- public function setUp() {\r
- parent::setUp();\r
- }\r
-\r
- public function tearDown() {\r
- parent::tearDown();\r
- }\r
-\r
- public function testCaseActivityCopyTemplate() {\r
- $client_id = $this->individualCreate();\r
- $contact_id = $this->individualCreate();\r
-\r
- $tplParams = array(\r
- 'isCaseActivity' => 1,\r
- 'client_id' => $client_id,\r
- 'activityTypeName' => 'Follow up',\r
- 'activity' => array(\r
- 'fields' => array(\r
- array(\r
- 'label' => 'Case ID',\r
- 'type' => 'String',\r
- 'value' => '1234',\r
- ),\r
- ),\r
- ),\r
- 'activitySubject' => 'Test 123',\r
- 'idHash' => substr(sha1(CIVICRM_SITE_KEY . '1234'), 0, 7),\r
- );\r
-\r
- list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(\r
- array(\r
- 'groupName' => 'msg_tpl_workflow_case',\r
- 'valueName' => 'case_activity',\r
- 'contactId' => $contact_id,\r
- 'tplParams' => $tplParams,\r
- 'from' => 'admin@example.com',\r
- 'toName' => 'Demo',\r
- 'toEmail' => 'admin@example.com',\r
- 'attachments' => NULL,\r
- )\r
- );\r
-\r
- $this->assertEquals('[case #' . $tplParams['idHash'] . '] Test 123', $subject);\r
- $this->assertContains('Your Case Role', $message);\r
- $this->assertContains('Case ID : 1234', $message);\r
- }\r
-\r
-}\r
+<?php
+
+/**
+ * Class CRM_Core_BAO_MessageTemplateTest
+ * @group headless
+ */
+class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase {
+
+ public function setUp() {
+ parent::setUp();
+ }
+
+ public function tearDown() {
+ parent::tearDown();
+ }
+
+ public function testCaseActivityCopyTemplate() {
+ $client_id = $this->individualCreate();
+ $contact_id = $this->individualCreate();
+
+ $tplParams = [
+ 'isCaseActivity' => 1,
+ 'client_id' => $client_id,
+ 'activityTypeName' => 'Follow up',
+ 'activity' => [
+ 'fields' => [
+ [
+ 'label' => 'Case ID',
+ 'type' => 'String',
+ 'value' => '1234',
+ ],
+ ],
+ ],
+ 'activitySubject' => 'Test 123',
+ 'idHash' => substr(sha1(CIVICRM_SITE_KEY . '1234'), 0, 7),
+ ];
+
+ list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
+ [
+ 'groupName' => 'msg_tpl_workflow_case',
+ 'valueName' => 'case_activity',
+ 'contactId' => $contact_id,
+ 'tplParams' => $tplParams,
+ 'from' => 'admin@example.com',
+ 'toName' => 'Demo',
+ 'toEmail' => 'admin@example.com',
+ 'attachments' => NULL,
+ ]
+ );
+
+ $this->assertEquals('[case #' . $tplParams['idHash'] . '] Test 123', $subject);
+ $this->assertContains('Your Case Role', $message);
+ $this->assertContains('Case ID : 1234', $message);
+ }
+
+}
* by rebuilding reports.
*/
public function testNoDuplicateAllReportsLink() {
- $existing_links = $this->callAPISuccess('Navigation', 'get', array('label' => 'All Reports', 'sequential' => 1));
+ $existing_links = $this->callAPISuccess('Navigation', 'get', ['label' => 'All Reports', 'sequential' => 1]);
$this->assertNotEquals($existing_links['values'][0]['parent_id'], $existing_links['values'][1]['parent_id']);
CRM_Core_BAO_Navigation::rebuildReportsNavigation(CRM_Core_Config::domainID());
- $new_links = $this->callAPISuccess('Navigation', 'get', array('label' => 'All Reports', 'sequential' => 1));
+ $new_links = $this->callAPISuccess('Navigation', 'get', ['label' => 'All Reports', 'sequential' => 1]);
$this->assertEquals($existing_links['values'][0]['parent_id'], $new_links['values'][0]['parent_id']);
$this->assertEquals($existing_links['values'][1]['parent_id'], $new_links['values'][1]['parent_id']);
}
$name = "Test Menu Link {$random_string}";
$url = "civicrm/test/{$random_string}";
$url_params = "reset=1";
- $params = array(
+ $params = [
'name' => $name,
'label' => ts($name),
'url' => "{$url}?{$url_params}",
'parent_id' => NULL,
'is_active' => TRUE,
- 'permission' => array(
+ 'permission' => [
'access CiviCRM',
- ),
- );
+ ],
+ ];
CRM_Core_BAO_Navigation::add($params);
$new_nav = CRM_Core_BAO_Navigation::getNavItemByUrl($url, $url_params);
$this->assertObjectHasAttribute('id', $new_nav);
$name = "Test Menu Link {$random_string}";
$url = "civicrm/test/{$random_string}";
$url_params = "reset=1&output=criteria";
- $params = array(
+ $params = [
'name' => $name,
'label' => ts($name),
'url' => "{$url}?{$url_params}",
'parent_id' => NULL,
'is_active' => TRUE,
- 'permission' => array(
+ 'permission' => [
'access CiviCRM',
- ),
- );
+ ],
+ ];
CRM_Core_BAO_Navigation::add($params);
$new_nav = CRM_Core_BAO_Navigation::getNavItemByUrl($url, 'reset=1%');
$this->assertObjectHasAttribute('id', $new_nav);
* everywhere. They should be unchanged.
*/
public function testFixNavigationMenu_preserveIDs() {
- $input[10] = array(
- 'attributes' => array(
+ $input[10] = [
+ 'attributes' => [
'label' => 'Custom Menu Entry',
'parentID' => NULL,
'navID' => 10,
'active' => 1,
- ),
- 'child' => array(
- '11' => array(
- 'attributes' => array(
+ ],
+ 'child' => [
+ '11' => [
+ 'attributes' => [
'label' => 'Custom Child Menu',
'parentID' => 10,
'navID' => 11,
- ),
+ ],
'child' => NULL,
- ),
- ),
- );
+ ],
+ ],
+ ];
$output = $input;
CRM_Core_BAO_Navigation::fixNavigationMenu($output);
* should be filled in, and others should be preserved.
*/
public function testFixNavigationMenu_inferIDs() {
- $input[10] = array(
- 'attributes' => array(
+ $input[10] = [
+ 'attributes' => [
'label' => 'Custom Menu Entry',
'parentID' => NULL,
'navID' => 10,
'active' => 1,
- ),
- 'child' => array(
- '0' => array(
- 'attributes' => array(
+ ],
+ 'child' => [
+ '0' => [
+ 'attributes' => [
'label' => 'Custom Child Menu',
- ),
+ ],
'child' => NULL,
- ),
- '100' => array(
- 'attributes' => array(
+ ],
+ '100' => [
+ 'attributes' => [
'label' => 'Custom Child Menu 2',
'navID' => 100,
- ),
+ ],
'child' => NULL,
- ),
- ),
- );
+ ],
+ ],
+ ];
$output = $input;
CRM_Core_BAO_Navigation::fixNavigationMenu($output);
}
public function testFixNavigationMenu_inferIDs_deep() {
- $input[10] = array(
- 'attributes' => array(
+ $input[10] = [
+ 'attributes' => [
'label' => 'Custom Menu Entry',
'parentID' => NULL,
'navID' => 10,
'active' => 1,
- ),
- 'child' => array(
- '0' => array(
- 'attributes' => array(
+ ],
+ 'child' => [
+ '0' => [
+ 'attributes' => [
'label' => 'Custom Child Menu',
- ),
- 'child' => array(
- '100' => array(
- 'attributes' => array(
+ ],
+ 'child' => [
+ '100' => [
+ 'attributes' => [
'label' => 'Custom Child Menu 2',
'navID' => 100,
- ),
+ ],
'child' => NULL,
- ),
- ),
- ),
- ),
- );
+ ],
+ ],
+ ],
+ ],
+ ];
$output = $input;
CRM_Core_BAO_Navigation::fixNavigationMenu($output);
$this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId);
$openIdURL = "http://test-username.civicrm.org/";
- $params = array(
+ $params = [
'contact_id' => $contactId,
'location_type_id' => 1,
'openid' => $openIdURL,
'is_primary' => 1,
- );
+ ];
$openObject = CRM_Core_BAO_OpenID::add($params);
// Now call add() to modify an existing open-id record
- $params = array(
+ $params = [
'id' => $openId,
'contact_id' => $contactId,
'openid' => $openIdURL,
'is_bulkmail' => 1,
'allowed_to_login' => 1,
- );
+ ];
CRM_Core_BAO_OpenID::add($params);
$this->assertDBRowExist('CRM_Contact_DAO_Contact', $contactId);
$openIdURL = "http://test-username.civicrm.org/";
- $params = array(
+ $params = [
'contact_id' => $contactId,
'location_type_id' => 1,
'openid' => $openIdURL,
'is_primary' => 1,
- );
+ ];
$openObject = CRM_Core_BAO_OpenID::add($params);
// Now call add() to modify an existing open-id record
- $params = array(
+ $params = [
'id' => $openId,
'contact_id' => $contactId,
'openid' => $openIdURL,
'is_bulkmail' => 1,
'allowed_to_login' => 1,
- );
+ ];
CRM_Core_BAO_OpenID::add($params);
// create first openid
$openIdURLOne = "http://test-one-username.civicrm.org/";
- $params = array(
+ $params = [
'contact_id' => $contactId,
'location_type_id' => 1,
'openid' => $openIdURLOne,
'is_primary' => 1,
'allowed_to_login' => 1,
- );
+ ];
$openObjectOne = CRM_Core_BAO_OpenID::add($params);
// create second openid
$openIdURLTwo = "http://test-two-username.civicrm.org/";
- $params = array(
+ $params = [
'contact_id' => $contactId,
'location_type_id' => 1,
'openid' => $openIdURLTwo,
- );
+ ];
$openObjectTwo = CRM_Core_BAO_OpenID::add($params);
$openIdTwo = $openObjectTwo->id;
* Ensure only one option value exists after calling ensureOptionValueExists.
*/
public function testEnsureOptionGroupExistsExistingValue() {
- CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array('name' => 'contribution_status'));
- $this->callAPISuccessGetSingle('OptionGroup', array('name' => 'contribution_status'));
+ CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'contribution_status']);
+ $this->callAPISuccessGetSingle('OptionGroup', ['name' => 'contribution_status']);
}
/**
* Ensure only one option value exists adds a new value.
*/
public function testEnsureOptionGroupExistsNewValue() {
- CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array('name' => 'Bombed'));
- $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', array('field' => 'option_group_id'))['values'];
+ CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'Bombed']);
+ $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', ['field' => 'option_group_id'])['values'];
$this->assertTrue(in_array('Bombed', $optionGroups));
- CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array('name' => 'Bombed Again'));
- $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', array('field' => 'option_group_id'))['values'];
+ CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'Bombed Again']);
+ $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', ['field' => 'option_group_id'])['values'];
$this->assertTrue(in_array('Bombed Again', $optionGroups));
}
* Ensure only one option value exists after calling ensureOptionValueExists.
*/
public function testEnsureOptionValueExistsExistingValue() {
- CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Completed', 'option_group_id' => 'contribution_status'));
- $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Completed', 'option_group_id' => 'contribution_status'));
+ CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Completed', 'option_group_id' => 'contribution_status']);
+ $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Completed', 'option_group_id' => 'contribution_status']);
}
/**
* Ensure only one option value exists adds a new value.
*/
public function testEnsureOptionValueExistsNewValue() {
- CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Bombed', 'option_group_id' => 'contribution_status'));
- $optionValues = $this->callAPISuccess('OptionValue', 'get', array('option_group_id' => 'contribution_status'));
+ CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Bombed', 'option_group_id' => 'contribution_status']);
+ $optionValues = $this->callAPISuccess('OptionValue', 'get', ['option_group_id' => 'contribution_status']);
foreach ($optionValues['values'] as $value) {
if ($value['name'] == 'Bombed') {
return;
* decision to disable it & leaving it in that state.
*/
public function testEnsureOptionValueExistsDisabled() {
- $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Crashed', 'option_group_id' => 'contribution_status', 'is_active' => 0));
- $value = $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Crashed', 'option_group_id' => 'contribution_status'));
+ $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Crashed', 'option_group_id' => 'contribution_status', 'is_active' => 0]);
+ $value = $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Crashed', 'option_group_id' => 'contribution_status']);
$this->assertEquals(0, $value['is_active']);
$this->assertEquals($value['id'], $optionValue['id']);
- $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(array('name' => 'Crashed', 'option_group_id' => 'contribution_status'));
- $value = $this->callAPISuccessGetSingle('OptionValue', array('name' => 'Crashed', 'option_group_id' => 'contribution_status'));
+ $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Crashed', 'option_group_id' => 'contribution_status']);
+ $value = $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Crashed', 'option_group_id' => 'contribution_status']);
$this->assertEquals(0, $value['is_active']);
$this->assertEquals($value['id'], $optionValue['id']);
}
public function testAdd() {
$contactId = $this->individualCreate();
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'phone' => '(415) 222-1011 x 221',
'is_primary' => 1,
'location_type_id' => 1,
'phone_type' => 'Mobile',
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Phone::add($params);
// Now call add() to modify the existing phone number
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'id' => $phoneId,
'contact_id' => $contactId,
'phone' => '(415) 222-5432',
- );
+ ];
CRM_Core_BAO_Phone::add($params);
* AllPhones() method - get all Phones for our contact, with primary Phone first.
*/
public function testAllPhones() {
- $contactParams = array(
+ $contactParams = [
'first_name' => 'Alan',
'last_name' => 'Smith',
- 'api.phone.create' => array('phone' => '(415) 222-1011 x 221', 'location_type_id' => 'Home'),
- 'api.phone.create.1' => array('phone' => '(415) 222-5432', 'location_type_id' => 'Work'),
- );
+ 'api.phone.create' => ['phone' => '(415) 222-1011 x 221', 'location_type_id' => 'Home'],
+ 'api.phone.create.1' => ['phone' => '(415) 222-5432', 'location_type_id' => 'Work'],
+ ];
$contactId = $this->individualCreate($contactParams);
$dao = new CRM_Core_BAO_PrevNextCache();
$dao->entity_id1 = 1;
$dao->entity_id2 = 2;
- $dao->data = serialize(array(
+ $dao->data = serialize([
'srcID' => 1,
'srcName' => 'Ms. Meliissa Mouse II',
'dstID' => 2,
'dstName' => 'Mr. Maurice Mouse II',
'weight' => 20,
'canMerge' => TRUE,
- ));
+ ]);
$dao->save();
$dao = new CRM_Core_BAO_PrevNextCache();
$dao->id = 1;
- CRM_Core_BAO_PrevNextCache::flipPair(array(1), 0);
+ CRM_Core_BAO_PrevNextCache::flipPair([1], 0);
$dao->find(TRUE);
$this->assertEquals(1, $dao->entity_id1);
$this->assertEquals(2, $dao->entity_id2);
- $this->assertEquals(serialize(array(
+ $this->assertEquals(serialize([
'srcName' => 'Mr. Maurice Mouse II',
'dstID' => 1,
'dstName' => 'Ms. Meliissa Mouse II',
'weight' => 20,
'canMerge' => TRUE,
'srcID' => 2,
- )), $dao->data);
+ ]), $dao->data);
- $this->quickCleanup(array('civicrm_prevnext_cache'));
+ $this->quickCleanup(['civicrm_prevnext_cache']);
}
public function testSetItem() {
$recursion = new CRM_Core_BAO_RecurringEntity();
$recursion->entity_id = $daoActivity->id;
$recursion->entity_table = 'civicrm_activity';
- $recursion->dateColumns = array('activity_date_time');
- $recursion->schedule = array(
+ $recursion->dateColumns = ['activity_date_time'];
+ $recursion->schedule = [
'entity_value' => $daoActivity->id,
'start_action_date' => $daoActivity->activity_date_time,
'entity_status' => 'fourth saturday',
'repetition_frequency_interval' => 3,
'start_action_offset' => 5,
'used_for' => 'activity',
- );
+ ];
$generatedEntities = $recursion->generate();
$this->assertEquals(5, count($generatedEntities['civicrm_activity']), "Cehck if number of iterations are 5");
- $expectedDates = array(
+ $expectedDates = [
'20141025103000',
'20141227103000',
'20150328103000',
'20150627103000',
'20150926103000',
- );
+ ];
foreach ($generatedEntities['civicrm_activity'] as $entityID) {
$this->assertDBNotNull('CRM_Activity_DAO_Activity', $entityID, 'id',
'id', 'Check DB if repeating activities were created'
$daoActivity->save();
// check if other activities were affected
- $actualDates = array();
+ $actualDates = [];
foreach ($generatedEntities['civicrm_activity'] as $entityID) {
$this->assertDBCompareValue('CRM_Activity_DAO_Activity', $entityID, 'subject', 'id', 'Changed Activity', 'Check if subject was updated');
$actualDates[] = date('YmdHis', strtotime(CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $entityID, 'activity_date_time', 'id')));
* Creating action schedule
*/
private function createActionSchedule($entity_id, $entity_table) {
- $params = array(
+ $params = [
"used_for" => $entity_table,
"entity_value" => $entity_id,
"start_action_date" => date("YmdHis"),
"repetition_frequency_interval" => "3",
"start_action_condition" => "monday,tuesday,wednesday,thursday,friday,saturday",
"start_action_offset" => "2",
- );
+ ];
$actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($params);
return $actionScheduleObj;
}
*/
private function createRecurringEntities($actionScheduleObj, $entity_id, $entity_table) {
$recursion = new CRM_Core_BAO_RecurringEntity();
- $recursion->dateColumns = array(
+ $recursion->dateColumns = [
"start_date",
- );
+ ];
$recursion->scheduleId = $actionScheduleObj->id;
$recursion->entity_id = $entity_id;
$recursion->entity_table = $entity_table;
- $recursion->linkedEntities = array(
- array(
+ $recursion->linkedEntities = [
+ [
"table" => "civicrm_price_set_entity",
- "findCriteria" => array(
+ "findCriteria" => [
"entity_id" => $entity_id,
"entity_table" => $entity_table,
- ),
- "linkedColumns" => array(
+ ],
+ "linkedColumns" => [
"entity_id",
- ),
+ ],
"isRecurringEntityRecord" => FALSE,
- ),
- );
+ ],
+ ];
return $recursion->generate();
}
CRM_Price_BAO_PriceSet::addTo($entity_table, $entity_id, 1);
$actionScheduleObj = $this->createActionSchedule($entity_id, $entity_table);
$recurringEntities = $this->createRecurringEntities($actionScheduleObj, $entity_id, $entity_table);
- $finalResult = CRM_Core_BAO_RecurringEntity::updateModeAndPriceSet($entity_id, $entity_table, CRM_Core_BAO_RecurringEntity::MODE_ALL_ENTITY_IN_SERIES, array(), 2);
+ $finalResult = CRM_Core_BAO_RecurringEntity::updateModeAndPriceSet($entity_id, $entity_table, CRM_Core_BAO_RecurringEntity::MODE_ALL_ENTITY_IN_SERIES, [], 2);
$this->assertEquals(2, count($recurringEntities["civicrm_event"]), "Recurring events not created.");
$this->assertEquals(2, count($recurringEntities["civicrm_price_set_entity"]), "Recurring price sets not created.");
$priceSetOne = CRM_Price_BAO_PriceSet::getFor($entity_table, $recurringEntities["civicrm_price_set_entity"][0]);
$recursion = new CRM_Core_BAO_RecurringEntity();
$recursion->entity_id = $daoEvent->id;
$recursion->entity_table = 'civicrm_event';
- $recursion->dateColumns = array('start_date');
- $recursion->schedule = array(
+ $recursion->dateColumns = ['start_date'];
+ $recursion->schedule = [
'entity_value' => $daoEvent->id,
'start_action_date' => $daoEvent->start_date,
'start_action_condition' => 'monday',
'repetition_frequency_interval' => 1,
'start_action_offset' => 4,
'used_for' => 'event',
- );
+ ];
- $recursion->linkedEntities = array(
- array(
+ $recursion->linkedEntities = [
+ [
'table' => 'civicrm_tell_friend',
- 'findCriteria' => array(
+ 'findCriteria' => [
'entity_id' => $recursion->entity_id,
'entity_table' => 'civicrm_event',
- ),
- 'linkedColumns' => array('entity_id'),
+ ],
+ 'linkedColumns' => ['entity_id'],
'isRecurringEntityRecord' => TRUE,
- ),
- );
+ ],
+ ];
$interval = $recursion->getInterval($daoEvent->start_date, $daoEvent->end_date);
- $recursion->intervalDateColumns = array('end_date' => $interval);
+ $recursion->intervalDateColumns = ['end_date' => $interval];
$generatedEntities = $recursion->generate();
$this->assertArrayHasKey('civicrm_event', $generatedEntities, 'Check if generatedEntities has civicrm_event as required key');
- $expectedDates = array(
+ $expectedDates = [
'20141027103000' => '20141029103000',
'20141103103000' => '20141105103000',
'20141110103000' => '20141112103000',
'20141117103000' => '20141119103000',
- );
+ ];
$this->assertCount($recursion->schedule['start_action_offset'], $generatedEntities['civicrm_event'], 'Check if the number of events created are right');
- $actualDates = array();
+ $actualDates = [];
foreach ($generatedEntities['civicrm_event'] as $key => $val) {
$this->assertDBNotNull('CRM_Event_DAO_Event', $val, 'id', 'id', 'Check if repeating events were created.');
$startDate = date('YmdHis', strtotime(CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $val, 'start_date', 'id')));
$this->assertEquals($key, $actKey, "Check if both the keys are same");
//Cross check event exists before we test deletion
- $searchParamsEventBeforeDelete = array(
+ $searchParamsEventBeforeDelete = [
'entity_id' => $generatedEntities['civicrm_event'][$key],
'entity_table' => 'civicrm_event',
- );
- $expectedValuesEventBeforeDelete = array(
+ ];
+ $expectedValuesEventBeforeDelete = [
'entity_id' => $generatedEntities['civicrm_event'][$key],
'entity_table' => 'civicrm_event',
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsEventBeforeDelete, $expectedValuesEventBeforeDelete);
//Cross check event exists before we test deletion
- $searchParamsTellAFriendBeforeDelete = array(
+ $searchParamsTellAFriendBeforeDelete = [
'entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey],
'entity_table' => 'civicrm_tell_friend',
- );
- $expectedValuesTellAFriendBeforeDelete = array(
+ ];
+ $expectedValuesTellAFriendBeforeDelete = [
'entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey],
'entity_table' => 'civicrm_tell_friend',
- );
+ ];
$this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParamsTellAFriendBeforeDelete, $expectedValuesTellAFriendBeforeDelete);
//Delete an event from recurring set and respective linked entity should be deleted from civicrm_recurring_entity_table
//Check if this event_id was deleted
$this->assertDBNull('CRM_Event_DAO_Event', $generatedEntities['civicrm_event'][$key], 'id', 'id', 'Check if event was deleted');
- $searchParams = array(
+ $searchParams = [
'entity_id' => $generatedEntities['civicrm_event'][$key],
'entity_table' => 'civicrm_event',
- );
- $compareParams = array();
+ ];
+ $compareParams = [];
$this->assertDBCompareValues('CRM_Core_DAO_RecurringEntity', $searchParams, $compareParams);
//Find tell_a_friend id if that was deleted from civicrm
- $searchActParams = array(
+ $searchActParams = [
'entity_id' => $generatedEntities['civicrm_tell_friend'][$actKey],
'entity_table' => 'civicrm_tell_friend',
- );
- $compareActParams = array();
+ ];
+ $compareActParams = [];
$this->assertDBCompareValues('CRM_Friend_DAO_Friend', $searchActParams, $compareActParams);
}
'extends' => 'Activity',
]);
$customField = $this->customFieldCreate([
- 'custom_group_id' => $customGroup['id'],
- 'default_value' => '',
- ]
- );
+ 'custom_group_id' => $customGroup['id'],
+ 'default_value' => '',
+ ]);
// Create activity Tag
$tag = $this->tagCreate([
* already exists.
*/
public function testCreateIndex() {
- $tables = array('civicrm_uf_join' => array('weight'));
+ $tables = ['civicrm_uf_join' => ['weight']];
CRM_Core_BAO_SchemaHandler::createIndexes($tables);
CRM_Core_BAO_SchemaHandler::createIndexes($tables);
$dao = CRM_Core_DAO::executeQuery("SHOW INDEX FROM civicrm_uf_join");
* Test CRM_Core_BAO_SchemaHandler::getIndexes() function
*/
public function testGetIndexes() {
- $indexes = CRM_Core_BAO_SchemaHandler::getIndexes(array('civicrm_contact'));
+ $indexes = CRM_Core_BAO_SchemaHandler::getIndexes(['civicrm_contact']);
$this->assertTrue(array_key_exists('index_contact_type', $indexes['civicrm_contact']));
}
* already exists.
*/
public function testCombinedIndex() {
- $tables = array('civicrm_uf_join' => array('weight'));
+ $tables = ['civicrm_uf_join' => ['weight']];
CRM_Core_BAO_SchemaHandler::createIndexes($tables);
- $tables = array('civicrm_uf_join' => array(array('weight', 'module')));
+ $tables = ['civicrm_uf_join' => [['weight', 'module']]];
CRM_Core_BAO_SchemaHandler::createIndexes($tables);
$dao = CRM_Core_DAO::executeQuery("SHOW INDEX FROM civicrm_uf_join");
$weightCount = 0;
$combinedCount = 0;
- $indexes = array();
+ $indexes = [];
while ($dao->fetch()) {
if ($dao->Column_name == 'weight') {
$this->assertFalse(CRM_Core_BAO_SchemaHandler::checkIfIndexExists('civicrm_contact', 'index_hash'));
// Recreate it to clean up after the test.
- CRM_Core_BAO_SchemaHandler::createIndexes(array('civicrm_contact' => array('hash')));
+ CRM_Core_BAO_SchemaHandler::createIndexes(['civicrm_contact' => ['hash']]);
}
/**
* @return array
*/
public function columnTests() {
- $columns = array();
- $columns[] = array('civicrm_contribution', 'total_amount');
- $columns[] = array('civicrm_contact', 'first_name');
- $columns[] = array('civicrm_contact', 'xxxx');
+ $columns = [];
+ $columns[] = ['civicrm_contribution', 'total_amount'];
+ $columns[] = ['civicrm_contact', 'first_name'];
+ $columns[] = ['civicrm_contact', 'xxxx'];
return $columns;
}
* @return array
*/
public function foreignKeyTests() {
- $keys = array();
- $keys[] = array('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_email_id');
- $keys[] = array('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_id');
+ $keys = [];
+ $keys[] = ['civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_email_id'];
+ $keys[] = ['civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_id'];
return $keys;
}
* Test that missing indices are correctly created
*/
public function testCreateMissingIndices() {
- $indices = array(
- 'test_table' => array(
- 'test_index1' => array(
+ $indices = [
+ 'test_table' => [
+ 'test_index1' => [
'name' => 'test_index1',
- 'field' => array(
+ 'field' => [
'title',
- ),
+ ],
'unique' => FALSE,
- ),
- 'test_index2' => array(
+ ],
+ 'test_index2' => [
'name' => 'test_index2',
- 'field' => array(
+ 'field' => [
'title',
- ),
+ ],
'unique' => TRUE,
- ),
- 'test_index3' => array(
+ ],
+ 'test_index3' => [
'name' => 'test_index3',
- 'field' => array(
+ 'field' => [
'title(3)',
'name',
- ),
+ ],
'unique' => FALSE,
- ),
- ),
- );
+ ],
+ ],
+ ];
CRM_Core_DAO::executeQuery('DROP table if exists `test_table`');
CRM_Core_DAO::executeQuery('CREATE table `test_table` (`title` varchar(255), `name` varchar(255))');
CRM_Core_BAO_SchemaHandler::createMissingIndices($indices);
- $actualIndices = CRM_Core_BAO_SchemaHandler::getIndexes(array('test_table'));
+ $actualIndices = CRM_Core_BAO_SchemaHandler::getIndexes(['test_table']);
$this->assertEquals($actualIndices, $indices);
}
public function testReconcileMissingIndices() {
CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_contact DROP INDEX index_sort_name');
$missingIndices = CRM_Core_BAO_SchemaHandler::getMissingIndices();
- $this->assertEquals(array(
- 'civicrm_contact' => array(
- array(
+ $this->assertEquals([
+ 'civicrm_contact' => [
+ [
'name' => 'index_sort_name',
- 'field' => array('sort_name'),
+ 'field' => ['sort_name'],
'localizable' => FALSE,
'sig' => 'civicrm_contact::0::sort_name',
- ),
- ),
- ), $missingIndices);
- $this->callAPISuccess('System', 'updateindexes', array());
+ ],
+ ],
+ ], $missingIndices);
+ $this->callAPISuccess('System', 'updateindexes', []);
$missingIndices = CRM_Core_BAO_SchemaHandler::getMissingIndices();
$this->assertTrue(empty($missingIndices));
}
* Check for partial indices
*/
public function testPartialIndices() {
- $tables = array(
+ $tables = [
'index_all' => 'civicrm_prevnext_cache',
'UI_entity_id_entity_table_tag_id' => 'civicrm_entity_tag',
- );
+ ];
CRM_Core_BAO_SchemaHandler::dropIndexIfExists('civicrm_prevnext_cache', 'index_all');
//Missing Column `is_selected`.
CRM_Core_DAO::executeQuery('CREATE INDEX index_all ON civicrm_prevnext_cache (cachekey, entity_id1, entity_id2, entity_table)');
* Test index signatures are added correctly
*/
public function testAddIndexSignatures() {
- $indices = array(
- 'one' => array(
- 'field' => array('id', 'name(3)'),
+ $indices = [
+ 'one' => [
+ 'field' => ['id', 'name(3)'],
'unique' => TRUE,
- ),
- 'two' => array(
- 'field' => array('title'),
- ),
- );
+ ],
+ 'two' => [
+ 'field' => ['title'],
+ ],
+ ];
CRM_Core_BAO_SchemaHandler::addIndexSignature('my_table', $indices);
$this->assertEquals($indices['one']['sig'], 'my_table::1::id::name(3)');
$this->assertEquals($indices['two']['sig'], 'my_table::0::title');
*/
public function testOnChange() {
global $_testOnChange_hookCalls;
- $this->setMockSettingsMetaData(array(
- 'onChangeExample' => array(
+ $this->setMockSettingsMetaData([
+ 'onChangeExample' => [
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'onChangeExample',
'type' => 'Array',
'quick_form_type' => 'Element',
'html_type' => 'advmultiselect',
- 'default' => array('CiviEvent', 'CiviContribute'),
+ 'default' => ['CiviEvent', 'CiviContribute'],
'add' => '4.4',
'title' => 'List of Components',
'is_domain' => '1',
'description' => NULL,
'help_text' => NULL,
// list of callbacks
- 'on_change' => array(
- array(__CLASS__, '_testOnChange_onChangeExample'),
- ),
- ),
- ));
+ 'on_change' => [
+ [__CLASS__, '_testOnChange_onChangeExample'],
+ ],
+ ],
+ ]);
// set initial value
- $_testOnChange_hookCalls = array('count' => 0);
- Civi::settings()->set('onChangeExample', array('First', 'Value'));
+ $_testOnChange_hookCalls = ['count' => 0];
+ Civi::settings()->set('onChangeExample', ['First', 'Value']);
$this->assertEquals(1, $_testOnChange_hookCalls['count']);
- $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['newValue']);
+ $this->assertEquals(['First', 'Value'], $_testOnChange_hookCalls['newValue']);
$this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']);
// change value
- $_testOnChange_hookCalls = array('count' => 0);
- Civi::settings()->set('onChangeExample', array('Second', 'Value'));
+ $_testOnChange_hookCalls = ['count' => 0];
+ Civi::settings()->set('onChangeExample', ['Second', 'Value']);
$this->assertEquals(1, $_testOnChange_hookCalls['count']);
- $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['oldValue']);
- $this->assertEquals(array('Second', 'Value'), $_testOnChange_hookCalls['newValue']);
+ $this->assertEquals(['First', 'Value'], $_testOnChange_hookCalls['oldValue']);
+ $this->assertEquals(['Second', 'Value'], $_testOnChange_hookCalls['newValue']);
$this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']);
}
public function setUp() {
parent::setUp();
- $this->quickCleanup(array('civicrm_uf_group', 'civicrm_uf_field'));
+ $this->quickCleanup(['civicrm_uf_group', 'civicrm_uf_field']);
}
/**
* When passing in a GID, fields should be omitted if they already appear in the group.
*/
public function testGetAvailable_byGid() {
- $ufGroupId = $this->createUFGroup(array(
- array(
+ $ufGroupId = $this->createUFGroup([
+ [
'field_name' => 'do_not_sms',
'field_type' => 'Contact',
- ),
- array(
+ ],
+ [
'field_name' => 'first_name',
'field_type' => 'Individual',
- ),
- array(
+ ],
+ [
'field_name' => 'amount_level',
'field_type' => 'Contribution',
- ),
- array(
+ ],
+ [
'field_name' => 'participant_note',
'field_type' => 'Participant',
- ),
- array(
+ ],
+ [
'field_name' => 'join_date',
'field_type' => 'Membership',
- ),
- array(
+ ],
+ [
'field_name' => 'activity_date_time',
'field_type' => 'Activity',
- ),
- ));
+ ],
+ ]);
$fields = CRM_Core_BAO_UFField::getAvailableFields($ufGroupId);
// Make sure that each entity has 1+ present field and 1+ missing (already-used) field
* it's already part of the profile.
*/
public function testGetAvailable_byGidDefaults() {
- $ufGroupId = $this->createUFGroup(array(
- array(
+ $ufGroupId = $this->createUFGroup([
+ [
'field_name' => 'do_not_sms',
'field_type' => 'Contact',
- ),
- array(
+ ],
+ [
'field_name' => 'first_name',
'field_type' => 'Individual',
- ),
- ));
- $defaults = array('field_name' => array('Individual', 'first_name'));
+ ],
+ ]);
+ $defaults = ['field_name' => ['Individual', 'first_name']];
$fields = CRM_Core_BAO_UFField::getAvailableFields($ufGroupId, $defaults);
// already used
$this->assertTrue(is_numeric($ufGroup->id));
foreach ($fields as $field) {
- $defaults = array(
+ $defaults = [
'uf_group_id' => $ufGroup->id,
'visibility' => 'Public Pages and Listings',
'weight' => 1,
'is_searchable' => 1,
'is_active' => 1,
'location_type_id' => NULL,
- );
+ ];
$params = array_merge($field, $defaults);
$ufField = $this->callAPISuccess('UFField', 'create', $params);
$this->assertAPISuccess($ufField);
public function testDAOs() {
$tasks = $this->findTasks('CRM_Core_CodeGen_DAO');
- $names = array();
+ $names = [];
foreach ($tasks as $task) {
/** @var CRM_Core_CodeGen_DAO $task */
$names[] = $task->name;
protected function findTasks($clazz) {
$genCode = $this->createCodeGen();
$tasks = $genCode->getTasks();
- $matches = array();
+ $matches = [];
foreach ($tasks as $task) {
if ($task instanceof $clazz) {
$matches[] = $task;
*/
public static function initWebResponses() {
if (self::$webResponses === NULL) {
- self::$webResponses = array(
- 'http-error' => array(
+ self::$webResponses = [
+ 'http-error' => [
CRM_Utils_HttpClient::STATUS_DL_ERROR,
NULL,
- ),
- 'bad-json' => array(
+ ],
+ 'bad-json' => [
CRM_Utils_HttpClient::STATUS_OK,
'<html>this is not json!</html>',
- ),
- 'invalid-ttl-document' => array(
+ ],
+ 'invalid-ttl-document' => [
CRM_Utils_HttpClient::STATUS_OK,
- json_encode(array(
+ json_encode([
// not an integer!
'ttl' => 'z',
// not an integer!
'retry' => 'z',
- 'messages' => array(
- array(
+ 'messages' => [
+ [
'markup' => '<h1>Invalid document</h1>',
- ),
- ),
- )),
- ),
- 'first-valid-response' => array(
+ ],
+ ],
+ ]),
+ ],
+ 'first-valid-response' => [
CRM_Utils_HttpClient::STATUS_OK,
- json_encode(array(
+ json_encode([
'ttl' => 600,
'retry' => 600,
- 'messages' => array(
- array(
+ 'messages' => [
+ [
'markup' => '<h1>First valid response</h1>',
- ),
- ),
- )),
- ),
- 'second-valid-response' => array(
+ ],
+ ],
+ ]),
+ ],
+ 'second-valid-response' => [
CRM_Utils_HttpClient::STATUS_OK,
- json_encode(array(
+ json_encode([
'ttl' => 600,
'retry' => 600,
- 'messages' => array(
- array(
+ 'messages' => [
+ [
'markup' => '<h1>Second valid response</h1>',
- ),
- ),
- )),
- ),
- 'two-messages' => array(
+ ],
+ ],
+ ]),
+ ],
+ 'two-messages' => [
CRM_Utils_HttpClient::STATUS_OK,
- json_encode(array(
+ json_encode([
'ttl' => 600,
'retry' => 600,
- 'messages' => array(
- array(
+ 'messages' => [
+ [
'markup' => '<h1>One</h1>',
- 'components' => array('CiviMail'),
- ),
- array(
+ 'components' => ['CiviMail'],
+ ],
+ [
'markup' => '<h1>Two</h1>',
- 'components' => array('CiviMail'),
- ),
- ),
- )),
- ),
- 'two-messages-halfbadcomp' => array(
+ 'components' => ['CiviMail'],
+ ],
+ ],
+ ]),
+ ],
+ 'two-messages-halfbadcomp' => [
CRM_Utils_HttpClient::STATUS_OK,
- json_encode(array(
+ json_encode([
'ttl' => 600,
'retry' => 600,
- 'messages' => array(
- array(
+ 'messages' => [
+ [
'markup' => '<h1>One</h1>',
- 'components' => array('NotARealComponent'),
- ),
- array(
+ 'components' => ['NotARealComponent'],
+ ],
+ [
'markup' => '<h1>Two</h1>',
- 'components' => array('CiviMail'),
- ),
- ),
- )),
- ),
- );
+ 'components' => ['CiviMail'],
+ ],
+ ],
+ ]),
+ ],
+ ];
}
return self::$webResponses;
}
public function setUp() {
parent::setUp();
- $this->cache = new CRM_Utils_Cache_Arraycache(array());
+ $this->cache = new CRM_Utils_Cache_Arraycache([]);
self::initWebResponses();
}
*/
public function badWebResponses() {
self::initWebResponses();
- $result = array(
- array(self::$webResponses['http-error']),
- array(self::$webResponses['bad-json']),
- array(self::$webResponses['invalid-ttl-document']),
- );
+ $result = [
+ [self::$webResponses['http-error']],
+ [self::$webResponses['bad-json']],
+ [self::$webResponses['invalid-ttl-document']],
+ ];
return $result;
}
$this->expectOneHttpRequest($badWebResponse)
);
$doc1 = $communityMessages->getDocument();
- $this->assertEquals(array(), $doc1['messages']);
+ $this->assertEquals([], $doc1['messages']);
$this->assertTrue($doc1['expires'] > CRM_Utils_Time::getTimeRaw());
// second try, $doc1 hasn't expired yet, so still use it
$this->expectNoHttpRequest()
);
$doc2 = $communityMessages->getDocument();
- $this->assertEquals(array(), $doc2['messages']);
+ $this->assertEquals([], $doc2['messages']);
$this->assertEquals($doc1['expires'], $doc2['expires']);
// third try, $doc1 expired, try again, get a good response
// randomly pick many times
$trials = 80;
// array($message => $count)
- $freq = array();
+ $freq = [];
for ($i = 0; $i < $trials; $i++) {
$message = $communityMessages->pick();
$freq[$message['markup']] = CRM_Utils_Array::value($message['markup'], $freq, 0) + 1;
// randomly pick many times
$trials = 10;
// array($message => $count)
- $freq = array();
+ $freq = [];
for ($i = 0; $i < $trials; $i++) {
$message = $communityMessages->pick();
$freq[$message['markup']] = CRM_Utils_Array::value($message['markup'], $freq, 0) + 1;
* because reviewers' eyes tend to gloss over `composer.lock`.
*/
public function testHardLocks() {
- $hardLocks = array(
+ $hardLocks = [
'symfony/config' => '/^v2\.8\./',
'symfony/dependency-injection' => '/^v2\.8\./',
'symfony/event-dispatcher' => '/^v2\.8\./',
'symfony/filesystem' => '/^v2\.8\./',
'symfony/finder' => '/^v2\.8\./',
'symfony/process' => '/^v2\.8\./',
- );
+ ];
$lockFile = Civi::paths()->getPath('[civicrm.root]/composer.lock');
$lock = json_decode(file_get_contents($lockFile), 1);
unset($hardLocks[$package['name']]);
}
}
- $this->assertEquals(array(), $hardLocks,
+ $this->assertEquals([], $hardLocks,
'composer.lock should have references to all hardlocks');
}
public $calls;
public function setUp() {
- $this->calls = array(
+ $this->calls = [
'civicrm_alterMailer' => 0,
'send' => 0,
- );
+ ];
parent::setUp();
}
public function testHookAlterMailer() {
$test = $this;
- $mockMailer = new CRM_Utils_FakeObject(array(
+ $mockMailer = new CRM_Utils_FakeObject([
'send' => function ($recipients, $headers, $body) use ($test) {
$test->calls['send']++;
- $test->assertEquals(array('to@example.org'), $recipients);
+ $test->assertEquals(['to@example.org'], $recipients);
$test->assertEquals('Subject Example', $headers['Subject']);
},
- ));
+ ]);
CRM_Utils_Hook::singleton()->setHook('civicrm_alterMailer',
function (&$mailer, $driver, $params) use ($test, $mockMailer) {
$test->calls['civicrm_alterMailer']++;
$test->assertTrue(is_string($driver) && !empty($driver));
$test->assertTrue(is_array($params));
- $test->assertTrue(is_callable(array($mailer, 'send')));
+ $test->assertTrue(is_callable([$mailer, 'send']));
$mailer = $mockMailer;
}
);
- $params = array();
+ $params = [];
$params['groupName'] = 'CRM_Core_Config_MailerTest';
$params['from'] = 'From Example <from@example.com>';
$params['toName'] = 'To Example';
$this->assertFalse(isset($exports['contact_id']));
// 2. Now, let's hook into it...
- $this->hookClass->setHook('civicrm_entityTypes', array($this, '_hook_civicrm_entityTypes'));
+ $this->hookClass->setHook('civicrm_entityTypes', [$this, '_hook_civicrm_entityTypes']);
unset(Civi::$statics['CRM_Core_DAO_Email']);
CRM_Core_DAO_AllCoreTables::init(1);
// Not sure how we should be setting the locales, but this works for testing purposes
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
- $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, array('en_UK', 'fr_FR'));
+ $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, ['en_UK', 'fr_FR']);
$domain->save();
// Check indices with localization
*/
public function testMultilingualize() {
// in civicrm_group, title is localizable, name is not
- $originalIndices = array(
- 'test_index1' => array(
+ $originalIndices = [
+ 'test_index1' => [
'name' => 'test_index1',
- 'field' => array(
+ 'field' => [
'name',
- ),
+ ],
'localizable' => 0,
- ),
- 'test_index2' => array(
+ ],
+ 'test_index2' => [
'name' => 'test_index2',
- 'field' => array(
+ 'field' => [
'title',
- ),
+ ],
'localizable' => 1,
- ),
- 'test_index3' => array(
+ ],
+ 'test_index3' => [
'name' => 'test_index3',
- 'field' => array(
+ 'field' => [
'name(3)',
- ),
+ ],
'localizable' => 0,
- ),
- 'test_index4' => array(
+ ],
+ 'test_index4' => [
'name' => 'test_index4',
- 'field' => array(
+ 'field' => [
'title(4)',
- ),
+ ],
'localizable' => 1,
- ),
- 'test_index5' => array(
+ ],
+ 'test_index5' => [
'name' => 'test_index5',
- 'field' => array(
+ 'field' => [
'title(4)',
'name(3)',
- ),
+ ],
'localizable' => 1,
- ),
- );
+ ],
+ ];
- $expectedIndices = array(
- 'test_index1' => array(
+ $expectedIndices = [
+ 'test_index1' => [
'name' => 'test_index1',
- 'field' => array(
+ 'field' => [
'name',
- ),
+ ],
'localizable' => 0,
'sig' => 'civicrm_group::0::name',
- ),
- 'test_index2_en_UK' => array(
+ ],
+ 'test_index2_en_UK' => [
'name' => 'test_index2_en_UK',
- 'field' => array(
+ 'field' => [
'title_en_UK',
- ),
+ ],
'localizable' => 1,
'sig' => 'civicrm_group::0::title_en_UK',
- ),
- 'test_index2_fr_FR' => array(
+ ],
+ 'test_index2_fr_FR' => [
'name' => 'test_index2_fr_FR',
- 'field' => array(
+ 'field' => [
'title_fr_FR',
- ),
+ ],
'localizable' => 1,
'sig' => 'civicrm_group::0::title_fr_FR',
- ),
- 'test_index3' => array(
+ ],
+ 'test_index3' => [
'name' => 'test_index3',
- 'field' => array(
+ 'field' => [
'name(3)',
- ),
+ ],
'localizable' => 0,
'sig' => 'civicrm_group::0::name(3)',
- ),
- 'test_index4_en_UK' => array(
+ ],
+ 'test_index4_en_UK' => [
'name' => 'test_index4_en_UK',
- 'field' => array(
+ 'field' => [
'title_en_UK(4)',
- ),
+ ],
'localizable' => 1,
'sig' => 'civicrm_group::0::title_en_UK(4)',
- ),
- 'test_index4_fr_FR' => array(
+ ],
+ 'test_index4_fr_FR' => [
'name' => 'test_index4_fr_FR',
- 'field' => array(
+ 'field' => [
'title_fr_FR(4)',
- ),
+ ],
'localizable' => 1,
'sig' => 'civicrm_group::0::title_fr_FR(4)',
- ),
- 'test_index5_en_UK' => array(
+ ],
+ 'test_index5_en_UK' => [
'name' => 'test_index5_en_UK',
- 'field' => array(
+ 'field' => [
'title_en_UK(4)',
'name(3)',
- ),
+ ],
'localizable' => 1,
'sig' => 'civicrm_group::0::title_en_UK(4)::name(3)',
- ),
- 'test_index5_fr_FR' => array(
+ ],
+ 'test_index5_fr_FR' => [
'name' => 'test_index5_fr_FR',
- 'field' => array(
+ 'field' => [
'title_fr_FR(4)',
'name(3)',
- ),
+ ],
'localizable' => 1,
'sig' => 'civicrm_group::0::title_fr_FR(4)::name(3)',
- ),
- );
+ ],
+ ];
// Not sure how we should be setting the locales, but this works for testing purposes
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
- $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, array('en_UK', 'fr_FR'));
+ $domain->locales = implode(CRM_Core_DAO::VALUE_SEPARATOR, ['en_UK', 'fr_FR']);
$domain->save();
// needs a real DAO so use Group
// Ugh. Need full bootstrap to enumerate classes.
$this->setUp();
$classList = CRM_Core_DAO_AllCoreTables::getClasses();
- $return = array();
+ $return = [];
foreach ($classList as $class) {
- $return[] = array($class);
+ $return[] = [$class];
}
return $return;
}
public function testGetReferenceColumns() {
// choose CRM_Core_DAO_Email as an arbitrary example
$emailRefs = CRM_Core_DAO_Email::getReferenceColumns();
- $refsByTarget = array();
+ $refsByTarget = [];
foreach ($emailRefs as $refSpec) {
$refsByTarget[$refSpec->getTargetTable()] = $refSpec;
}
public function testGetReferencesToTable() {
$refs = CRM_Core_DAO::getReferencesToTable(CRM_Financial_DAO_FinancialType::getTableName());
- $refsBySource = array();
+ $refsBySource = [];
foreach ($refs as $refSpec) {
$refsBySource[$refSpec->getReferenceTable()] = $refSpec;
}
}
public function testFindReferences() {
- $params = array(
+ $params = [
'first_name' => 'Testy',
'last_name' => 'McScallion',
'contact_type' => 'Individual',
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
$this->assertNotNull($contact->id);
- $params = array(
+ $params = [
'email' => 'spam@dev.null',
'contact_id' => $contact->id,
'is_primary' => 0,
'location_type_id' => 1,
- );
+ ];
$email = CRM_Core_BAO_Email::add($params);
$refs = $contact->findReferences();
- $refsByTable = array();
+ $refsByTable = [];
foreach ($refs as $refObj) {
$refsByTable[$refObj->__table] = $refObj;
}
* @return array
*/
public function composeQueryExamples() {
- $cases = array();
+ $cases = [];
// $cases[] = array('Input-SQL', 'Input-Params', 'Expected-SQL');
- $cases[0] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'String')), 'UPDATE civicrm_foo SET bar = \'\'');
- $cases[1] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('the text', 'String')), 'UPDATE civicrm_foo SET bar = \'the text\'');
- $cases[2] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'String')), self::ABORTED_SQL);
- $cases[3] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'String')), 'UPDATE civicrm_foo SET bar = NULL');
+ $cases[0] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'String']], 'UPDATE civicrm_foo SET bar = \'\''];
+ $cases[1] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['the text', 'String']], 'UPDATE civicrm_foo SET bar = \'the text\''];
+ $cases[2] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'String']], self::ABORTED_SQL];
+ $cases[3] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'String']], 'UPDATE civicrm_foo SET bar = NULL'];
- $cases[3] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'Float')), self::ABORTED_SQL);
- $cases[4] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('1.23', 'Float')), 'UPDATE civicrm_foo SET bar = 1.23');
- $cases[5] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'Float')), self::ABORTED_SQL);
- $cases[6] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'Float')), self::ABORTED_SQL);
+ $cases[3] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'Float']], self::ABORTED_SQL];
+ $cases[4] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['1.23', 'Float']], 'UPDATE civicrm_foo SET bar = 1.23'];
+ $cases[5] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'Float']], self::ABORTED_SQL];
+ $cases[6] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'Float']], self::ABORTED_SQL];
- $cases[11] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'Money')), self::ABORTED_SQL);
- $cases[12] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('1.23', 'Money')), 'UPDATE civicrm_foo SET bar = 1.23');
- $cases[13] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'Money')), self::ABORTED_SQL);
- $cases[14] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'Money')), self::ABORTED_SQL);
+ $cases[11] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'Money']], self::ABORTED_SQL];
+ $cases[12] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['1.23', 'Money']], 'UPDATE civicrm_foo SET bar = 1.23'];
+ $cases[13] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'Money']], self::ABORTED_SQL];
+ $cases[14] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'Money']], self::ABORTED_SQL];
- $cases[15] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'Int')), self::ABORTED_SQL);
- $cases[16] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('123', 'Int')), 'UPDATE civicrm_foo SET bar = 123');
- $cases[17] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'Int')), self::ABORTED_SQL);
- $cases[18] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'Int')), self::ABORTED_SQL);
+ $cases[15] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'Int']], self::ABORTED_SQL];
+ $cases[16] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['123', 'Int']], 'UPDATE civicrm_foo SET bar = 123'];
+ $cases[17] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'Int']], self::ABORTED_SQL];
+ $cases[18] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'Int']], self::ABORTED_SQL];
- $cases[19] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('', 'Timestamp')), 'UPDATE civicrm_foo SET bar = null');
- $cases[20] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('20150102030405', 'Timestamp')), 'UPDATE civicrm_foo SET bar = 20150102030405');
- $cases[21] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array(NULL, 'Timestamp')), 'UPDATE civicrm_foo SET bar = null');
- $cases[22] = array('UPDATE civicrm_foo SET bar = %1', array(1 => array('null', 'Timestamp')), self::ABORTED_SQL);
+ $cases[19] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['', 'Timestamp']], 'UPDATE civicrm_foo SET bar = null'];
+ $cases[20] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['20150102030405', 'Timestamp']], 'UPDATE civicrm_foo SET bar = 20150102030405'];
+ $cases[21] = ['UPDATE civicrm_foo SET bar = %1', [1 => [NULL, 'Timestamp']], 'UPDATE civicrm_foo SET bar = null'];
+ $cases[22] = ['UPDATE civicrm_foo SET bar = %1', [1 => ['null', 'Timestamp']], self::ABORTED_SQL];
// CASE: No params
- $cases[1000] = array(
+ $cases[1000] = [
'SELECT * FROM whatever',
- array(),
+ [],
'SELECT * FROM whatever',
- );
+ ];
// CASE: Integer param
- $cases[1001] = array(
+ $cases[1001] = [
'SELECT * FROM whatever WHERE id = %1',
- array(
- 1 => array(10, 'Integer'),
- ),
+ [
+ 1 => [10, 'Integer'],
+ ],
'SELECT * FROM whatever WHERE id = 10',
- );
+ ];
// CASE: String param
- $cases[1002] = array(
+ $cases[1002] = [
'SELECT * FROM whatever WHERE name = %1',
- array(
- 1 => array('Alice', 'String'),
- ),
+ [
+ 1 => ['Alice', 'String'],
+ ],
'SELECT * FROM whatever WHERE name = \'Alice\'',
- );
+ ];
// CASE: Two params
- $cases[1003] = array(
+ $cases[1003] = [
'SELECT * FROM whatever WHERE name = %1 AND title = %2',
- array(
- 1 => array('Alice', 'String'),
- 2 => array('Bob', 'String'),
- ),
+ [
+ 1 => ['Alice', 'String'],
+ 2 => ['Bob', 'String'],
+ ],
'SELECT * FROM whatever WHERE name = \'Alice\' AND title = \'Bob\'',
- );
+ ];
// CASE: Two params with special character (%1)
- $cases[1004] = array(
+ $cases[1004] = [
'SELECT * FROM whatever WHERE name = %1 AND title = %2',
- array(
- 1 => array('Alice %2', 'String'),
- 2 => array('Bob', 'String'),
- ),
+ [
+ 1 => ['Alice %2', 'String'],
+ 2 => ['Bob', 'String'],
+ ],
'SELECT * FROM whatever WHERE name = \'Alice %2\' AND title = \'Bob\'',
- );
+ ];
// CASE: Two params with special character ($1)
- $cases[1005] = array(
+ $cases[1005] = [
'SELECT * FROM whatever WHERE name = %1 AND title = %2',
- array(
- 1 => array('Alice $1', 'String'),
- 2 => array('Bob', 'String'),
- ),
+ [
+ 1 => ['Alice $1', 'String'],
+ 2 => ['Bob', 'String'],
+ ],
'SELECT * FROM whatever WHERE name = \'Alice $1\' AND title = \'Bob\'',
- );
+ ];
return $cases;
}
* i.e. the place holder should be unique and should not contain in any other operational use in query
*/
public function testComposeQueryFailure() {
- $cases[] = array(
+ $cases[] = [
'SELECT * FROM whatever WHERE name = %1 AND title = %2 AND year LIKE \'%2012\' ',
- array(
- 1 => array('Alice', 'String'),
- 2 => array('Bob', 'String'),
- ),
+ [
+ 1 => ['Alice', 'String'],
+ 2 => ['Bob', 'String'],
+ ],
'SELECT * FROM whatever WHERE name = \'Alice\' AND title = \'Bob\' AND year LIKE \'%2012\' ',
- );
+ ];
list($inputSql, $inputParams, $expectSql) = $cases[0];
$actualSql = CRM_Core_DAO::composeQuery($inputSql, $inputParams);
$this->assertFalse(($expectSql == $actualSql));
* @return array
*/
public function sqlNameDataProvider() {
- return array(
- array('this is a long string', 30, FALSE, 'this is a long string'),
- array(
+ return [
+ ['this is a long string', 30, FALSE, 'this is a long string'],
+ [
'this is an even longer string which is exactly 60 character',
60,
FALSE,
'this is an even longer string which is exactly 60 character',
- ),
- array(
+ ],
+ [
'this is an even longer string which is exactly 60 character',
60,
TRUE,
'this is an even longer string which is exactly 60 character',
- ),
- array(
+ ],
+ [
'this is an even longer string which is a bit more than 60 character',
60,
FALSE,
'this is an even longer string which is a bit more than 60 ch',
- ),
- array(
+ ],
+ [
'this is an even longer string which is a bit more than 60 character',
60,
TRUE,
'this is an even longer string which is a bit more th_c1cbd519',
- ),
- );
+ ],
+ ];
}
/**
* requireSafeDBName() method (to check valid database name)
*/
public function testRequireSafeDBName() {
- $databases = array(
+ $databases = [
'testdb' => TRUE,
'test_db' => TRUE,
'TEST_db' => TRUE,
'testdb;Delete test' => FALSE,
'123456' => FALSE,
'test#$%^&*' => FALSE,
- );
- $testDetails = array();
+ ];
+ $testDetails = [];
foreach ($databases as $database => $val) {
$this->assertEquals(CRM_Core_DAO::requireSafeDBName($database), $val);
}
*/
public function testDAOtoArray() {
$format = 'user[%s]';
- $params = array(
+ $params = [
'first_name' => 'Testy',
'last_name' => 'McScallion',
'contact_type' => 'Individual',
- );
+ ];
$dao = CRM_Contact_BAO_Contact::add($params);
$query = "SELECT contact_type, display_name FROM civicrm_contact WHERE id={$dao->id}";
- $toArray = array(
+ $toArray = [
'contact_type' => 'Individual',
'display_name' => 'Testy McScallion',
- );
- $modifiedKeyArray = array();
+ ];
+ $modifiedKeyArray = [];
foreach ($toArray as $k => $v) {
$modifiedKeyArray[sprintf($format, $k)] = $v;
}
* CRM-17748: Test internal DAO options
*/
public function testDBOptions() {
- $contactIDs = array();
+ $contactIDs = [];
for ($i = 0; $i < 10; $i++) {
- $contactIDs[] = $this->individualCreate(array(
+ $contactIDs[] = $this->individualCreate([
'first_name' => 'Alan' . substr(sha1(rand()), 0, 7),
'last_name' => 'Smith' . substr(sha1(rand()), 0, 4),
- ));
+ ]);
}
// Test option 'result_buffering'
// cleanup
foreach ($contactIDs as $contactID) {
- $this->callAPISuccess('Contact', 'delete', array('id' => $contactID));
+ $this->callAPISuccess('Contact', 'delete', ['id' => $contactID]);
}
}
* @return array
*/
public function serializationMethods() {
- $constants = array();
- $simpleData = array(
+ $constants = [];
+ $simpleData = [
NULL,
- array('Foo', 'Bar', '3', '4', '5'),
- array(),
- array('0'),
- );
- $complexData = array(
- array(
+ ['Foo', 'Bar', '3', '4', '5'],
+ [],
+ ['0'],
+ ];
+ $complexData = [
+ [
'foo' => 'bar',
- 'baz' => array('1', '2', '3', array('one', 'two')),
+ 'baz' => ['1', '2', '3', ['one', 'two']],
'3' => '0',
- ),
- );
+ ],
+ ];
$daoInfo = new ReflectionClass('CRM_Core_DAO');
foreach ($daoInfo->getConstants() as $constant => $val) {
if ($constant == 'SERIALIZE_JSON' || $constant == 'SERIALIZE_PHP') {
- $constants[] = array($val, array_merge($simpleData, $complexData));
+ $constants[] = [$val, array_merge($simpleData, $complexData)];
}
elseif (strpos($constant, 'SERIALIZE_') === 0) {
- $constants[] = array($val, $simpleData);
+ $constants[] = [$val, $simpleData];
}
}
return $constants;
public function setUp() {
parent::setUp();
- CRM_Utils_Hook::singleton()->setHook('civicrm_fieldOptions', array($this, 'hook_civicrm_fieldOptions'));
+ CRM_Utils_Hook::singleton()->setHook('civicrm_fieldOptions', [$this, 'hook_civicrm_fieldOptions']);
}
public function tearDown() {
parent::tearDown();
- $this->quickCleanup(array('civicrm_custom_field', 'civicrm_custom_group'));
+ $this->quickCleanup(['civicrm_custom_field', 'civicrm_custom_group']);
}
/**
* - exclude: Any one value which should not be in the list.
* - max: integer (default = 10) maximum number of option values expected.
*/
- $fields = array(
- 'CRM_Core_BAO_Address' => array(
- array(
+ $fields = [
+ 'CRM_Core_BAO_Address' => [
+ [
'fieldName' => 'state_province_id',
'sample' => 'California',
'max' => 60,
- 'props' => array('country_id' => 1228),
- ),
- ),
- 'CRM_Contact_BAO_Contact' => array(
- array(
+ 'props' => ['country_id' => 1228],
+ ],
+ ],
+ 'CRM_Contact_BAO_Contact' => [
+ [
'fieldName' => 'contact_sub_type',
'sample' => 'Team',
'exclude' => 'Organization',
- 'props' => array('contact_type' => 'Organization'),
- ),
- ),
- );
+ 'props' => ['contact_type' => 'Organization'],
+ ],
+ ],
+ ];
foreach ($fields as $baoName => $baoFields) {
foreach ($baoFields as $field) {
$message = "BAO name: '{$baoName}', field: '{$field['fieldName']}'";
- $props = CRM_Utils_Array::value('props', $field, array());
+ $props = CRM_Utils_Array::value('props', $field, []);
$optionValues = $baoName::buildOptions($field['fieldName'], 'create', $props);
$this->assertNotEmpty($optionValues, $message);
// Test replacing all options with a hook
$this->targetField = 'case_type_id';
- $this->replaceOptions = array('foo' => 'Foo', 'bar' => 'Bar');
- $result = $this->callAPISuccess('case', 'getoptions', array('field' => 'case_type_id'));
+ $this->replaceOptions = ['foo' => 'Foo', 'bar' => 'Bar'];
+ $result = $this->callAPISuccess('case', 'getoptions', ['field' => 'case_type_id']);
$this->assertEquals($result['values'], $this->replaceOptions);
// TargetField doesn't match - should get unmodified option list
// This time we should get foo bar appended to the list
$this->targetField = 'gender_id';
- $this->appendOptions = array('foo' => 'Foo', 'bar' => 'Bar');
+ $this->appendOptions = ['foo' => 'Foo', 'bar' => 'Bar'];
$this->replaceOptions = NULL;
CRM_Core_PseudoConstant::flush();
$result = CRM_Contact_BAO_Contact::buildOptions('gender_id');
public function testHookFieldOptionsWithCustomFields() {
// Create a custom field group for testing.
$custom_group_name = md5(microtime());
- $api_params = array(
+ $api_params = [
'title' => $custom_group_name,
'extends' => 'Individual',
'is_active' => TRUE,
- );
+ ];
$customGroup = $this->callAPISuccess('customGroup', 'create', $api_params);
// Add a custom select field.
- $api_params = array(
+ $api_params = [
'custom_group_id' => $customGroup['id'],
'label' => $custom_group_name . 1,
'html_type' => 'Select',
'data_type' => 'String',
- 'option_values' => array(
+ 'option_values' => [
'foo' => 'Foo',
'bar' => 'Bar',
- ),
- );
+ ],
+ ];
$result = $this->callAPISuccess('custom_field', 'create', $api_params);
$customField1 = $result['id'];
// Add a custom country field.
- $api_params = array(
+ $api_params = [
'custom_group_id' => $customGroup['id'],
'label' => $custom_group_name . 2,
'html_type' => 'Select Country',
'data_type' => 'Country',
- );
+ ];
$result = $this->callAPISuccess('custom_field', 'create', $api_params);
$customField2 = $result['id'];
// Add a custom boolean field.
- $api_params = array(
+ $api_params = [
'custom_group_id' => $customGroup['id'],
'label' => $custom_group_name . 3,
'html_type' => 'Radio',
'data_type' => 'Boolean',
- );
+ ];
$result = $this->callAPISuccess('custom_field', 'create', $api_params);
$customField3 = $result['id'];
$this->targetField = 'custom_' . $customField1;
$this->replaceOptions = NULL;
- $this->appendOptions = array('baz' => 'Baz');
+ $this->appendOptions = ['baz' => 'Baz'];
$field = new CRM_Core_BAO_CustomField();
$field->id = $customField1;
- $this->assertEquals(array('foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'), $field->getOptions());
+ $this->assertEquals(['foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'], $field->getOptions());
$this->targetField = 'custom_' . $customField2;
- $this->replaceOptions = array('nowhere' => 'Nowhere');
+ $this->replaceOptions = ['nowhere' => 'Nowhere'];
$field = new CRM_Core_BAO_CustomField();
$field->id = $customField2;
$this->assertEquals($this->replaceOptions + $this->appendOptions, $field->getOptions());
$this->targetField = 'custom_' . $customField3;
$this->replaceOptions = NULL;
- $this->appendOptions = array(2 => 'Maybe');
+ $this->appendOptions = [2 => 'Maybe'];
$options = CRM_Core_PseudoConstant::get('CRM_Core_BAO_CustomField', $this->targetField);
- $this->assertEquals(array(1 => 'Yes', 0 => 'No', 2 => 'Maybe'), $options);
+ $this->assertEquals([1 => 'Yes', 0 => 'No', 2 => 'Maybe'], $options);
}
/**
* @return array
*/
public static function translateTables() {
- $tables = array();
- $tables[] = array('civicrm_option_group', 'civicrm_option_group_en_US');
- $tables[] = array('civicrm_events_in_carts', 'civicrm_events_in_carts');
- $tables[] = array('civicrm_event', 'civicrm_event_en_US');
+ $tables = [];
+ $tables[] = ['civicrm_option_group', 'civicrm_option_group_en_US'];
+ $tables[] = ['civicrm_events_in_carts', 'civicrm_events_in_carts'];
+ $tables[] = ['civicrm_event', 'civicrm_event_en_US'];
return $tables;
}
public function testI18nSchemaRewrite($table, $expectedRewrite) {
CRM_Core_I18n_Schema::makeMultilingual('en_US');
$skip_tests = FALSE;
- if (in_array($table, array('civicrm_option_group', 'civicrm_event'))) {
+ if (in_array($table, ['civicrm_option_group', 'civicrm_event'])) {
$skip_tests = TRUE;
}
global $dbLocale;
// May or may not cleanup well if there's a bug in the indexer.
// This is better than nothing -- and better than duplicating the
// cleanup logic.
- $idx = new CRM_Core_InnoDBIndexer(FALSE, array());
+ $idx = new CRM_Core_InnoDBIndexer(FALSE, []);
$idx->fixSchemaDifferences();
parent::tearDown();
}
public function testHasDeclaredIndex() {
- $idx = new CRM_Core_InnoDBIndexer(TRUE, array(
- 'civicrm_contact' => array(
- array('first_name', 'last_name'),
- array('foo'),
- ),
- 'civicrm_email' => array(
- array('whiz'),
- ),
- ));
+ $idx = new CRM_Core_InnoDBIndexer(TRUE, [
+ 'civicrm_contact' => [
+ ['first_name', 'last_name'],
+ ['foo'],
+ ],
+ 'civicrm_email' => [
+ ['whiz'],
+ ],
+ ]);
- $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('first_name', 'last_name')));
- $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('last_name', 'first_name')));
+ $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['first_name', 'last_name']));
+ $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['last_name', 'first_name']));
// not sure if this is right behavior
- $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('first_name')));
+ $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['first_name']));
// not sure if this is right behavior
- $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('last_name')));
- $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('foo')));
- $this->assertFalse($idx->hasDeclaredIndex('civicrm_contact', array('whiz')));
+ $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['last_name']));
+ $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['foo']));
+ $this->assertFalse($idx->hasDeclaredIndex('civicrm_contact', ['whiz']));
- $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('first_name', 'last_name')));
- $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('foo')));
- $this->assertTrue($idx->hasDeclaredIndex('civicrm_email', array('whiz')));
+ $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', ['first_name', 'last_name']));
+ $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', ['foo']));
+ $this->assertTrue($idx->hasDeclaredIndex('civicrm_email', ['whiz']));
}
/**
* When disabled, there is no FTS index, so queries that rely on FTS index fail.
*/
public function testDisabled() {
- $idx = new CRM_Core_InnoDBIndexer(FALSE, array(
- 'civicrm_contact' => array(
- array('first_name', 'last_name'),
- ),
- ));
+ $idx = new CRM_Core_InnoDBIndexer(FALSE, [
+ 'civicrm_contact' => [
+ ['first_name', 'last_name'],
+ ],
+ ]);
$idx->fixSchemaDifferences();
try {
return;
}
- $idx = new CRM_Core_InnoDBIndexer(TRUE, array(
- 'civicrm_contact' => array(
- array('first_name', 'last_name'),
- ),
- ));
+ $idx = new CRM_Core_InnoDBIndexer(TRUE, [
+ 'civicrm_contact' => [
+ ['first_name', 'last_name'],
+ ],
+ ]);
$idx->fixSchemaDifferences();
CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")');
public function setUp() {
$this->useTransaction(TRUE);
parent::setUp();
- $this->modules = array(
+ $this->modules = [
'one' => new CRM_Core_Module('com.example.one', TRUE),
'two' => new CRM_Core_Module('com.example.two', TRUE),
- );
+ ];
// Testing on drupal-demo fails because some extensions have mgd ents.
CRM_Core_DAO::singleValueQuery('DELETE FROM civicrm_managed');
- $this->fixtures['com.example.one-foo'] = array(
+ $this->fixtures['com.example.one-foo'] = [
'module' => 'com.example.one',
'name' => 'foo',
'entity' => 'CustomSearch',
- 'params' => array(
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Foo',
'is_reserved' => 1,
- ),
- );
- $this->fixtures['com.example.one-bar'] = array(
+ ],
+ ];
+ $this->fixtures['com.example.one-bar'] = [
'module' => 'com.example.one',
'name' => 'bar',
'entity' => 'CustomSearch',
- 'params' => array(
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Bar',
'is_reserved' => 1,
- ),
- );
- $this->fixtures['com.example.one-CustomGroup'] = array(
+ ],
+ ];
+ $this->fixtures['com.example.one-CustomGroup'] = [
'module' => 'com.example.one',
'name' => 'CustomGroup',
'entity' => 'CustomGroup',
- 'params' => array(
+ 'params' => [
'version' => 3,
'name' => 'test_custom_group',
'title' => 'Test custom group',
'extends' => 'Individual',
- ),
- );
- $this->fixtures['com.example.one-CustomField'] = array(
+ ],
+ ];
+ $this->fixtures['com.example.one-CustomField'] = [
'module' => 'com.example.one',
'name' => 'CustomField',
'entity' => 'CustomField',
- 'params' => array(
+ 'params' => [
'version' => 3,
'name' => 'test_custom_field',
'label' => 'Test custom field',
'custom_group_id' => 'test_custom_group',
'data_type' => 'String',
'html_type' => 'Text',
- ),
- );
+ ],
+ ];
$this->apiKernel = \Civi::service('civi_api_kernel');
$this->adhocProvider = new \Civi\API\Provider\AdhocProvider(3, 'CustomSearch');
* entity
*/
public function testAddRemoveEntitiesModule_UpdateAlways_DeleteAlways() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
$decls[] = $this->fixtures['com.example.one-foo'];
* time, the content of the entity changes
*/
public function testModifyDeclaration_UpdateAlways() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
$decls[] = $this->fixtures['com.example.one-foo'];
* time, the content of the entity changes
*/
public function testModifyDeclaration_UpdateNever() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
- $decls[] = array_merge($this->fixtures['com.example.one-foo'], array(
+ $decls[] = array_merge($this->fixtures['com.example.one-foo'], [
// Policy is to never update after initial creation
'update' => 'never',
- ));
+ ]);
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo = $me->get('com.example.one', 'foo');
* deleted).
*/
public function testRemoveDeclaration_CleanupNever() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
- $decls[] = array_merge($this->fixtures['com.example.one-foo'], array(
+ $decls[] = array_merge($this->fixtures['com.example.one-foo'], [
'cleanup' => 'never',
- ));
+ ]);
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo = $me->get('com.example.one', 'foo');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Example_One_Foo"');
// later on, entity definition disappears; but we decide not to do any cleanup (per policy)
- $decls = array();
+ $decls = [];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo2 = $me->get('com.example.one', 'foo');
* deleted).
*/
public function testRemoveDeclaration_CleanupUnused() {
- $decls = array();
+ $decls = [];
// create first managed entity ('foo')
- $decls[] = array_merge($this->fixtures['com.example.one-foo'], array(
+ $decls[] = array_merge($this->fixtures['com.example.one-foo'], [
'cleanup' => 'unused',
- ));
+ ]);
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo = $me->get('com.example.one', 'foo');
// Override 'getrefcount' ==> The refcount is 1
$this->adhocProvider->addAction('getrefcount', 'access CiviCRM', function ($apiRequest) {
- return civicrm_api3_create_success(array(
- array(
+ return civicrm_api3_create_success([
+ [
'name' => 'mock',
'type' => 'mock',
'count' => 1,
- ),
- ));
+ ],
+ ]);
});
// Later on, entity definition disappears; but we decide not to do any cleanup (per policy)
- $decls = array();
+ $decls = [];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo2 = $me->get('com.example.one', 'foo');
// Override 'getrefcount' ==> The refcount is 0
$this->adhocProvider->addAction('getrefcount', 'access CiviCRM', function ($apiRequest) {
- return civicrm_api3_create_success(array());
+ return civicrm_api3_create_success([]);
});
// The entity definition disappeared and there's no reference; we decide to cleanup (per policy)
- $decls = array();
+ $decls = [];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
$foo3 = $me->get('com.example.one', 'foo');
*/
public function testInvalidDeclarationModule() {
// create first managed entity ('foo')
- $decls = array();
- $decls[] = array(
+ $decls = [];
+ $decls[] = [
// erroneous
'module' => 'com.example.unknown',
'name' => 'foo',
'entity' => 'CustomSearch',
- 'params' => array(
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Foo',
'is_reserved' => 1,
- ),
- );
+ ],
+ ];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
try {
$me->reconcile();
*/
public function testMissingName() {
// create first managed entity ('foo')
- $decls = array();
- $decls[] = array(
+ $decls = [];
+ $decls[] = [
'module' => 'com.example.unknown',
// erroneous
'name' => NULL,
'entity' => 'CustomSearch',
- 'params' => array(
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Foo',
'is_reserved' => 1,
- ),
- );
+ ],
+ ];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
try {
$me->reconcile();
*/
public function testMissingEntity() {
// create first managed entity ('foo')
- $decls = array();
- $decls[] = array(
+ $decls = [];
+ $decls[] = [
'module' => 'com.example.unknown',
'name' => 'foo',
// erroneous
'entity' => NULL,
- 'params' => array(
+ 'params' => [
'version' => 3,
'class_name' => 'CRM_Example_One_Foo',
'is_reserved' => 1,
- ),
- );
+ ],
+ ];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
try {
$me->reconcile();
*/
public function testDeactivateReactivateModule() {
// create first managed entity ('foo')
- $decls = array();
+ $decls = [];
$decls[] = $this->fixtures['com.example.one-foo'];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
// now deactivate module, which has empty decls and which cascades to managed object
$this->modules['one']->is_active = FALSE;
- $me = new CRM_Core_ManagedEntities($this->modules, array());
+ $me = new CRM_Core_ManagedEntities($this->modules, []);
$me->reconcile();
$foo = $me->get('com.example.one', 'foo');
$this->assertEquals(0, $foo['is_active']);
*/
public function testUninstallModule() {
// create first managed entity ('foo')
- $decls = array();
+ $decls = [];
$decls[] = $this->fixtures['com.example.one-foo'];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
$me->reconcile();
// then destroy module; note that decls go away
unset($this->modules['one']);
- $me = new CRM_Core_ManagedEntities($this->modules, array());
+ $me = new CRM_Core_ManagedEntities($this->modules, []);
$me->reconcile();
$fooNew = $me->get('com.example.one', 'foo');
$this->assertTrue(NULL === $fooNew);
public function testDependentEntitiesUninstallCleanly() {
// Install a module with two dependent managed entities
- $decls = array();
+ $decls = [];
$decls[] = $this->fixtures['com.example.one-CustomGroup'];
$decls[] = $this->fixtures['com.example.one-CustomField'];
$me = new CRM_Core_ManagedEntities($this->modules, $decls);
</menu>
';
$xml = simplexml_load_string($xmlString);
- $menu = array();
+ $menu = [];
CRM_Core_Menu::readXML($xml, $menu);
$this->assertTrue(isset($menu['civicrm/foo/bar']));
$this->assertEquals('Foo Bar', $menu['civicrm/foo/bar']['title']);
</menu>
';
$xml = simplexml_load_string($xmlString);
- $menu = array();
+ $menu = [];
CRM_Core_Menu::readXML($xml, $menu);
$this->assertTrue(isset($menu['civicrm/foo/bar']));
$this->assertEquals('Foo Bar', $menu['civicrm/foo/bar']['title']);
- $this->assertEquals(array('alpha', 'beta'), $menu['civicrm/foo/bar']['ids_arguments']['json']);
- $this->assertEquals(array('gamma'), $menu['civicrm/foo/bar']['ids_arguments']['exceptions']);
- $this->assertEquals(array(), $menu['civicrm/foo/bar']['ids_arguments']['html']);
+ $this->assertEquals(['alpha', 'beta'], $menu['civicrm/foo/bar']['ids_arguments']['json']);
+ $this->assertEquals(['gamma'], $menu['civicrm/foo/bar']['ids_arguments']['exceptions']);
+ $this->assertEquals([], $menu['civicrm/foo/bar']['ids_arguments']['html']);
$idsConfig = CRM_Core_IDS::createRouteConfig($menu['civicrm/foo/bar']);
// XML
*/
public function pathArguments() {
// array(0 => string $input, 1 => array $expectedOutput)
- $cases = array();
+ $cases = [];
//$cases[] = array(NULL, array());
//$cases[] = array('', array());
//$cases[] = array('freestanding', array('freestanding' => NULL));
- $cases[] = array('addSequence=1', array('addSequence' => '1'));
- $cases[] = array('attachUpload=1', array('attachUpload' => '1'));
- $cases[] = array('mode=256', array('mode' => '256'));
- $cases[] = array(
+ $cases[] = ['addSequence=1', ['addSequence' => '1']];
+ $cases[] = ['attachUpload=1', ['attachUpload' => '1']];
+ $cases[] = ['mode=256', ['mode' => '256']];
+ $cases[] = [
'mode=256,addSequence=1,attachUpload=1',
- array('mode' => '256', 'addSequence' => '1', 'attachUpload' => 1),
- );
- $cases[] = array(
+ ['mode' => '256', 'addSequence' => '1', 'attachUpload' => 1],
+ ];
+ $cases[] = [
'mode=256,urlToSession=a:b:c:d',
- array(
+ [
'mode' => '256',
- 'urlToSession' => array(
- array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'),
- ),
- ),
- );
- $cases[] = array(
+ 'urlToSession' => [
+ ['urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'],
+ ],
+ ],
+ ];
+ $cases[] = [
'mode=256,urlToSession=a:b:c:d;z:y:x:w',
- array(
+ [
'mode' => '256',
- 'urlToSession' => array(
- array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'),
- array('urlVar' => 'z', 'sessionVar' => 'y', 'type' => 'x', 'default' => 'w'),
- ),
- ),
- );
- $cases[] = array('url=whiz!;.:#=%/|+bang?', array('url' => 'whiz!;.:#=%/|+bang?'));
+ 'urlToSession' => [
+ ['urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'],
+ ['urlVar' => 'z', 'sessionVar' => 'y', 'type' => 'x', 'default' => 'w'],
+ ],
+ ],
+ ];
+ $cases[] = ['url=whiz!;.:#=%/|+bang?', ['url' => 'whiz!;.:#=%/|+bang?']];
return $cases;
}
* Ensure only one option value exists after calling ensureOptionValueExists.
*/
public function testWeightOptionGroup() {
- $values = array();
+ $values = [];
$options1 = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, NULL, 'label', FALSE);
$options2 = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, NULL, 'label', FALSE, FALSE, 'value', 'name');
// Verify that arrays are equal.
* @return array
*/
public function optionGroupTests() {
- $tests = array();
- $tests[] = array('event_type', 'Integer');
- $tests[] = array('addressee', 'null');
- $tests[] = array('activity_status', 'Integer');
+ $tests = [];
+ $tests[] = ['event_type', 'Integer'];
+ $tests[] = ['addressee', 'null'];
+ $tests[] = ['activity_status', 'Integer'];
return $tests;
}
}
public function emailAddressTests() {
- $tests[] = array('"Name"<email@example.com>', '"Name" <email@example.com>');
- $tests[] = array('"Name" <email@example.com>', '"Name" <email@example.com>');
- $tests[] = array('"Name" <email@example.com>', '"Name" <email@example.com>');
+ $tests[] = ['"Name"<email@example.com>', '"Name" <email@example.com>'];
+ $tests[] = ['"Name" <email@example.com>', '"Name" <email@example.com>'];
+ $tests[] = ['"Name" <email@example.com>', '"Name" <email@example.com>'];
return $tests;
}
class CRM_Core_Page_AJAXTest extends CiviUnitTestCase {
public function testCheckAuthz() {
- $cases = array();
+ $cases = [];
- $cases[] = array('method', 'CRM_Foo', FALSE, 'method');
- $cases[] = array('method', 'CRM_Foo_Page_AJAX_Bar', FALSE, 'method');
- $cases[] = array('method', 'CRM_Contact_Page_AJAX', TRUE, 'getAddressDisplay');
- $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method(');
- $cases[] = array('method', 'CRM_Foo_Page_AJAX', FALSE, 'method()');
- $cases[] = array('method', 'othermethod;CRM_Foo_Page_AJAX', FALSE, 'method');
- $cases[] = array('method', 'CRM_Foo_Page_AJAX;othermethod', FALSE, 'method');
- $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, '');
- $cases[] = array('method', 'CRM_Foo_Page_Inline_Bar', FALSE, 'method');
- $cases[] = array('method', 'CRM_Foo->method', FALSE);
+ $cases[] = ['method', 'CRM_Foo', FALSE, 'method'];
+ $cases[] = ['method', 'CRM_Foo_Page_AJAX_Bar', FALSE, 'method'];
+ $cases[] = ['method', 'CRM_Contact_Page_AJAX', TRUE, 'getAddressDisplay'];
+ $cases[] = ['method', 'CRM_Foo_Page_AJAX', FALSE, 'method('];
+ $cases[] = ['method', 'CRM_Foo_Page_AJAX', FALSE, 'method()'];
+ $cases[] = ['method', 'othermethod;CRM_Foo_Page_AJAX', FALSE, 'method'];
+ $cases[] = ['method', 'CRM_Foo_Page_AJAX;othermethod', FALSE, 'method'];
+ $cases[] = ['method', 'CRM_Foo_Page_Inline_Bar', FALSE, ''];
+ $cases[] = ['method', 'CRM_Foo_Page_Inline_Bar', FALSE, 'method'];
+ $cases[] = ['method', 'CRM_Foo->method', FALSE];
- $cases[] = array('page', 'CRM_Foo', FALSE);
- $cases[] = array('page', 'CRM_Foo_Bar', FALSE);
- $cases[] = array('page', 'CRM_Foo_Page', FALSE);
- $cases[] = array('page', 'CRM_Foo_Page_Bar', FALSE);
- $cases[] = array('page', 'CRM_Foo_Page_Inline', FALSE);
- $cases[] = array('page', 'CRM_Contact_Page_Inline_CommunicationPreferences', TRUE);
- $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar_Bang', FALSE);
- $cases[] = array('page', 'othermethod;CRM_Foo_Page_Inline_Bar', FALSE);
- $cases[] = array('page', 'CRM_Foo_Page_Inline_Bar;othermethod', FALSE);
- $cases[] = array('page', 'CRM_Foo_Form', FALSE);
- $cases[] = array('page', 'CRM_Foo_Form_Bar', FALSE);
- $cases[] = array('page', 'CRM_Foo_Form_Inline', FALSE);
- $cases[] = array('page', 'CRM_Contact_Form_Inline_Email', TRUE);
- $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar_Bang', FALSE);
- $cases[] = array('page', 'othermethod;CRM_Foo_Form_Inline_Bar', FALSE);
- $cases[] = array('page', 'CRM_Foo_Form_Inline_Bar;othermethod', FALSE);
+ $cases[] = ['page', 'CRM_Foo', FALSE];
+ $cases[] = ['page', 'CRM_Foo_Bar', FALSE];
+ $cases[] = ['page', 'CRM_Foo_Page', FALSE];
+ $cases[] = ['page', 'CRM_Foo_Page_Bar', FALSE];
+ $cases[] = ['page', 'CRM_Foo_Page_Inline', FALSE];
+ $cases[] = ['page', 'CRM_Contact_Page_Inline_CommunicationPreferences', TRUE];
+ $cases[] = ['page', 'CRM_Foo_Page_Inline_Bar_Bang', FALSE];
+ $cases[] = ['page', 'othermethod;CRM_Foo_Page_Inline_Bar', FALSE];
+ $cases[] = ['page', 'CRM_Foo_Page_Inline_Bar;othermethod', FALSE];
+ $cases[] = ['page', 'CRM_Foo_Form', FALSE];
+ $cases[] = ['page', 'CRM_Foo_Form_Bar', FALSE];
+ $cases[] = ['page', 'CRM_Foo_Form_Inline', FALSE];
+ $cases[] = ['page', 'CRM_Contact_Form_Inline_Email', TRUE];
+ $cases[] = ['page', 'CRM_Foo_Form_Inline_Bar_Bang', FALSE];
+ $cases[] = ['page', 'othermethod;CRM_Foo_Form_Inline_Bar', FALSE];
+ $cases[] = ['page', 'CRM_Foo_Form_Inline_Bar;othermethod', FALSE];
// aliases for 'page'
- $cases[] = array('class', 'CRM_Foo_Bar', FALSE);
- $cases[] = array('class', 'CRM_Contact_Page_Inline_Phone', TRUE);
- $cases[] = array('', 'CRM_Foo_Bar', FALSE);
- $cases[] = array('', 'CRM_Contact_Page_Inline_Demographics', TRUE);
+ $cases[] = ['class', 'CRM_Foo_Bar', FALSE];
+ $cases[] = ['class', 'CRM_Contact_Page_Inline_Phone', TRUE];
+ $cases[] = ['', 'CRM_Foo_Bar', FALSE];
+ $cases[] = ['', 'CRM_Contact_Page_Inline_Demographics', TRUE];
// invalid type
- $cases[] = array('invalidtype', 'CRM_Foo_Page_Inline_Bar', FALSE);
- $cases[] = array('invalidtype', 'CRM_Foo_Page_AJAX::method', FALSE);
+ $cases[] = ['invalidtype', 'CRM_Foo_Page_Inline_Bar', FALSE];
+ $cases[] = ['invalidtype', 'CRM_Foo_Page_AJAX::method', FALSE];
foreach ($cases as $case) {
list ($type, $className, $expectedResult) = $case;
*
* @var array
*/
- public $basicPages = array();
+ public $basicPages = [];
/**
* A place to hold the counts of hook invocations.
*
* @var array
*/
- public $hookCount = array();
+ public $hookCount = [];
/**
* Classes that should be skipped
*
* @var array
*/
- public $skip = array(
+ public $skip = [
'CRM_Contact_Page_DedupeFind',
'CRM_Mailing_Page_Report',
'CRM_Financial_Page_BatchTransaction',
'CRM_Admin_Page_LabelFormats',
// This is a page with no corresponding form:
'CRM_Admin_Page_EventTemplate',
- );
+ ];
/**
* Set up the list of pages to evaluate by going through the menu.
* Make sure form hooks are only invoked once.
*/
public function testFormsCallBuildFormOnce() {
- CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_buildForm', array($this, 'onBuildForm'));
- CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_preProcess', array($this, 'onPreProcess'));
- $_REQUEST = array('action' => 'add');
+ CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_buildForm', [$this, 'onBuildForm']);
+ CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_preProcess', [$this, 'onPreProcess']);
+ $_REQUEST = ['action' => 'add'];
foreach ($this->basicPages as $pageName) {
// Reset the counters
- $this->hookCount = array(
- 'buildForm' => array(),
- 'preProcess' => array(),
- );
+ $this->hookCount = [
+ 'buildForm' => [],
+ 'preProcess' => [],
+ ];
$page = new $pageName();
ob_start();
$page->run();
* Make sure pageRun hook is only invoked once.
*/
public function testPagesCallPageRunOnce() {
- CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_pageRun', array($this, 'onPageRun'));
- $_REQUEST = array('action' => 'browse');
+ CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_pageRun', [$this, 'onPageRun']);
+ $_REQUEST = ['action' => 'browse'];
foreach ($this->basicPages as $pageName) {
// Reset the counters
- $this->hookCount = array('pageRun' => array());
+ $this->hookCount = ['pageRun' => []];
$page = new $pageName();
ob_start();
$page->run();
* @return array
*/
public function examples() {
- $cases = array();
+ $cases = [];
// $cases[] = array(string $requestPath, string $requestArgs, string $pageArgs, string $expectedUrl)
// Note: CRM_Utils_System::url() and CRM_Utils_System::redirect() represent the
// URL in "htmlized" format, so the $expectedUrl is "htmlized".
- $cases[] = array('', '', 'url=civicrm/dashboard', '/index.php?q=civicrm/dashboard');
- $cases[] = array('', '', 'url=civicrm/dashboard,mode=256', '/index.php?q=civicrm/dashboard');
- $cases[] = array('', '', 'url=civicrm/a/#/foo/bar', '/index.php?q=civicrm/a/#/foo/bar');
- $cases[] = array('', '', 'url=civicrm/foo/bar?whiz=1&bang=2', '/index.php?q=civicrm/foo/bar&whiz=1&bang=2');
- $cases[] = array('', '', 'url=civicrm/foo?unknown=%%unknown%%', '/index.php?q=civicrm/foo&unknown=');
- $cases[] = array('civicrm/foo/bar', '', 'url=civicrm/a/#/%%2%%', '/index.php?q=civicrm/a/#/bar');
+ $cases[] = ['', '', 'url=civicrm/dashboard', '/index.php?q=civicrm/dashboard'];
+ $cases[] = ['', '', 'url=civicrm/dashboard,mode=256', '/index.php?q=civicrm/dashboard'];
+ $cases[] = ['', '', 'url=civicrm/a/#/foo/bar', '/index.php?q=civicrm/a/#/foo/bar'];
+ $cases[] = ['', '', 'url=civicrm/foo/bar?whiz=1&bang=2', '/index.php?q=civicrm/foo/bar&whiz=1&bang=2'];
+ $cases[] = ['', '', 'url=civicrm/foo?unknown=%%unknown%%', '/index.php?q=civicrm/foo&unknown='];
+ $cases[] = ['civicrm/foo/bar', '', 'url=civicrm/a/#/%%2%%', '/index.php?q=civicrm/a/#/bar'];
- $cases[] = array(
+ $cases[] = [
'',
'gid=2&reset=1',
'url=civicrm/newfoo/%%gid%%?reset=%%reset%%',
'/index.php?q=civicrm/newfoo/2&reset=1',
- );
+ ];
return $cases;
}
public function setUp() {
parent::setUp();
- $this->_paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate(array('is_test' => 0));
+ $this->_paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate(['is_test' => 0]);
$this->_contactID = $this->individualCreate();
- $contributionPage = $this->callAPISuccess('contribution_page', 'create', array(
+ $contributionPage = $this->callAPISuccess('contribution_page', 'create', [
'title' => "Test Contribution Page",
'financial_type_id' => $this->_financialTypeID,
'currency' => 'USD',
'receipt_from_email' => 'gaia@the.cosmos',
'receipt_from_name' => 'Pachamama',
'is_email_receipt' => TRUE,
- ));
+ ]);
$this->_contributionPageID = $contributionPage['id'];
}
public function testIPNPaymentRecurNoReceipt() {
$mut = new CiviMailUtils($this, TRUE);
// Turn off receipts in contribution page.
- $api_params = array(
+ $api_params = [
'id' => $this->_contributionPageID,
'is_email_receipt' => FALSE,
- );
+ ];
$this->callAPISuccess('contributionPage', 'update', $api_params);
// Create initial recurring payment and initial contribution.
// has is_email_receipt set to 0.
$form = new CRM_Contribute_Form_Contribution();
$form->_mode = 'Live';
- $contribution = $form->testSubmit(array(
+ $contribution = $form->testSubmit([
'total_amount' => 200,
'financial_type_id' => 1,
'receive_date' => date('m/d/Y'),
'contribution_status_id' => 1,
'credit_card_number' => 4444333322221111,
'cvv2' => 123,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 9,
'Y' => 2025,
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Junko',
'billing_middle_name' => '',
'source' => 'bob sled race',
'contribution_page_id' => $this->_contributionPageID,
'is_recur' => TRUE,
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
$this->_contributionID = $contribution->id;
$this->_contributionRecurID = $contribution->contribution_recur_id;
- $recur_params = array(
+ $recur_params = [
'id' => $this->_contributionRecurID,
'return' => 'processor_id',
- );
+ ];
$processor_id = civicrm_api3('ContributionRecur', 'getvalue', $recur_params);
// Process the initial one.
$IPN = new CRM_Core_Payment_AuthorizeNetIPN(
- $this->getRecurTransaction(array('x_subscription_id' => $processor_id))
+ $this->getRecurTransaction(['x_subscription_id' => $processor_id])
);
$IPN->main();
// Now send a second one (authorize seems to treat first and second contributions
// differently.
$IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction(
- array('x_subscription_id' => $processor_id)
+ ['x_subscription_id' => $processor_id]
));
$IPN->main();
$this->setupRecurringPaymentProcessorTransaction();
$IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
$IPN->main();
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('6511143069', $contribution['trxn_id']);
// source gets set by processor
$this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
$IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction());
$IPN->main();
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(2, $contribution['count']);
$this->assertEquals('second_one', $contribution['values'][1]['trxn_id']);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][1]['receive_date'])));
*/
public function testIPNPaymentRecurSuccessMultiAuthNetProcessor() {
//Create and set up recur payment using second instance of AuthNet Processor.
- $this->_paymentProcessorID2 = $this->paymentProcessorAuthorizeNetCreate(array('name' => 'Authorize2', 'is_test' => 0));
- $this->setupRecurringPaymentProcessorTransaction(array('payment_processor_id' => $this->_paymentProcessorID2));
+ $this->_paymentProcessorID2 = $this->paymentProcessorAuthorizeNetCreate(['name' => 'Authorize2', 'is_test' => 0]);
+ $this->setupRecurringPaymentProcessorTransaction(['payment_processor_id' => $this->_paymentProcessorID2]);
//Call IPN with processor id.
- $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('processor_id' => $this->_paymentProcessorID2)));
+ $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(['processor_id' => $this->_paymentProcessorID2]));
$IPN->main();
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('6511143069', $contribution['trxn_id']);
// source gets set by processor
$this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
}
$this->setupRecurringPaymentProcessorTransaction();
$IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
$IPN->main();
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('6511143069', $contribution['trxn_id']);
// source gets set by processor
$this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
- $IPN = new CRM_Core_Payment_AuthorizeNetIPN(array_merge(array('receive_date' => '1 July 2010'), $this->getRecurSubsequentTransaction()));
+ $IPN = new CRM_Core_Payment_AuthorizeNetIPN(array_merge(['receive_date' => '1 July 2010'], $this->getRecurSubsequentTransaction()));
$IPN->main();
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(2, $contribution['count']);
$this->assertEquals('second_one', $contribution['values'][1]['trxn_id']);
$this->assertEquals('2010-07-01', date('Y-m-d', strtotime($contribution['values'][1]['receive_date'])));
$this->setupMembershipRecurringPaymentProcessorTransaction();
$IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
$IPN->main();
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('6511143069', $contribution['trxn_id']);
// source gets set by processor
$this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
$IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction());
$IPN->main();
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(2, $contribution['count']);
// Ensure both contributions are coded as credit card contributions.
$this->assertEquals(1, $contribution['values'][0]['payment_instrument_id']);
$this->assertEquals(1, $contribution['values'][1]['payment_instrument_id']);
$this->assertEquals('second_one', $contribution['values'][1]['trxn_id']);
- $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id']));
- $this->callAPISuccessGetSingle('line_item', array(
+ $this->callAPISuccessGetSingle('membership_payment', ['contribution_id' => $contribution['values'][1]['id']]);
+ $this->callAPISuccessGetSingle('line_item', [
'contribution_id' => $contribution['values'][1]['id'],
'entity_table' => 'civicrm_membership',
- ));
+ ]);
}
/**
*/
public function testIPNPaymentMembershipRecurSuccessNoLeakage() {
$mut = new CiviMailUtils($this, TRUE);
- $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE));
+ $this->setupMembershipRecurringPaymentProcessorTransaction(['is_email_receipt' => TRUE]);
$this->addProfile('supporter_profile', $this->_contributionPageID);
$this->addProfile('honoree_individual', $this->_contributionPageID, 'soft_credit');
$IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
$IPN->main();
- $mut->checkAllMailLog(array(
+ $mut->checkAllMailLog([
'Membership Type: General',
'Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
'Amount: $ 200.00',
'Dear Mr. Anthony Anderson II',
'Thanks for your auto renew membership sign-up',
'In Memory of',
- ));
+ ]);
$mut->clearMessages();
- $this->_contactID = $this->individualCreate(array('first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org'));
+ $this->_contactID = $this->individualCreate(['first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org']);
$this->_invoiceID = uniqid();
// Note, the second contribution is not in honor of anyone and the
// receipt should not mention honor at all.
- $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE));
- $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('x_trans_id' => 'hers')));
+ $this->setupMembershipRecurringPaymentProcessorTransaction(['is_email_receipt' => TRUE]);
+ $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(['x_trans_id' => 'hers']));
$IPN->main();
- $mut->checkAllMailLog(array(
+ $mut->checkAllMailLog([
'Membership Type: General',
'Mrs. Antonia Anderson II',
'antonia_anderson@civicrm.org',
'This membership will be automatically renewed every',
'Dear Mrs. Antonia Anderson II',
'Thanks for your auto renew membership sign-up',
- ));
+ ]);
- $shouldNotBeInMailing = array(
+ $shouldNotBeInMailing = [
'Honor',
'In Memory of',
- );
+ ];
$mails = $mut->getAllMessages('raw');
foreach ($mails as $mail) {
- $mut->checkMailForStrings(array(), $shouldNotBeInMailing, '', $mail);
+ $mut->checkMailForStrings([], $shouldNotBeInMailing, '', $mail);
}
$mut->stop();
$mut->clearMessages();
*/
public function testIPNPaymentMembershipRecurSuccessNoLeakageOnlineThenOffline() {
$mut = new CiviMailUtils($this, TRUE);
- $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE));
+ $this->setupMembershipRecurringPaymentProcessorTransaction(['is_email_receipt' => TRUE]);
$this->addProfile('supporter_profile', $this->_contributionPageID);
$IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
$IPN->main();
- $mut->checkAllMailLog(array(
+ $mut->checkAllMailLog([
'Membership Type: General',
'Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
'Amount: $ 200.00',
'This membership will be automatically renewed every',
'Dear Mr. Anthony Anderson II',
'Thanks for your auto renew membership sign-up',
- ));
+ ]);
- $this->_contactID = $this->individualCreate(array('first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org'));
+ $this->_contactID = $this->individualCreate(['first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org']);
$this->_invoiceID = uniqid();
$this->_contributionPageID = NULL;
- $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE));
+ $this->setupMembershipRecurringPaymentProcessorTransaction(['is_email_receipt' => TRUE]);
$mut->clearMessages();
- $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('x_trans_id' => 'hers')));
+ $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(['x_trans_id' => 'hers']));
$IPN->main();
- $mut->checkAllMailLog(array(
+ $mut->checkAllMailLog([
'Membership Type: General',
'Mrs. Antonia Anderson II',
'antonia_anderson@civicrm.org',
'This membership will be automatically renewed every',
'Dear Mrs. Antonia Anderson II',
'Thanks for your auto renew membership sign-up',
- ),
- array(
+ ],
+ [
'First Name: Anthony',
'First Name: Antonia',
'Last Name: Anderson',
'Supporter Profile',
'Email Address: antonia_anderson@civicrm.org',
- ));
+ ]);
$mut->stop();
$mut->clearMessages();
* @return array
* Parameters like AuthorizeNet silent post paramters.
*/
- public function getRecurTransaction($params = array()) {
- return array_merge(array(
+ public function getRecurTransaction($params = []) {
+ return array_merge([
"x_amount" => "200.00",
"x_country" => 'US',
"x_phone" => "",
'x_response_reason_text' => 'This transaction has been approved.',
'x_response_reason_code' => '1',
'x_response_code' => '1',
- ), $params);
+ ], $params);
}
/**
* @return array
*/
- public function getRecurSubsequentTransaction($params = array()) {
- return array_merge($this->getRecurTransaction(), array(
+ public function getRecurSubsequentTransaction($params = []) {
+ return array_merge($this->getRecurTransaction(), [
'x_trans_id' => 'second_one',
'x_MD5_Hash' => 'EA7A3CD65A85757827F51212CA1486A8',
- ), $params);
+ ], $params);
}
}
// for some strange unknown reason, in batch mode this value gets set to null
// so crude hack here to avoid an exception and hence an error
- $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = array();
+ $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = [];
}
public function tearDown() {
public function testCreateSingleNowDated() {
$firstName = 'John_' . substr(sha1(rand()), 0, 7) . uniqid();
$lastName = 'Smith_' . substr(sha1(rand()), 0, 7) . uniqid();
- $nameParams = array('first_name' => $firstName, 'last_name' => $lastName);
+ $nameParams = ['first_name' => $firstName, 'last_name' => $lastName];
$contactId = $this->individualCreate($nameParams);
$invoiceID = sha1(rand());
$amount = rand(100, 1000) . '.00';
- $recur = $this->callAPISuccess('ContributionRecur', 'create', array(
+ $recur = $this->callAPISuccess('ContributionRecur', 'create', [
'contact_id' => $contactId,
'amount' => $amount,
'currency' => 'USD',
'contribution_status_id' => 2,
'is_test' => 1,
'payment_processor_id' => $this->_paymentProcessorID,
- ));
+ ]);
- $contribution = $this->callAPISuccess('Contribution', 'create', array(
+ $contribution = $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $contactId,
'financial_type_id' => $this->_financialTypeId,
'receive_date' => date('Ymd'),
'contribution_recur_id' => $recur['id'],
'is_test' => 1,
'contribution_status_id' => 2,
- ));
+ ]);
- $params = array(
+ $params = [
'qfKey' => '08ed21c7ca00a1f7d32fff2488596ef7_4454',
'hidden_CreditCard' => 1,
'billing_first_name' => $firstName,
'billing_country_id-5' => 1228,
'credit_card_number' => '4007000000027',
'cvv2' => 123,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 10,
'Y' => 2019,
- ),
+ ],
'credit_card_type' => 'Visa',
'is_recur' => 1,
'frequency_interval' => 1,
'contributionID' => $contribution['id'],
'contributionTypeID' => $this->_financialTypeId,
'contributionRecurID' => $recur['id'],
- );
+ ];
// turn verifySSL off
Civi::settings()->set('verifySSL', '0');
// cancel it or the transaction will be rejected by A.net if the test is re-run
$subscriptionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $recur['id'], 'processor_id');
$message = '';
- $result = $this->processor->cancelSubscription($message, array('subscriptionId' => $subscriptionID));
+ $result = $this->processor->cancelSubscription($message, ['subscriptionId' => $subscriptionID]);
$this->assertTrue($result, 'Failed to cancel subscription with Authorize.');
}
$firstName = 'John_' . substr(sha1(rand()), 0, 7);
$lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
- $nameParams = array('first_name' => $firstName, 'last_name' => $lastName);
+ $nameParams = ['first_name' => $firstName, 'last_name' => $lastName];
$contactId = $this->individualCreate($nameParams);
- $ids = array('contribution' => NULL);
+ $ids = ['contribution' => NULL];
$invoiceID = sha1(rand());
$amount = rand(100, 1000) . '.00';
- $contributionRecurParams = array(
+ $contributionRecurParams = [
'contact_id' => $contactId,
'amount' => $amount,
'currency' => 'USD',
'contribution_status_id' => 2,
'is_test' => 1,
'payment_processor_id' => $this->_paymentProcessorID,
- );
+ ];
$recur = CRM_Contribute_BAO_ContributionRecur::add($contributionRecurParams, $ids);
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $contactId,
'financial_type_id' => $this->_financialTypeId,
'receive_date' => $start_date,
'contribution_recur_id' => $recur->id,
'is_test' => 1,
'contribution_status_id' => 2,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
- $params = array(
+ $params = [
'qfKey' => '00ed21c7ca00a1f7d555555596ef7_4454',
'hidden_CreditCard' => 1,
'billing_first_name' => $firstName,
'billing_country_id-5' => 1228,
'credit_card_number' => '4007000000027',
'cvv2' => 123,
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => 11,
'Y' => 2022,
- ),
+ ],
'credit_card_type' => 'Visa',
'is_recur' => 1,
'frequency_interval' => 1,
'contactID' => $contactId,
'contributionID' => $contribution['id'],
'contributionRecurID' => $recur->id,
- );
+ ];
// if cancel-subscription has been called earlier 'subscriptionType' would be set to cancel.
// to make a successful call for another trxn, we need to set it to something else.
// cancel it or the transaction will be rejected by A.net if the test is re-run
$subscriptionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $recur->id, 'processor_id');
$message = '';
- $result = $this->processor->cancelSubscription($message, array('subscriptionId' => $subscriptionID));
+ $result = $this->processor->cancelSubscription($message, ['subscriptionId' => $subscriptionID]);
$this->assertTrue($result, 'Failed to cancel subscription with Authorize.');
}
*
* @var array
*/
- protected $_membershipParams = array();
+ protected $_membershipParams = [];
/**
* IPN instance.
*/
public function setUp() {
parent::setUp();
- $this->_processorId = $this->paymentProcessorAuthorizeNetCreate(array('is_test' => 0));
- $this->input = $this->ids = $this->objects = array();
+ $this->_processorId = $this->paymentProcessorAuthorizeNetCreate(['is_test' => 0]);
+ $this->input = $this->ids = $this->objects = [];
$this->IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->input);
$this->_contactId = $this->individualCreate();
$this->ids['contact'] = $this->_contactId;
$this->_financialTypeId = 1;
- $this->_contributionParams = array(
+ $this->_contributionParams = [
'contact_id' => $this->_contactId,
'financial_type_id' => $this->_financialTypeId,
'receive_date' => date('Ymd'),
'currency' => 'USD',
'contribution_recur_id' => $this->_recurId,
'contribution_status_id' => 2,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $this->_contributionParams);
$this->_contributionId = $contribution['id'];
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertEquals('Anthony', $this->objects['contact']->first_name);
- $this->ids['contact'] = $this->_contactId = $this->individualCreate(array(
+ $this->ids['contact'] = $this->_contactId = $this->individualCreate([
'first_name' => 'Donald',
'last_name' => 'Duck',
'email' => 'the-don@duckville.com',
- ));
- $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, array('invoice_id' => 'abc')));
+ ]);
+ $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, ['invoice_id' => 'abc']));
$this->_contributionId = $contribution['id'];
$this->_setUpMembershipObjects();
$this->input['invoiceID'] = 'abc';
*/
public function testsendMailMembershipObjects() {
$this->_setUpMembershipObjects();
- $values = array();
+ $values = [];
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertTrue(is_array($msg), "Message returned as an array in line");
*/
public function testSendMailMembershipObjectsNoLeakage() {
$this->_setUpMembershipObjects();
- $values = array();
+ $values = [];
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
$this->assertContains('Membership Type: General', $msg['body']);
- $this->ids['contact'] = $this->_contactId = $this->individualCreate(array('prefix_id' => 'Dr.', 'first_name' => 'Donald', 'last_name' => 'Duck', 'email' => 'the-don@duckville.com'));
- $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, array('invoice_id' => 'abc')));
+ $this->ids['contact'] = $this->_contactId = $this->individualCreate(['prefix_id' => 'Dr.', 'first_name' => 'Donald', 'last_name' => 'Duck', 'email' => 'the-don@duckville.com']);
+ $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, ['invoice_id' => 'abc']));
$this->_contributionId = $contribution['id'];
- $this->_membershipTypeID = $this->membershipTypeCreate(array('name' => 'Fowl'));
+ $this->_membershipTypeID = $this->membershipTypeCreate(['name' => 'Fowl']);
$this->_setUpMembershipObjects();
$this->input['invoiceID'] = 'abc';
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
*/
public function testsendMailMembershipWithoutLoadObjects() {
$this->_setUpMembershipObjects();
- $values = array();
+ $values = [];
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__);
$this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
public function testComposeMailParticipant() {
$this->_setUpParticipantObjects();
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
- $values = array();
+ $values = [];
$this->assertFalse(empty($this->objects['event']));
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertContains('registration has been received and your status has been updated to Attended.', $msg['body']);
*/
public function testComposeMailParticipantObjects() {
$this->_setUpParticipantObjects();
- $values = array();
+ $values = [];
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__);
$this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
*/
public function testsendMailParticipantObjectsCheckLog() {
$this->_setUpParticipantObjects();
- $values = array();
+ $values = [];
$mut = new CiviMailUtils($this, TRUE);
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Thank you for your participation',
'Annual CiviCRM meet',
'Mr. Anthony Anderson II',
- ));
+ ]);
$mut->stop();
}
$event->id = $this->_eventId;
$event->is_email_confirm = FALSE;
$event->save();
- $values = array();
- $tablesToTruncate = array(
+ $values = [];
+ $tablesToTruncate = [
'civicrm_mailing_spool',
- );
+ ];
$this->quickCleanup($tablesToTruncate, FALSE);
$mut = new CiviMailUtils($this, TRUE);
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
public function testLoadPledgeObjectsInvalidPledgeID() {
$this->_setUpPledgeObjects();
$this->ids['pledge_payment'][0] = 0;
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
$this->assertArrayHasKey('error_message', $result);
$this->assertArrayNotHasKey('pledge_payment', $this->objects);
$this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
$this->ids['pledge_payment'][0] = NULL;
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
$this->assertArrayHasKey('error_message', $result);
$this->assertArrayNotHasKey('pledge_payment', $this->objects);
$this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
$this->ids['pledge_payment'][0] = '';
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
$this->assertArrayHasKey('error_message', $result);
$this->assertArrayNotHasKey('pledge_payment', $this->objects);
$this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
$this->ids['pledge_payment'][0] = 999;
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, $this->_processorId, array('return_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, $this->_processorId, ['return_error' => 1]);
$this->assertArrayHasKey('error_message', $result);
$this->assertEquals('Could not find pledge payment record: 999', $result['error_message']);
}
*/
public function testsendMailPledge() {
$this->_setUpPledgeObjects();
- $values = array();
+ $values = [];
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL);
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertContains('Contribution Information', $msg['html']);
*/
public function testRequiredWithoutProcessorID() {
$this->_setUpPledgeObjects();
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
$this->assertArrayHasKey('error_message', $result);
$this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
// error is only returned if $required set to True
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, array('return_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, ['return_error' => 1]);
$this->assertFalse(is_array($result));
//check that error is not returned if error checking not set
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('log_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['log_error' => 1]);
$this->assertFalse(is_array($result));
}
*/
public function testRequiredWithContributionPage() {
$this->_setUpContributionObjects(TRUE);
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
$this->assertEquals(1, $result['is_error']);
;
}
*/
public function testPaymentProcessorLoadsAsParam() {
$this->_setUpContributionObjects();
- $this->input = array_merge($this->input, array('payment_processor_id' => $this->_processorId));
- $this->assertTrue($this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)));
+ $this->input = array_merge($this->input, ['payment_processor_id' => $this->_processorId]);
+ $this->assertTrue($this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]));
}
/**
*/
public function testRequiredWithContributionPageError() {
$this->_setUpContributionObjects();
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['return_error' => 1]);
$this->assertArrayHasKey('error_message', $result);
$this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
// error is only returned if $required set to True
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, array('return_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, ['return_error' => 1]);
$this->assertFalse(is_array($result));
//check that error is not returned if error checking not set
- $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('log_error' => 1));
+ $result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, ['log_error' => 1]);
$this->assertFalse(is_array($result));
}
public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() {
$this->_setUpParticipantObjects('Pending from incomplete transaction');
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
- $additionalParticipantId = $this->participantCreate(array(
+ $additionalParticipantId = $this->participantCreate([
'event_id' => $this->_eventId,
'registered_by_id' => $this->_participantId,
'status_id' => 'Pending from incomplete transaction',
- ));
+ ]);
$transaction = new CRM_Core_Transaction();
$this->IPN->cancelled($this->objects, $transaction);
public function testThatFailedEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() {
$this->_setUpParticipantObjects('Pending from incomplete transaction');
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
- $additionalParticipantId = $this->participantCreate(array(
+ $additionalParticipantId = $this->participantCreate([
'event_id' => $this->_eventId,
'registered_by_id' => $this->_participantId,
'status_id' => 'Pending from incomplete transaction',
- ));
+ ]);
$transaction = new CRM_Core_Transaction();
$this->IPN->failed($this->objects, $transaction);
}
$this->objects['contribution'] = $contribution;
- $this->input = array(
+ $this->input = [
'component' => 'contribute',
'contribution_page_id' => $contributionPageID,
'total_amount' => 110.00,
'invoiceID' => "c8acb91e080ad7777a2adc119c192885",
'contactID' => $this->_contactId,
'contributionID' => $this->objects['contribution']->id,
- );
+ ];
}
/**
}
CRM_Member_PseudoConstant::membershipType($this->_membershipTypeID, TRUE);
CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
- $this->_membershipParams = array(
+ $this->_membershipParams = [
'contact_id' => $this->_contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2009-01-21',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
'version' => 3,
- );
+ ];
$membership = $this->callAPISuccess('membership', 'create', $this->_membershipParams);
if ($this->objects['contribution']->id != $this->_contributionId) {
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$contribution->find(TRUE);
- $this->objects = array('contribution' => $contribution);
+ $this->objects = ['contribution' => $contribution];
}
$this->_membershipId = $membership['id'];
//we'll create membership payment here because to make setup more re-usable
- $this->callAPISuccess('membership_payment', 'create', array(
+ $this->callAPISuccess('membership_payment', 'create', [
'contribution_id' => $this->_contributionId,
'membership_id' => $this->_membershipId,
- ));
+ ]);
- $this->input = array(
+ $this->input = [
'component' => 'contribute',
'total_amount' => 150.00,
'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
'contactID' => $this->_contactId,
'contributionID' => $this->_contributionId,
'membershipID' => $this->_membershipId,
- );
+ ];
$this->ids['membership'] = $this->_membershipId;
}
public function _setUpRecurringContribution() {
- $this->_contributionRecurParams = array(
+ $this->_contributionRecurParams = [
'contact_id' => $this->_contactId,
'amount' => 150.00,
'currency' => 'USD',
'financial_type_id' => $this->_financialTypeId,
'version' => 3,
'payment_processor_id' => $this->_processorId,
- );
+ ];
$this->_recurId = $this->callAPISuccess('contribution_recur', 'create', $this->_contributionRecurParams);
$this->_recurId = $this->_recurId['id'];
$this->input['contributionRecurId'] = $this->_recurId;
* The participant to create status
*/
public function _setUpParticipantObjects($participantStatus = 'Attended') {
- $event = $this->eventCreate(array('is_email_confirm' => 1));
+ $event = $this->eventCreate(['is_email_confirm' => 1]);
$this->_eventId = $event['id'];
- $this->_participantId = $this->participantCreate(array(
+ $this->_participantId = $this->participantCreate([
'event_id' => $this->_eventId,
'contact_id' => $this->_contactId,
'status_id' => $participantStatus,
- ));
+ ]);
- $this->callAPISuccess('participant_payment', 'create', array(
+ $this->callAPISuccess('participant_payment', 'create', [
'contribution_id' => $this->_contributionId,
'participant_id' => $this->_participantId,
- ));
+ ]);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$contribution->find();
$this->objects['contribution'] = $contribution;
- $this->input = array(
+ $this->input = [
'component' => 'event',
'total_amount' => 150.00,
'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
'contactID' => $this->_contactId,
'contributionID' => $contribution->id,
'participantID' => $this->_participantId,
- );
+ ];
$this->ids['participant'] = $this->_participantId;
$this->ids['event'] = $this->_eventId;
* Set up participant requirements for test.
*/
public function _setUpPledgeObjects() {
- $this->_pledgeId = $this->pledgeCreate(array('contact_id' => $this->_contactId));
+ $this->_pledgeId = $this->pledgeCreate(['contact_id' => $this->_contactId]);
//we'll create membership payment here because to make setup more re-usable
- $pledgePayment = $this->callAPISuccess('pledge_payment', 'create', array(
+ $pledgePayment = $this->callAPISuccess('pledge_payment', 'create', [
'version' => 3,
'pledge_id' => $this->_pledgeId,
'contribution_id' => $this->_contributionId,
'status_id' => 1,
'actual_amount' => 50,
- ));
+ ]);
- $this->input = array(
+ $this->input = [
'component' => 'contribute',
'total_amount' => 150.00,
'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
'contactID' => $this->_contactId,
'contributionID' => $this->_contributionId,
'pledgeID' => $this->_pledgeId,
- );
+ ];
$this->ids['pledge_payment'][] = $pledgePayment['id'];
}
*
* @var array
*/
- protected $ids = array();
+ protected $ids = [];
/**
* Set up function.
*/
public function setUp() {
parent::setUp();
- $this->_paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0, 'payment_processor_type_id' => 'PayPal_Standard'));
+ $this->_paymentProcessorID = $this->paymentProcessorCreate(['is_test' => 0, 'payment_processor_type_id' => 'PayPal_Standard']);
$this->_contactID = $this->individualCreate();
- $contributionPage = $this->callAPISuccess('contribution_page', 'create', array(
+ $contributionPage = $this->callAPISuccess('contribution_page', 'create', [
'title' => "Test Contribution Page",
'financial_type_id' => $this->_financialTypeID,
'currency' => 'USD',
'payment_processor' => $this->_paymentProcessorID,
- ));
+ ]);
$this->_contributionPageID = $contributionPage['id'];
}
$pendingStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
$completedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
- $params = array(
+ $params = [
'payment_processor_id' => $this->_paymentProcessorID,
'contact_id' => $this->_contactID,
'trxn_id' => NULL,
'invoice_id' => $this->_invoiceID,
'contribution_status_id' => $pendingStatusID,
'is_email_receipt' => TRUE,
- );
+ ];
$this->_contributionID = $this->contributionCreate($params);
- $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1));
+ $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $this->_contributionID, 'sequential' => 1]);
// assert that contribution created before handling payment via paypal standard has no transaction id set and pending status
$this->assertEquals(NULL, $contribution['values'][0]['trxn_id']);
$this->assertEquals($pendingStatusID, $contribution['values'][0]['contribution_status_id']);
global $_REQUEST;
- $_REQUEST = array('q' => CRM_Utils_System::url('civicrm/payment/ipn/' . $this->_paymentProcessorID)) + $this->getPaypalTransaction();
+ $_REQUEST = ['q' => CRM_Utils_System::url('civicrm/payment/ipn/' . $this->_paymentProcessorID)] + $this->getPaypalTransaction();
$mut = new CiviMailUtils($this, TRUE);
- $paymentProcesors = civicrm_api3('PaymentProcessor', 'getsingle', array('id' => $this->_paymentProcessorID));
+ $paymentProcesors = civicrm_api3('PaymentProcessor', 'getsingle', ['id' => $this->_paymentProcessorID]);
$payment = Civi\Payment\System::singleton()->getByProcessor($paymentProcesors);
$payment->handlePaymentNotification();
// Check if invoice pdf is attached with contribution mail reciept
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Content-Transfer-Encoding: base64',
'Content-Type: application/pdf',
'filename=Invoice.pdf',
- ));
+ ]);
$mut->stop();
- $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1));
+ $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $this->_contributionID, 'sequential' => 1]);
// assert that contribution is completed after getting response from paypal standard which has transaction id set and completed status
$this->assertEquals($_REQUEST['txn_id'], $contribution['values'][0]['trxn_id']);
$this->assertEquals($completedStatusID, $contribution['values'][0]['contribution_status_id']);
$this->setupRecurringPaymentProcessorTransaction([], ['total_amount' => '15.00']);
$paypalIPN = new CRM_Core_Payment_PayPalIPN($this->getPaypalRecurTransaction());
$paypalIPN->main();
- $contribution1 = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+ $contribution1 = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
$this->assertEquals(1, $contribution1['contribution_status_id']);
$this->assertEquals('8XA571746W2698126', $contribution1['trxn_id']);
// source gets set by processor
$this->assertTrue(substr($contribution1['contribution_source'], 0, 20) == "Online Contribution:");
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
$paypalIPN = new CRM_Core_Payment_PayPalIPN($this->getPaypalRecurSubsequentTransaction());
$paypalIPN->main();
- $contributions = $this->callAPISuccess('contribution', 'get', array(
+ $contributions = $this->callAPISuccess('contribution', 'get', [
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(2, $contributions['count']);
$contribution2 = $contributions['values'][1];
$this->assertEquals('secondone', $contribution2['trxn_id']);
*/
public function testIPNPaymentMembershipRecurSuccess() {
$durationUnit = 'year';
- $this->setupMembershipRecurringPaymentProcessorTransaction(array('duration_unit' => $durationUnit, 'frequency_unit' => $durationUnit));
- $this->callAPISuccessGetSingle('membership_payment', array());
+ $this->setupMembershipRecurringPaymentProcessorTransaction(['duration_unit' => $durationUnit, 'frequency_unit' => $durationUnit]);
+ $this->callAPISuccessGetSingle('membership_payment', []);
$paypalIPN = new CRM_Core_Payment_PayPalIPN($this->getPaypalRecurTransaction());
$paypalIPN->main();
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
- $membershipEndDate = $this->callAPISuccessGetValue('membership', array('return' => 'end_date'));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
+ $membershipEndDate = $this->callAPISuccessGetValue('membership', ['return' => 'end_date']);
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('8XA571746W2698126', $contribution['trxn_id']);
// source gets set by processor
$this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
$paypalIPN = new CRM_Core_Payment_PaypalIPN($this->getPaypalRecurSubsequentTransaction());
$paypalIPN->main();
$renewedMembershipEndDate = $this->membershipRenewalDate($durationUnit, $membershipEndDate);
- $this->assertEquals($renewedMembershipEndDate, $this->callAPISuccessGetValue('membership', array('return' => 'end_date')));
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $this->assertEquals($renewedMembershipEndDate, $this->callAPISuccessGetValue('membership', ['return' => 'end_date']));
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(2, $contribution['count']);
$this->assertEquals('secondone', $contribution['values'][1]['trxn_id']);
- $this->callAPISuccessGetCount('line_item', array(
+ $this->callAPISuccessGetCount('line_item', [
'entity_id' => $this->ids['membership'],
'entity_table' => 'civicrm_membership',
- ), 2);
- $this->callAPISuccessGetSingle('line_item', array(
+ ], 2);
+ $this->callAPISuccessGetSingle('line_item', [
'contribution_id' => $contribution['values'][1]['id'],
'entity_table' => 'civicrm_membership',
- ));
- $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id']));
+ ]);
+ $this->callAPISuccessGetSingle('membership_payment', ['contribution_id' => $contribution['values'][1]['id']]);
}
* Get IPN style details for an incoming recurring transaction.
*/
public function getPaypalRecurTransaction() {
- return array(
+ return [
'contactID' => $this->_contactID,
'contributionID' => $this->_contributionID,
'invoice' => $this->_invoiceID,
'first_name' => 'Robert',
'txn_id' => '8XA571746W2698126',
'residence_country' => 'US',
- );
+ ];
}
/**
* Get IPN style details for an incoming paypal standard transaction.
*/
public function getPaypalTransaction() {
- return array(
+ return [
'contactID' => $this->_contactID,
'contributionID' => $this->_contributionID,
'invoice' => $this->_invoiceID,
'txn_id' => '8XA571746W2698126',
'residence_country' => 'US',
'custom' => json_encode(['cgid' => 'test12345']),
- );
+ ];
}
/**
* @return array
*/
public function getPaypalRecurSubsequentTransaction() {
- return array_merge($this->getPaypalRecurTransaction(), array('txn_id' => 'secondone'));
+ return array_merge($this->getPaypalRecurTransaction(), ['txn_id' => 'secondone']);
}
/**
$pendingStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
$completedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
- $params = array(
+ $params = [
'payment_processor_id' => $this->_paymentProcessorID,
'contact_id' => $this->_contactID,
'trxn_id' => NULL,
'invoice_id' => $this->_invoiceID,
'contribution_status_id' => $pendingStatusID,
'is_email_receipt' => TRUE,
- );
+ ];
$this->_contributionID = $this->contributionCreate($params);
$this->createCustomField();
- $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1));
+ $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $this->_contributionID, 'sequential' => 1]);
// assert that contribution created before handling payment via paypal standard has no transaction id set and pending status
$this->assertEquals(NULL, $contribution['values'][0]['trxn_id']);
$this->assertEquals($pendingStatusID, $contribution['values'][0]['contribution_status_id']);
- $this->hookClass->setHook('civicrm_postIPNProcess', array($this, 'hookCiviCRMAlterIPNData'));
+ $this->hookClass->setHook('civicrm_postIPNProcess', [$this, 'hookCiviCRMAlterIPNData']);
global $_REQUEST;
- $_REQUEST = array('q' => CRM_Utils_System::url('civicrm/payment/ipn/' . $this->_paymentProcessorID)) + $this->getPaypalTransaction();
+ $_REQUEST = ['q' => CRM_Utils_System::url('civicrm/payment/ipn/' . $this->_paymentProcessorID)] + $this->getPaypalTransaction();
$mut = new CiviMailUtils($this, TRUE);
$payment = CRM_Core_Payment::handlePaymentMethod('PaymentNotification', ['processor_id' => $this->_paymentProcessorID]);
- $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $this->_contributionID, 'sequential' => 1));
+ $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $this->_contributionID, 'sequential' => 1]);
// assert that contribution is completed after getting response from paypal standard which has transaction id set and completed status
$this->assertEquals($_REQUEST['txn_id'], $contribution['values'][0]['trxn_id']);
$this->assertEquals($completedStatusID, $contribution['values'][0]['contribution_status_id']);
* @return array
*/
protected function createCustomField() {
- $customGroup = $this->customGroupCreate(array('extends' => 'Contribution'));
- $fields = array(
+ $customGroup = $this->customGroupCreate(['extends' => 'Contribution']);
+ $fields = [
'label' => 'TestCustomFieldIPNHook',
'data_type' => 'String',
'html_type' => 'Text',
'custom_group_id' => $customGroup['id'],
- );
+ ];
$field = CRM_Core_BAO_CustomField::create($fields);
$this->_customFieldID = $field->id;
return $customGroup;
*
* @var array
*/
- protected $ids = array();
+ protected $ids = [];
/**
* Set up function.
*/
public function setUp() {
parent::setUp();
- $this->_paymentProcessorID = $this->paymentProcessorCreate(array('is_test' => 0));
+ $this->_paymentProcessorID = $this->paymentProcessorCreate(['is_test' => 0]);
$this->_contactID = $this->individualCreate();
- $contributionPage = $this->callAPISuccess('contribution_page', 'create', array(
+ $contributionPage = $this->callAPISuccess('contribution_page', 'create', [
'title' => "Test Contribution Page",
'financial_type_id' => $this->_financialTypeID,
'currency' => 'USD',
'payment_processor' => $this->_paymentProcessorID,
- ));
+ ]);
$this->_contributionPageID = $contributionPage['id'];
}
$_GET = $this->getPaypalProRecurTransaction();
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurTransaction());
$paypalIPN->main();
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('8XA571746W2698126', $contribution['trxn_id']);
// source gets set by processor
$this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurSubsequentTransaction());
$paypalIPN->main();
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(2, $contribution['count']);
$this->assertEquals('secondone', $contribution['values'][1]['trxn_id']);
$this->assertEquals('Debit Card', $contribution['values'][1]['payment_instrument']);
*/
public function testIPNPaymentMembershipRecurSuccess() {
$durationUnit = 'year';
- $this->setupMembershipRecurringPaymentProcessorTransaction(array('duration_unit' => $durationUnit, 'frequency_unit' => $durationUnit));
- $this->callAPISuccessGetSingle('membership_payment', array());
+ $this->setupMembershipRecurringPaymentProcessorTransaction(['duration_unit' => $durationUnit, 'frequency_unit' => $durationUnit]);
+ $this->callAPISuccessGetSingle('membership_payment', []);
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurTransaction());
$paypalIPN->main();
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
- $membershipEndDate = $this->callAPISuccessGetValue('membership', array('return' => 'end_date'));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
+ $membershipEndDate = $this->callAPISuccessGetValue('membership', ['return' => 'end_date']);
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('8XA571746W2698126', $contribution['trxn_id']);
// source gets set by processor
$this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
$paypalIPN = new CRM_Core_Payment_PaypalProIPN($this->getPaypalProRecurSubsequentTransaction());
$paypalIPN->main();
$renewedMembershipEndDate = $this->membershipRenewalDate($durationUnit, $membershipEndDate);
- $this->assertEquals($renewedMembershipEndDate, $this->callAPISuccessGetValue('membership', array('return' => 'end_date')));
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $this->assertEquals($renewedMembershipEndDate, $this->callAPISuccessGetValue('membership', ['return' => 'end_date']));
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(2, $contribution['count']);
$this->assertEquals('secondone', $contribution['values'][1]['trxn_id']);
- $this->callAPISuccessGetCount('line_item', array(
+ $this->callAPISuccessGetCount('line_item', [
'entity_id' => $this->ids['membership'],
'entity_table' => 'civicrm_membership',
- ), 2);
- $this->callAPISuccessGetSingle('line_item', array(
+ ], 2);
+ $this->callAPISuccessGetSingle('line_item', [
'contribution_id' => $contribution['values'][1]['id'],
'entity_table' => 'civicrm_membership',
- ));
- $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id']));
+ ]);
+ $this->callAPISuccessGetSingle('membership_payment', ['contribution_id' => $contribution['values'][1]['id']]);
}
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($firstPaymentParams);
$paypalIPN->main();
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
$this->assertEquals(2, $contribution['contribution_status_id']);
$this->assertEquals('', $contribution['trxn_id']);
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals(2, $contributionRecur['contribution_status_id']);
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurSubsequentTransaction());
$paypalIPN->main();
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(1, $contribution['count']);
$this->assertEquals('secondone', $contribution['values'][0]['trxn_id']);
$this->assertEquals(strtotime('03:59:05 Jul 14, 2013 PDT'), strtotime($contribution['values'][0]['receive_date']));
$paypalIPN->main();
}
catch (CRM_Core_Exception $e) {
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $this->_contributionID]);
// no change
$this->assertEquals(2, $contribution['contribution_status_id']);
$this->assertEquals('Paypal IPNS not handled other than recurring_payments', $e->getMessage());
* array representing a Paypal IPN POST
*/
public function getPaypalExpressTransactionIPN() {
- return array(
+ return [
'mc_gross' => '200.00',
'invoice' => $this->_invoiceID,
'protection_eligibility' => 'Eligible',
'shipping' => '0.00',
'ipn_track_id' => '5r27c2e31rl7c',
'is_unit_test' => TRUE,
- );
+ ];
}
/**
* array representing a Paypal IPN POST
*/
public function getSubsequentPaypalExpressTransaction() {
- return array(
+ return [
'mc_gross' => '5.00',
'period_type' => ' Regular',
'outstanding_balance' => '0.00',
'product_type' => '1',
'time_created' => '12:02:25 May 14, 2013 PDT',
'ipn_track_id' => '912e5010eb5a6',
- );
+ ];
}
/**
* Get IPN style details for an incoming recurring transaction.
*/
public function getPaypalProRecurTransaction() {
- return array(
+ return [
'amount' => '15.00',
'initial_payment_amount' => '0.00',
'profile_status' => 'Active',
'next_payment_date' => '03:00:00 Aug 14, 2013 PDT',
'tax' => '0.00',
'residence_country' => 'US',
- );
+ ];
}
/**
* @return array
*/
public function getPaypalProRecurSubsequentTransaction() {
- return array_merge($this->getPaypalProRecurTransaction(), array('txn_id' => 'secondone'));
+ return array_merge($this->getPaypalProRecurTransaction(), ['txn_id' => 'secondone']);
}
/**
$this->setupRecurringPaymentProcessorTransaction(['processor_id' => '']);
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalExpressRecurSubscriptionConfirmation());
$paypalIPN->main();
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $this->_contributionRecurID]);
$this->assertEquals('I-JW77S1PY2032', $contributionRecur['processor_id']);
}
* Test the payment method is adequately logged - we don't expect the processing to succeed
*/
public function testHandlePaymentMethodLogging() {
- $params = array('processor_name' => 'Paypal', 'data' => 'blah');
+ $params = ['processor_name' => 'Paypal', 'data' => 'blah'];
try {
CRM_Core_Payment::handlePaymentMethod('method', $params);
}
catch (Exception $e) {
}
- $log = $this->callAPISuccess('SystemLog', 'get', array());
+ $log = $this->callAPISuccess('SystemLog', 'get', []);
$this->assertEquals('payment_notification processor_name=Paypal', $log['values'][$log['id']]['message']);
}
* (0 => input to translatePermission, 1 => expected output from translatePermission)
*/
public function translateData() {
- $cases = array();
+ $cases = [];
- $cases[] = array("administer CiviCRM", "administer CiviCRM");
- $cases[] = array("cms:universal name", "local name");
- $cases[] = array("cms:universal name2", "local name2");
- $cases[] = array("cms:unknown universal name", CRM_Core_Permission::ALWAYS_DENY_PERMISSION);
- $cases[] = array("myruntime:foo", "foo");
- $cases[] = array("otherruntime:foo", CRM_Core_Permission::ALWAYS_DENY_PERMISSION);
- $cases[] = array("otherruntime:foo:bar", CRM_Core_Permission::ALWAYS_DENY_PERMISSION);
- $cases[] = array(CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION);
+ $cases[] = ["administer CiviCRM", "administer CiviCRM"];
+ $cases[] = ["cms:universal name", "local name"];
+ $cases[] = ["cms:universal name2", "local name2"];
+ $cases[] = ["cms:unknown universal name", CRM_Core_Permission::ALWAYS_DENY_PERMISSION];
+ $cases[] = ["myruntime:foo", "foo"];
+ $cases[] = ["otherruntime:foo", CRM_Core_Permission::ALWAYS_DENY_PERMISSION];
+ $cases[] = ["otherruntime:foo:bar", CRM_Core_Permission::ALWAYS_DENY_PERMISSION];
+ $cases[] = [CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION];
return $cases;
}
*/
public function testTranslate($input, $expected) {
$perm = new CRM_Core_Permission_Base();
- $actual = $perm->translatePermission($input, "myruntime", array(
+ $actual = $perm->translatePermission($input, "myruntime", [
'universal name' => 'local name',
'universal name2' => 'local name2',
'gunk' => 'gunky',
- ));
+ ]);
$this->assertEquals($expected, $actual);
}
* Array of CRM_Core_Permission_Base
*/
public function permissionClasses() {
- $cases = array();
+ $cases = [];
- $cases[] = array('CRM_Core_Permission_Drupal');
- $cases[] = array('CRM_Core_Permission_Drupal6');
- $cases[] = array('CRM_Core_Permission_Joomla');
- $cases[] = array('CRM_Core_Permission_WordPress');
+ $cases[] = ['CRM_Core_Permission_Drupal'];
+ $cases[] = ['CRM_Core_Permission_Drupal6'];
+ $cases[] = ['CRM_Core_Permission_Joomla'];
+ $cases[] = ['CRM_Core_Permission_WordPress'];
return $cases;
}
* (0 => input to translatePermission, 1 => expected output from translatePermission)
*/
public function translateData() {
- $cases = array();
+ $cases = [];
- $cases[] = array("administer CiviCRM", array("civicrm.administer_civicrm", "com_civicrm"));
+ $cases[] = ["administer CiviCRM", ["civicrm.administer_civicrm", "com_civicrm"]];
// TODO $cases[] = array("cms:universal name", "local name");
// TODO $cases[] = array("cms:universal name2", "local name2");
- $cases[] = array("cms:unknown universal name", CRM_Core_Permission::ALWAYS_DENY_PERMISSION);
- $cases[] = array(
+ $cases[] = ["cms:unknown universal name", CRM_Core_Permission::ALWAYS_DENY_PERMISSION];
+ $cases[] = [
"Joomla:civicrmplusplus.extragood:com_civicrmplusplus",
- array("civicrmplusplus.extragood", "com_civicrmplusplus"),
- );
- $cases[] = array("otherruntime:foo", CRM_Core_Permission::ALWAYS_DENY_PERMISSION);
- $cases[] = array(CRM_Core_Permission::ALWAYS_DENY_PERMISSION, CRM_Core_Permission::ALWAYS_DENY_PERMISSION);
- $cases[] = array(CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION);
+ ["civicrmplusplus.extragood", "com_civicrmplusplus"],
+ ];
+ $cases[] = ["otherruntime:foo", CRM_Core_Permission::ALWAYS_DENY_PERMISSION];
+ $cases[] = [CRM_Core_Permission::ALWAYS_DENY_PERMISSION, CRM_Core_Permission::ALWAYS_DENY_PERMISSION];
+ $cases[] = [CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION];
return $cases;
}
// Create a custom field group for testing.
$custom_group_name = md5(microtime());
- $api_params = array(
+ $api_params = [
'title' => $custom_group_name,
'extends' => 'Individual',
'is_active' => TRUE,
- );
+ ];
$result = civicrm_api3('customGroup', 'create', $api_params);
// Add a custom field to the above field group.
- $api_params = array(
+ $api_params = [
'debug' => 1,
'custom_group_id' => $result['id'],
'label' => $custom_group_name,
'html_type' => 'Select',
'data_type' => 'String',
'is_active' => TRUE,
- 'option_values' => array(
- array(
+ 'option_values' => [
+ [
'label' => 'Foo',
'value' => 'foo',
'is_active' => 1,
'weight' => 0,
- ),
- ),
- );
+ ],
+ ],
+ ];
$result = civicrm_api3('custom_field', 'create', $api_params);
$customFieldId = $result['id'];
// Create a Contact Group for testing.
$group_name = md5(microtime());
- $api_params = array(
+ $api_params = [
'title' => $group_name,
'is_active' => TRUE,
- );
+ ];
$result = civicrm_api3('group', 'create', $api_params);
// Create a PaymentProcessor for testing.
$pp_name = md5(microtime());
- $api_params = array(
+ $api_params = [
'domain_id' => 1,
'payment_processor_type_id' => 'Dummy',
'name' => $pp_name,
'url_site' => 'https://test.com/',
'url_recur' => 'https://test.com/',
'is_active' => 1,
- );
+ ];
$result = civicrm_api3('payment_processor', 'create', $api_params);
// Create a Campaign for testing.
$campaign_name = md5(microtime());
- $api_params = array(
+ $api_params = [
'title' => $campaign_name,
'is_active' => TRUE,
'status_id' => 2,
- );
+ ];
$result = civicrm_api3('campaign', 'create', $api_params);
// Create a membership type for testing.
$membership_type = md5(microtime());
- $api_params = array(
+ $api_params = [
'name' => $membership_type,
'is_active' => TRUE,
'financial_type_id' => 1,
'duration_unit' => 'day',
'duration_interval' => 1,
'period_type' => 'rolling',
- );
+ ];
$result = civicrm_api3('membership_type', 'create', $api_params);
// Create a contribution page for testing.
$contribution_page = md5(microtime());
- $api_params = array(
+ $api_params = [
'title' => $contribution_page,
'is_active' => TRUE,
'financial_type_id' => 1,
- );
+ ];
$result = civicrm_api3('contribution_page', 'create', $api_params);
/**
* - exclude: Any one value which should not be in the list.
* - max: integer (default = 20) maximum number of option values expected.
*/
- $fields = array(
- 'CRM_ACL_DAO_ACL' => array(
- array(
+ $fields = [
+ 'CRM_ACL_DAO_ACL' => [
+ [
'fieldName' => 'operation',
'sample' => 'View',
- ),
- ),
- 'CRM_Contact_DAO_Group' => array(
- array(
+ ],
+ ],
+ 'CRM_Contact_DAO_Group' => [
+ [
'fieldName' => 'visibility',
'sample' => 'Public Pages',
- ),
- ),
- 'CRM_Contact_DAO_GroupContact' => array(
- array(
+ ],
+ ],
+ 'CRM_Contact_DAO_GroupContact' => [
+ [
'fieldName' => 'group_id',
'sample' => $group_name,
- ),
- array(
+ ],
+ [
'fieldName' => 'status',
'sample' => 'Added',
- ),
- ),
- 'CRM_Contact_DAO_GroupContactCache' => array(
- array(
+ ],
+ ],
+ 'CRM_Contact_DAO_GroupContactCache' => [
+ [
'fieldName' => 'group_id',
'sample' => $group_name,
- ),
- ),
- 'CRM_Contact_DAO_GroupOrganization' => array(
- array(
+ ],
+ ],
+ 'CRM_Contact_DAO_GroupOrganization' => [
+ [
'fieldName' => 'group_id',
'sample' => $group_name,
- ),
- ),
- 'CRM_Contact_DAO_SubscriptionHistory' => array(
- array(
+ ],
+ ],
+ 'CRM_Contact_DAO_SubscriptionHistory' => [
+ [
'fieldName' => 'group_id',
'sample' => $group_name,
- ),
- array(
+ ],
+ [
'fieldName' => 'method',
'sample' => 'Web',
- ),
- array(
+ ],
+ [
'fieldName' => 'status',
'sample' => 'Added',
- ),
- ),
- 'CRM_Core_DAO_Cache' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Cache' => [
+ [
'fieldName' => 'component_id',
'sample' => 'CiviMail',
- ),
- ),
- 'CRM_Contact_DAO_ACLContactCache' => array(
- array(
+ ],
+ ],
+ 'CRM_Contact_DAO_ACLContactCache' => [
+ [
'fieldName' => 'operation',
'sample' => 'All',
- ),
- ),
- 'CRM_Core_DAO_Setting' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Setting' => [
+ [
'fieldName' => 'component_id',
'sample' => 'CiviMail',
- ),
- ),
- 'CRM_Core_DAO_ActionSchedule' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_ActionSchedule' => [
+ [
'fieldName' => 'group_id',
'sample' => $group_name,
- ),
- array(
+ ],
+ [
'fieldName' => 'start_action_unit',
'sample' => 'hour',
- ),
- array(
+ ],
+ [
'fieldName' => 'repetition_frequency_unit',
'sample' => 'hour',
- ),
- array(
+ ],
+ [
'fieldName' => 'end_frequency_unit',
'sample' => 'hour',
- ),
- array(
+ ],
+ [
'fieldName' => 'mode',
'sample' => 'Email',
- ),
- ),
- 'CRM_Dedupe_DAO_RuleGroup' => array(
- array(
+ ],
+ ],
+ 'CRM_Dedupe_DAO_RuleGroup' => [
+ [
'fieldName' => 'contact_type',
'sample' => 'Individual',
- ),
- array(
+ ],
+ [
'fieldName' => 'used',
'sample' => 'Unsupervised',
- ),
- ),
- 'CRM_Activity_DAO_Activity' => array(
- array(
+ ],
+ ],
+ 'CRM_Activity_DAO_Activity' => [
+ [
'fieldName' => 'activity_type_id',
'sample' => 'Email',
'max' => 100,
- ),
- array(
+ ],
+ [
'fieldName' => 'status_id',
'sample' => 'Scheduled',
- ),
- array(
+ ],
+ [
'fieldName' => 'priority_id',
'sample' => 'Urgent',
- ),
- array(
+ ],
+ [
'fieldName' => 'engagement_level',
'sample' => '1',
- ),
- array(
+ ],
+ [
'fieldName' => 'medium_id',
'sample' => 'Phone',
- ),
- array(
+ ],
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- ),
- 'CRM_Campaign_DAO_Campaign' => array(
- array(
+ ],
+ ],
+ 'CRM_Campaign_DAO_Campaign' => [
+ [
'fieldName' => 'campaign_type_id',
'sample' => 'Constituent Engagement',
'max' => 50,
- ),
- array(
+ ],
+ [
'fieldName' => 'status_id',
'sample' => 'Completed',
'max' => 50,
- ),
- ),
- 'CRM_Campaign_DAO_Survey' => array(
- array(
+ ],
+ ],
+ 'CRM_Campaign_DAO_Survey' => [
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- array(
+ ],
+ [
'fieldName' => 'activity_type_id',
'sample' => 'Phone Call',
'max' => 100,
- ),
- ),
- 'CRM_Campaign_DAO_CampaignGroup' => array(
- array(
+ ],
+ ],
+ 'CRM_Campaign_DAO_CampaignGroup' => [
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- array(
+ ],
+ [
'fieldName' => 'group_type',
'sample' => 'Include',
- ),
- ),
- 'CRM_Contact_DAO_RelationshipType' => array(
- array(
+ ],
+ ],
+ 'CRM_Contact_DAO_RelationshipType' => [
+ [
'fieldName' => 'contact_type_a',
'sample' => 'Individual',
- ),
- array(
+ ],
+ [
'fieldName' => 'contact_type_b',
'sample' => 'Organization',
- ),
- ),
- 'CRM_Event_DAO_ParticipantStatusType' => array(
- array(
+ ],
+ ],
+ 'CRM_Event_DAO_ParticipantStatusType' => [
+ [
'fieldName' => 'class',
'sample' => 'Waiting',
- ),
- array(
+ ],
+ [
'fieldName' => 'visibility_id',
'sample' => 'Public',
- ),
- ),
- 'CRM_Price_DAO_LineItem' => array(
- array(
+ ],
+ ],
+ 'CRM_Price_DAO_LineItem' => [
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- ),
- 'CRM_Price_DAO_PriceField' => array(
- array(
+ ],
+ ],
+ 'CRM_Price_DAO_PriceField' => [
+ [
'fieldName' => 'html_type',
'sample' => 'Select',
- ),
- array(
+ ],
+ [
'fieldName' => 'visibility_id',
'sample' => 'Public',
- ),
- ),
- 'CRM_Price_DAO_PriceFieldValue' => array(
- array(
+ ],
+ ],
+ 'CRM_Price_DAO_PriceFieldValue' => [
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- ),
- 'CRM_Price_DAO_PriceSet' => array(
- array(
+ ],
+ ],
+ 'CRM_Price_DAO_PriceSet' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- array(
+ ],
+ [
'fieldName' => 'extends',
'sample' => 'CiviEvent',
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- ),
- 'CRM_Financial_DAO_EntityFinancialAccount' => array(
- array(
+ ],
+ ],
+ 'CRM_Financial_DAO_EntityFinancialAccount' => [
+ [
'fieldName' => 'financial_account_id',
'sample' => 'Member Dues',
- ),
- array(
+ ],
+ [
'fieldName' => 'account_relationship',
'sample' => 'Income Account is',
- ),
- ),
- 'CRM_Financial_DAO_FinancialItem' => array(
- array(
+ ],
+ ],
+ 'CRM_Financial_DAO_FinancialItem' => [
+ [
'fieldName' => 'status_id',
'sample' => 'Partially paid',
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_account_id',
'sample' => 'Accounts Receivable',
- ),
- array(
+ ],
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- ),
- 'CRM_Financial_DAO_FinancialTrxn' => array(
- array(
+ ],
+ ],
+ 'CRM_Financial_DAO_FinancialTrxn' => [
+ [
'fieldName' => 'from_financial_account_id',
'sample' => 'Accounts Receivable',
- ),
- array(
+ ],
+ [
'fieldName' => 'to_financial_account_id',
'sample' => 'Accounts Receivable',
- ),
- array(
+ ],
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'payment_instrument_id',
'sample' => 'Check',
- ),
- ),
- 'CRM_Financial_DAO_FinancialAccount' => array(
- array(
+ ],
+ ],
+ 'CRM_Financial_DAO_FinancialAccount' => [
+ [
'fieldName' => 'financial_account_type_id',
'sample' => 'Cost of Sales',
- ),
- ),
- 'CRM_Financial_DAO_PaymentProcessor' => array(
- array(
+ ],
+ ],
+ 'CRM_Financial_DAO_PaymentProcessor' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- ),
- 'CRM_Financial_BAO_PaymentProcessorType' => array(
- array(
+ ],
+ ],
+ 'CRM_Financial_BAO_PaymentProcessorType' => [
+ [
'fieldName' => 'billing_mode',
'sample' => 'form',
- ),
- ),
- 'CRM_Core_DAO_UFField' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_UFField' => [
+ [
'fieldName' => 'uf_group_id',
'sample' => 'Name and Address',
- ),
- array(
+ ],
+ [
'fieldName' => 'visibility',
'sample' => 'Expose Publicly',
- ),
- ),
- 'CRM_Core_DAO_UFJoin' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_UFJoin' => [
+ [
'fieldName' => 'uf_group_id',
'sample' => 'Name and Address',
- ),
- ),
- 'CRM_Core_DAO_UFMatch' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_UFMatch' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- ),
- 'CRM_Core_DAO_Job' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Job' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- array(
+ ],
+ [
'fieldName' => 'run_frequency',
'sample' => 'Daily',
- ),
- ),
- 'CRM_Core_DAO_JobLog' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_JobLog' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- ),
- 'CRM_Contribute_DAO_ContributionSoft' => array(
- array(
+ ],
+ ],
+ 'CRM_Contribute_DAO_ContributionSoft' => [
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'soft_credit_type_id',
'sample' => 'In Honor of',
- ),
- ),
- 'CRM_Contribute_DAO_Product' => array(
- array(
+ ],
+ ],
+ 'CRM_Contribute_DAO_Product' => [
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- array(
+ ],
+ [
'fieldName' => 'period_type',
'sample' => 'Rolling',
- ),
- array(
+ ],
+ [
'fieldName' => 'duration_unit',
'sample' => 'Day',
- ),
- array(
+ ],
+ [
'fieldName' => 'frequency_unit',
'sample' => 'Day',
- ),
- ),
- 'CRM_Contribute_DAO_ContributionProduct' => array(
- array(
+ ],
+ ],
+ 'CRM_Contribute_DAO_ContributionProduct' => [
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- ),
- 'CRM_Contribute_DAO_ContributionRecur' => array(
- array(
+ ],
+ ],
+ 'CRM_Contribute_DAO_ContributionRecur' => [
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'frequency_unit',
'sample' => 'month',
- ),
- array(
+ ],
+ [
'fieldName' => 'contribution_status_id',
'sample' => 'Completed',
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- array(
+ ],
+ [
'fieldName' => 'payment_instrument_id',
'sample' => 'Check',
- ),
- array(
+ ],
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- ),
- 'CRM_Pledge_DAO_PledgePayment' => array(
- array(
+ ],
+ ],
+ 'CRM_Pledge_DAO_PledgePayment' => [
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- ),
- 'CRM_Pledge_DAO_Pledge' => array(
- array(
+ ],
+ ],
+ 'CRM_Pledge_DAO_Pledge' => [
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- array(
+ ],
+ [
'fieldName' => 'frequency_unit',
'sample' => 'month',
- ),
- array(
+ ],
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- ),
- 'CRM_PCP_DAO_PCP' => array(
- array(
+ ],
+ ],
+ 'CRM_PCP_DAO_PCP' => [
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'status_id',
'sample' => 'Approved',
- ),
- ),
- 'CRM_Core_DAO_CustomField' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_CustomField' => [
+ [
'fieldName' => 'custom_group_id',
'sample' => $custom_group_name,
- ),
- array(
+ ],
+ [
'fieldName' => 'data_type',
'sample' => 'Alphanumeric',
- ),
- array(
+ ],
+ [
'fieldName' => 'html_type',
'sample' => 'Select Date',
- ),
- ),
- 'CRM_Core_DAO_CustomGroup' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_CustomGroup' => [
+ [
'fieldName' => 'style',
'sample' => 'Inline',
- ),
- ),
- 'CRM_Core_DAO_Dashboard' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Dashboard' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- ),
- 'CRM_Core_DAO_Tag' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Tag' => [
+ [
'fieldName' => 'used_for',
'sample' => 'Contacts',
- ),
- ),
- 'CRM_Core_DAO_EntityTag' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_EntityTag' => [
+ [
'fieldName' => 'tag_id',
'sample' => 'Government Entity',
- ),
- ),
- 'CRM_Core_DAO_Extension' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Extension' => [
+ [
'fieldName' => 'type',
'sample' => 'Module',
- ),
- ),
- 'CRM_Core_DAO_OptionValue' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_OptionValue' => [
+ [
'fieldName' => 'option_group_id',
'sample' => 'gender',
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'component_id',
'sample' => 'CiviContribute',
- ),
- array(
+ ],
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- ),
- 'CRM_Core_DAO_MailSettings' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_MailSettings' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- array(
+ ],
+ [
'fieldName' => 'protocol',
'sample' => 'Localdir',
- ),
- ),
- 'CRM_Core_DAO_Managed' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Managed' => [
+ [
'fieldName' => 'cleanup',
'sample' => 'Always',
- ),
- ),
- 'CRM_Core_DAO_Mapping' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Mapping' => [
+ [
'fieldName' => 'mapping_type_id',
'sample' => 'Search Builder',
- ),
- ),
- 'CRM_Core_DAO_Navigation' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Navigation' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- ),
- 'CRM_Core_DAO_Phone' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Phone' => [
+ [
'fieldName' => 'phone_type_id',
'sample' => 'Phone',
- ),
- array(
+ ],
+ [
'fieldName' => 'location_type_id',
'sample' => 'Home',
- ),
- ),
- 'CRM_Core_DAO_PrintLabel' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_PrintLabel' => [
+ [
'fieldName' => 'label_format_name',
'sample' => 'Avery 5395',
- ),
- array(
+ ],
+ [
'fieldName' => 'label_type_id',
'sample' => 'Event Badge',
- ),
- ),
- 'CRM_Core_DAO_Email' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Email' => [
+ [
'fieldName' => 'location_type_id',
'sample' => 'Home',
- ),
- ),
- 'CRM_Core_DAO_Address' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Address' => [
+ [
'fieldName' => 'location_type_id',
'sample' => 'Home',
- ),
- ),
- 'CRM_Core_DAO_Website' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Website' => [
+ [
'fieldName' => 'website_type_id',
'sample' => 'Facebook',
- ),
- ),
- 'CRM_Core_DAO_WordReplacement' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_WordReplacement' => [
+ [
'fieldName' => 'match_type',
'sample' => 'Exact Match',
- ),
- array(
+ ],
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- ),
- 'CRM_Core_DAO_MappingField' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_MappingField' => [
+ [
'fieldName' => 'website_type_id',
'sample' => 'Facebook',
- ),
- array(
+ ],
+ [
'fieldName' => 'im_provider_id',
'sample' => 'Yahoo',
- ),
- array(
+ ],
+ [
'fieldName' => 'operator',
'sample' => '=',
- ),
- ),
- 'CRM_Contact_DAO_Contact' => array(
- array(
+ ],
+ ],
+ 'CRM_Contact_DAO_Contact' => [
+ [
'fieldName' => 'prefix_id',
'sample' => 'Mr.',
- ),
- array(
+ ],
+ [
'fieldName' => 'suffix_id',
'sample' => 'Sr.',
- ),
- array(
+ ],
+ [
'fieldName' => 'gender_id',
'sample' => 'Male',
- ),
- array(
+ ],
+ [
'fieldName' => 'preferred_communication_method',
'sample' => 'Postal Mail',
- ),
- array(
+ ],
+ [
'fieldName' => 'contact_type',
'sample' => 'Individual',
'exclude' => 'Team',
- ),
- array(
+ ],
+ [
'fieldName' => 'contact_sub_type',
'sample' => 'Team',
'exclude' => 'Individual',
- ),
- array(
+ ],
+ [
'fieldName' => 'preferred_language',
- 'sample' => array('en_US' => 'English (United States)'),
+ 'sample' => ['en_US' => 'English (United States)'],
'max' => 250,
- ),
- array(
+ ],
+ [
'fieldName' => 'preferred_mail_format',
'sample' => 'Text',
- ),
- array(
+ ],
+ [
'fieldName' => 'communication_style_id',
'sample' => 'Formal',
- ),
- array(
+ ],
+ [
'fieldName' => "custom_$customFieldId",
- 'sample' => array('foo' => 'Foo'),
+ 'sample' => ['foo' => 'Foo'],
'max' => 1,
- ),
- ),
- 'CRM_Batch_DAO_Batch' => array(
- array(
+ ],
+ ],
+ 'CRM_Batch_DAO_Batch' => [
+ [
'fieldName' => 'type_id',
'sample' => 'Membership',
- ),
- array(
+ ],
+ [
'fieldName' => 'status_id',
'sample' => 'Reopened',
- ),
- array(
+ ],
+ [
'fieldName' => 'mode_id',
'sample' => 'Automatic Batch',
- ),
- array(
+ ],
+ [
'fieldName' => 'payment_instrument_id',
'sample' => 'Check',
- ),
- ),
- 'CRM_Core_DAO_IM' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_IM' => [
+ [
'fieldName' => 'provider_id',
'sample' => 'Yahoo',
- ),
- array(
+ ],
+ [
'fieldName' => 'location_type_id',
'sample' => 'Home',
- ),
- ),
- 'CRM_Event_DAO_Participant' => array(
- array(
+ ],
+ ],
+ 'CRM_Event_DAO_Participant' => [
+ [
'fieldName' => 'status_id',
'sample' => 'Registered',
- ),
- array(
+ ],
+ [
'fieldName' => 'role_id',
'sample' => 'Speaker',
- ),
- array(
+ ],
+ [
'fieldName' => 'fee_currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- ),
- 'CRM_Event_DAO_Event' => array(
- array(
+ ],
+ ],
+ 'CRM_Event_DAO_Event' => [
+ [
'fieldName' => 'event_type_id',
'sample' => 'Fundraiser',
- ),
- array(
+ ],
+ [
'fieldName' => 'participant_listing_id',
'sample' => 'Name and Email',
- ),
- array(
+ ],
+ [
'fieldName' => 'payment_processor',
'sample' => $pp_name,
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- array(
+ ],
+ [
'fieldName' => 'default_role_id',
'sample' => 'Attendee',
- ),
- array(
+ ],
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- ),
- 'CRM_Core_DAO_Menu' => array(
- array(
+ ],
+ ],
+ 'CRM_Core_DAO_Menu' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- array(
+ ],
+ [
'fieldName' => 'component_id',
'sample' => 'CiviMember',
- ),
- ),
- 'CRM_Member_DAO_Membership' => array(
- array(
+ ],
+ ],
+ 'CRM_Member_DAO_Membership' => [
+ [
'fieldName' => 'membership_type_id',
'sample' => $membership_type,
- ),
- array(
+ ],
+ [
'fieldName' => 'status_id',
'sample' => 'New',
- ),
- array(
+ ],
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- ),
- 'CRM_Member_DAO_MembershipStatus' => array(
- array(
+ ],
+ ],
+ 'CRM_Member_DAO_MembershipStatus' => [
+ [
'fieldName' => 'start_event',
'sample' => 'start date',
- ),
- array(
+ ],
+ [
'fieldName' => 'end_event',
'sample' => 'member since',
- ),
- array(
+ ],
+ [
'fieldName' => 'start_event_adjust_unit',
'sample' => 'month',
- ),
- array(
+ ],
+ [
'fieldName' => 'end_event_adjust_unit',
'sample' => 'year',
- ),
- ),
- 'CRM_Member_DAO_MembershipType' => array(
- array(
+ ],
+ ],
+ 'CRM_Member_DAO_MembershipType' => [
+ [
'fieldName' => 'visibility',
'sample' => 'Public',
- ),
- array(
+ ],
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- array(
+ ],
+ [
'fieldName' => 'duration_unit',
'sample' => 'lifetime',
- ),
- array(
+ ],
+ [
'fieldName' => 'period_type',
'sample' => 'Rolling',
- ),
- ),
- 'CRM_Mailing_DAO_Mailing' => array(
- array(
+ ],
+ ],
+ 'CRM_Mailing_DAO_Mailing' => [
+ [
'fieldName' => 'approval_status_id',
'sample' => 'Approved',
- ),
- array(
+ ],
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- array(
+ ],
+ [
'fieldName' => 'visibility',
'sample' => 'Public Pages',
- ),
- array(
+ ],
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- ),
- 'CRM_Mailing_DAO_MailingComponent' => array(
- array(
+ ],
+ ],
+ 'CRM_Mailing_DAO_MailingComponent' => [
+ [
'fieldName' => 'component_type',
'sample' => 'Header',
- ),
- ),
- 'CRM_Mailing_DAO_MailingGroup' => array(
- array(
+ ],
+ ],
+ 'CRM_Mailing_DAO_MailingGroup' => [
+ [
'fieldName' => 'group_type',
'sample' => 'Include',
- ),
- ),
- 'CRM_Mailing_DAO_MailingJob' => array(
- array(
+ ],
+ ],
+ 'CRM_Mailing_DAO_MailingJob' => [
+ [
'fieldName' => 'status',
'sample' => 'Scheduled',
- ),
- ),
- 'CRM_Mailing_Event_DAO_Bounce' => array(
- array(
+ ],
+ ],
+ 'CRM_Mailing_Event_DAO_Bounce' => [
+ [
'fieldName' => 'bounce_type_id',
'sample' => 'Invalid',
- ),
- ),
- 'CRM_Mailing_Event_DAO_Subscribe' => array(
- array(
+ ],
+ ],
+ 'CRM_Mailing_Event_DAO_Subscribe' => [
+ [
'fieldName' => 'group_id',
'sample' => $group_name,
- ),
- ),
- 'CRM_Grant_DAO_Grant' => array(
- array(
+ ],
+ ],
+ 'CRM_Grant_DAO_Grant' => [
+ [
'fieldName' => 'status_id',
'sample' => 'Approved for Payment',
- ),
- array(
+ ],
+ [
'fieldName' => 'grant_type_id',
'sample' => 'Emergency',
- ),
- array(
+ ],
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- ),
- 'CRM_Contribute_DAO_Contribution' => array(
- array(
+ ],
+ ],
+ 'CRM_Contribute_DAO_Contribution' => [
+ [
'fieldName' => 'payment_instrument_id',
'sample' => 'Credit Card',
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- array(
+ ],
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'contribution_status_id',
'sample' => 'Completed',
- ),
- array(
+ ],
+ [
'fieldName' => 'contribution_page_id',
'sample' => $contribution_page,
- ),
- array(
+ ],
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- ),
- 'CRM_Contribute_DAO_PremiumsProduct' => array(
- array(
+ ],
+ ],
+ 'CRM_Contribute_DAO_PremiumsProduct' => [
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- ),
- 'CRM_Contribute_DAO_ContributionPage' => array(
- array(
+ ],
+ ],
+ 'CRM_Contribute_DAO_ContributionPage' => [
+ [
'fieldName' => 'payment_processor',
'sample' => $pp_name,
- ),
- array(
+ ],
+ [
'fieldName' => 'financial_type_id',
'sample' => 'Donation',
- ),
- array(
+ ],
+ [
'fieldName' => 'currency',
- 'sample' => array('USD' => 'US Dollar'),
+ 'sample' => ['USD' => 'US Dollar'],
'max' => 200,
- ),
- array(
+ ],
+ [
'fieldName' => 'campaign_id',
'sample' => $campaign_name,
- ),
- ),
- 'CRM_Case_DAO_Case' => array(
- array(
+ ],
+ ],
+ 'CRM_Case_DAO_Case' => [
+ [
'fieldName' => 'status_id',
'sample' => 'Ongoing',
- ),
- array(
+ ],
+ [
'fieldName' => 'case_type_id',
'sample' => 'Housing Support',
- ),
- ),
- 'CRM_Report_DAO_ReportInstance' => array(
- array(
+ ],
+ ],
+ 'CRM_Report_DAO_ReportInstance' => [
+ [
'fieldName' => 'domain_id',
'sample' => 'Default Domain Name',
- ),
- ),
- );
+ ],
+ ],
+ ];
foreach ($fields as $daoName => $daoFields) {
foreach ($daoFields as $field) {
}
public function testContactTypes() {
- $byName = array(
+ $byName = [
'Individual' => 'Individual',
'Household' => 'Household',
'Organization' => 'Organization',
- );
- $byId = array(
+ ];
+ $byId = [
1 => 'Individual',
2 => 'Household',
3 => 'Organization',
- );
+ ];
// By default this should return an array keyed by name
$result = CRM_Contact_DAO_Contact::buildOptions('contact_type');
$this->assertEquals($byName, $result);
// But we can also fetch by ID
- $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', array(
+ $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', [
'keyColumn' => 'id',
'labelColumn' => 'name',
- ));
+ ]);
$this->assertEquals($byId, $result);
// Make sure flip param works
- $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', array(
+ $result = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'contact_type', [
'keyColumn' => 'id',
'labelColumn' => 'name',
'flip' => TRUE,
- ));
+ ]);
$this->assertEquals(array_flip($byId), $result);
}
public function testGetTaxRates() {
$contact = $this->createLoggedInUser();
- $financialType = $this->callAPISuccess('financial_type', 'create', array(
+ $financialType = $this->callAPISuccess('financial_type', 'create', [
'name' => 'Test taxable financial Type',
'is_reserved' => 0,
'is_active' => 1,
- ));
- $financialAccount = $this->callAPISuccess('financial_account', 'create', array(
+ ]);
+ $financialAccount = $this->callAPISuccess('financial_account', 'create', [
'name' => 'Test Tax financial account ',
'contact_id' => $contact,
'financial_account_type_id' => 2,
'is_reserved' => 0,
'is_active' => 1,
'is_default' => 0,
- ));
+ ]);
$financialTypeId = $financialType['id'];
$financialAccountId = $financialAccount['id'];
- $financialAccountParams = array(
+ $financialAccountParams = [
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialTypeId,
'account_relationship' => 10,
'financial_account_id' => $financialAccountId,
- );
+ ];
CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams);
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
$this->assertEquals('5.00', $taxRates[$financialType['id']]);
* Disable the normal content of a {crmRegion} and apply different content from a snippet
*/
public function testOverride() {
- CRM_Core_Region::instance('testOverride')->update('default', array(
+ CRM_Core_Region::instance('testOverride')->update('default', [
'disabled' => TRUE,
- ));
- CRM_Core_Region::instance('testOverride')->add(array(
+ ]);
+ CRM_Core_Region::instance('testOverride')->add([
'markup' => 'override<br/>',
- ));
+ ]);
$smarty = CRM_Core_Smarty::singleton();
$actual = $smarty->fetch('string:{crmRegion name=testOverride}default<br/>{/crmRegion}');
* Test that each of the major content formats are correctly evaluated.
*/
public function testAllTypes() {
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ CRM_Core_Region::instance('testAllTypes')->add([
'markup' => 'some-markup<br/>',
- ));
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
// note: 'template' would normally be a file name
'template' => 'string:smarty-is-{$snippet.extrainfo}<br/>',
'extrainfo' => 'dynamic',
- ));
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
// note: returns a value which gets appended to the region
'callback' => 'implode',
- 'arguments' => array('-', array('callback', 'with', 'specific', 'args<br/>')),
- ));
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ 'arguments' => ['-', ['callback', 'with', 'specific', 'args<br/>']],
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
// note: returns a value which gets appended to the region
'callback' => function(&$spec, &$html) {
return "callback-return<br/>";
},
- ));
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
// note: returns void; directly modifies region's $html
'callback' => function(&$spec, &$html) {
$html = "callback-ref<br/>" . $html;
},
- ));
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
'scriptUrl' => '/foo%20bar.js',
- ));
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
'script' => 'alert("hi");',
- ));
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
'jquery' => '$("div");',
- ));
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
'styleUrl' => '/foo%20bar.css',
- ));
- CRM_Core_Region::instance('testAllTypes')->add(array(
+ ]);
+ CRM_Core_Region::instance('testAllTypes')->add([
'style' => 'body { background: black; }',
- ));
+ ]);
$smarty = CRM_Core_Smarty::singleton();
$actual = $smarty->fetch('string:{crmRegion name=testAllTypes}default<br/>{/crmRegion}');
* Test of nested arrangement in which one {crmRegion} directly includes another {crmRegion}
*/
public function testDirectNest() {
- CRM_Core_Region::instance('testDirectNestOuter')->add(array(
+ CRM_Core_Region::instance('testDirectNestOuter')->add([
'template' => 'string:O={$snippet.weight} ',
'weight' => -5,
- ));
- CRM_Core_Region::instance('testDirectNestOuter')->add(array(
+ ]);
+ CRM_Core_Region::instance('testDirectNestOuter')->add([
'template' => 'string:O={$snippet.weight} ',
'weight' => 5,
- ));
+ ]);
- CRM_Core_Region::instance('testDirectNestInner')->add(array(
+ CRM_Core_Region::instance('testDirectNestInner')->add([
'template' => 'string:I={$snippet.weight} ',
'weight' => -5,
- ));
- CRM_Core_Region::instance('testDirectNestInner')->add(array(
+ ]);
+ CRM_Core_Region::instance('testDirectNestInner')->add([
'template' => 'string:I={$snippet.weight} ',
'weight' => 5,
- ));
+ ]);
$smarty = CRM_Core_Smarty::singleton();
$actual = $smarty->fetch('string:{crmRegion name=testDirectNestOuter}left {crmRegion name=testDirectNestInner}middle {/crmRegion}right {/crmRegion}');
* Test of nested arrangement in which one {crmRegion} is enhanced with a snippet which, in turn, includes another {crmRegion}
*/
public function testIndirectNest() {
- CRM_Core_Region::instance('testIndirectNestOuter')->add(array(
+ CRM_Core_Region::instance('testIndirectNestOuter')->add([
// Note: all three $snippet references are bound to the $snippet which caused this template to be included,
// regardless of any nested {crmRegion}s
'template' => 'string: O={$snippet.region}{crmRegion name=testIndirectNestInner} O={$snippet.region}{/crmRegion} O={$snippet.region}',
- ));
+ ]);
- CRM_Core_Region::instance('testIndirectNestInner')->add(array(
+ CRM_Core_Region::instance('testIndirectNestInner')->add([
'template' => 'string: I={$snippet.region}',
- ));
+ ]);
$smarty = CRM_Core_Smarty::singleton();
$actual = $smarty->fetch('string:{crmRegion name=testIndirectNestOuter}default{/crmRegion}');
* Output from an inner-region should not be executed verbatim; this is obvious but good to verify
*/
public function testNoInjection() {
- CRM_Core_Region::instance('testNoInjectionOuter')->add(array(
+ CRM_Core_Region::instance('testNoInjectionOuter')->add([
'template' => 'string:{$snippet.scarystuff} ',
'scarystuff' => '{$is_outer_scary}',
- ));
- CRM_Core_Region::instance('testNoInjectionInner')->add(array(
+ ]);
+ CRM_Core_Region::instance('testNoInjectionInner')->add([
'template' => 'string:{$snippet.scarystuff} ',
'scarystuff' => '{$is_inner_scary}',
- ));
+ ]);
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('is_outer_scary', 'egad');
public function testSmartyVars() {
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('extrainfo', 'one');
- CRM_Core_Region::instance('testSmartyVars')->add(array(
+ CRM_Core_Region::instance('testSmartyVars')->add([
'template' => 'string:var-style-{$extrainfo}<br/>',
- ));
+ ]);
- CRM_Core_Region::instance('testSmartyVars')->add(array(
+ CRM_Core_Region::instance('testSmartyVars')->add([
'template' => 'string:var-style-{$snippet.extrainfo}<br/>',
'extrainfo' => 'two',
- ));
+ ]);
$actual = $smarty->fetch('string:{crmRegion name=testSmartyVars}default<br/>{/crmRegion}');
$expected = 'default<br/>var-style-one<br/>var-style-two<br/>';
}
public function testWeight() {
- CRM_Core_Region::instance('testWeight')->add(array(
+ CRM_Core_Region::instance('testWeight')->add([
'markup' => 'prepend-5<br/>',
'weight' => -5,
- ));
- CRM_Core_Region::instance('testWeight')->add(array(
+ ]);
+ CRM_Core_Region::instance('testWeight')->add([
'markup' => 'append+3<br/>',
'weight' => 3,
- ));
- CRM_Core_Region::instance('testWeight')->add(array(
+ ]);
+ CRM_Core_Region::instance('testWeight')->add([
'markup' => 'prepend-3<br/>',
'weight' => -3,
- ));
- CRM_Core_Region::instance('testWeight')->add(array(
+ ]);
+ CRM_Core_Region::instance('testWeight')->add([
'markup' => 'append+5<br/>',
'weight' => 5,
- ));
+ ]);
$smarty = CRM_Core_Smarty::singleton();
$actual = $smarty->fetch('string:{crmRegion name=testWeight}default<br/>{/crmRegion}');
new CRM_Utils_Cache_Arraycache(NULL)
);
$this->assertEquals(
- array('Hello from Javascript'),
+ ['Hello from Javascript'],
$strings->get('example', "$basedir/hello.js", "text/javascript")
);
$this->assertEquals(
- array('Hello from HTML'),
+ ['Hello from HTML'],
$strings->get('example', "$basedir/hello.html", "text/html")
);
}
parent::setUp();
list ($this->basedir, $this->container, $this->mapper) = $this->_createMapper();
- $cache = new CRM_Utils_Cache_Arraycache(array());
+ $cache = new CRM_Utils_Cache_Arraycache([]);
$this->res = new CRM_Core_Resources($this->mapper, $cache, NULL);
$this->res->setCacheCode('resTest');
CRM_Core_Resources::singleton($this->res);
public function testAddVars() {
$this->res
- ->addVars('food', array('fruit' => array('mine' => 'apple', 'ours' => 'banana')))
- ->addVars('food', array('fruit' => array('mine' => 'new apple', 'yours' => 'orange')));
+ ->addVars('food', ['fruit' => ['mine' => 'apple', 'ours' => 'banana']])
+ ->addVars('food', ['fruit' => ['mine' => 'new apple', 'yours' => 'orange']]);
$this->assertTreeEquals(
- array(
- 'vars' => array(
- 'food' => array(
- 'fruit' => array(
+ [
+ 'vars' => [
+ 'food' => [
+ 'fruit' => [
'yours' => 'orange',
'mine' => 'new apple',
'ours' => 'banana',
- ),
- ),
- ),
- ),
+ ],
+ ],
+ ],
+ ],
$this->res->getSettings()
);
}
public function testAddSetting() {
$this->res
- ->addSetting(array('fruit' => array('mine' => 'apple')))
- ->addSetting(array('fruit' => array('yours' => 'orange')));
+ ->addSetting(['fruit' => ['mine' => 'apple']])
+ ->addSetting(['fruit' => ['yours' => 'orange']]);
$this->assertTreeEquals(
- array('fruit' => array('yours' => 'orange', 'mine' => 'apple')),
+ ['fruit' => ['yours' => 'orange', 'mine' => 'apple']],
$this->res->getSettings()
);
$actual = $this->res->renderSetting();
- $expected = json_encode(array('fruit' => array('yours' => 'orange', 'mine' => 'apple')));
+ $expected = json_encode(['fruit' => ['yours' => 'orange', 'mine' => 'apple']]);
$this->assertTrue(strpos($actual, $expected) !== FALSE);
}
$test->assertEquals('apple', $event->data['fruit']['mine']);
$event->data['fruit']['mine'] = 'banana';
});
- $this->res->addSetting(array('fruit' => array('mine' => 'apple')));
+ $this->res->addSetting(['fruit' => ['mine' => 'apple']]);
$settings = $this->res->getSettings();
- $this->assertTreeEquals(array('fruit' => array('mine' => 'banana')), $settings);
+ $this->assertTreeEquals(['fruit' => ['mine' => 'banana']], $settings);
}
public function testAddSettingFactory() {
$this->res->addSettingsFactory(function () {
- return array('fruit' => array('yours' => 'orange'));
+ return ['fruit' => ['yours' => 'orange']];
});
$this->res->addSettingsFactory(function () {
- return array('fruit' => array('mine' => 'apple'));
+ return ['fruit' => ['mine' => 'apple']];
});
$actual = $this->res->getSettings();
- $expected = array('fruit' => array('yours' => 'orange', 'mine' => 'apple'));
+ $expected = ['fruit' => ['yours' => 'orange', 'mine' => 'apple']];
$this->assertTreeEquals($expected, $actual);
}
public function testAddSettingAndSettingFactory() {
- $this->res->addSetting(array('fruit' => array('mine' => 'apple')));
+ $this->res->addSetting(['fruit' => ['mine' => 'apple']]);
- $muckableValue = array('fruit' => array('yours' => 'orange', 'theirs' => 'apricot'));
+ $muckableValue = ['fruit' => ['yours' => 'orange', 'theirs' => 'apricot']];
$this->res->addSettingsFactory(function () use (&$muckableValue) {
return $muckableValue;
});
$actual = $this->res->getSettings();
- $expected = array('fruit' => array('mine' => 'apple', 'yours' => 'orange', 'theirs' => 'apricot'));
+ $expected = ['fruit' => ['mine' => 'apple', 'yours' => 'orange', 'theirs' => 'apricot']];
$this->assertTreeEquals($expected, $actual);
// note: the setting is not fixed based on what the factory returns when registered; it's based
// on what the factory returns when getSettings is called
- $muckableValue = array('fruit' => array('yours' => 'banana'));
+ $muckableValue = ['fruit' => ['yours' => 'banana']];
$actual = $this->res->getSettings();
- $expected = array('fruit' => array('mine' => 'apple', 'yours' => 'banana'));
+ $expected = ['fruit' => ['mine' => 'apple', 'yours' => 'banana']];
$this->assertTreeEquals($expected, $actual);
}
public function testGlob() {
$this->assertEquals(
- array('info.xml'),
+ ['info.xml'],
$this->res->glob('com.example.ext', 'info.xml')
);
$this->assertEquals(
- array('js/example.js'),
+ ['js/example.js'],
$this->res->glob('com.example.ext', 'js/*.js')
);
$this->assertEquals(
- array('js/example.js'),
- $this->res->glob('com.example.ext', array('js/*.js'))
+ ['js/example.js'],
+ $this->res->glob('com.example.ext', ['js/*.js'])
);
}
}
public function ajaxModeData() {
- return array(
- array(array('q' => 'civicrm/ajax/foo'), TRUE),
- array(array('q' => 'civicrm/angularprofiles/template'), TRUE),
- array(array('q' => 'civicrm/asset/builder'), TRUE),
- array(array('q' => 'civicrm/test/page'), FALSE),
- array(array('q' => 'civicrm/test/page', 'snippet' => 'json'), TRUE),
- array(array('q' => 'civicrm/test/page', 'snippet' => 'foo'), FALSE),
- );
+ return [
+ [['q' => 'civicrm/ajax/foo'], TRUE],
+ [['q' => 'civicrm/angularprofiles/template'], TRUE],
+ [['q' => 'civicrm/asset/builder'], TRUE],
+ [['q' => 'civicrm/test/page'], FALSE],
+ [['q' => 'civicrm/test/page', 'snippet' => 'json'], TRUE],
+ [['q' => 'civicrm/test/page', 'snippet' => 'foo'], FALSE],
+ ];
}
/**
// not needed for now // file_put_contents("$basedir/weird/bar/oddball.php", "<?php\n");
$c = new CRM_Extension_Container_Basic($basedir, 'http://ext-dir', $cache, $cacheKey);
$mapper = new CRM_Extension_Mapper($c, NULL, NULL, '/pathto/civicrm', 'http://core-app');
- return array($basedir, $c, $mapper);
+ return [$basedir, $c, $mapper];
}
/**
* @return array
*/
public function urlForCacheCodeProvider() {
- return array(
- array(
+ return [
+ [
'http://www.civicrm.org',
'http://www.civicrm.org?r=' . $this->cacheBusterString,
- ),
- array(
+ ],
+ [
'www.civicrm.org/custom.css?foo=bar',
'www.civicrm.org/custom.css?foo=bar&r=' . $this->cacheBusterString,
- ),
- array(
+ ],
+ [
'civicrm.org/custom.css?car=blue&foo=bar',
'civicrm.org/custom.css?car=blue&foo=bar&r=' . $this->cacheBusterString,
- ),
- );
+ ],
+ ];
}
/**
* @return array
*/
public function scopeCases() {
- $cases = array();
- $cases[] = array('', '{crmScope}{/crmScope}');
- $cases[] = array('', '{crmScope x=1}{/crmScope}');
- $cases[] = array('x=', 'x={$x}');
- $cases[] = array('x=1', '{crmScope x=1}x={$x}{/crmScope}');
- $cases[] = array('x=1', '{$x}{crmScope x=1}x={$x}{/crmScope}{$x}');
- $cases[] = array('x=1 x=2 x=1', '{crmScope x=1}x={$x} {crmScope x=2}x={$x}{/crmScope} x={$x}{/crmScope}');
- $cases[] = array(
+ $cases = [];
+ $cases[] = ['', '{crmScope}{/crmScope}'];
+ $cases[] = ['', '{crmScope x=1}{/crmScope}'];
+ $cases[] = ['x=', 'x={$x}'];
+ $cases[] = ['x=1', '{crmScope x=1}x={$x}{/crmScope}'];
+ $cases[] = ['x=1', '{$x}{crmScope x=1}x={$x}{/crmScope}{$x}'];
+ $cases[] = ['x=1 x=2 x=1', '{crmScope x=1}x={$x} {crmScope x=2}x={$x}{/crmScope} x={$x}{/crmScope}'];
+ $cases[] = [
'x=1 x=2 x=3 x=2 x=1',
'{crmScope x=1}x={$x} {crmScope x=2}x={$x} {crmScope x=3}x={$x}{/crmScope} x={$x}{/crmScope} x={$x}{/crmScope}',
- );
- $cases[] = array('x=1,y=9', '{crmScope x=1 y=9}x={$x},y={$y}{/crmScope}');
- $cases[] = array(
+ ];
+ $cases[] = ['x=1,y=9', '{crmScope x=1 y=9}x={$x},y={$y}{/crmScope}'];
+ $cases[] = [
'x=1,y=9 x=1,y=8 x=1,y=9',
'{crmScope x=1 y=9}x={$x},y={$y} {crmScope y=8}x={$x},y={$y}{/crmScope} x={$x},y={$y}{/crmScope}',
- );
- $cases[] = array('x=', 'x={$x}');
+ ];
+ $cases[] = ['x=', 'x={$x}'];
return $cases;
}
public function setUp() {
parent::setUp();
- $this->quickCleanup(array('civicrm_contact', 'civicrm_activity'));
- $this->callbackLog = array();
- $this->cids = array();
+ $this->quickCleanup(['civicrm_contact', 'civicrm_activity']);
+ $this->callbackLog = [];
+ $this->cids = [];
}
/**
* @return array
*/
public function dataCreateStyle() {
- return array(
- array('sql-insert'),
- array('bao-create'),
- );
+ return [
+ ['sql-insert'],
+ ['bao-create'],
+ ];
}
/**
* @return array
*/
public function dataCreateAndCommitStyles() {
- return array(
- array('sql-insert', 'implicit-commit'),
- array('sql-insert', 'explicit-commit'),
- array('bao-create', 'implicit-commit'),
- array('bao-create', 'explicit-commit'),
- );
+ return [
+ ['sql-insert', 'implicit-commit'],
+ ['sql-insert', 'explicit-commit'],
+ ['bao-create', 'implicit-commit'],
+ ['bao-create', 'explicit-commit'],
+ ];
}
/**
public function testBasicCommit($createStyle, $commitStyle) {
$this->createContactWithTransaction('reuse-tx', $createStyle, $commitStyle);
$this->assertCount(1, $this->cids);
- $this->assertContactsExistByOffset(array(0 => TRUE));
+ $this->assertContactsExistByOffset([0 => TRUE]);
}
/**
public function testBasicRollback($createStyle) {
$this->createContactWithTransaction('reuse-tx', $createStyle, 'rollback');
$this->assertCount(1, $this->cids);
- $this->assertContactsExistByOffset(array(0 => FALSE));
+ $this->assertContactsExistByOffset([0 => FALSE]);
}
/**
public function testBatchRollback($createStyle, $commitStyle) {
$this->runBatch(
'reuse-tx',
- array(
+ [
// cid 0
- array('reuse-tx', $createStyle, $commitStyle),
+ ['reuse-tx', $createStyle, $commitStyle],
// cid 1
- array('reuse-tx', $createStyle, $commitStyle),
- ),
- array(0 => TRUE, 1 => TRUE),
+ ['reuse-tx', $createStyle, $commitStyle],
+ ],
+ [0 => TRUE, 1 => TRUE],
'rollback'
);
$this->assertCount(2, $this->cids);
- $this->assertContactsExistByOffset(array(0 => FALSE, 1 => FALSE));
+ $this->assertContactsExistByOffset([0 => FALSE, 1 => FALSE]);
}
/**
public function testMixedBatchCommit_nesting($createStyle, $commitStyle) {
$this->runBatch(
'reuse-tx',
- array(
+ [
// cid 0
- array('nest-tx', $createStyle, $commitStyle),
+ ['nest-tx', $createStyle, $commitStyle],
// cid 1
- array('nest-tx', $createStyle, 'rollback'),
+ ['nest-tx', $createStyle, 'rollback'],
// cid 2
- array('nest-tx', $createStyle, $commitStyle),
- ),
- array(0 => TRUE, 1 => FALSE, 2 => TRUE),
+ ['nest-tx', $createStyle, $commitStyle],
+ ],
+ [0 => TRUE, 1 => FALSE, 2 => TRUE],
$commitStyle
);
$this->assertCount(3, $this->cids);
- $this->assertContactsExistByOffset(array(0 => TRUE, 1 => FALSE, 2 => TRUE));
+ $this->assertContactsExistByOffset([0 => TRUE, 1 => FALSE, 2 => TRUE]);
}
/**
public function testMixedBatchCommit_reuse($createStyle, $commitStyle) {
$this->runBatch(
'reuse-tx',
- array(
+ [
// cid 0
- array('reuse-tx', $createStyle, $commitStyle),
+ ['reuse-tx', $createStyle, $commitStyle],
// cid 1
- array('reuse-tx', $createStyle, 'rollback'),
+ ['reuse-tx', $createStyle, 'rollback'],
// cid 2
- array('reuse-tx', $createStyle, $commitStyle),
- ),
- array(0 => TRUE, 1 => TRUE, 2 => TRUE),
+ ['reuse-tx', $createStyle, $commitStyle],
+ ],
+ [0 => TRUE, 1 => TRUE, 2 => TRUE],
$commitStyle
);
$this->assertCount(3, $this->cids);
- $this->assertContactsExistByOffset(array(0 => FALSE, 1 => FALSE, 2 => FALSE));
+ $this->assertContactsExistByOffset([0 => FALSE, 1 => FALSE, 2 => FALSE]);
}
/**
$this->assertFalse(CRM_Core_Transaction::isActive());
$this->runBatch(
'reuse-tx',
- array(
+ [
// cid 0
- array('nest-tx', $createStyle, $commitStyle),
+ ['nest-tx', $createStyle, $commitStyle],
// cid 1
- array('nest-tx', $createStyle, 'rollback'),
+ ['nest-tx', $createStyle, 'rollback'],
// cid 2
- array('nest-tx', $createStyle, $commitStyle),
- ),
- array(0 => TRUE, 1 => FALSE, 2 => TRUE),
+ ['nest-tx', $createStyle, $commitStyle],
+ ],
+ [0 => TRUE, 1 => FALSE, 2 => TRUE],
'rollback'
);
$this->assertFalse(CRM_Core_Transaction::isActive());
$this->assertCount(3, $this->cids);
- $this->assertContactsExistByOffset(array(0 => FALSE, 1 => FALSE, 2 => FALSE));
+ $this->assertContactsExistByOffset([0 => FALSE, 1 => FALSE, 2 => FALSE]);
}
public function testIsActive() {
public function testCallback_commit() {
$tx = new CRM_Core_Transaction();
- CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_COMMIT, array($this, '_preCommit'), array(
+ CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_COMMIT, [$this, '_preCommit'], [
'qwe',
'rty',
- ));
- CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, array($this, '_postCommit'), array(
+ ]);
+ CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, [$this, '_postCommit'], [
'uio',
'p[]',
- ));
- CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_ROLLBACK, array(
+ ]);
+ CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_ROLLBACK, [
$this,
'_preRollback',
- ), array('asd', 'fgh'));
- CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_ROLLBACK, array(
+ ], ['asd', 'fgh']);
+ CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_ROLLBACK, [
$this,
'_postRollback',
- ), array('jkl', ';'));
+ ], ['jkl', ';']);
CRM_Core_DAO::executeQuery('UPDATE civicrm_contact SET id = 100 WHERE id = 100');
- $this->assertEquals(array(), $this->callbackLog);
+ $this->assertEquals([], $this->callbackLog);
$tx = NULL;
- $this->assertEquals(array('_preCommit', 'qwe', 'rty'), $this->callbackLog[0]);
- $this->assertEquals(array('_postCommit', 'uio', 'p[]'), $this->callbackLog[1]);
+ $this->assertEquals(['_preCommit', 'qwe', 'rty'], $this->callbackLog[0]);
+ $this->assertEquals(['_postCommit', 'uio', 'p[]'], $this->callbackLog[1]);
}
public function testCallback_rollback() {
$tx = new CRM_Core_Transaction();
- CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_COMMIT, array($this, '_preCommit'), array(
+ CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_COMMIT, [$this, '_preCommit'], [
'ewq',
'ytr',
- ));
- CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, array($this, '_postCommit'), array(
+ ]);
+ CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, [$this, '_postCommit'], [
'oiu',
'][p',
- ));
- CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_ROLLBACK, array(
+ ]);
+ CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_PRE_ROLLBACK, [
$this,
'_preRollback',
- ), array('dsa', 'hgf'));
- CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_ROLLBACK, array(
+ ], ['dsa', 'hgf']);
+ CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_ROLLBACK, [
$this,
'_postRollback',
- ), array('lkj', ';'));
+ ], ['lkj', ';']);
CRM_Core_DAO::executeQuery('UPDATE civicrm_contact SET id = 100 WHERE id = 100');
$tx->rollback();
- $this->assertEquals(array(), $this->callbackLog);
+ $this->assertEquals([], $this->callbackLog);
$tx = NULL;
- $this->assertEquals(array('_preRollback', 'dsa', 'hgf'), $this->callbackLog[0]);
- $this->assertEquals(array('_postRollback', 'lkj', ';'), $this->callbackLog[1]);
+ $this->assertEquals(['_preRollback', 'dsa', 'hgf'], $this->callbackLog[0]);
+ $this->assertEquals(['_postRollback', 'lkj', ';'], $this->callbackLog[1]);
}
/**
$test = $this;
CRM_Core_Transaction::create(TRUE)->run(function ($tx) use (&$test, $createStyle, $commitStyle) {
$test->createContactWithTransaction('nest-tx', $createStyle, $commitStyle);
- $test->assertContactsExistByOffset(array(0 => TRUE));
+ $test->assertContactsExistByOffset([0 => TRUE]);
});
- $this->assertContactsExistByOffset(array(0 => TRUE));
+ $this->assertContactsExistByOffset([0 => TRUE]);
}
/**
try {
CRM_Core_Transaction::create(TRUE)->run(function ($tx) use (&$test, $createStyle, $commitStyle) {
$test->createContactWithTransaction('nest-tx', $createStyle, $commitStyle);
- $test->assertContactsExistByOffset(array(0 => TRUE));
+ $test->assertContactsExistByOffset([0 => TRUE]);
throw new Exception("Ruh-roh");
});
}
}
}
$this->assertTrue($e instanceof Exception);
- $this->assertContactsExistByOffset(array(0 => FALSE));
+ $this->assertContactsExistByOffset([0 => FALSE]);
}
/**
public function assertContactsExist($cids, $exist = TRUE) {
foreach ($cids as $cid) {
$this->assertTrue(is_numeric($cid));
- $this->assertDBQuery($exist ? 1 : 0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', array(
- 1 => array($cid, 'Integer'),
- ));
+ $this->assertDBQuery($exist ? 1 : 0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', [
+ 1 => [$cid, 'Integer'],
+ ]);
}
}
$this->assertTrue(isset($this->cids[$generalOffset + $offset]), "Find cid at offset($generalOffset + $offset)");
$cid = $this->cids[$generalOffset + $offset];
$this->assertTrue(is_numeric($cid));
- $this->assertDBQuery($expectExists ? 1 : 0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', array(
- 1 => array($cid, 'Integer'),
- ), "Check contact at offset($generalOffset + $offset)");
+ $this->assertDBQuery($expectExists ? 1 : 0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', [
+ 1 => [$cid, 'Integer'],
+ ], "Check contact at offset($generalOffset + $offset)");
}
}
$cid = $r->getConnection()->lastInsertId();
}
elseif ($insert == 'bao-create') {
- $params = array(
+ $params = [
'contact_type' => 'Individual',
'first_name' => 'FF',
'last_name' => 'LL',
- );
+ ];
$r = CRM_Contact_BAO_Contact::create($params);
$cid = $r->id;
}
$this->cids[] = $cid;
- $this->assertContactsExist(array($cid), TRUE);
+ $this->assertContactsExist([$cid], TRUE);
if ($outcome == 'rollback') {
$tx->rollback();
* @param $arg2
*/
public function _preCommit($arg1, $arg2) {
- $this->callbackLog[] = array('_preCommit', $arg1, $arg2);
+ $this->callbackLog[] = ['_preCommit', $arg1, $arg2];
}
/**
* @param $arg2
*/
public function _postCommit($arg1, $arg2) {
- $this->callbackLog[] = array('_postCommit', $arg1, $arg2);
+ $this->callbackLog[] = ['_postCommit', $arg1, $arg2];
}
/**
* @param $arg2
*/
public function _preRollback($arg1, $arg2) {
- $this->callbackLog[] = array('_preRollback', $arg1, $arg2);
+ $this->callbackLog[] = ['_preRollback', $arg1, $arg2];
}
/**
* @param $arg2
*/
public function _postRollback($arg1, $arg2) {
- $this->callbackLog[] = array('_postRollback', $arg1, $arg2);
+ $this->callbackLog[] = ['_postRollback', $arg1, $arg2];
}
}
*/
public function testMultiRecordFieldList() {
//create multi record custom group
- $ids = $this->CustomGroupMultipleCreateWithFields(array('style' => 'Tab with table'));
- $params = array(
+ $ids = $this->CustomGroupMultipleCreateWithFields(['style' => 'Tab with table']);
+ $params = [
'contact_type' => 'Individual',
'first_name' => 'Test',
'last_name' => 'Contact',
- );
+ ];
$customFields = $ids['custom_field_id'];
$result = $this->callAPISuccess('contact', 'create', $params);
$contactId = $result['id'];
//enter values for custom fields
- $customParams = array(
+ $customParams = [
"custom_{$customFields[0]}_-1" => "test value {$customFields[0]} one",
"custom_{$customFields[0]}_-2" => "test value {$customFields[0]} two",
"custom_{$customFields[0]}_-3" => "test value {$customFields[0]} three",
"custom_{$customFields[2]}_-1" => "test value {$customFields[2]} one",
"custom_{$customFields[2]}_-2" => "test value {$customFields[2]} two",
"custom_{$customFields[2]}_-3" => "test value {$customFields[2]} three",
- );
+ ];
CRM_Core_BAO_CustomValueTable::postProcess($customParams, "civicrm_contact", $contactId, NULL);
- $_GET = array(
+ $_GET = [
'cid' => $contactId,
'cgid' => $ids['custom_group_id'],
'is_unit_test' => TRUE,
- );
+ ];
$multiRecordFields = CRM_Custom_Page_AJAX::getMultiRecordFieldList();
//check sorting
foreach ($customFields as $fieldId) {
$columnName = "field_{$fieldId}{$ids['custom_group_id']}_{$fieldId}";
- $_GET['columns'][] = array(
+ $_GET['columns'][] = [
'data' => $columnName,
- );
+ ];
}
// get the results in descending order
- $_GET['order'] = array(
- '0' => array(
+ $_GET['order'] = [
+ '0' => [
'column' => 0,
'dir' => 'desc',
- ),
- );
+ ],
+ ];
$sortedRecords = CRM_Custom_Page_AJAX::getMultiRecordFieldList();
$this->assertEquals(3, $sortedRecords['recordsTotal']);
$sorted = FALSE;
// sorted order result should be two, three, one
- $sortedCount = array(1 => 2, 2 => 3, 3 => 1);
- foreach (array($multiRecordFields, $sortedRecords) as $records) {
+ $sortedCount = [1 => 2, 2 => 3, 3 => 1];
+ foreach ([$multiRecordFields, $sortedRecords] as $records) {
$count = 1;
foreach ($records['data'] as $key => $val) {
//check links for result sorted in descending order
*
* @var array
*/
- protected $contactIDs = array();
+ protected $contactIDs = [];
/**
* ID of the group holding the contacts.
$this->contactDelete($contactId);
}
if ($this->groupID) {
- $this->callAPISuccess('group', 'delete', array('id' => $this->groupID));
+ $this->callAPISuccess('group', 'delete', ['id' => $this->groupID]);
}
parent::tearDown();
}
// will - dale - will@example.com
$this->setupForGroupDedupe();
- $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', array('is_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Unsupervised'));
+ $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', ['is_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Unsupervised']);
$foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID);
$this->assertEquals(count($foundDupes), 3, 'Check Individual-Fuzzy dupe rule for dupesInGroup().');
public function testCustomRule() {
$this->setupForGroupDedupe();
- $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', array(
+ $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [
'contact_type' => 'Individual',
'threshold' => 8,
'used' => 'General',
'name' => 'TestRule',
'title' => 'TestRule',
'is_reserved' => 0,
- ));
+ ]);
$rules = [];
- foreach (array('birth_date', 'first_name', 'last_name') as $field) {
+ foreach (['birth_date', 'first_name', 'last_name'] as $field) {
$rules[$field] = $this->callAPISuccess('Rule', 'create', [
'dedupe_rule_group_id' => $ruleGroup['id'],
'rule_table' => 'civicrm_contact',
public function testCustomRuleWithAddress() {
$this->setupForGroupDedupe();
- $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', array(
+ $ruleGroup = $this->callAPISuccess('RuleGroup', 'create', [
'contact_type' => 'Individual',
'threshold' => 10,
'used' => 'General',
'name' => 'TestRule',
'title' => 'TestRule',
'is_reserved' => 0,
- ));
+ ]);
$rules = [];
- foreach (array('postal_code') as $field) {
+ foreach (['postal_code'] as $field) {
$rules[$field] = $this->callAPISuccess('Rule', 'create', [
'dedupe_rule_group_id' => $ruleGroup['id'],
'rule_table' => 'civicrm_address',
*/
public function testSupervisedDupes() {
$this->setupForGroupDedupe();
- $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', array('is_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Supervised'));
+ $ruleGroup = $this->callAPISuccessGetSingle('RuleGroup', ['is_reserved' => 1, 'contact_type' => 'Individual', 'used' => 'Supervised']);
$foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID);
// -------------------------------------------------------------------------
// default dedupe rule: threshold = 20 => (First + Last + Email) Matches ( 1 pair )
// contact data set
// FIXME: move create params to separate function
- $params = array(
- array(
+ $params = [
+ [
'first_name' => 'robin',
'last_name' => 'hood',
'email' => 'robin@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'robin',
'last_name' => 'hood',
'email' => 'hood@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'robin',
'last_name' => 'dale',
'email' => 'robin@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'little',
'last_name' => 'dale',
'email' => 'dale@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'will',
'last_name' => 'dale',
'email' => 'dale@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'will',
'last_name' => 'dale',
'email' => 'will@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'will',
'last_name' => 'dale',
'email' => 'will@example.com',
'contact_type' => 'Individual',
- ),
- );
+ ],
+ ];
- $this->hookClass->setHook('civicrm_findDuplicates', array($this, 'hook_civicrm_findDuplicates'));
+ $this->hookClass->setHook('civicrm_findDuplicates', [$this, 'hook_civicrm_findDuplicates']);
$count = 1;
foreach ($params as $param) {
$contact = $this->callAPISuccess('contact', 'create', $param);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
'street_address' => 'Ambachtstraat 23',
'location_type_id' => 1,
- );
+ ];
$this->callAPISuccess('address', 'create', $params);
$contactIds[$count++] = $contact['id'];
}
// verify that all contacts have been created separately
$this->assertEquals(count($contactIds), 7, 'Check for number of contacts.');
- $fields = array(
+ $fields = [
'first_name' => 'robin',
'last_name' => 'hood',
'email' => 'hood@example.com',
'street_address' => 'Ambachtstraat 23',
- );
+ ];
CRM_Core_TemporaryErrorScope::useException();
$ids = CRM_Contact_BAO_Contact::getDuplicateContacts($fields, 'Individual', 'General', [], TRUE, NULL, ['event_id' => 1]);
* Set up a group of dedupable contacts.
*/
protected function setupForGroupDedupe() {
- $params = array(
+ $params = [
'name' => 'Dupe Group',
'title' => 'New Test Dupe Group',
'domain_id' => 1,
'is_active' => 1,
'visibility' => 'Public Pages',
- );
+ ];
$result = $this->callAPISuccess('group', 'create', $params);
$this->groupID = $result['id'];
- $params = array(
- array(
+ $params = [
+ [
'first_name' => 'robin',
'last_name' => 'hood',
'email' => 'robin@example.com',
'contact_type' => 'Individual',
'birth_date' => '2016-01-01',
'api.Address.create' => ['location_type_id' => 'Billing', 'postal_code' => '99999'],
- ),
- array(
+ ],
+ [
'first_name' => 'robin',
'last_name' => 'hood',
'email' => 'hood@example.com',
'contact_type' => 'Individual',
'birth_date' => '2016-01-01',
'api.Address.create' => ['location_type_id' => 'Billing', 'postal_code' => '99999'],
- ),
- array(
+ ],
+ [
'first_name' => 'robin',
'last_name' => 'dale',
'email' => 'robin@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'little',
'last_name' => 'dale',
'email' => 'dale@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'will',
'last_name' => 'dale',
'email' => 'dale@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'will',
'last_name' => 'dale',
'email' => 'will@example.com',
'contact_type' => 'Individual',
- ),
- array(
+ ],
+ [
'first_name' => 'will',
'last_name' => 'dale',
'email' => 'will@example.com',
'contact_type' => 'Individual',
- ),
- );
+ ],
+ ];
$count = 1;
foreach ($params as $param) {
$contact = $this->callAPISuccess('contact', 'create', $param);
$this->contactIDs[$count++] = $contact['id'];
- $grpParams = array(
+ $grpParams = [
'contact_id' => $contact['id'],
'group_id' => $this->groupID,
- );
+ ];
$this->callAPISuccess('group_contact', 'create', $grpParams);
}
}
public function createOwnEvent() {
- $event = $this->eventCreate(array(
+ $event = $this->eventCreate([
'created_id' => $this->_contactId,
- ));
+ ]);
$this->_ownEventId = $event['id'];
}
public function createOtherEvent() {
$this->_otherContactId = $this->_contactId + 1;
- $event = $this->eventCreate(array(
+ $event = $this->eventCreate([
'created_id' => $this->_otherContactId,
- ));
+ ]);
$this->_otherEventId = $event['id'];
}
public function testCreateAndDelete() {
// create using required params
- $params = array(
+ $params = [
'name' => 'testStatus',
'label' => 'testParticipant',
'class' => 'Positive',
'weight' => 13,
'visibility_id' => 1,
- );
+ ];
$statusType = CRM_Event_BAO_ParticipantStatusType::create($params);
// Checking for participant status type id in db.
*/
public function testAddStatusType() {
- $params = array(
+ $params = [
'name' => 'testStatus',
'label' => 'testParticipant',
'class' => 'Positive',
'is_counted' => 1,
'weight' => 13,
'visibility_id' => 1,
- );
+ ];
// check for add participant status type
$statusType = CRM_Event_BAO_ParticipantStatusType::add($params);
$this->assertEquals($value, $statusType->$param);
}
- $params = array(
+ $params = [
'id' => $statusType->id,
'name' => 'testStatus',
'label' => 'testAlterParticipant',
'is_counted' => 0,
'weight' => 14,
'visibility_id' => 2,
- );
+ ];
// check for add participant status type
$statusType = CRM_Event_BAO_ParticipantStatusType::add($params);
*/
public function testRetrieveStatusType() {
- $params = array(
+ $params = [
'name' => 'testStatus',
'label' => 'testParticipant',
'class' => 'Positive',
'is_counted' => 1,
'weight' => 13,
'visibility_id' => 1,
- );
+ ];
$statusType = CRM_Event_BAO_ParticipantStatusType::create($params);
// retrieve status type
- $retrieveParams = array('id' => $statusType->id);
- $default = array();
+ $retrieveParams = ['id' => $statusType->id];
+ $default = [];
$retrieveStatusType = CRM_Event_BAO_ParticipantStatusType::retrieve($retrieveParams, $default);
// check on retrieve values
*/
public function testSetIsActiveStatusType() {
- $params = array(
+ $params = [
'name' => 'testStatus',
'label' => 'testParticipant',
'class' => 'Positive',
'is_counted' => 1,
'weight' => 15,
'visibility_id' => 1,
- );
+ ];
$statusType = CRM_Event_BAO_ParticipantStatusType::create($params);
$isActive = 1;
*/
public function testSubmit() {
$event = $this->eventCreate();
- CRM_Event_Form_Registration_Confirm::testSubmit(array(
+ CRM_Event_Form_Registration_Confirm::testSubmit([
'id' => $event['id'],
'contributeMode' => 'direct',
'registerByID' => $this->createLoggedInUser(),
- 'params' => array(
- array(
+ 'params' => [
+ [
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3',
'first_name' => 'k',
'hidden_processor' => '1',
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => '1',
'Y' => '2019',
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'p',
'billing_middle_name' => '',
'scriptFee' => '',
'scriptArray' => '',
'priceSetId' => '6',
- 'price_7' => array(
+ 'price_7' => [
13 => 1,
- ),
+ ],
'payment_processor_id' => '1',
'bypass_payment' => '',
'MAX_FILE_SIZE' => '33554432',
'button' => '_qf_Register_upload',
'billing_state_province-5' => 'AP',
'billing_country-5' => 'US',
- ),
- ),
- ));
- $this->callAPISuccessGetSingle('Participant', array());
+ ],
+ ],
+ ]);
+ $this->callAPISuccessGetSingle('Participant', []);
}
/**
public function testPaidSubmit($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$paymentProcessorID = $this->processorCreate();
- $params = array('is_monetary' => 1, 'financial_type_id' => 1);
+ $params = ['is_monetary' => 1, 'financial_type_id' => 1];
$event = $this->eventCreate($params);
$individualID = $this->individualCreate();
- CRM_Event_Form_Registration_Confirm::testSubmit(array(
+ CRM_Event_Form_Registration_Confirm::testSubmit([
'id' => $event['id'],
'contributeMode' => 'direct',
'registerByID' => $individualID,
'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID),
'totalAmount' => $this->formatMoneyInput(8000.67),
- 'params' => array(
- array(
+ 'params' => [
+ [
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3',
'first_name' => 'k',
'hidden_processor' => '1',
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => '1',
'Y' => '2019',
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'p',
'billing_middle_name' => '',
'scriptFee' => '',
'scriptArray' => '',
'priceSetId' => '6',
- 'price_7' => array(
+ 'price_7' => [
13 => 1,
- ),
+ ],
'payment_processor_id' => $paymentProcessorID,
'bypass_payment' => '',
'MAX_FILE_SIZE' => '33554432',
'button' => '_qf_Register_upload',
'billing_state_province-5' => 'AP',
'billing_country-5' => 'US',
- ),
- ),
- ));
- $this->callAPISuccessGetCount('Participant', array(), 1);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array());
+ ],
+ ],
+ ]);
+ $this->callAPISuccessGetCount('Participant', [], 1);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', []);
$this->assertEquals(8000.67, $contribution['total_amount']);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('payment_processor_id', 'card_type_id.label', 'pan_truncation'),
- )
+ 'return' => ['payment_processor_id', 'card_type_id.label', 'pan_truncation'],
+ ]
);
$this->assertEquals(CRM_Utils_Array::value('payment_processor_id', $financialTrxn), $paymentProcessorID);
$this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa');
* @throws \Exception
*/
public function testTaxMultipleParticipant() {
- $params = array('is_monetary' => 1, 'financial_type_id' => 1);
+ $params = ['is_monetary' => 1, 'financial_type_id' => 1];
$event = $this->eventCreate($params);
- CRM_Event_Form_Registration_Confirm::testSubmit(array(
+ CRM_Event_Form_Registration_Confirm::testSubmit([
'id' => $event['id'],
'contributeMode' => 'direct',
'registerByID' => $this->createLoggedInUser(),
'totalAmount' => 440,
'event' => reset($event['values']),
- 'params' => array(
- array(
+ 'params' => [
+ [
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Participant1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'trxn_id' => '123456789',
'button' => '_qf_Register_upload',
- ),
- array(
+ ],
+ [
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Participant2',
'amount_level' => '\ 1Tiny-tots (ages 9-18) - 1\ 1',
'amount' => '200.00',
'tax_amount' => 20,
- ),
- array(
+ ],
+ [
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Participant3',
'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
'amount' => '100.00',
'tax_amount' => 10,
- ),
- ),
- ));
- $this->callAPISuccessGetCount('Participant', array(), 3);
+ ],
+ ],
+ ]);
+ $this->callAPISuccessGetCount('Participant', [], 3);
$contribution = $this->callAPISuccessGetSingle(
'Contribution',
- array(
- 'return' => array('tax_amount', 'total_amount'),
- )
+ [
+ 'return' => ['tax_amount', 'total_amount'],
+ ]
);
$this->assertEquals($contribution['tax_amount'], 40, 'Invalid Tax amount.');
$this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.');
* Test online registration for event with no price options selected as per CRM-19964.
*/
public function testOnlineRegNoPrice() {
- $paymentProcessorID = $this->processorCreate(array('is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE));
- $paymentProcessorID = $this->processorCreate(array('is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE));
- $params = array(
+ $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE]);
+ $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE]);
+ $params = [
'start_date' => date('YmdHis', strtotime('+ 1 week')),
'end_date' => date('YmdHis', strtotime('+ 1 year')),
'registration_start_date' => date('YmdHis', strtotime('- 1 day')),
'payment_processor_id' => $paymentProcessorID,
'is_monetary' => TRUE,
'financial_type_id' => 'Event Fee',
- );
+ ];
$event = $this->eventCreate($params);
- $priceFieldOptions = array(
+ $priceFieldOptions = [
'option_label' => 'Price Field',
'option_value' => 100,
'is_required' => FALSE,
'html_type' => 'Text',
- );
+ ];
$this->createPriceSet('event', $event['id'], $priceFieldOptions);
$priceField = $this->callAPISuccess('PriceField', 'get',
- array(
+ [
'label' => 'Price Field',
- )
+ ]
);
// Create online event registration.
- CRM_Event_Form_Registration_Confirm::testSubmit(array(
+ CRM_Event_Form_Registration_Confirm::testSubmit([
'id' => $event['id'],
'contributeMode' => 'direct',
'registerByID' => $this->createLoggedInUser(),
- 'params' => array(
- array(
+ 'params' => [
+ [
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Bruce',
'button' => '_qf_Register_upload',
'scriptFee' => '',
'scriptArray' => '',
- ),
- ),
- ));
- $contribution = $this->callAPISuccess('Contribution', 'get', array('invoice_id' => '57adc34957a29171948e8643ce906332'));
+ ],
+ ],
+ ]);
+ $contribution = $this->callAPISuccess('Contribution', 'get', ['invoice_id' => '57adc34957a29171948e8643ce906332']);
$this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected.");
}
$form->_values['event'] = $event['values'][$event['id']];
$form->_skipDupeRegistrationCheck = 1;
- $priceField = $this->callAPISuccess('PriceField', 'get', array('price_set_id' => $priceSetId));
- $params = array(
+ $priceField = $this->callAPISuccess('PriceField', 'get', ['price_set_id' => $priceSetId]);
+ $params = [
'email-Primary' => 'someone@example.com',
'priceSetId' => $priceSetId,
- );
+ ];
// Check empty values for price fields.
foreach (array_keys($priceField['values']) as $fieldId) {
$params['price_' . $fieldId] = 0;
$form->set('priceSetId', $priceSetId);
$form->set('priceSet', $priceSet);
$form->set('name', 'CRM_Event_Form_Registration_Register');
- $files = array();
+ $files = [];
$errors = CRM_Event_Form_Registration_Register::formRule($params, $files, $form);
//Assert the validation Error.
- $expectedResult = array(
- '_qf_default' => ts('A minimum amount of %1 should be selected from Event Fee(s).', array(1 => CRM_Utils_Money::format($minAmt))),
- );
+ $expectedResult = [
+ '_qf_default' => ts('A minimum amount of %1 should be selected from Event Fee(s).', [1 => CRM_Utils_Money::format($minAmt)]),
+ ];
$this->checkArrayEquals($expectedResult, $errors);
}
* Test that search form returns correct number of rows for complex regex filters.
*/
public function testSearch() {
- $priceFieldValues = $this->createPriceSet('event', NULL, array(
+ $priceFieldValues = $this->createPriceSet('event', NULL, [
'html_type' => 'Radio',
- 'option_label' => array('1' => 'Radio Label A (inc. GST)', '2' => 'Radio Label B (inc. GST)'),
- 'option_name' => array('1' => 'Radio Label A', '2' => 'Radio Label B'),
- ));
+ 'option_label' => ['1' => 'Radio Label A (inc. GST)', '2' => 'Radio Label B (inc. GST)'],
+ 'option_name' => ['1' => 'Radio Label A', '2' => 'Radio Label B'],
+ ]);
$priceFieldValues = $priceFieldValues['values'];
$participantPrice = NULL;
$event = $this->eventCreate();
$individualID = $this->individualCreate();
$today = new DateTime();
- $this->participantCreate(array(
+ $this->participantCreate([
'event_id' => $event['id'],
'contact_id' => $individualID,
'status_id' => 1,
'fee_amount' => $participantPrice['amount'],
'fee_currency' => 'USD',
'register_date' => $today->format('YmdHis'),
- ));
+ ]);
$form = new CRM_Event_Form_Search();
$form->controller = new CRM_Event_Controller_Search();
$form->preProcess();
- $form->testSubmit(array(
+ $form->testSubmit([
'participant_test' => 0,
- 'participant_fee_id' => array(
+ 'participant_fee_id' => [
$participantPrice['id'],
- ),
+ ],
'radio_ts' => 'ts_all',
- ));
+ ]);
$rows = $form->controller->get('rows');
$this->assertEquals(1, count($rows), 'Exactly one row should be returned for given price field value.');
}
public function testDisabled() {
$browser = new CRM_Extension_Browser(FALSE, '/index.html', 'file:///itd/oesn/tmat/ter');
$this->assertEquals(FALSE, $browser->isEnabled());
- $this->assertEquals(array(), $browser->checkRequirements());
- $this->assertEquals(array(), $browser->getExtensions());
+ $this->assertEquals([], $browser->checkRequirements());
+ $this->assertEquals([], $browser->getExtensions());
}
public function testCheckRequirements_BadCachedir_false() {
public function testGetExtensions_good() {
$browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-'));
$this->assertEquals(TRUE, $browser->isEnabled());
- $this->assertEquals(array(), $browser->checkRequirements());
+ $this->assertEquals([], $browser->checkRequirements());
$exts = $browser->getExtensions();
$keys = array_keys($exts);
sort($keys);
- $this->assertEquals(array('test.crm.extension.browsertest.a', 'test.crm.extension.browsertest.b'), $keys);
+ $this->assertEquals(['test.crm.extension.browsertest.a', 'test.crm.extension.browsertest.b'], $keys);
$this->assertEquals('report', $exts['test.crm.extension.browsertest.a']->type);
$this->assertEquals('module', $exts['test.crm.extension.browsertest.b']->type);
$this->assertEquals('http://example.com/test.crm.extension.browsertest.a-0.1.zip', $exts['test.crm.extension.browsertest.a']->downloadUrl);
public function testGetExtension_good() {
$browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-'));
$this->assertEquals(TRUE, $browser->isEnabled());
- $this->assertEquals(array(), $browser->checkRequirements());
+ $this->assertEquals([], $browser->checkRequirements());
$info = $browser->getExtension('test.crm.extension.browsertest.b');
$this->assertEquals('module', $info->type);
public function testGetExtension_nonexistent() {
$browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-'));
$this->assertEquals(TRUE, $browser->isEnabled());
- $this->assertEquals(array(), $browser->checkRequirements());
+ $this->assertEquals([], $browser->checkRequirements());
$info = $browser->getExtension('test.crm.extension.browsertest.nonexistent');
$this->assertEquals(NULL, $info);
public function testGetKeysEmpty() {
$basedir = $this->createTempDir('ext-empty-');
$c = new CRM_Extension_Container_Basic($basedir, 'http://example/basedir', NULL, NULL);
- $this->assertEquals($c->getKeys(), array());
+ $this->assertEquals($c->getKeys(), []);
}
public function testGetKeys() {
list($basedir, $c) = $this->_createContainer();
- $this->assertEquals($c->getKeys(), array('test.foo', 'test.foo.bar'));
+ $this->assertEquals($c->getKeys(), ['test.foo', 'test.foo.bar']);
}
public function testGetPath() {
}
public function testCaching() {
- $cache = new CRM_Utils_Cache_Arraycache(array());
+ $cache = new CRM_Utils_Cache_Arraycache([]);
$this->assertTrue(!is_array($cache->get('basic-scan')));
list($basedir, $c) = $this->_createContainer($cache, 'basic-scan');
$this->assertEquals('http://example/basedir/foo', $c->getResUrl('test.foo'));
file_put_contents("$basedir/foo/bar/info.xml", "<extension key='test.foo.bar' type='report'><file>oddball</file></extension>");
// not needed for now // file_put_contents("$basedir/foo/bar/oddball.php", "<?php\n");
$c = new CRM_Extension_Container_Basic($basedir . $appendPathGarbage, 'http://example/basedir' . $appendPathGarbage, $cache, $cacheKey);
- return array($basedir, $c);
+ return [$basedir, $c];
}
public function testConvertPathsToUrls() {
- $relPaths = array(
+ $relPaths = [
'foo.bar' => 'foo\bar',
'whiz.bang' => 'tests\extensions\whiz\bang',
- );
- $expectedRelUrls = array(
+ ];
+ $expectedRelUrls = [
'foo.bar' => 'foo/bar',
'whiz.bang' => 'tests/extensions/whiz/bang',
- );
+ ];
$actualRelUrls = CRM_Extension_Container_Basic::convertPathsToUrls('\\', $relPaths);
$this->assertEquals($expectedRelUrls, $actualRelUrls);
}
}
public function testGetKeysEmpty() {
- $c = new CRM_Extension_Container_Collection(array());
- $this->assertEquals($c->getKeys(), array());
+ $c = new CRM_Extension_Container_Collection([]);
+ $this->assertEquals($c->getKeys(), []);
}
public function testGetKeys() {
$c = $this->_createContainer();
- $this->assertEquals(array(
+ $this->assertEquals([
'test.conflict',
'test.whiz',
'test.whizbang',
'test.foo',
'test.foo.bar',
- ), $c->getKeys());
+ ], $c->getKeys());
}
public function testGetPath() {
}
public function testCaching() {
- $cache = new CRM_Utils_Cache_Arraycache(array());
+ $cache = new CRM_Utils_Cache_Arraycache([]);
$this->assertTrue(!is_array($cache->get('ext-collection')));
$c = $this->_createContainer($cache, 'ext-collection');
$this->assertEquals('http://foo', $c->getResUrl('test.foo'));
* @return CRM_Extension_Container_Collection
*/
public function _createContainer(CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) {
- $containers = array();
- $containers['a'] = new CRM_Extension_Container_Static(array(
- 'test.foo' => array(
+ $containers = [];
+ $containers['a'] = new CRM_Extension_Container_Static([
+ 'test.foo' => [
'path' => '/path/to/foo',
'resUrl' => 'http://foo',
- ),
- 'test.foo.bar' => array(
+ ],
+ 'test.foo.bar' => [
'path' => '/path/to/bar',
'resUrl' => 'http://foobar',
- ),
- ));
- $containers['b'] = new CRM_Extension_Container_Static(array(
- 'test.whiz' => array(
+ ],
+ ]);
+ $containers['b'] = new CRM_Extension_Container_Static([
+ 'test.whiz' => [
'path' => '/path/to/whiz',
'resUrl' => 'http://whiz',
- ),
- 'test.whizbang' => array(
+ ],
+ 'test.whizbang' => [
'path' => '/path/to/whizbang',
'resUrl' => 'http://whizbang',
- ),
- 'test.conflict' => array(
+ ],
+ 'test.conflict' => [
'path' => '/path/to/conflict-b',
'resUrl' => 'http://conflict-b',
- ),
- ));
- $containers['c'] = new CRM_Extension_Container_Static(array(
- 'test.conflict' => array(
+ ],
+ ]);
+ $containers['c'] = new CRM_Extension_Container_Static([
+ 'test.conflict' => [
'path' => '/path/to/conflict-c',
'resUrl' => 'http://conflict-c',
- ),
- ));
+ ],
+ ]);
$c = new CRM_Extension_Container_Collection($containers, $cache, $cacheKey);
return $c;
}
}
public function testGetKeysEmpty() {
- $c = new CRM_Extension_Container_Static(array());
- $this->assertEquals($c->getKeys(), array());
+ $c = new CRM_Extension_Container_Static([]);
+ $this->assertEquals($c->getKeys(), []);
}
public function testGetKeys() {
$c = $this->_createContainer();
- $this->assertEquals($c->getKeys(), array('test.foo', 'test.foo.bar'));
+ $this->assertEquals($c->getKeys(), ['test.foo', 'test.foo.bar']);
}
public function testGetPath() {
* @return CRM_Extension_Container_Static
*/
public function _createContainer() {
- return new CRM_Extension_Container_Static(array(
- 'test.foo' => array(
+ return new CRM_Extension_Container_Static([
+ 'test.foo' => [
'path' => '/path/to/foo',
'resUrl' => 'http://foo',
- ),
- 'test.foo.bar' => array(
+ ],
+ 'test.foo.bar' => [
'path' => '/path/to/bar',
'resUrl' => 'http://foobar',
- ),
- ));
+ ],
+ ]);
}
}
$this->assertEquals('test.foo', $info->key);
$this->assertEquals('foo', $info->file);
$this->assertEquals('zamboni', $info->typeInfo['extra']);
- $this->assertEquals(array(), $info->requires);
+ $this->assertEquals([], $info->requires);
}
public function testGood_string_extras() {
$this->assertEquals('testbar', $info->file);
$this->assertEquals('Civi\\', $info->classloader[0]['prefix']);
$this->assertEquals('Civi', $info->classloader[0]['path']);
- $this->assertEquals(array('org.civicrm.a', 'org.civicrm.b'), $info->requires);
+ $this->assertEquals(['org.civicrm.a', 'org.civicrm.b'], $info->requires);
}
public function testBad_string() {
// $query = "INSERT INTO civicrm_domain ( name, version ) VALUES ( 'domain', 3 )";
// $result = CRM_Core_DAO::executeQuery($query);
global $_test_extension_manager_moduletest_counts;
- $_test_extension_manager_moduletest_counts = array();
+ $_test_extension_manager_moduletest_counts = [];
$this->basedir = $this->createTempDir('ext-');
- $this->system = new CRM_Extension_System(array(
+ $this->system = new CRM_Extension_System([
'extensionsDir' => $this->basedir,
'extensionsURL' => 'http://testbase/',
- ));
+ ]);
$this->setExtensionSystem($this->system);
}
$manager = $this->system->getManager();
$this->assertModuleActiveByName(FALSE, 'moduletest');
- $manager->install(array('test.extension.manager.moduletest'));
- $this->assertHookCounts('moduletest', array(
+ $manager->install(['test.extension.manager.moduletest']);
+ $this->assertHookCounts('moduletest', [
'install' => 1,
'postInstall' => 1,
'enable' => 1,
'disable' => 0,
'uninstall' => 0,
- ));
+ ]);
$this->assertModuleActiveByName(TRUE, 'moduletest');
$this->assertModuleActiveByKey(TRUE, 'test.extension.manager.moduletest');
- $manager->disable(array('test.extension.manager.moduletest'));
- $this->assertHookCounts('moduletest', array(
+ $manager->disable(['test.extension.manager.moduletest']);
+ $this->assertHookCounts('moduletest', [
'install' => 1,
'postInstall' => 1,
'enable' => 1,
'disable' => 1,
'uninstall' => 0,
- ));
+ ]);
$this->assertModuleActiveByName(FALSE, 'moduletest');
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest');
- $manager->uninstall(array('test.extension.manager.moduletest'));
- $this->assertHookCounts('moduletest', array(
+ $manager->uninstall(['test.extension.manager.moduletest']);
+ $this->assertHookCounts('moduletest', [
'install' => 1,
'postInstall' => 1,
'enable' => 1,
'disable' => 1,
'uninstall' => 1,
- ));
+ ]);
$this->assertModuleActiveByName(FALSE, 'moduletest');
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest');
}
$this->assertModuleActiveByName(FALSE, 'moduletest');
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest');
- $manager->install(array('test.extension.manager.moduletest'));
- $this->assertHookCounts('moduletest', array(
+ $manager->install(['test.extension.manager.moduletest']);
+ $this->assertHookCounts('moduletest', [
'install' => 1,
'enable' => 1,
'disable' => 0,
'uninstall' => 0,
- ));
+ ]);
$this->assertModuleActiveByName(TRUE, 'moduletest');
$this->assertModuleActiveByKey(TRUE, 'test.extension.manager.moduletest');
- $manager->disable(array('test.extension.manager.moduletest'));
- $this->assertHookCounts('moduletest', array(
+ $manager->disable(['test.extension.manager.moduletest']);
+ $this->assertHookCounts('moduletest', [
'install' => 1,
'enable' => 1,
'disable' => 1,
'uninstall' => 0,
- ));
+ ]);
$this->assertModuleActiveByName(FALSE, 'moduletest');
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest');
- $manager->enable(array('test.extension.manager.moduletest'));
- $this->assertHookCounts('moduletest', array(
+ $manager->enable(['test.extension.manager.moduletest']);
+ $this->assertHookCounts('moduletest', [
'install' => 1,
'enable' => 2,
'disable' => 1,
'uninstall' => 0,
- ));
+ ]);
$this->assertModuleActiveByName(TRUE, 'moduletest');
$this->assertModuleActiveByKey(TRUE, 'test.extension.manager.moduletest');
}
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto1');
// install it
- $manager->install(array('test.extension.manager.module.auto1'));
+ $manager->install(['test.extension.manager.module.auto1']);
$this->assertEquals('installed', $manager->getStatus('test.extension.manager.module.auto1'));
- $this->assertHookCounts('test_extension_manager_module_auto1', array(
+ $this->assertHookCounts('test_extension_manager_module_auto1', [
'install' => 1,
'enable' => 1,
'disable' => 0,
'uninstall' => 0,
- ));
+ ]);
$this->assertModuleActiveByName(TRUE, 'test_extension_manager_module_auto1');
$this->assertModuleActiveByKey(TRUE, 'test.extension.manager.module.auto1');
$this->assertEquals('installed-missing', $manager->getStatus('test.extension.manager.module.auto1'));
// disable while missing
- $manager->disable(array('test.extension.manager.module.auto1'));
+ $manager->disable(['test.extension.manager.module.auto1']);
$this->assertEquals('disabled-missing', $manager->getStatus('test.extension.manager.module.auto1'));
- $this->assertHookCounts('test_extension_manager_module_auto1', array(
+ $this->assertHookCounts('test_extension_manager_module_auto1', [
'install' => 1,
'enable' => 1,
// normally called -- but not for missing modules!
'disable' => 0,
'uninstall' => 0,
- ));
+ ]);
$this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto1');
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest');
- $manager->uninstall(array('test.extension.manager.module.auto1'));
- $this->assertHookCounts('test_extension_manager_module_auto1', array(
+ $manager->uninstall(['test.extension.manager.module.auto1']);
+ $this->assertHookCounts('test_extension_manager_module_auto1', [
'install' => 1,
'enable' => 1,
// normally called -- but not for missing modules!
'disable' => 0,
// normally called -- but not for missing modules!
'uninstall' => 0,
- ));
+ ]);
$this->assertEquals('unknown', $manager->getStatus('test.extension.manager.module.auto1'));
$this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto1');
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto1');
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto2');
// install it
- $manager->install(array('test.extension.manager.module.auto2'));
+ $manager->install(['test.extension.manager.module.auto2']);
$this->assertEquals('installed', $manager->getStatus('test.extension.manager.module.auto2'));
- $this->assertHookCounts('test_extension_manager_module_auto2', array(
+ $this->assertHookCounts('test_extension_manager_module_auto2', [
'install' => 1,
'enable' => 1,
'disable' => 0,
'uninstall' => 0,
- ));
+ ]);
$this->assertModuleActiveByName(TRUE, 'test_extension_manager_module_auto2');
$this->assertModuleActiveByKey(TRUE, 'test.extension.manager.module.auto2');
$this->assertEquals('installed-missing', $manager->getStatus('test.extension.manager.module.auto2'));
// disable while missing
- $manager->disable(array('test.extension.manager.module.auto2'));
+ $manager->disable(['test.extension.manager.module.auto2']);
$this->assertEquals('disabled-missing', $manager->getStatus('test.extension.manager.module.auto2'));
- $this->assertHookCounts('test_extension_manager_module_auto2', array(
+ $this->assertHookCounts('test_extension_manager_module_auto2', [
'install' => 1,
'enable' => 1,
// normally called -- but not for missing modules!
'disable' => 0,
'uninstall' => 0,
- ));
+ ]);
$this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto2');
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest');
// restore the code
$this->_createExtension('test.extension.manager.module.auto2', 'module', 'test_extension_manager_module_auto2');
$manager->refresh();
- $this->assertHookCounts('test_extension_manager_module_auto2', array(
+ $this->assertHookCounts('test_extension_manager_module_auto2', [
'install' => 1,
'enable' => 1,
'disable' => 0,
'uninstall' => 0,
- ));
+ ]);
$this->assertEquals('disabled', $manager->getStatus('test.extension.manager.module.auto2'));
$this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto2');
$this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto2');
$basedir = $this->basedir;
mkdir("$basedir/$key");
file_put_contents("$basedir/$key/info.xml", "<extension key='$key' type='$type'><file>$file</file></extension>");
- file_put_contents("$basedir/$key/$file.php", strtr($template, array('_FILE_' => $file)));
+ file_put_contents("$basedir/$key/$file.php", strtr($template, ['_FILE_' => $file]));
$this->system->getCache()->flush();
$this->system->getManager()->refresh();
}
public function setUp() {
parent::setUp();
if (class_exists('test_extension_manager_paymenttest')) {
- test_extension_manager_paymenttest::$counts = array();
+ test_extension_manager_paymenttest::$counts = [];
}
- $this->system = new CRM_Extension_System(array(
+ $this->system = new CRM_Extension_System([
'extensionsDir' => '',
'extensionsURL' => '',
- ));
- $this->quickCleanup(array('civicrm_payment_processor'));
+ ]);
+ $this->quickCleanup(['civicrm_payment_processor']);
}
public function tearDown() {
parent::tearDown();
$this->system = NULL;
- $this->quickCleanup(array('civicrm_payment_processor'));
+ $this->quickCleanup(['civicrm_payment_processor']);
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
}
public function testInstallDisableUninstall() {
$manager = $this->system->getManager();
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
- $manager->install(array('test.extension.manager.paymenttest'));
+ $manager->install(['test.extension.manager.paymenttest']);
$this->assertEquals(1, test_extension_manager_paymenttest::$counts['install']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
- $manager->disable(array('test.extension.manager.paymenttest'));
+ $manager->disable(['test.extension.manager.paymenttest']);
$this->assertEquals(1, test_extension_manager_paymenttest::$counts['disable']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0');
- $manager->uninstall(array('test.extension.manager.paymenttest'));
+ $manager->uninstall(['test.extension.manager.paymenttest']);
$this->assertEquals(1, test_extension_manager_paymenttest::$counts['uninstall']);
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
}
$manager = $this->system->getManager();
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
- $manager->install(array('test.extension.manager.paymenttest'));
+ $manager->install(['test.extension.manager.paymenttest']);
$this->assertEquals(1, test_extension_manager_paymenttest::$counts['install']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
- $manager->disable(array('test.extension.manager.paymenttest'));
+ $manager->disable(['test.extension.manager.paymenttest']);
$this->assertEquals(1, test_extension_manager_paymenttest::$counts['disable']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0');
- $manager->enable(array('test.extension.manager.paymenttest'));
+ $manager->enable(['test.extension.manager.paymenttest']);
$this->assertEquals(1, test_extension_manager_paymenttest::$counts['enable']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
$manager = $this->system->getManager();
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
- $manager->install(array('test.extension.manager.paymenttest'));
+ $manager->install(['test.extension.manager.paymenttest']);
$this->assertEquals(1, test_extension_manager_paymenttest::$counts['install']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 1');
$payment_processor_type_id = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
- $ppDAO = CRM_Financial_BAO_PaymentProcessor::create(array(
+ $ppDAO = CRM_Financial_BAO_PaymentProcessor::create([
'payment_processor_type_id' => $payment_processor_type_id,
'domain_id' => CRM_Core_Config::domainID(),
- ));
+ ]);
- $manager->disable(array('test.extension.manager.paymenttest'));
+ $manager->disable(['test.extension.manager.paymenttest']);
$this->assertEquals(1, test_extension_manager_paymenttest::$counts['disable']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest" AND is_active = 0');
// first attempt to uninstall -- fail
try {
- $manager->uninstall(array('test.extension.manager.paymenttest'));
+ $manager->uninstall(['test.extension.manager.paymenttest']);
$this->fail('Failed to catch expected exception');
}
catch (CRM_Extension_Exception_DependencyException $e) {
$ppDAO->delete();
// second attempt to uninstall -- ok
- $manager->uninstall(array('test.extension.manager.paymenttest'));
+ $manager->uninstall(['test.extension.manager.paymenttest']);
$this->assertEquals(1, test_extension_manager_paymenttest::getCount('uninstall'));
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_payment_processor_type WHERE class_name = "test.extension.manager.paymenttest"');
}
//if (class_exists('test_extension_manager_reporttest')) {
// test_extension_manager_reporttest::$counts = array();
//}
- $this->system = new CRM_Extension_System(array(
+ $this->system = new CRM_Extension_System([
'extensionsDir' => '',
'extensionsURL' => '',
- ));
+ ]);
}
public function tearDown() {
$manager = $this->system->getManager();
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"');
- $manager->install(array('test.extension.manager.reporttest'));
+ $manager->install(['test.extension.manager.reporttest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 1');
- $manager->disable(array('test.extension.manager.reporttest'));
+ $manager->disable(['test.extension.manager.reporttest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 0');
- $manager->uninstall(array('test.extension.manager.reporttest'));
+ $manager->uninstall(['test.extension.manager.reporttest']);
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"');
}
$manager = $this->system->getManager();
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"');
- $manager->install(array('test.extension.manager.reporttest'));
+ $manager->install(['test.extension.manager.reporttest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 1');
- $manager->disable(array('test.extension.manager.reporttest'));
+ $manager->disable(['test.extension.manager.reporttest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 0');
- $manager->enable(array('test.extension.manager.reporttest'));
+ $manager->enable(['test.extension.manager.reporttest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.reporttest" AND is_active = 1');
}
//if (class_exists('test_extension_manager_searchtest')) {
// test_extension_manager_searchtest::$counts = array();
//}
- $this->system = new CRM_Extension_System(array(
+ $this->system = new CRM_Extension_System([
'extensionsDir' => '',
'extensionsURL' => '',
- ));
+ ]);
}
public function tearDown() {
$manager = $this->system->getManager();
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"');
- $manager->install(array('test.extension.manager.searchtest'));
+ $manager->install(['test.extension.manager.searchtest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 1');
- $manager->disable(array('test.extension.manager.searchtest'));
+ $manager->disable(['test.extension.manager.searchtest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 0');
- $manager->uninstall(array('test.extension.manager.searchtest'));
+ $manager->uninstall(['test.extension.manager.searchtest']);
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"');
}
$manager = $this->system->getManager();
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"');
- $manager->install(array('test.extension.manager.searchtest'));
+ $manager->install(['test.extension.manager.searchtest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 1');
- $manager->disable(array('test.extension.manager.searchtest'));
+ $manager->disable(['test.extension.manager.searchtest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 0');
- $manager->enable(array('test.extension.manager.searchtest'));
+ $manager->enable(['test.extension.manager.searchtest']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest"');
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "test.extension.manager.searchtest" AND is_active = 1');
}
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
$testingTypeManager->expects($this->never())
->method('onPreInstall');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::OTHER_TESTING_TYPE => $testingTypeManager,
- ));
- $manager->install(array('test.foo.bar'));
+ ]);
+ $manager->install(['test.foo.bar']);
}
/**
public function testInstall_Disable_Uninstall() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$testingTypeManager
->expects($this->exactly(2))
->method('onPostInstall');
- $manager->install(array('test.whiz.bang', 'test.foo.bar'));
+ $manager->install(['test.whiz.bang', 'test.foo.bar']);
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
$testingTypeManager
->expects($this->once())
->method('onPostDisable');
- $manager->disable(array('test.foo.bar'));
+ $manager->disable(['test.foo.bar']);
$this->assertEquals('disabled', $manager->getStatus('test.foo.bar'));
// no side-effect
$this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
$testingTypeManager
->expects($this->once())
->method('onPostUninstall');
- $manager->uninstall(array('test.foo.bar'));
+ $manager->uninstall(['test.foo.bar']);
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar'));
// no side-effect
$this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
public function test_InstallAuto_DisableDownstream_UninstallDownstream() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar'));
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.downstream'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$testingTypeManager->expects($this->exactly(2))->method('onPreInstall');
$testingTypeManager->expects($this->exactly(2))->method('onPostInstall');
- $this->assertEquals(array('test.foo.bar', 'test.foo.downstream'),
- $manager->findInstallRequirements(array('test.foo.downstream')));
+ $this->assertEquals(['test.foo.bar', 'test.foo.downstream'],
+ $manager->findInstallRequirements(['test.foo.downstream']));
$manager->install(
- $manager->findInstallRequirements(array('test.foo.downstream')));
+ $manager->findInstallRequirements(['test.foo.downstream']));
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertEquals('installed', $manager->getStatus('test.foo.downstream'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$testingTypeManager->expects($this->once())->method('onPreDisable');
$testingTypeManager->expects($this->once())->method('onPostDisable');
- $this->assertEquals(array('test.foo.downstream'),
- $manager->findDisableRequirements(array('test.foo.downstream')));
- $manager->disable(array('test.foo.downstream'));
+ $this->assertEquals(['test.foo.downstream'],
+ $manager->findDisableRequirements(['test.foo.downstream']));
+ $manager->disable(['test.foo.downstream']);
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertEquals('disabled', $manager->getStatus('test.foo.downstream'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$testingTypeManager->expects($this->once())->method('onPreUninstall');
$testingTypeManager->expects($this->once())->method('onPostUninstall');
- $manager->uninstall(array('test.foo.downstream'));
+ $manager->uninstall(['test.foo.downstream']);
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.downstream'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
public function testInstallAuto_Twice() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar'));
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.downstream'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$testingTypeManager->expects($this->exactly(2))->method('onPreInstall');
$testingTypeManager->expects($this->exactly(2))->method('onPostInstall');
- $this->assertEquals(array('test.foo.bar', 'test.foo.downstream'),
- $manager->findInstallRequirements(array('test.foo.downstream')));
+ $this->assertEquals(['test.foo.bar', 'test.foo.downstream'],
+ $manager->findInstallRequirements(['test.foo.downstream']));
$manager->install(
- $manager->findInstallRequirements(array('test.foo.downstream')));
+ $manager->findInstallRequirements(['test.foo.downstream']));
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertEquals('installed', $manager->getStatus('test.foo.downstream'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$testingTypeManager->expects($this->exactly(0))->method('onPreInstall');
$testingTypeManager->expects($this->exactly(0))->method('onPostInstall');
$manager->install(
- $manager->findInstallRequirements(array('test.foo.downstream')));
+ $manager->findInstallRequirements(['test.foo.downstream']));
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertEquals('installed', $manager->getStatus('test.foo.downstream'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
public function test_InstallAuto_DisableUpstream() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar'));
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.downstream'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$testingTypeManager->expects($this->exactly(2))->method('onPreInstall');
$testingTypeManager->expects($this->exactly(2))->method('onPostInstall');
- $this->assertEquals(array('test.foo.bar', 'test.foo.downstream'),
- $manager->findInstallRequirements(array('test.foo.downstream')));
+ $this->assertEquals(['test.foo.bar', 'test.foo.downstream'],
+ $manager->findInstallRequirements(['test.foo.downstream']));
$manager->install(
- $manager->findInstallRequirements(array('test.foo.downstream')));
+ $manager->findInstallRequirements(['test.foo.downstream']));
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertEquals('installed', $manager->getStatus('test.foo.downstream'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$testingTypeManager->expects($this->never())->method('onPreDisable');
$testingTypeManager->expects($this->never())->method('onPostDisable');
- $this->assertEquals(array('test.foo.downstream', 'test.foo.bar'),
- $manager->findDisableRequirements(array('test.foo.bar')));
+ $this->assertEquals(['test.foo.downstream', 'test.foo.bar'],
+ $manager->findDisableRequirements(['test.foo.bar']));
try {
- $manager->disable(array('test.foo.bar'));
+ $manager->disable(['test.foo.bar']);
$this->fail('Expected disable to fail due to dependency');
}
catch (CRM_Extension_Exception $e) {
public function testInstall_DirtyRemove_Disable_Uninstall() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar'));
- $manager->install(array('test.foo.bar'));
+ $manager->install(['test.foo.bar']);
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertTrue(file_exists("{$this->basedir}/weird/foobar/info.xml"));
$testingTypeManager
->expects($this->once())
->method('onPostDisable');
- $manager->disable(array('test.foo.bar'));
+ $manager->disable(['test.foo.bar']);
$this->assertEquals('disabled-missing', $manager->getStatus('test.foo.bar'));
$testingTypeManager
$testingTypeManager
->expects($this->once())
->method('onPostUninstall');
- $manager->uninstall(array('test.foo.bar'));
+ $manager->uninstall(['test.foo.bar']);
$this->assertEquals('unknown', $manager->getStatus('test.foo.bar'));
}
public function testInstall_Disable_Enable() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar'));
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$testingTypeManager
->expects($this->exactly(2))
->method('onPostInstall');
- $manager->install(array('test.whiz.bang', 'test.foo.bar'));
+ $manager->install(['test.whiz.bang', 'test.foo.bar']);
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
$testingTypeManager
->expects($this->once())
->method('onPostDisable');
- $manager->disable(array('test.foo.bar'));
+ $manager->disable(['test.foo.bar']);
$this->assertEquals('disabled', $manager->getStatus('test.foo.bar'));
$this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
$testingTypeManager
->expects($this->once())
->method('onPostEnable');
- $manager->enable(array('test.foo.bar'));
+ $manager->enable(['test.foo.bar']);
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
}
public function testInstall_Disable_Install() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar'));
$testingTypeManager
$testingTypeManager
->expects($this->once())
->method('onPostInstall');
- $manager->install(array('test.foo.bar'));
+ $manager->install(['test.foo.bar']);
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
$testingTypeManager
$testingTypeManager
->expects($this->once())
->method('onPostDisable');
- $manager->disable(array('test.foo.bar'));
+ $manager->disable(['test.foo.bar']);
$this->assertEquals('disabled', $manager->getStatus('test.foo.bar'));
$testingTypeManager
->expects($this->once())
->method('onPostEnable');
// install() instead of enable()
- $manager->install(array('test.foo.bar'));
+ $manager->install(['test.foo.bar']);
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
}
public function testEnableBare() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.foo.bar'));
$testingTypeManager
->expects($this->never())
->method('onPostEnable');
// enable not install
- $manager->enable(array('test.foo.bar'));
+ $manager->enable(['test.foo.bar']);
$this->assertEquals('installed', $manager->getStatus('test.foo.bar'));
}
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
$testingTypeManager->expects($this->never())
->method('onPreInstall');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('unknown', $manager->getStatus('test.foo.bar.whiz.bang'));
}
public function testReplace_Unknown() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('unknown', $manager->getStatus('test.newextension'));
$this->download = $this->_createDownload('test.newextension', 'newextension');
public function testReplace_Uninstalled() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$this->assertEquals('oddball', $this->mapper->keyToInfo('test.whiz.bang')->file);
public function testReplace_Installed() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
$this->assertEquals('oddball', $this->mapper->keyToInfo('test.whiz.bang')->file);
- $manager->install(array('test.whiz.bang'));
+ $manager->install(['test.whiz.bang']);
$this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
$this->assertEquals('oddball', $this->mapper->keyToInfo('test.whiz.bang')->file);
$this->assertDBQuery('oddball', 'SELECT file FROM civicrm_extension WHERE full_name ="test.whiz.bang"');
public function testReplace_InstalledMissing() {
$mockFunction = $this->mockMethod;
$testingTypeManager = $this->$mockFunction('CRM_Extension_Manager_Interface');
- $manager = $this->_createManager(array(
+ $manager = $this->_createManager([
self::TESTING_TYPE => $testingTypeManager,
- ));
+ ]);
// initial installation
$this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
- $manager->install(array('test.whiz.bang'));
+ $manager->install(['test.whiz.bang']);
$this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
// dirty remove
file_put_contents("$basedir/weird/downstream/info.xml", "<extension key='test.foo.downstream' type='" . self::TESTING_TYPE . "'><file>oddball</file><requires><ext>test.foo.bar</ext></requires></extension>");
// not needed for now // file_put_contents("$basedir/weird/downstream/oddball.php", "<?php\n");
$c = new CRM_Extension_Container_Basic($basedir, 'http://example/basedir', $cache, $cacheKey);
- return array($basedir, $c);
+ return [$basedir, $c];
}
/**
}
public function testGetKeysByPath() {
- $mappers = array(
+ $mappers = [
$this->basedir => $this->mapper,
$this->basedir2 => $this->mapperWithSlash,
- );
+ ];
foreach ($mappers as $basedir => $mapper) {
/** @var CRM_Extension_Mapper $mapper */
- $this->assertEquals(array(), $mapper->getKeysByPath($basedir));
- $this->assertEquals(array(), $mapper->getKeysByPath($basedir . '/weird'));
- $this->assertEquals(array(), $mapper->getKeysByPath($basedir . '/weird/'));
- $this->assertEquals(array(), $mapper->getKeysByPath($basedir . '/weird//'));
- $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/*'));
- $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '//*'));
- $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/*'));
- $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/foobar'));
- $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/foobar/'));
- $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/foobar//'));
- $this->assertEquals(array('test.foo.bar'), $mapper->getKeysByPath($basedir . '/weird/foobar/*'));
+ $this->assertEquals([], $mapper->getKeysByPath($basedir));
+ $this->assertEquals([], $mapper->getKeysByPath($basedir . '/weird'));
+ $this->assertEquals([], $mapper->getKeysByPath($basedir . '/weird/'));
+ $this->assertEquals([], $mapper->getKeysByPath($basedir . '/weird//'));
+ $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/*'));
+ $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '//*'));
+ $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/*'));
+ $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/foobar'));
+ $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/foobar/'));
+ $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/foobar//'));
+ $this->assertEquals(['test.foo.bar'], $mapper->getKeysByPath($basedir . '/weird/foobar/*'));
}
}
file_put_contents("$basedir/weird/foobar/info.xml", "<extension key='test.foo.bar' type='report'><file>oddball</file></extension>");
// not needed for now // file_put_contents("$basedir/weird/bar/oddball.php", "<?php\n");
$c = new CRM_Extension_Container_Basic($basedir . $appendPathGarbage, 'http://example/basedir' . $appendPathGarbage, $cache, $cacheKey);
- return array($basedir, $c);
+ return [$basedir, $c];
}
}
* Check method add()
*/
public function testAdd() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
$result = $this->assertDBNotNull(
* Check method retrive()
*/
public function testRetrieve() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = $defaults = array();
+ ];
+ $ids = $defaults = [];
CRM_Financial_BAO_FinancialAccount::add($params);
$result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
* Check method setIsActive()
*/
public function testSetIsActive() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
$result = CRM_Financial_BAO_FinancialAccount::setIsActive($financialAccount->id, 0);
$this->assertEquals($result, TRUE, 'Verify financial account record updation for is_active.');
* Check method del()
*/
public function testdel() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
CRM_Financial_BAO_FinancialAccount::del($financialAccount->id);
- $params = array('id' => $financialAccount->id);
+ $params = ['id' => $financialAccount->id];
$result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
$this->assertEquals(empty($result), TRUE, 'Verify financial account record deletion.');
}
* Check method del()
*/
public function testdelIfHasContribution() {
- $params = array(
+ $params = [
'name' => 'Donation Test',
'is_active' => 1,
'is_deductible' => 1,
'is_reserved' => 1,
- );
+ ];
$financialType = CRM_Financial_BAO_FinancialType::add($params);
- $defaults = array();
- $params = array(
+ $defaults = [];
+ $params = [
'name' => 'Donation Test',
'is_active' => 1,
- );
+ ];
$result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
$contactId = $this->individualCreate();
- $contributionParams = array(
+ $contributionParams = [
'total_amount' => 300,
'currency' => 'USD',
'contact_id' => $contactId,
'financial_type_id' => $financialType->id,
'contribution_status_id' => 1,
- );
+ ];
$this->callAPISuccess('Contribution', 'create', $contributionParams);
CRM_Financial_BAO_FinancialAccount::del($result->id);
- $params = array('id' => $result->id);
+ $params = ['id' => $result->id];
$result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
$this->assertEquals(empty($result), FALSE, 'Verify financial account record deletion.');
}
* Check method getAccountingCode()
*/
public function testGetAccountingCode() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_active' => 1,
'is_reserved' => 0,
- );
+ ];
- $ids = array();
+ $ids = [];
$financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
$financialAccountid = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', 'Donations', 'id', 'name');
CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccountid, 'accounting_code', '4800');
* Test getting financial account for a given financial Type with a particular relationship.
*/
public function testGetFinancialAccountByFinancialTypeAndRelationshipCustomAddedRefunded() {
- $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array(
+ $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', [
'name' => 'Refund Account',
'is_active' => TRUE,
- ));
+ ]);
- $this->callAPISuccess('EntityFinancialAccount', 'create', array(
+ $this->callAPISuccess('EntityFinancialAccount', 'create', [
'entity_id' => 2,
'entity_table' => 'civicrm_financial_type',
'account_relationship' => 'Credit/Contra Revenue Account is',
'financial_account_id' => 'Refund Account',
- ));
+ ]);
$this->assertEquals($financialAccount['id'],
CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship(2, 'Credit/Contra Revenue Account is'));
}
* Test getting financial account relations for a given financial type.
*/
public function testGetFinancialAccountRelations() {
- $fAccounts = $rAccounts = array();
+ $fAccounts = $rAccounts = [];
$relations = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
- $links = array(
+ $links = [
'Expense Account is' => 'Expenses',
'Accounts Receivable Account is' => 'Asset',
'Income Account is' => 'Revenue',
'Discounts Account is' => 'Revenue',
'Sales Tax Account is' => 'Liability',
'Deferred Revenue Account is' => 'Liability',
- );
+ ];
$dao = CRM_Core_DAO::executeQuery("SELECT ov.value, ov.name
FROM civicrm_option_value ov
INNER JOIN civicrm_option_group og ON og.id = ov.option_group_id
$valid = CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params);
$this->assertFalse($valid, "This should have been false");
$cid = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $cid,
'receive_date' => '2016-01-20',
'total_amount' => 100,
'financial_type_id' => 4,
'revenue_recognition_date' => date('Ymd', strtotime("+1 month")),
- 'line_items' => array(
- array(
- 'line_item' => array(
- array(
+ 'line_items' => [
+ [
+ 'line_item' => [
+ [
'entity_table' => 'civicrm_contribution',
'price_field_id' => 8,
'price_field_value_id' => 16,
'unit_price' => 100,
'line_total' => 100,
'financial_type_id' => 4,
- ),
- array(
+ ],
+ [
'entity_table' => 'civicrm_contribution',
'price_field_id' => 8,
'price_field_value_id' => 17,
'unit_price' => 200,
'line_total' => 200,
'financial_type_id' => 4,
- ),
- ),
- ),
- ),
- );
+ ],
+ ],
+ ],
+ ],
+ ];
try {
CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params);
}
catch (CRM_Core_Exception $e) {
$this->fail("Missed expected exception");
}
- $params = array(
+ $params = [
'contact_id' => $cid,
'receive_date' => '2016-01-20',
'total_amount' => 100,
'financial_type_id' => 1,
'revenue_recognition_date' => date('Ymd', strtotime("+1 month")),
- );
+ ];
try {
CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params);
$this->fail("Missed expected exception");
public function testGetAllDeferredFinancialAccount() {
$financialAccount = CRM_Financial_BAO_FinancialAccount::getAllDeferredFinancialAccount();
// The two deferred financial accounts which are created by default.
- $expected = array(
+ $expected = [
"Deferred Revenue - Member Dues (2740)",
"Deferred Revenue - Event Fee (2730)",
- );
+ ];
$this->assertEquals(array_count_values($expected), array_count_values($financialAccount), "The two arrays are not the same");
$this->_createDeferredFinancialAccount();
$financialAccount = CRM_Financial_BAO_FinancialAccount::getAllDeferredFinancialAccount();
* CRM-20037: Test balance due amount, if contribution is done using deferred Financial Type
*/
public function testBalanceDueIfDeferredRevenueEnabled() {
- Civi::settings()->set('contribution_invoice_settings', array('deferred_revenue_enabled' => '1'));
+ Civi::settings()->set('contribution_invoice_settings', ['deferred_revenue_enabled' => '1']);
$deferredFinancialTypeID = $this->_createDeferredFinancialAccount();
$totalAmount = 100.00;
- $contribution = $this->callAPISuccess('Contribution', 'create', array(
+ $contribution = $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $this->individualCreate(),
'receive_date' => '20120511',
'total_amount' => $totalAmount,
'net_amount' => 95.00,
'source' => 'SSF',
'contribution_status_id' => 1,
- ));
+ ]);
$balance = CRM_Contribute_BAO_Contribution::getContributionBalance($contribution['id'], $totalAmount);
$this->assertEquals(0.0, $balance);
Civi::settings()->revert('contribution_invoice_settings');
* Helper function to create deferred financial account.
*/
public function _createDeferredFinancialAccount() {
- $params = array(
+ $params = [
'name' => 'TestFinancialAccount_1',
'accounting_code' => 4800,
'contact_id' => 1,
'is_deductible' => 0,
'is_active' => 1,
'is_reserved' => 0,
- );
+ ];
$financialAccount = $this->callAPISuccess('FinancialAccount', 'create', $params);
$params['name'] = 'test_financialType1';
$financialType = $this->callAPISuccess('FinancialType', 'create', $params);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Deferred Revenue Account is' "));
- $financialParams = array(
+ $financialParams = [
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialType['id'],
'account_relationship' => $relationTypeId,
'financial_account_id' => $financialAccount['id'],
- );
+ ];
$this->callAPISuccess('EntityFinancialAccount', 'create', $financialParams);
$result = $this->assertDBNotNull(
];
$contribution = $this->callAPISuccess('Contribution', 'create', $cParams);
- $lParams = array(
+ $lParams = [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'price_field_id' => 1,
'line_total' => $price,
'price_field_value_id' => 1,
'financial_type_id' => 1,
- );
+ ];
$lineItem = CRM_Price_BAO_LineItem::create($lParams);
$contributionObj = $this->getContributionObject($contribution['id']);
];
$contribution = $this->callAPISuccess('Contribution', 'create', $cParams);
- $lParams = array(
+ $lParams = [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'price_field_id' => 1,
'line_total' => $price,
'price_field_value_id' => 1,
'financial_type_id' => 1,
- );
+ ];
$contributionObj = $this->getContributionObject($contribution['id']);
$lineItem = CRM_Price_BAO_LineItem::create($lParams);
CRM_Financial_BAO_FinancialItem::add($lineItem, $contributionObj);
- $values = array();
- $fParams = array(
+ $values = [];
+ $fParams = [
'entity_id' => $lineItem->id,
'entity_table' => 'civicrm_line_item',
- );
+ ];
$financialItem = CRM_Financial_BAO_FinancialItem::retrieve($fParams, $values);
$this->assertEquals($financialItem->amount, $price, 'Verify financial item amount.');
}
$contact = $this->callAPISuccess('Contact', 'create', $params);
$price = 100.00;
- $cParams = array(
+ $cParams = [
'contact_id' => $contact['id'],
'total_amount' => $price,
'financial_type_id' => 1,
'is_active' => 1,
'skipLineItem' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $cParams);
- $lParams = array(
+ $lParams = [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'price_field_id' => 1,
'line_total' => $price,
'price_field_value_id' => 1,
'financial_type_id' => 1,
- );
+ ];
$lineItem = CRM_Price_BAO_LineItem::create($lParams);
- $fParams = array(
+ $fParams = [
'contact_id' => $contact['id'],
'description' => 'Contribution Amount',
'amount' => $price,
'transaction_date' => date('YmdHis'),
'entity_id' => $lineItem->id,
'entity_table' => 'civicrm_line_item',
- );
+ ];
CRM_Financial_BAO_FinancialItem::create($fParams);
$entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
* Check method del()
*/
public function testCreateEntityTrxn() {
- $fParams = array(
+ $fParams = [
'name' => 'Donations' . substr(sha1(rand()), 0, 7),
'is_deductible' => 0,
'is_active' => 1,
- );
+ ];
$amount = 200;
- $ids = array();
+ $ids = [];
$financialAccount = CRM_Financial_BAO_FinancialAccount::add($fParams, $ids);
$financialTrxn = new CRM_Financial_DAO_FinancialTrxn();
$financialTrxn->to_financial_account_id = $financialAccount->id;
$financialTrxn->total_amount = $amount;
$financialTrxn->save();
- $params = array(
+ $params = [
'entity_table' => 'civicrm_contribution',
'entity_id' => 1,
'financial_trxn_id' => $financialTrxn->id,
'amount' => $amount,
- );
+ ];
$entityTrxn = CRM_Financial_BAO_FinancialItem::createEntityTrxn($params);
$entityResult = $this->assertDBNotNull(
*/
public function testRetrieveEntityFinancialTrxn() {
$entityTrxn = self::testCreateEntityTrxn();
- $params = array(
+ $params = [
'entity_table' => 'civicrm_contribution',
'entity_id' => 1,
'financial_trxn_id' => $entityTrxn->financial_trxn_id,
'amount' => $entityTrxn->amount,
- );
+ ];
CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($params);
$entityResult = $this->assertDBNotNull(
public function testGetPreviousFinancialItem() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => 1,
'total_amount' => 100.00,
'trxn_id' => '22ereerwww444444',
'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81',
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params);
- $params = array(
+ $params = [
'id' => $contribution['id'],
'total_amount' => 300.00,
- );
+ ];
$contribution = $this->callAPISuccess('Contribution', 'create', $params);
$financialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']);
- $params = array('id' => $financialItem['id']);
+ $params = ['id' => $financialItem['id']];
$financialItem = $this->callAPISuccess('FinancialItem', 'get', $params);
$this->assertEquals(200.00, $financialItem['values'][$financialItem['id']]['amount'], "The amounts do not match.");
}
$this->enableTaxAndInvoicing();
$this->relationForFinancialTypeWithFinancialAccount(1);
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 100,
'financial_type_id' => 1,
'contact_id' => $contactId,
'contribution_status_id' => 1,
'price_set_id' => 0,
- ), CRM_Core_Action::ADD);
+ ], CRM_Core_Action::ADD);
$contribution = $this->callAPISuccessGetSingle('Contribution',
- array(
+ [
'contact_id' => $contactId,
- 'return' => array('id'),
- )
+ 'return' => ['id'],
+ ]
);
$financialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']);
- $params = array(
+ $params = [
'id' => $financialItem['id'],
- 'return' => array(
+ 'return' => [
'description',
'status_id',
'amount',
'financial_account_id',
- ),
- );
- $checkAgainst = array(
+ ],
+ ];
+ $checkAgainst = [
'id' => $financialItem['id'],
'description' => 'Contribution Amount',
'status_id' => '1',
'amount' => '100.00',
'financial_account_id' => '1',
- );
+ ];
$this->callAPISuccessGetSingle('FinancialItem', $params, $checkAgainst);
}
);
CRM_Financial_BAO_FinancialTypeAccount::del($financialAccountType->id);
- $params = array('id' => $financialAccountType->id);
+ $params = ['id' => $financialAccountType->id];
$result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults);
$this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
}
'Asset Account is'
);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
- $financialParams = array(
+ $financialParams = [
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialType->id,
'account_relationship' => $relationTypeId,
'financial_account_id' => $financialAccount->id,
- );
+ ];
- $defaults = array();
+ $defaults = [];
$financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::retrieve($financialParams, $defaults);
$this->assertEquals($financialAccountType['entity_id'], $financialType->id, 'Verify Entity Id.');
$this->assertEquals($financialAccountType['financial_account_id'], $financialAccount->id, 'Verify Financial Account Id.');
list($financialAccount, $financialType, $financialAccountType) = $this->createFinancialAccount(
'Asset'
);
- $optionParams = array(
+ $optionParams = [
'name' => 'Credit Card',
'value' => $paymentInstrumentValue,
- );
+ ];
$optionValue = CRM_Core_BAO_OptionValue::retrieve($optionParams, $defaults);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
- $financialParams = array(
+ $financialParams = [
'entity_table' => 'civicrm_option_value',
'entity_id' => $optionValue->id,
'account_relationship' => $relationTypeId,
'financial_account_id' => $financialAccount->id,
- );
+ ];
CRM_Financial_BAO_FinancialTypeAccount::add($financialParams);
$financialAccountId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($paymentInstrumentValue);
* Test validate account relationship with financial account type.
*/
public function testValidateRelationship() {
- $params = array('labelColumn' => 'name');
+ $params = ['labelColumn' => 'name'];
$financialAccount = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params);
$accountRelationships = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params);
$financialType = CRM_Contribute_PseudoConstant::financialType();
* obj CRM_Financial_DAO_FinancialAccount, obj CRM_Financial_DAO_FinancialType, obj CRM_Financial_DAO_EntityFinancialAccount
*/
public function createFinancialAccount($financialAccountType, $relationType = NULL) {
- $params = array('labelColumn' => 'name');
+ $params = ['labelColumn' => 'name'];
$relationTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params);
$financialAccountTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params);
- $params = array(
+ $params = [
'name' => 'TestFinancialAccount_' . rand(),
'contact_id' => 1,
'is_deductible' => 0,
'is_active' => 1,
'is_reserved' => 0,
'financial_account_type_id' => array_search($financialAccountType, $financialAccountTypes),
- );
+ ];
$financialAccount = CRM_Financial_BAO_FinancialAccount::add($params);
$financialType = $financialAccountType = NULL;
if ($relationType) {
$params['name'] = 'test_financialType1';
$financialType = CRM_Financial_BAO_FinancialType::add($params);
- $financialParams = array(
+ $financialParams = [
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialType->id,
'account_relationship' => array_search($relationType, $relationTypes),
- );
+ ];
//CRM-20313: As per unique index added in civicrm_entity_financial_account table,
// first check if there's any record on basis of unique key (entity_table, account_relationship, entity_id)
$financialParams['financial_account_id'] = $financialAccount->id;
$financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::add($financialParams);
}
- return array($financialAccount, $financialType, $financialAccountType);
+ return [$financialAccount, $financialType, $financialAccountType];
}
}
* Check method add().
*/
public function testAdd() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_active' => 1,
'is_deductible' => 1,
'is_reserved' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
$result = $this->assertDBNotNull(
'CRM_Financial_DAO_FinancialType',
* Check method retrieve().
*/
public function testRetrieve() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_active' => 1,
'is_deductible' => 1,
'is_reserved' => 1,
- );
+ ];
- $ids = array();
+ $ids = [];
CRM_Financial_BAO_FinancialType::add($params, $ids);
- $defaults = array();
+ $defaults = [];
$result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults);
$this->assertEquals($result->name, 'Donations', 'Verify Name for Financial Type');
}
* Check method setIsActive()
*/
public function testSetIsActive() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
$result = CRM_Financial_BAO_FinancialType::setIsActive($financialType->id, 0);
$this->assertEquals($result, TRUE, 'Verify financial type record updation for is_active.');
* Check method del()
*/
public function testDel() {
- $params = array(
+ $params = [
'name' => 'Donations',
'is_deductible' => 0,
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
CRM_Financial_BAO_FinancialType::del($financialType->id);
- $params = array('id' => $financialType->id);
+ $params = ['id' => $financialType->id];
$result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults);
$this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
}
* Set ACLs for Financial Types()
*/
public function setACL() {
- CRM_Core_BAO_Setting::setItem(array('acl_financial_type' => 1), NULL, 'contribution_invoice_settings');
+ CRM_Core_BAO_Setting::setItem(['acl_financial_type' => 1], NULL, 'contribution_invoice_settings');
}
/**
*/
public function testGetAvailableFinancialTypes() {
$this->setACL();
- $this->setPermissions(array(
+ $this->setPermissions([
'view contributions of type Donation',
'view contributions of type Member Dues',
- ));
- $types = array();
+ ]);
+ $types = [];
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
- $expectedResult = array(
+ $expectedResult = [
1 => "Donation",
2 => "Member Dues",
- );
+ ];
$this->assertEquals($expectedResult, $types, 'Verify that only certain financial types can be retrieved');
- $this->setPermissions(array(
+ $this->setPermissions([
'view contributions of type Donation',
- ));
+ ]);
unset($expectedResult[2]);
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
$this->assertEquals($expectedResult, $types, 'Verify that removing permission for a financial type restricts the available financial types');
*/
public function testgetAvailableMembershipTypes() {
// Create Membership types
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'Type One',
'domain_id' => 1,
'minimum_fee' => 10,
'financial_type_id' => 1,
'visibility' => 'Public',
'is_active' => 1,
- );
+ ];
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
// Add another
$this->setACL();
- $this->setPermissions(array(
+ $this->setPermissions([
'view contributions of type Donation',
'view contributions of type Member Dues',
- ));
+ ]);
CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($types);
- $expectedResult = array(
+ $expectedResult = [
1 => "Type One",
2 => "Type Two",
- );
+ ];
$this->assertEquals($expectedResult, $types, 'Verify that only certain membership types can be retrieved');
- $this->setPermissions(array(
+ $this->setPermissions([
'view contributions of type Donation',
- ));
+ ]);
unset($expectedResult[2]);
CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($types);
$this->assertEquals($expectedResult, $types, 'Verify that removing permission for a financial type restricts the available membership types');
CRM_Financial_BAO_FinancialType::permissionedFinancialTypes($permissions, TRUE);
$financialTypes = CRM_Contribute_PseudoConstant::financialType();
$prefix = ts('CiviCRM') . ': ';
- $actions = array('add', 'view', 'edit', 'delete');
+ $actions = ['add', 'view', 'edit', 'delete'];
foreach ($financialTypes as $id => $type) {
foreach ($actions as $action) {
- $checkPerms[$action . ' contributions of type ' . $type] = array(
+ $checkPerms[$action . ' contributions of type ' . $type] = [
$prefix . ts($action . ' contributions of type ') . $type,
ts(ucfirst($action) . ' contributions of type ') . $type,
- );
+ ];
}
}
- $checkPerms['administer CiviCRM Financial Types'] = array(
+ $checkPerms['administer CiviCRM Financial Types'] = [
$prefix . ts('administer CiviCRM Financial Types'),
ts('Administer access to Financial Types'),
- );
+ ];
$this->assertEquals($permissions, $checkPerms, 'Verify that permissions for each financial type have been added');
}
$this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title',
'id', $paramsSet['title'], 'Check DB for created priceset'
);
- $paramsField = array(
+ $paramsField = [
'label' => 'Price Field',
'name' => CRM_Utils_String::titleToVar('Price Field'),
'html_type' => 'CheckBox',
- 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'),
- 'option_value' => array('1' => 100, '2' => 200),
- 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'),
- 'option_weight' => array('1' => 1, '2' => 2),
- 'option_amount' => array('1' => 100, '2' => 200),
+ 'option_label' => ['1' => 'Price Field 1', '2' => 'Price Field 2'],
+ 'option_value' => ['1' => 100, '2' => 200],
+ 'option_name' => ['1' => 'Price Field 1', '2' => 'Price Field 2'],
+ 'option_weight' => ['1' => 1, '2' => 2],
+ 'option_amount' => ['1' => 100, '2' => 200],
'is_display_amounts' => 1,
'weight' => 1,
'options_per_line' => 1,
- 'is_active' => array('1' => 1, '2' => 1),
+ 'is_active' => ['1' => 1, '2' => 1],
'price_set_id' => $priceset->id,
'is_enter_qty' => 1,
'financial_type_id' => 1,
- );
+ ];
$priceField = CRM_Price_BAO_PriceField::create($paramsField);
- $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id));
- $contributionParams = array(
+ $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', ['price_field_id' => $priceField->id]);
+ $contributionParams = [
'total_amount' => 300,
'currency' => 'USD',
'contact_id' => $contactId,
'financial_type_id' => 1,
'contribution_status_id' => 1,
'skipCleanMoney' => TRUE,
- );
+ ];
foreach ($priceFields['values'] as $key => $priceField) {
- $lineItems[1][$key] = array(
+ $lineItems[1][$key] = [
'price_field_id' => $priceField['price_field_id'],
'price_field_value_id' => $priceField['id'],
'label' => $priceField['label'],
'unit_price' => $priceField['amount'],
'line_total' => $priceField['amount'],
'financial_type_id' => $priceField['financial_type_id'],
- );
+ ];
}
$contributionParams['line_item'] = $lineItems;
$contributions = CRM_Contribute_BAO_Contribution::create($contributionParams);
- CRM_Financial_BAO_FinancialType::$_statusACLFt = array();
+ CRM_Financial_BAO_FinancialType::$_statusACLFt = [];
$this->setACL();
- $this->setPermissions(array(
+ $this->setPermissions([
'view contributions of type Member Dues',
- ));
+ ]);
try {
CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributions->id, 'view');
$this->assertEquals("A fatal error was triggered: You do not have permission to access this page.", $e->getMessage());
}
- $this->setPermissions(array(
+ $this->setPermissions([
'view contributions of type Donation',
- ));
+ ]);
$perm = CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributions->id, 'view');
$this->assertEquals($perm, TRUE, 'Verify that lineitems now have permission.');
}
$this->assertEquals(array_search('acl_financial_type', $isACL), NULL);
$this->setACL();
$isACL = CRM_Core_BAO_Setting::getItem(NULL, 'contribution_invoice_settings');
- $this->assertEquals($isACL, array('acl_financial_type' => 1));
+ $this->assertEquals($isACL, ['acl_financial_type' => 1]);
}
/**
*/
public function testBuildPermissionedClause() {
$this->setACL();
- $this->setPermissions(array(
+ $this->setPermissions([
'view contributions of type Donation',
'view contributions of type Member Dues',
- ));
+ ]);
CRM_Financial_BAO_FinancialType::buildPermissionedClause($whereClause, 'contribution');
$this->assertEquals($whereClause, ' civicrm_contribution.financial_type_id IN (1,2)');
- $this->setPermissions(array(
+ $this->setPermissions([
'view contributions of type Donation',
'view contributions of type Member Dues',
'view contributions of type Event Fee',
- ));
+ ]);
$whereClause = NULL;
CRM_Financial_BAO_FinancialType::buildPermissionedClause($whereClause, 'contribution');
* Check method create()
*/
public function testGetCreditCards() {
- $params = array(
+ $params = [
'name' => 'API_Test_PP_Type',
'title' => 'API Test Payment Processor Type',
'class_name' => 'CRM_Core_Payment_APITest',
'payment_processor_type_id' => 1,
'is_recur' => 0,
'domain_id' => 1,
- 'accepted_credit_cards' => json_encode(array(
+ 'accepted_credit_cards' => json_encode([
'Visa' => 'Visa',
'Mastercard' => 'Mastercard',
'Amex' => 'Amex',
- )),
- );
+ ]),
+ ];
$paymentProcessor = CRM_Financial_BAO_PaymentProcessor::create($params);
- $expectedCards = array(
+ $expectedCards = [
'Visa' => 'Visa',
'Mastercard' => 'Mastercard',
'Amex' => 'Amex',
- );
+ ];
$cards = CRM_Financial_BAO_PaymentProcessor::getCreditCards($paymentProcessor->id);
$this->assertEquals($cards, $expectedCards, 'Verify correct credit card types are returned');
}
* Check method create()
*/
public function testCreate() {
- $params = array(
+ $params = [
'name' => 'Test_Payment_Processor',
'title' => 'Test Payment Processor',
'billing_mode' => 1,
- );
+ ];
$paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params);
$result = $this->assertDBNotNull(
'CRM_Financial_DAO_PaymentProcessorType',
* Check method retrieve()
*/
public function testRetrieve() {
- $params = array(
+ $params = [
'name' => 'Test_Retrieve_Payment_Processor',
'title' => 'Test Retrieve Payment Processor',
'billing_mode' => 1,
- );
- $defaults = array();
+ ];
+ $defaults = [];
CRM_Financial_BAO_PaymentProcessorType::create($params);
$result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults);
$this->assertEquals($result->name, 'Test_Retrieve_Payment_Processor', 'Verify Payment Processor Type');
* Check method setIsActive()
*/
public function testSetIsActive() {
- $params = array(
+ $params = [
'name' => 'Test_Set_Payment_Processor',
'title' => 'Test Set Payment Processor',
'billing_mode' => 1,
'is_active' => 1,
- );
+ ];
$paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params);
$result = CRM_Financial_BAO_PaymentProcessorType::setIsActive($paymentProcessor->id, 0);
* Check method getDefault()
*/
public function testGetDefault() {
- $params = array('is_default' => 1);
- $defaults = array();
+ $params = ['is_default' => 1];
+ $defaults = [];
$result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults);
$default = CRM_Financial_BAO_PaymentProcessorType::getDefault();
* Check method del()
*/
public function testDel() {
- $params = array(
+ $params = [
'name' => 'Test_Del_Payment_Processor',
'title' => 'Test Del Payment Processor',
'billing_mode' => 1,
'is_active' => 1,
- );
+ ];
- $defaults = array();
+ $defaults = [];
$paymentProcessor = CRM_Financial_BAO_PaymentProcessorType::create($params);
CRM_Financial_BAO_PaymentProcessorType::del($paymentProcessor->id);
- $params = array('id' => $paymentProcessor->id);
+ $params = ['id' => $paymentProcessor->id];
$result = CRM_Financial_BAO_PaymentProcessorType::retrieve($params, $defaults);
$this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
}
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
- $this->quickCleanup(array('civicrm_note', 'civicrm_uf_match', 'civicrm_address'));
+ $this->quickCleanup(['civicrm_note', 'civicrm_uf_match', 'civicrm_address']);
}
/**
public function testSubmitOnPaymentInstrumentChange() {
// First create a contribution using 'Check' as payment instrument
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'receive_date' => '2015-04-21 23:27:00',
'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'),
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'),
'check_number' => '123XA',
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'),
- ),
+ ],
CRM_Core_Action::ADD);
// fetch the financial trxn record later used in setting default values of payment edit form
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualID));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualID]);
$payments = CRM_Contribute_BAO_Contribution::getPaymentInfo($contribution['id'], 'contribute', TRUE);
$financialTrxnInfo = $payments['transaction'][0];
// build parameters which changed payment instrument and tran date values
- $params = array(
+ $params = [
'id' => $financialTrxnInfo['id'],
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Credit Card'),
'card_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_DAO_FinancialTrxn', 'card_type_id', 'Visa'),
'trnx_id' => 'txn_12AAAA',
'trxn_date' => date('Y-m-d H:i:s'),
'contribution_id' => $contribution['id'],
- );
+ ];
$form = new CRM_Financial_Form_PaymentEdit();
$form->testSubmit($params);
$payments = CRM_Contribute_BAO_Contribution::getPaymentInfo($contribution['id'], 'contribute', TRUE);
- $expectedPaymentParams = array(
- array(
+ $expectedPaymentParams = [
+ [
'total_amount' => 50.00,
'financial_type' => 'Donation',
'payment_instrument' => 'Check',
'status' => 'Completed',
'receive_date' => '2015-04-21 23:27:00',
'check_number' => '123XA',
- ),
- array(
+ ],
+ [
'total_amount' => -50.00,
'financial_type' => 'Donation',
'payment_instrument' => 'Check',
'status' => 'Completed',
'receive_date' => $params['trxn_date'],
'check_number' => '123XA',
- ),
- array(
+ ],
+ [
'total_amount' => 50.00,
'financial_type' => 'Donation',
'payment_instrument' => sprintf('Credit Card (Visa: %s)', $params['pan_truncation']),
'status' => 'Completed',
'receive_date' => $params['trxn_date'],
- ),
- );
+ ],
+ ];
$this->assertEquals(3, count($payments['transaction']));
foreach ($expectedPaymentParams as $key => $paymentParams) {
foreach ($paymentParams as $fieldName => $expectedValue) {
$checkPaymentInstrumentID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check');
// First create a contribution using 'Check' as payment instrument
$form = new CRM_Contribute_Form_Contribution();
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 50,
'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Donation'),
'contact_id' => $this->_individualID,
'payment_instrument_id' => $checkPaymentInstrumentID,
'check_number' => $checkNumber1,
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'),
- ),
+ ],
CRM_Core_Action::ADD);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('contact_id' => $this->_individualID));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualID]);
$payments = CRM_Contribute_BAO_Contribution::getPaymentInfo($contribution['id'], 'contribute', TRUE);
$financialTrxnInfo = $payments['transaction'][0];
// ensure that contribution's check_number has concatenated check-numbers
$checkNumber2 = '456XA';
// build parameters which changed payment instrument and tran date values
- $params = array(
+ $params = [
'id' => $financialTrxnInfo['id'],
'payment_instrument_id' => $checkPaymentInstrumentID,
'check_number' => $checkNumber2,
'trxn_date' => date('Y-m-d H:i:s'),
'contribution_id' => $contribution['id'],
- );
+ ];
$form = new CRM_Financial_Form_PaymentEdit();
$form->testSubmit($params);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contribution['id']));
- $expectedConcatanatedCheckNumbers = implode(',', array($checkNumber1, $checkNumber2));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
+ $expectedConcatanatedCheckNumbers = implode(',', [$checkNumber1, $checkNumber2]);
$this->assertEquals($expectedConcatanatedCheckNumbers, $contribution['check_number']);
// CASE 3: Submit payment details via edit form without any change,
// ensure that contribution's check_number concatenated value isn't changed
$form->testSubmit($params);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contribution['id']));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
$this->assertEquals($expectedConcatanatedCheckNumbers, $contribution['check_number']);
}
* does not cause any regression.
*/
public function testMakeBatchSummary() {
- $batch = $this->callAPISuccess('Batch', 'create', array('title' => 'test', 'status_id' => 'Open', 'payment_instrument_id' => 'Cash'));
+ $batch = $this->callAPISuccess('Batch', 'create', ['title' => 'test', 'status_id' => 'Open', 'payment_instrument_id' => 'Cash']);
$batchID = $batch['id'];
- $params = array('id' => $batchID);
+ $params = ['id' => $batchID];
$makeBatchSummary = CRM_Financial_Page_AJAX::makeBatchSummary($batchID, $params);
$this->assertEquals('Open', $makeBatchSummary['status']);
*/
public function testGetFinancialTransactionsList() {
$individualID = $this->individualCreate();
- $this->contributionCreate(array('contact_id' => $individualID, 'trxn_id' => 12345));
- $batch = $this->callAPISuccess('Batch', 'create', array('title' => 'test', 'status_id' => 'Open'));
+ $this->contributionCreate(['contact_id' => $individualID, 'trxn_id' => 12345]);
+ $batch = $this->callAPISuccess('Batch', 'create', ['title' => 'test', 'status_id' => 'Open']);
CRM_Core_DAO::executeQuery("
INSERT INTO civicrm_entity_batch (entity_table, entity_id, batch_id)
values('civicrm_financial_trxn', 1, 1)
*/
public $hookClass;
- protected $_params = array();
+ protected $_params = [];
public function setUp() {
parent::setUp();
- $this->_params = array(
+ $this->_params = [
'page' => 1,
'rp' => 50,
'offset' => 0,
'sort' => NULL,
'parentsOnly' => FALSE,
'is_unit_test' => TRUE,
- );
+ ];
$this->hookClass = CRM_Utils_Hook::singleton();
$this->createLoggedInUser();
- $this->_permissionedDisabledGroup = $this->groupCreate(array(
+ $this->_permissionedDisabledGroup = $this->groupCreate([
'title' => 'pick-me-disabled',
'is_active' => 0,
'name' => 'pick-me-disabled',
- ));
- $this->_permissionedGroup = $this->groupCreate(array(
+ ]);
+ $this->_permissionedGroup = $this->groupCreate([
'title' => 'pick-me-active',
'is_active' => 1,
'name' => 'pick-me-active',
- ));
- $this->groupCreate(array('title' => 'not-me-disabled', 'is_active' => 0, 'name' => 'not-me-disabled'));
- $this->groupCreate(array('title' => 'not-me-active', 'is_active' => 1, 'name' => 'not-me-active'));
+ ]);
+ $this->groupCreate(['title' => 'not-me-disabled', 'is_active' => 0, 'name' => 'not-me-disabled']);
+ $this->groupCreate(['title' => 'not-me-active', 'is_active' => 1, 'name' => 'not-me-active']);
}
public function tearDown() {
CRM_Utils_Hook::singleton()->reset();
- $this->quickCleanup(array('civicrm_group'));
+ $this->quickCleanup(['civicrm_group']);
$config = CRM_Core_Config::singleton();
unset($config->userPermissionClass->permissions);
parent::tearDown();
*/
public function setHookAndRequest($permission, $hook) {
CRM_Core_Config::singleton()->userPermissionClass->permissions = (array) $permission;
- $this->hookClass->setHook('civicrm_aclGroup', array($this, $hook));
+ $this->hookClass->setHook('civicrm_aclGroup', [$this, $hook]);
global $_REQUEST;
$_REQUEST = $this->_params;
}
* CRM-18528 - Retrieve groups with filter
*/
public function testGroupListWithFilter() {
- $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['view all contacts', 'edit groups']);
$_GET = $this->_params;
$obj = new CRM_Group_Page_AJAX();
* Retrieve groups as 'view all contacts'
*/
public function testGroupListViewAllContacts() {
- $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['view all contacts', 'edit groups']);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(2, $groups['recordsTotal']);
$this->assertEquals('<span><a href="/index.php?q=civicrm/group/search&reset=1&force=1&context=smog&gid=2&component_mode=1" class="action-item crm-hover-button" title=\'Group Contacts\' >Contacts</a></span>', $groups['data'][1]['links']);
// as per changes made in PR-6822
- $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['view all contacts', 'edit groups']);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(2, $groups['recordsTotal']);
*/
public function testGroupListViewAllContactsFoundTitle() {
$this->_params['title'] = 'p';
- $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['view all contacts', 'edit groups']);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(2, $groups['recordsTotal']);
* Retrieve groups as 'edit all contacts'
*/
public function testGroupListEditAllContacts() {
- $this->setPermissionAndRequest(array('edit all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['edit all contacts', 'edit groups']);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(2, $groups['recordsTotal']);
*/
public function testGroupListViewAllContactsEnabled() {
$this->_params['status'] = 1;
- $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['view all contacts', 'edit groups']);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(2, $groups['recordsTotal']);
*/
public function testGroupListViewAllContactsDisabled() {
$this->_params['status'] = 2;
- $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['view all contacts', 'edit groups']);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(2, $groups['recordsTotal']);
public function testGroupListViewAllContactsDisabledNotFoundTitle() {
$this->_params['status'] = 2;
$this->_params['title'] = 'n';
- $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['view all contacts', 'edit groups']);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(1, $groups['recordsTotal']);
public function testGroupListViewAllContactsDisabledFoundTitle() {
$this->_params['status'] = 2;
$this->_params['title'] = 'p';
- $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['view all contacts', 'edit groups']);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(1, $groups['recordsTotal']);
*/
public function testGroupListViewAllContactsAll() {
$this->_params['status'] = 3;
- $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ $this->setPermissionAndRequest(['view all contacts', 'edit groups']);
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(4, $groups['recordsTotal']);
*/
public function testGroupListAclGroupHookDisabled() {
$this->_params['status'] = 2;
- $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup');
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(1, count($groups['data']), 'Returned groups should exclude disabled by default');
public function testGroupListAclGroupHookDisabledFound() {
$this->_params['status'] = 2;
$this->_params['title'] = 'p';
- $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup');
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(1, count($groups['data']), 'Returned groups should exclude disabled by default');
* ACL Group hook.
*/
public function testGroupListAclGroupHook() {
- $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup');
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(1, count($groups['data']), 'Returned groups should exclude disabled by default');
*/
public function testGroupListAclGroupHookTitleFound() {
$this->_params['title'] = 'p';
- $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup');
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(2, count($groups['data']), 'Returned groups should exclude disabled by default');
*/
public function testGroupListAclGroupHookAll() {
$this->_params['status'] = 3;
- $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup');
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(2, count($groups['data']), 'Returned groups should exclude disabled by default');
*/
public function testGroupListAclGroupHookEnabled() {
$this->_params['status'] = 1;
- $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(['access CiviCRM', 'edit groups'], 'hook_civicrm_aclGroup');
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(1, count($groups['data']), 'Returned groups should exclude disabled by default');
// Create a contact.
$firstName = 'Tweak';
$lastName = 'Octonaut';
- $params = array(
+ $params = [
'first_name' => $firstName,
'last_name' => $lastName,
'contact_type' => 'Individual',
- );
+ ];
$contact = CRM_Contact_BAO_Contact::add($params);
// Create a smart group.
- $searchParams = array(
+ $searchParams = [
'last_name' => $lastName,
- );
- $groupParams = array('title' => 'Find all Octonauts', 'formValues' => $searchParams, 'is_active' => 1);
+ ];
+ $groupParams = ['title' => 'Find all Octonauts', 'formValues' => $searchParams, 'is_active' => 1];
$group = CRM_Contact_BAO_Group::createSmartGroup($groupParams);
// Ensure the smart group is created.
// Ensure it is populating the cache when loaded.
$sql = 'SELECT contact_id FROM civicrm_group_contact_cache WHERE group_id = %1';
- $params = array(1 => array($group->id, 'Integer'));
+ $params = [1 => [$group->id, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($sql, $params);
$this->assertEquals($dao->N, 1, '1 record should be found in smart group');
// Ensure we did not populate the cache.
$sql = 'SELECT contact_id FROM civicrm_group_contact_cache WHERE group_id = %1';
- $params = array(1 => array($group->id, 'Integer'));
+ $params = [1 => [$group->id, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($sql, $params);
$test = 'Group contact cache should not be populated on Manage Groups ' .
'when cache_date is null';
$cache_date = date('YmdHis', time() - $timeout - 60);
$sql = "UPDATE civicrm_group SET cache_date = %1 WHERE id = %2";
- $update_params = array(
- 1 => array($cache_date, 'Timestamp'),
- 2 => array($group->id, 'Integer'),
- );
+ $update_params = [
+ 1 => [$cache_date, 'Timestamp'],
+ 2 => [$group->id, 'Integer'],
+ ];
CRM_Core_DAO::executeQuery($sql, $update_params);
// Load the Manage Group page code.
// Ensure we did not regenerate the cache.
$sql = 'SELECT DATE_FORMAT(cache_date, "%Y%m%d%H%i%s") AS cache_date ' .
'FROM civicrm_group WHERE id = %1';
- $params = array(1 => array($group->id, 'Integer'));
+ $params = [1 => [$group->id, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($sql, $params);
$dao->fetch();
$test = 'Group contact cache should not be re-populated on Manage Groups ' .
public function hook_civicrm_aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
//don't use api - you will get a loop
$sql = " SELECT * FROM civicrm_group WHERE name LIKE '%pick%'";
- $groups = array();
+ $groups = [];
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
$groups[] = $dao->id;
global $_REQUEST;
$_REQUEST = $this->_params;
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
- $optionGroupID = $this->callAPISuccessGetValue('option_group', array('return' => 'id', 'name' => 'acl_role'));
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
+ $optionGroupID = $this->callAPISuccessGetValue('option_group', ['return' => 'id', 'name' => 'acl_role']);
$ov = new CRM_Core_DAO_OptionValue();
$ov->option_group_id = $optionGroupID;
$ov->value = 55;
if ($ov->find(TRUE)) {
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_option_value WHERE id = {$ov->id}");
}
- $optionValue = $this->callAPISuccess('option_value', 'create', array(
+ $optionValue = $this->callAPISuccess('option_value', 'create', [
'option_group_id' => $optionGroupID,
'label' => 'groupmaster',
'value' => 55,
- ));
+ ]);
$groupId = $this->groupCreate(['name' => 'groupmaster group']);
// Assign groupmaster to groupmaster group in civicrm_acl_entity_role
CRM_Core_DAO::executeQuery("
");
// Put the user into this group
$this->_loggedInUser = CRM_Core_Session::singleton()->get('userID');
- $this->callAPISuccess('group_contact', 'create', array(
+ $this->callAPISuccess('group_contact', 'create', [
'group_id' => $groupId,
'contact_id' => $this->_loggedInUser,
- ));
+ ]);
// Add the ACL
CRM_Core_DAO::executeQuery("
INSERT INTO civicrm_acl (
*/
public function testToCsv($fileName) {
$dataSource = new CRM_Import_DataSource_Csv();
- $params = array(
- 'uploadFile' => array(
+ $params = [
+ 'uploadFile' => [
'name' => __DIR__ . '/' . $fileName,
- ),
+ ],
'skipColumnHeader' => TRUE,
- );
+ ];
// Get the PEAR::DB object
$dao = new CRM_Core_DAO();
* @return array
*/
public function getCsvFiles() {
- return array(array('import.csv'), array('yogi.csv'));
+ return [['import.csv'], ['yogi.csv']];
}
}
CRM_Core_I18n_Schema::makeSinglelingual('en_US');
$logging = new CRM_Logging_Schema();
$logging->dropAllLogTables();
- \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array();
+ \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = [];
parent::tearDown();
}
CRM_Core_I18n_Schema::makeMultilingual('en_US');
$logging = new CRM_Logging_Schema();
$logging->enableLogging();
- $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", array(), FALSE, FALSE);
+ $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", [], FALSE, FALSE);
$this->assertNotNull($value, 'Logging not enabled successfully');
$logging->disableLogging();
}
CRM_Core_I18n_Schema::makeMultilingual('en_US');
$logging = new CRM_Logging_Schema();
$logging->enableLogging();
- $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", array(), FALSE, FALSE);
+ $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", [], FALSE, FALSE);
$this->assertNotNull($value, 'Logging not enabled successfully');
- CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` ADD COLUMN `logging_test` INT DEFAULT '0'", array(), FALSE, NULL, FALSE, FALSE);
- CRM_Core_I18n_Schema::rebuildMultilingualSchema(array('en_US'));
- \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array();
+ CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` ADD COLUMN `logging_test` INT DEFAULT '0'", [], FALSE, NULL, FALSE, FALSE);
+ CRM_Core_I18n_Schema::rebuildMultilingualSchema(['en_US']);
+ \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = [];
$logging->fixSchemaDifferencesFor('civicrm_option_value');
Civi::service('sql_triggers')->rebuild('civicrm_option_value');
$query = CRM_Core_DAO::executeQuery("SHOW CREATE TABLE `log_civicrm_option_value`", [], TRUE, NULL, FALSE, FALSE);
* Test that the log table engine can be changed via hook to e.g. MyISAM
*/
public function testHookLogEngine() {
- $this->hookClass->setHook('civicrm_alterLogTables', array($this, 'alterLogTables'));
+ $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'alterLogTables']);
$schema = new CRM_Logging_Schema();
$schema->enableLogging();
$log_table = CRM_Core_DAO::executeQuery("SHOW CREATE TABLE log_civicrm_acl");
$this->assertTrue(empty($diffs['ADD']));
$this->assertTrue(empty($diffs['OBSOLETE']));
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_test_table ADD COLUMN test_varchar varchar(255) DEFAULT NULL");
- \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array();
+ \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = [];
// Check that it still picks up new columns added.
$diffs = $schema->columnsWithDiffSpecs("civicrm_test_table", "log_civicrm_test_table");
$this->assertTrue(!empty($diffs['ADD']));
$schema->fixSchemaDifferences();
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_test_table CHANGE COLUMN test_varchar test_varchar varchar(400) DEFAULT NULL");
// Check that it properly picks up modifications to columns.
- \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array();
+ \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = [];
$diffs = $schema->columnsWithDiffSpecs("civicrm_test_table", "log_civicrm_test_table");
$this->assertTrue(!empty($diffs['MODIFY']));
$this->assertTrue(empty($diffs['ADD']));
$schema->fixSchemaDifferences();
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_test_table CHANGE COLUMN test_varchar test_varchar varchar(300) DEFAULT NULL");
// Check that when we reduce the size of column that the log table doesn't shrink as well.
- \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = array();
+ \Civi::$statics['CRM_Logging_Schema']['columnSpecs'] = [];
$diffs = $schema->columnsWithDiffSpecs("civicrm_test_table", "log_civicrm_test_table");
$this->assertTrue(empty($diffs['MODIFY']));
$this->assertTrue(empty($diffs['ADD']));
// Load the recipients as a list of contact IDs
CRM_Mailing_BAO_Mailing::getRecipients($mailingID);
- $recipients = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $mailingID));
- $contactIDs = array();
+ $recipients = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $mailingID]);
+ $contactIDs = [];
foreach ($recipients['values'] as $recipient) {
$contactIDs[] = $recipient['contact_id'];
}
* @return array|int
*/
private function createMailingGroup($mailingID, $groupID, $type = 'Include') {
- return $this->callAPISuccess('MailingGroup', 'create', array(
+ return $this->callAPISuccess('MailingGroup', 'create', [
'mailing_id' => $mailingID,
'group_type' => $type,
'entity_table' => CRM_Contact_BAO_Group::getTableName(),
'entity_id' => $groupID,
- ));
+ ]);
}
/**
$this->prepareForACLs();
$this->createLoggedInUser();
// create hook to build ACL where clause which choses $this->allowedContactId as the only contact to be considered as mail recipient
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereAllowedOnlyOne'));
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view my contact');
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereAllowedOnlyOne']);
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view my contact'];
// Create dummy group and assign 2 contacts
$name = 'Test static group ' . substr(sha1(rand()), 0, 7);
'is_active' => 1,
]);
// Create 2 contacts where one of them identified as $this->allowedContactId will be used in ACL where clause
- $contactID1 = $this->individualCreate(array(), 0);
- $this->allowedContactId = $this->individualCreate(array(), 1);
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $contactID1 = $this->individualCreate([], 0);
+ $this->allowedContactId = $this->individualCreate([], 1);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID,
'contact_id' => $contactID1,
- ));
- $this->callAPISuccess('GroupContact', 'Create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID,
'contact_id' => $this->allowedContactId,
- ));
+ ]);
// Create dummy mailing
- $mailingID = $this->callAPISuccess('Mailing', 'create', array())['id'];
+ $mailingID = $this->callAPISuccess('Mailing', 'create', [])['id'];
$this->createMailingGroup($mailingID, $groupID);
// Check that the desired contact (identified as Contact ID - $this->allowedContactId) is the only
'title' => $groupName2,
'is_active' => 1,
]);
- $contactID = $this->individualCreate(array(), 0);
- $contactID2 = $this->individualCreate(array(), 2);
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $contactID = $this->individualCreate([], 0);
+ $contactID2 = $this->individualCreate([], 2);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID,
'contact_id' => $contactID,
- ));
- $this->callAPISuccess('GroupContact', 'Create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID,
'contact_id' => $contactID2,
- ));
- $this->callAPISuccess('GroupContact', 'Create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID2,
'contact_id' => $contactID2,
- ));
+ ]);
// Create dummy mailing
- $mailingID = $this->callAPISuccess('Mailing', 'create', array())['id'];
+ $mailingID = $this->callAPISuccess('Mailing', 'create', [])['id'];
$this->createMailingGroup($mailingID, $groupID);
$expectedContactIDs = [$contactID, $contactID2];
$this->assertRecipientsCorrect($mailingID, $expectedContactIDs);
- $mailingID2 = $this->callAPISuccess('Mailing', 'create', array())['id'];
+ $mailingID2 = $this->callAPISuccess('Mailing', 'create', [])['id'];
$this->createMailingGroup($mailingID2, $groupID2, 'Exclude');
- $this->callAPISuccess('MailingGroup', 'create', array(
+ $this->callAPISuccess('MailingGroup', 'create', [
'mailing_id' => $mailingID2,
'group_type' => 'Include',
'entity_table' => CRM_Mailing_BAO_Mailing::getTableName(),
'entity_id' => $mailingID,
- ));
+ ]);
$expectedContactIDs = [$contactID];
$this->assertRecipientsCorrect($mailingID2, $expectedContactIDs);
$this->callAPISuccess('mailing', 'delete', ['id' => $mailingID2]);
$this->prepareForACLs();
$this->createLoggedInUser();
// create hook to build ACL where clause which choses $this->allowedContactId as the only contact to be considered as mail recipient
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereAllowedOnlyOne'));
- $this->hookClass->setHook('civicrm_aclGroup', array($this, 'hook_civicrm_aclGroup'));
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit groups');
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereAllowedOnlyOne']);
+ $this->hookClass->setHook('civicrm_aclGroup', [$this, 'hook_civicrm_aclGroup']);
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit groups'];
// Create dummy group and assign 2 contacts
$name = 'Test static group ' . substr(sha1(rand()), 0, 7);
$groupID = $this->groupCreate([
'title' => $name,
'is_active' => 1,
]);
- $contactID = $this->individualCreate(array(), 0);
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $contactID = $this->individualCreate([], 0);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID,
'contact_id' => $contactID,
- ));
+ ]);
// Create dummy mailing
- $mailingID = $this->callAPISuccess('Mailing', 'create', array())['id'];
+ $mailingID = $this->callAPISuccess('Mailing', 'create', [])['id'];
$this->createMailingGroup($mailingID, $groupID);
// Now disable the group.
$this->callAPISuccess('group', 'create', [
public function hook_civicrm_aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
//don't use api - you will get a loop
$sql = " SELECT * FROM civicrm_group";
- $groups = array();
+ $groups = [];
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
$groups[] = $dao->id;
*/
public function testgetRecipientsEmailGroupIncludeExclude() {
// Set up groups; 3 standard, 4 smart
- $groupIDs = array();
+ $groupIDs = [];
for ($i = 0; $i < 7; $i++) {
- $params = array(
+ $params = [
'name' => 'Test static group ' . $i,
'title' => 'Test static group ' . $i,
'is_active' => 1,
- );
+ ];
if ($i < 3) {
$groupIDs[$i] = $this->groupCreate($params);
}
else {
- $groupIDs[$i] = $this->smartGroupCreate(array(
+ $groupIDs[$i] = $this->smartGroupCreate([
'formValues' => ['last_name' => (($i == 6) ? 'smart5' : 'smart' . $i)],
- ), $params);
+ ], $params);
}
}
// Create contacts
- $contactIDs = array(
- $this->individualCreate(array('last_name' => 'smart5'), 0),
- $this->individualCreate(array(), 1),
- $this->individualCreate(array(), 2),
- $this->individualCreate(array(), 3),
- $this->individualCreate(array('last_name' => 'smart3'), 4),
- $this->individualCreate(array('last_name' => 'smart3'), 5),
- $this->individualCreate(array('last_name' => 'smart4'), 6),
- $this->individualCreate(array('last_name' => 'smart4'), 7),
- $this->individualCreate(array('last_name' => 'smart5'), 8),
- );
+ $contactIDs = [
+ $this->individualCreate(['last_name' => 'smart5'], 0),
+ $this->individualCreate([], 1),
+ $this->individualCreate([], 2),
+ $this->individualCreate([], 3),
+ $this->individualCreate(['last_name' => 'smart3'], 4),
+ $this->individualCreate(['last_name' => 'smart3'], 5),
+ $this->individualCreate(['last_name' => 'smart4'], 6),
+ $this->individualCreate(['last_name' => 'smart4'], 7),
+ $this->individualCreate(['last_name' => 'smart5'], 8),
+ ];
// Add contacts to static groups
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupIDs[0],
'contact_id' => $contactIDs[0],
- ));
- $this->callAPISuccess('GroupContact', 'Create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupIDs[0],
'contact_id' => $contactIDs[1],
- ));
- $this->callAPISuccess('GroupContact', 'Create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupIDs[1],
'contact_id' => $contactIDs[2],
- ));
- $this->callAPISuccess('GroupContact', 'Create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupIDs[1],
'contact_id' => $contactIDs[3],
- ));
- $this->callAPISuccess('GroupContact', 'Create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupIDs[2],
'contact_id' => $contactIDs[4],
- ));
+ ]);
// Force rebuild the smart groups
for ($i = 3; $i < 7; $i++) {
// Check that we can include static groups in the mailing.
// Expected: Contacts [0-3] should be included.
- $mailing = $this->callAPISuccess('Mailing', 'create', array());
+ $mailing = $this->callAPISuccess('Mailing', 'create', []);
$this->createMailingGroup($mailing['id'], $groupIDs[0]);
$this->createMailingGroup($mailing['id'], $groupIDs[1]);
$this->createMailingGroup($mailing['id'], $groupIDs[6], 'Base');
// In this case groupIDs6 will only pick up contacts[0] amd contacts[8] with it's
// criteria. However we are deliberly going to remove contactIds[8] from the group
// Which should mean the mainling only finds 1 contact that is contactIds[0]
- $mailing = $this->callAPISuccess('Mailing', 'create', array());
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $mailing = $this->callAPISuccess('Mailing', 'create', []);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupIDs[6],
'contact_id' => $contactIDs[8],
'status' => 'Removed',
- ));
+ ]);
$this->createMailingGroup($mailing['id'], $groupIDs[6]);
$this->assertRecipientsCorrect($mailing['id'], [$contactIDs[0]]);
// Tear down: delete mailing, groups, contacts
// +core/384 Ensure that a secondary mobile number is selected if the primary can not receive SMS
// Setup
- $smartGroupParams = array(
- 'formValues' => array('contact_type' => array('IN' => array('Individual'))),
- );
+ $smartGroupParams = [
+ 'formValues' => ['contact_type' => ['IN' => ['Individual']]],
+ ];
$group = $this->smartGroupCreate($smartGroupParams);
- $sms_provider = $this->callAPISuccess('SmsProvider', 'create', array(
+ $sms_provider = $this->callAPISuccess('SmsProvider', 'create', [
'sequential' => 1,
'name' => 1,
'title' => "Test",
'password' => "Test",
'api_type' => 1,
'is_active' => 1,
- ));
+ ]);
// Create Contact 1 and add in group
- $contactID1 = $this->individualCreate(array(), 0);
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $contactID1 = $this->individualCreate([], 0);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $group,
'contact_id' => $contactID1,
- ));
+ ]);
// Create contact 2 and add in group
- $contactID2 = $this->individualCreate(array(), 1);
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $contactID2 = $this->individualCreate([], 1);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $group,
'contact_id' => $contactID2,
- ));
+ ]);
// Create contact 3 and add in group
- $contactID3 = $this->individualCreate(array(), 2);
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $contactID3 = $this->individualCreate([], 2);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $group,
'contact_id' => $contactID3,
- ));
+ ]);
- $contactIDPhoneRecords = array(
- $contactID1 => array(
- 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array(
+ $contactIDPhoneRecords = [
+ $contactID1 => [
+ 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [
'contact_id' => $contactID1,
'phone' => "01 01",
'location_type_id' => "Home",
'phone_type_id' => "Mobile",
'is_primary' => 1,
- ))),
- 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array(
+ ])),
+ 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [
'contact_id' => $contactID1,
'phone' => "01 02",
'location_type_id' => "Work",
'phone_type_id' => "Mobile",
'is_primary' => 0,
- ))),
- ),
+ ])),
+ ],
// Create the non-primary with a lower ID than the primary, to test CRM-21320
- $contactID2 => array(
- 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array(
+ $contactID2 => [
+ 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [
'contact_id' => $contactID2,
'phone' => "02 01",
'location_type_id' => "Home",
'phone_type_id' => "Mobile",
'is_primary' => 0,
- ))),
- 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array(
+ ])),
+ 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [
'contact_id' => $contactID2,
'phone' => "02 02",
'location_type_id' => "Work",
'phone_type_id' => "Mobile",
'is_primary' => 1,
- ))),
- ),
+ ])),
+ ],
// Create primary that cant recieve SMS but a secondary that can, to test core/384
- $contactID3 => array(
- 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array(
+ $contactID3 => [
+ 'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [
'contact_id' => $contactID3,
'phone' => "03 01",
'location_type_id' => "Home",
'phone_type_id' => "Mobile",
'is_primary' => 0,
- ))),
- 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array(
+ ])),
+ 'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', [
'contact_id' => $contactID3,
'phone' => "03 02",
'location_type_id' => "Work",
'phone_type_id' => "Phone",
'is_primary' => 1,
- ))),
- ),
- );
+ ])),
+ ],
+ ];
// Prepare expected results
- $checkPhoneIDs = array(
+ $checkPhoneIDs = [
$contactID1 => $contactIDPhoneRecords[$contactID1]['primary_phone_id'],
$contactID2 => $contactIDPhoneRecords[$contactID2]['primary_phone_id'],
$contactID3 => $contactIDPhoneRecords[$contactID3]['other_phone_id'],
- );
+ ];
// Create mailing
- $mailing = $this->callAPISuccess('Mailing', 'create', array('sms_provider_id' => $sms_provider['id']));
+ $mailing = $this->callAPISuccess('Mailing', 'create', ['sms_provider_id' => $sms_provider['id']]);
$mailingInclude = $this->createMailingGroup($mailing['id'], $group);
// Get recipients
CRM_Mailing_BAO_Mailing::getRecipients($mailing['id']);
- $recipients = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $mailing['id']));
+ $recipients = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $mailing['id']]);
// Check the count is correct
$this->assertEquals(3, $recipients['count'], 'Check recipient count');
// Tidy up
$this->deleteMailing($mailing['id']);
- $this->callAPISuccess('SmsProvider', 'Delete', array('id' => $sms_provider['id']));
+ $this->callAPISuccess('SmsProvider', 'Delete', ['id' => $sms_provider['id']]);
$this->groupDelete($group);
$this->contactDelete($contactID1);
$this->contactDelete($contactID2);
*/
public function testAlterMailingRecipientsHook() {
$groupID = $this->groupCreate();
- $this->tagCreate(array('name' => 'Tagged'));
+ $this->tagCreate(['name' => 'Tagged']);
// Create deseased Contact 1 and add in group
- $contactID1 = $this->individualCreate(array('email' => 'abc@test.com', 'is_deceased' => 1), 0);
+ $contactID1 = $this->individualCreate(['email' => 'abc@test.com', 'is_deceased' => 1], 0);
// Create deseased Contact 2 and add in group
- $contactID2 = $this->individualCreate(array('email' => 'def@test.com'), 1);
+ $contactID2 = $this->individualCreate(['email' => 'def@test.com'], 1);
// Create deseased Contact 3 and add in group
- $contactID3 = $this->individualCreate(array('email' => 'ghi@test.com', 'is_deceased' => 1), 2);
+ $contactID3 = $this->individualCreate(['email' => 'ghi@test.com', 'is_deceased' => 1], 2);
// Add both the created contacts in group
- $this->callAPISuccess('GroupContact', 'Create', array(
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID,
'contact_id' => $contactID1,
- ));
- $this->callAPISuccess('GroupContact', 'Create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID,
'contact_id' => $contactID2,
- ));
- $this->callAPISuccess('GroupContact', 'Create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'Create', [
'group_id' => $groupID,
'contact_id' => $contactID3,
- ));
- $this->entityTagAdd(array('contact_id' => $contactID3, 'tag_id' => 'Tagged'));
+ ]);
+ $this->entityTagAdd(['contact_id' => $contactID3, 'tag_id' => 'Tagged']);
// trigger the alterMailingRecipients hook
- $this->hookClass->setHook('civicrm_alterMailingRecipients', array($this, 'alterMailingRecipients'));
+ $this->hookClass->setHook('civicrm_alterMailingRecipients', [$this, 'alterMailingRecipients']);
// create mailing that will trigger alterMailingRecipients hook
- $params = array(
+ $params = [
'name' => 'mailing name',
'subject' => 'Test Subject',
'body_html' => '<p>HTML Body</p>',
'text_html' => 'Text Body',
'created_id' => 1,
- 'groups' => array('include' => array($groupID)),
+ 'groups' => ['include' => [$groupID]],
'scheduled_date' => 'now',
- );
+ ];
$this->callAPISuccess('Mailing', 'create', $params);
}
->where("t.name = 'Tagged'");
}
else {
- $mailingRecipients = $this->callAPISuccess('MailingRecipients', 'get', array(
+ $mailingRecipients = $this->callAPISuccess('MailingRecipients', 'get', [
'mailing_id' => $mailingObject->id,
- 'api.Email.getvalue' => array(
+ 'api.Email.getvalue' => [
'id' => '$value.email_id',
'return' => 'email',
- ),
- ));
+ ],
+ ]);
$this->assertEquals(1, $mailingRecipients['count'], 'Check recipient count');
$this->assertEquals('ghi@test.com', $mailingRecipients['values'][$mailingRecipients['id']]['api.Email.getvalue'], 'Check if recipient email belong to deceased contact');
}
}
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_mailing_event_bounce',
'civicrm_mailing_event_delivered',
'civicrm_mailing_event_opened',
'civicrm_mailing_recipients',
'civicrm_email',
'civicrm_contact',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
}
$dao = $obj->searchQuery();
- $contacts = array();
+ $contacts = [];
while ($dao->fetch()) {
$contacts[] = $dao->contact_id;
}
* IDs should be selected when the form values are applied to the
* database in dataset.xml
*/
- private $dataset = array(
- array(
- 'fv' => array('mailing_name' => 'First%', 'mailing_open_status' => 'Y'),
- 'id' => array(109, 110, 111, 112),
- ),
- array(
- 'fv' => array('mailing_name' => 'First%', 'mailing_open_status' => 'N'),
- 'id' => array(102, 103, 104, 105, 108),
- ),
+ private $dataset = [
+ [
+ 'fv' => ['mailing_name' => 'First%', 'mailing_open_status' => 'Y'],
+ 'id' => [109, 110, 111, 112],
+ ],
+ [
+ 'fv' => ['mailing_name' => 'First%', 'mailing_open_status' => 'N'],
+ 'id' => [102, 103, 104, 105, 108],
+ ],
/*bounce*/
- array(
- 'fv' => array(
+ [
+ 'fv' => [
'mailing_name' => 'First%',
'mailing_delivery_status'
=> 'N',
- ),
- 'id' => array(105),
- ),
+ ],
+ 'id' => [105],
+ ],
/*bounce*/
- array(
- 'fv' => array(
+ [
+ 'fv' => [
'mailing_name' => 'First%',
'mailing_delivery_status'
=> 'Y',
- ),
- 'id' => array(102, 103, 104, 108, 109, 110, 111, 112),
- ),
- array(
- 'fv' => array('mailing_name' => 'First%', 'mailing_reply_status' => 'Y'),
- 'id' => array(103, 108, 110, 112),
- ),
- array(
- 'fv' => array('mailing_name' => 'First%', 'mailing_reply_status' => 'N'),
- 'id' => array(102, 104, 105, 109, 111),
- ),
- array(
- 'fv' => array('mailing_name' => 'First%', 'mailing_click_status' => 'Y'),
- 'id' => array(104, 108, 111, 112),
- ),
- array(
- 'fv' => array('mailing_name' => 'First%', 'mailing_click_status' => 'N'),
- 'id' => array(102, 103, 105, 109, 110),
- ),
+ ],
+ 'id' => [102, 103, 104, 108, 109, 110, 111, 112],
+ ],
+ [
+ 'fv' => ['mailing_name' => 'First%', 'mailing_reply_status' => 'Y'],
+ 'id' => [103, 108, 110, 112],
+ ],
+ [
+ 'fv' => ['mailing_name' => 'First%', 'mailing_reply_status' => 'N'],
+ 'id' => [102, 104, 105, 109, 111],
+ ],
+ [
+ 'fv' => ['mailing_name' => 'First%', 'mailing_click_status' => 'Y'],
+ 'id' => [104, 108, 111, 112],
+ ],
+ [
+ 'fv' => ['mailing_name' => 'First%', 'mailing_click_status' => 'N'],
+ 'id' => [102, 103, 105, 109, 110],
+ ],
/*bounce*/
- array(
- 'fv' => array(
+ [
+ 'fv' => [
'mailing_name' => 'Second%',
'mailing_delivery_status'
=> 'N',
- ),
- 'id' => array(),
- ),
+ ],
+ 'id' => [],
+ ],
/*bounce*/
- array(
- 'fv' => array(
+ [
+ 'fv' => [
'mailing_name' => 'Second%',
'mailing_delivery_status'
=> 'Y',
- ),
- 'id' => array(102, 103, 104, 108, 109, 110, 111, 112),
- ),
- array(
- 'fv' => array('mailing_name' => 'Second%', 'mailing_reply_status' => 'Y'),
- 'id' => array(103),
- ),
- array(
- 'fv' => array('mailing_name' => 'Second%', 'mailing_click_status' => 'Y'),
- 'id' => array(104),
- ),
- array(
- 'fv' => array('mailing_name' => 'Second%', 'mailing_click_status' => 'N'),
- 'id' => array(102, 103, 108, 109, 110, 111, 112),
- ),
- array(
- 'fv' => array('mailing_date_high' => '2011-05-25', 'mailing_open_status' => 'Y'),
- 'id' => array(109, 110, 111, 112),
- ),
- array(
- 'fv' => array('mailing_date_high' => '2011-05-25', 'mailing_open_status' => 'N'),
- 'id' => array(102, 103, 104, 105, 108),
- ),
- array(
- 'fv' => array('mailing_date_low' => '2011-05-26', 'mailing_open_status' => 'Y'),
- 'id' => array(102),
- ),
- array(
- 'fv' => array('mailing_date_low' => '2011-05-26', 'mailing_open_status' => 'N'),
- 'id' => array(103, 104, 108, 109, 110, 111, 112),
- ),
- );
+ ],
+ 'id' => [102, 103, 104, 108, 109, 110, 111, 112],
+ ],
+ [
+ 'fv' => ['mailing_name' => 'Second%', 'mailing_reply_status' => 'Y'],
+ 'id' => [103],
+ ],
+ [
+ 'fv' => ['mailing_name' => 'Second%', 'mailing_click_status' => 'Y'],
+ 'id' => [104],
+ ],
+ [
+ 'fv' => ['mailing_name' => 'Second%', 'mailing_click_status' => 'N'],
+ 'id' => [102, 103, 108, 109, 110, 111, 112],
+ ],
+ [
+ 'fv' => ['mailing_date_high' => '2011-05-25', 'mailing_open_status' => 'Y'],
+ 'id' => [109, 110, 111, 112],
+ ],
+ [
+ 'fv' => ['mailing_date_high' => '2011-05-25', 'mailing_open_status' => 'N'],
+ 'id' => [102, 103, 104, 105, 108],
+ ],
+ [
+ 'fv' => ['mailing_date_low' => '2011-05-26', 'mailing_open_status' => 'Y'],
+ 'id' => [102],
+ ],
+ [
+ 'fv' => ['mailing_date_low' => '2011-05-26', 'mailing_open_status' => 'N'],
+ 'id' => [103, 104, 108, 109, 110, 111, 112],
+ ],
+ ];
public function _construct() {
$this->i = 0;
public function current() {
$count = count($this->dataset[$this->i]['id']);
$ids = $this->dataset[$this->i]['id'];
- $full = array();
+ $full = [];
foreach ($this->dataset[$this->i]['id'] as $key => $value) {
- $full[] = array(
+ $full[] = [
'contact_id' => $value,
'contact_type' => 'Individual',
'sort_name' => "Test Contact $value",
- );
+ ];
}
- return array($this->dataset[$this->i]['fv'], $count, $ids, $full);
+ return [$this->dataset[$this->i]['fv'], $count, $ids, $full];
}
/**
* Basic send.
*/
public function testSend() {
- $contact_params_1 = array(
+ $contact_params_1 = [
'first_name' => substr(sha1(rand()), 0, 7),
'last_name' => 'Anderson',
'email' => substr(sha1(rand()), 0, 7) . '@example.org',
'contact_type' => 'Individual',
- );
+ ];
$contact_id_1 = $this->individualCreate($contact_params_1);
- $contact_params_2 = array(
+ $contact_params_2 = [
'first_name' => substr(sha1(rand()), 0, 7),
'last_name' => 'Xylophone',
'email' => substr(sha1(rand()), 0, 7) . '@example.org',
'contact_type' => 'Individual',
- );
+ ];
$contact_id_2 = $this->individualCreate($contact_params_2);
$subject = 'Test spool';
- $params = array(
+ $params = [
'from' => CRM_Utils_Mail::formatRFC822Email($contact_params_1['first_name'] . " " . $contact_params_1['last_name'], $contact_params_1['email']),
'toName' => $contact_params_2['first_name'] . " " . $contact_params_2['last_name'],
'toEmail' => $contact_params_2['email'],
'subject' => $subject,
'text' => self::$bodytext,
'html' => "<p>\n" . self::$bodytext . '</p>',
- );
+ ];
CRM_Utils_Mail::send($params);
$this->assertContains($contact_params_1['email'], $mail->from->email, 'From address incorrect.');
$this->assertContains($contact_params_2['email'], $mail->to[0]->email, 'Recipient incorrect.');
- $context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback'));
+ $context = new ezcMailPartWalkContext([get_class($this), 'mailWalkCallback']);
$mail->walkParts($context, $mail);
}
protected $_apiversion = 3;
public $DBResetRequired = FALSE;
- public $defaultParams = array();
+ public $defaultParams = [];
private $_groupID;
/**
$this->_groupID = $this->groupCreate();
$this->createContactsInGroup(2, $this->_groupID);
- $this->defaultParams = array(
+ $this->defaultParams = [
'name' => 'mailing name',
'created_id' => 1,
- 'groups' => array('include' => array($this->_groupID)),
+ 'groups' => ['include' => [$this->_groupID]],
'scheduled_date' => 'now',
- );
+ ];
$this->_mut = new CiviMailUtils($this, TRUE);
$this->callAPISuccess('mail_settings', 'get',
- array('api.mail_settings.create' => array('domain' => 'chaos.org')));
+ ['api.mail_settings.create' => ['domain' => 'chaos.org']]);
}
/**
* Generate a fully-formatted mailing with standard email headers.
*/
public function testBasicHeaders() {
- $allMessages = $this->runMailingSuccess(array(
+ $allMessages = $this->runMailingSuccess([
'subject' => 'Accidents in cars cause children for {contact.display_name}!',
'body_text' => 'BEWARE children need regular infusions of toys. Santa knows your {domain.address}. There is no {action.optOutUrl}.',
- ));
+ ]);
foreach ($allMessages as $k => $message) {
/** @var ezcMail $message */
* Generate a fully-formatted mailing (with body_text content).
*/
public function testText() {
- $allMessages = $this->runMailingSuccess(array(
+ $allMessages = $this->runMailingSuccess([
'subject' => 'Accidents in cars cause children for {contact.display_name}!',
'body_text' => 'BEWARE children need regular infusions of toys. Santa knows your {domain.address}. There is no {action.optOutUrl}.',
'open_tracking' => 1,
// Note: open_tracking does nothing with text, but we'll just verify that it does nothing
- ));
+ ]);
foreach ($allMessages as $message) {
/** @var ezcMail $message */
/** @var ezcMailText $textPart */
* Generate a fully-formatted mailing (with body_html content).
*/
public function testHtmlWithOpenTracking() {
- $allMessages = $this->runMailingSuccess(array(
+ $allMessages = $this->runMailingSuccess([
'subject' => 'Example Subject',
'body_html' => '<p>You can go to <a href="http://example.net/first?{contact.checksum}">Google</a> or <a href="{action.optOutUrl}">opt out</a>.</p>',
'open_tracking' => 1,
'url_tracking' => 0,
- ));
+ ]);
foreach ($allMessages as $message) {
/** @var ezcMail $message */
/** @var ezcMailText $htmlPart */
* Generate a fully-formatted mailing (with body_html content).
*/
public function testHtmlWithOpenAndUrlTracking() {
- $allMessages = $this->runMailingSuccess(array(
+ $allMessages = $this->runMailingSuccess([
'subject' => 'Example Subject',
'body_html' => '<p>You can go to <a href="http://example.net">Google</a> or <a href="{action.optOutUrl}">opt out</a>.</p>',
'open_tracking' => 1,
'url_tracking' => 1,
- ));
+ ]);
foreach ($allMessages as $message) {
/** @var ezcMail $message */
/** @var ezcMailText $htmlPart */
* @return array
*/
public function urlTrackingExamples() {
- $cases = array();
+ $cases = [];
// Tracking disabled
- $cases[] = array(
+ $cases[] = [
'<p><a href="http://example.net/">Foo</a></p>',
';<p><a href="http://example\.net/">Foo</a></p>;',
';\\[1\\] http://example\.net/;',
- array('url_tracking' => 0),
- );
- $cases[] = array(
+ ['url_tracking' => 0],
+ ];
+ $cases[] = [
'<p><a href="http://example.net/?id={contact.contact_id}">Foo</a></p>',
// FIXME: Legacy tracker adds extra quote after URL
';<p><a href="http://example\.net/\?id=\d+""?>Foo</a></p>;',
';\\[1\\] http://example\.net/\?id=\d+;',
- array('url_tracking' => 0),
- );
- $cases[] = array(
+ ['url_tracking' => 0],
+ ];
+ $cases[] = [
'<p><a href="{action.optOutUrl}">Foo</a></p>',
';<p><a href="http.*civicrm/mailing/optout.*">Foo</a></p>;',
';\\[1\\] http.*civicrm/mailing/optout.*;',
- array('url_tracking' => 0),
- );
- $cases[] = array(
+ ['url_tracking' => 0],
+ ];
+ $cases[] = [
'<p>Look at <img src="http://example.net/foo.png">.</p>',
';<p>Look at <img src="http://example\.net/foo\.png">\.</p>;',
';Look at \.;',
- array('url_tracking' => 0),
- );
- $cases[] = array(
+ ['url_tracking' => 0],
+ ];
+ $cases[] = [
// Plain-text URL's are tracked in plain-text emails...
// but not in HTML emails.
"<p>Please go to: http://example.net/</p>",
";<p>Please go to: http://example\.net/</p>;",
';Please go to: http://example\.net/;',
- array('url_tracking' => 0),
- );
+ ['url_tracking' => 0],
+ ];
// Tracking enabled
- $cases[] = array(
+ $cases[] = [
'<p><a href="http://example.net/">Foo</a></p>',
';<p><a href=[\'"].*extern/url\.php\?u=\d+.*[\'"]>Foo</a></p>;',
';\\[1\\] .*extern/url\.php\?u=\d+.*;',
- array('url_tracking' => 1),
- );
- $cases[] = array(
+ ['url_tracking' => 1],
+ ];
+ $cases[] = [
// FIXME: CiviMail URL tracking doesn't track tokenized links.
'<p><a href="http://example.net/?id={contact.contact_id}">Foo</a></p>',
// FIXME: Legacy tracker adds extra quote after URL
';<p><a href="http://example\.net/\?id=\d+""?>Foo</a></p>;',
';\\[1\\] http://example\.net/\?id=\d+;',
- array('url_tracking' => 1),
- );
- $cases[] = array(
+ ['url_tracking' => 1],
+ ];
+ $cases[] = [
// It would be redundant/slow to track the action URLs?
'<p><a href="{action.optOutUrl}">Foo</a></p>',
';<p><a href="http.*civicrm/mailing/optout.*">Foo</a></p>;',
';\\[1\\] http.*civicrm/mailing/optout.*;',
- array('url_tracking' => 1),
- );
- $cases[] = array(
+ ['url_tracking' => 1],
+ ];
+ $cases[] = [
// It would be excessive/slow to track every embedded image.
'<p>Look at <img src="http://example.net/foo.png">.</p>',
';<p>Look at <img src="http://example\.net/foo\.png">\.</p>;',
';Look at \.;',
- array('url_tracking' => 1),
- );
- $cases[] = array(
+ ['url_tracking' => 1],
+ ];
+ $cases[] = [
// Plain-text URL's are tracked in plain-text emails...
// but not in HTML emails.
"<p>Please go to: http://example.net/</p>",
";<p>Please go to: http://example\.net/</p>;",
';Please go to: .*extern/url.php\?u=\d+&qid=\d+;',
- array('url_tracking' => 1),
- );
+ ['url_tracking' => 1],
+ ];
return $cases;
}
* @dataProvider urlTrackingExamples
*/
public function testUrlTracking($inputHtml, $htmlUrlRegex, $textUrlRegex, $params) {
- $caseName = print_r(array('inputHtml' => $inputHtml, 'params' => $params), 1);
+ $caseName = print_r(['inputHtml' => $inputHtml, 'params' => $params], 1);
- $allMessages = $this->runMailingSuccess($params + array(
+ $allMessages = $this->runMailingSuccess($params + [
'subject' => 'Example Subject',
'body_html' => $inputHtml,
- ));
+ ]);
foreach ($allMessages as $message) {
/** @var ezcMail $message */
/** @var ezcMailText $htmlPart */
$domain = 'nul.example.com'
) {
for ($i = 1; $i <= $count; $i++) {
- $contactID = $this->individualCreate(array(
+ $contactID = $this->individualCreate([
'first_name' => "Foo{$i}",
'email' => 'mail' . $i . '@' . $domain,
- ));
- $this->callAPISuccess('group_contact', 'create', array(
+ ]);
+ $this->callAPISuccess('group_contact', 'create', [
'contact_id' => $contactID,
'group_id' => $groupID,
'status' => 'Added',
- ));
+ ]);
}
}
protected function runMailingSuccess($params) {
$mailingParams = array_merge($this->defaultParams, $params);
$this->callAPISuccess('mailing', 'create', $mailingParams);
- $this->_mut->assertRecipients(array());
- $this->callAPISuccess('job', 'process_mailing', array('runInNonProductionEnvironment' => TRUE));
+ $this->_mut->assertRecipients([]);
+ $this->callAPISuccess('job', 'process_mailing', ['runInNonProductionEnvironment' => TRUE]);
$allMessages = $this->_mut->getAllMessages('ezc');
// There are exactly two contacts produced by setUp().
public function setUp() {
parent::setUp();
- Civi::settings()->add(array('experimentalFlexMailerEngine' => FALSE));
+ Civi::settings()->add(['experimentalFlexMailerEngine' => FALSE]);
$hooks = \CRM_Utils_Hook::singleton();
$hooks->setHook('civicrm_alterMailParams',
- array($this, 'hook_alterMailParams'));
+ [$this, 'hook_alterMailParams']);
}
/**
$this->useTransaction();
parent::setUp();
$this->callAPISuccess('mail_settings', 'get',
- array('api.mail_settings.create' => array('domain' => 'chaos.org')));
+ ['api.mail_settings.create' => ['domain' => 'chaos.org']]);
}
public function getExampleTokens() {
- $cases = array();
+ $cases = [];
- $cases[] = array('text/plain', 'The {mailing.id}!', ';The [0-9]+!;');
- $cases[] = array('text/plain', 'The {mailing.name}!', ';The Example Name!;');
- $cases[] = array('text/plain', 'The {mailing.editUrl}!', ';The http.*civicrm/mailing/send.*!;');
- $cases[] = array('text/plain', 'To subscribe: {action.subscribeUrl}!', ';To subscribe: http.*civicrm/mailing/subscribe.*!;');
- $cases[] = array('text/plain', 'To optout: {action.optOutUrl}!', ';To optout: http.*civicrm/mailing/optout.*!;');
- $cases[] = array('text/plain', 'To unsubscribe: {action.unsubscribe}!', ';To unsubscribe: u\.123\.456\.abcd1234@chaos.org!;');
+ $cases[] = ['text/plain', 'The {mailing.id}!', ';The [0-9]+!;'];
+ $cases[] = ['text/plain', 'The {mailing.name}!', ';The Example Name!;'];
+ $cases[] = ['text/plain', 'The {mailing.editUrl}!', ';The http.*civicrm/mailing/send.*!;'];
+ $cases[] = ['text/plain', 'To subscribe: {action.subscribeUrl}!', ';To subscribe: http.*civicrm/mailing/subscribe.*!;'];
+ $cases[] = ['text/plain', 'To optout: {action.optOutUrl}!', ';To optout: http.*civicrm/mailing/optout.*!;'];
+ $cases[] = ['text/plain', 'To unsubscribe: {action.unsubscribe}!', ';To unsubscribe: u\.123\.456\.abcd1234@chaos.org!;'];
// TODO: Think about supporting dynamic tokens like "{action.subscribe.\d+}"
* @dataProvider getExampleTokens
*/
public function testTokensWithMailingId($inputTemplateFormat, $inputTemplate, $expectRegex) {
- $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', array(
+ $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', [
'name' => 'Example Name',
- ));
+ ]);
$contact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact');
- $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), array(
+ $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), [
'mailingId' => $mailing->id,
- ));
+ ]);
$p->addMessage('example', $inputTemplate, $inputTemplateFormat);
- $p->addRow()->context(array(
+ $p->addRow()->context([
'contactId' => $contact->id,
'mailingJobId' => 123,
- 'mailingActionTarget' => array(
+ 'mailingActionTarget' => [
'id' => 456,
'hash' => 'abcd1234',
'email' => 'someone@example.com',
- ),
- ));
+ ],
+ ]);
$p->evaluate();
$count = 0;
foreach ($p->getRows() as $row) {
$inputTemplate = 'To optout: {action.optOutUrl}!';
$expectRegex = ';To optout: http.*civicrm/mailing/optout.*!;';
- $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', array(
+ $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', [
'name' => 'Example Name',
- ));
+ ]);
$contact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact');
- $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), array(
+ $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), [
'mailing' => $mailing,
- ));
+ ]);
$p->addMessage('example', $inputTemplate, $inputTemplateFormat);
- $p->addRow()->context(array(
+ $p->addRow()->context([
'contactId' => $contact->id,
'mailingJobId' => 123,
- 'mailingActionTarget' => array(
+ 'mailingActionTarget' => [
'id' => 456,
'hash' => 'abcd1234',
'email' => 'someone@example.com',
- ),
- ));
+ ],
+ ]);
$p->evaluate();
$count = 0;
foreach ($p->getRows() as $row) {
* @dataProvider getExampleTokensForUseWithoutMailingJob
*/
public function testTokensWithoutMailingJob($inputTemplateFormat, $inputTemplateText, $expectRegex) {
- $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', array(
+ $mailing = CRM_Core_DAO::createTestObject('CRM_Mailing_DAO_Mailing', [
'name' => 'Example Name',
- ));
+ ]);
$contact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact');
- $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), array(
+ $p = new \Civi\Token\TokenProcessor(Civi::service('dispatcher'), [
'mailing' => $mailing,
- ));
+ ]);
$p->addMessage('example', $inputTemplateText, $inputTemplateFormat);
- $p->addRow()->context(array(
+ $p->addRow()->context([
'contactId' => $contact->id,
- ));
+ ]);
// try {
// $p->evaluate();
// $this->fail('TokenProcessor::evaluate() should have thrown an exception');
public function setUp() {
parent::setUp();
- $params = array(
+ $params = [
'contact_type_a' => 'Individual',
'contact_type_b' => 'Organization',
'name_a_b' => 'Test Employee of',
'name_b_a' => 'Test Employer of',
- );
+ ];
$this->_relationshipTypeId = $this->relationshipTypeCreate($params);
$this->_orgContactID = $this->organizationCreate();
$this->_financialTypeId = 1;
- $params = array(
+ $params = [
'name' => 'test type',
'description' => NULL,
'minimum_fee' => 10,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
'is_active' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
$this->_membershipTypeID = $membershipType->id;
$this->_mebershipStatusID = $this->membershipStatusCreate('test status');
*/
public function tearDown() {
$this->relationshipTypeDelete($this->_relationshipTypeId);
- $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
+ $this->membershipTypeDelete(['id' => $this->_membershipTypeID]);
$this->membershipStatusDelete($this->_mebershipStatusID);
$this->contactDelete($this->_orgContactID);
}
public function testadd() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_mebershipStatusID,
- );
+ ];
- $ids = array();
+ $ids = [];
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$this->assertDBNotNull('CRM_Member_BAO_MembershipLog', $membership->id,
'membership_id', 'id',
public function testdel() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_mebershipStatusID,
- );
- $ids = array(
+ ];
+ $ids = [
'userId' => $contactId,
- );
+ ];
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$membershipDelete = CRM_Member_BAO_MembershipLog::del($membership->id);
$this->assertDBNull('CRM_Member_BAO_MembershipLog', $membership->id, 'membership_id',
public function testresetmodifiedId() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_mebershipStatusID,
- );
- $ids = array(
+ ];
+ $ids = [
'userId' => $contactId,
- );
+ ];
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$resetModifiedId = CRM_Member_BAO_MembershipLog::resetModifiedID($contactId);
$this->assertDBNull('CRM_Member_BAO_MembershipLog', $contactId, 'modified_id',
* Check function add()
*/
public function testAdd() {
- $params = array(
+ $params = [
'name' => 'pending',
'is_active' => 1,
- );
+ ];
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
public function testRetrieve() {
- $params = array(
+ $params = [
'name' => 'testStatus',
'is_active' => 1,
- );
+ ];
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
- $defaults = array();
+ $defaults = [];
$result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults);
$this->assertEquals($result->name, 'testStatus', 'Verify membership status name.');
CRM_Member_BAO_MembershipStatus::del($membershipStatus->id);
}
public function testPseudoConstantflush() {
- $params = array(
+ $params = [
'name' => 'testStatus',
'is_active' => 1,
- );
+ ];
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
- $defaults = array();
+ $defaults = [];
$result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults);
$this->assertEquals($result->name, 'testStatus', 'Verify membership status name.');
- $updateParams = array(
+ $updateParams = [
'id' => $membershipStatus->id,
'name' => 'testStatus',
'label' => 'Changed Status',
'is_active' => 1,
- );
+ ];
$membershipStatus2 = CRM_Member_BAO_MembershipStatus::add($updateParams);
$result = CRM_Member_PseudoConstant::membershipStatus($membershipStatus->id, NULL, 'label', FALSE, FALSE);
$this->assertEquals($result, 'Changed Status', 'Verify updated membership status label From PseudoConstant.');
public function testSetIsActive() {
- $params = array(
+ $params = [
'name' => 'pending',
'is_active' => 1,
- );
+ ];
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
$result = CRM_Member_BAO_MembershipStatus::setIsActive($membershipStatus->id, 0);
}
public function testGetMembershipStatus() {
- $params = array(
+ $params = [
'name' => 'pending',
'is_active' => 1,
- );
+ ];
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
$result = CRM_Member_BAO_MembershipStatus::getMembershipStatus($membershipStatus->id);
}
public function testDel() {
- $params = array(
+ $params = [
'name' => 'testStatus',
'is_active' => 1,
- );
+ ];
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
CRM_Member_BAO_MembershipStatus::del($membershipStatus->id);
- $defaults = array();
+ $defaults = [];
$result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults);
$this->assertEquals(empty($result), TRUE, 'Verify membership status record deletion.');
}
}
public function testGetMembershipStatusByDate() {
- $params = array(
+ $params = [
'name' => 'Current',
'is_active' => 1,
'start_event' => 'start_date',
'end_event' => 'end_date',
- );
+ ];
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
$toDate = date('Ymd');
}
public function testgetMembershipStatusCurrent() {
- $params = array(
+ $params = [
'name' => 'Current',
'is_active' => 1,
'is_current_member' => 1,
- );
+ ];
$membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
$result = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
public function setUp() {
parent::setUp();
// 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'),
- );
+ $GLOBALS['_HTML_QuickForm_registered_rules'] = [
+ 'required' => ['html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'],
+ 'maxlength' => ['html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'],
+ 'minlength' => ['html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'],
+ 'rangelength' => ['html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'],
+ 'email' => ['html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'],
+ 'regex' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'],
+ 'lettersonly' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'],
+ 'alphanumeric' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'],
+ 'numeric' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'],
+ 'nopunctuation' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'],
+ 'nonzero' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'],
+ 'callback' => ['html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'],
+ 'compare' => ['html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'],
+ ];
$this->_contactID = $this->organizationCreate();
- $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
+ $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]);
// add a random number to avoid silly conflicts with old data
$this->_membershipStatusID = $this->membershipStatusCreate('test status' . rand(1, 1000));
}
* This method is called after a test is executed.
*/
public function tearDown() {
- $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
+ $this->membershipTypeDelete(['id' => $this->_membershipTypeID]);
$this->membershipStatusDelete($this->_membershipStatusID);
$this->contactDelete($this->_contactID);
* @return array|int
*/
private function createMembershipType($organizationId, $withRelationship = FALSE) {
- $membershipType = $this->callAPISuccess('MembershipType', 'create', array(
+ $membershipType = $this->callAPISuccess('MembershipType', 'create', [
//Default domain ID
'domain_id' => 1,
'member_of_contact_id' => $organizationId,
'name' => "Organiation Membership Type",
'relationship_type_id' => ($withRelationship) ? 5 : NULL,
'relationship_direction' => ($withRelationship) ? 'b_a' : NULL,
- ));
+ ]);
return $membershipType["values"][$membershipType["id"]];
}
* @return array|int
*/
private function getRelatedMembershipsCount($membershipId) {
- return $this->callAPISuccess("Membership", "getcount", array(
+ return $this->callAPISuccess("Membership", "getcount", [
'owner_membership_id' => $membershipId,
- ));
+ ]);
}
/**
$organizationId = $this->organizationCreate();
// Create relationship between organization and individual contact
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
// Employer of relationship
'relationship_type_id' => 5,
'contact_id_a' => $contactId,
'contact_id_b' => $organizationId,
'is_active' => 1,
- ));
+ ]);
// Create two membership types one with relationship and one without.
$membershipTypeWithRelationship = $this->createMembershipType($membershipOrganizationId, TRUE);
$membershipTypeWithoutRelationship = $this->createMembershipType($membershipOrganizationId);
// Creating membership of organisation
- $membership = $this->callAPISuccess("Membership", "create", array(
+ $membership = $this->callAPISuccess("Membership", "create", [
'membership_type_id' => $membershipTypeWithRelationship["id"],
'contact_id' => $organizationId,
'status_id' => $this->_membershipStatusID,
- ));
+ ]);
$membership = $membership["values"][$membership["id"]];
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
// Now call create() to modify an existing Membership
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array(
+ ];
+ $ids = [
'membership' => $membershipId,
- );
+ ];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipTypeId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId,
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd'),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
- $ids = array();
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId1 = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
'contact_id', 'Database check for created membership.'
);
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', $last_month),
'source' => 'Source123',
'is_override' => 0,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId2 = $this->assertDBNotNull('CRM_Member_BAO_Membership', 'source123', 'id',
'source', 'Database check for created membership.'
);
- $membership = array('contact_id' => $contactId);
- $membershipValues = array();
+ $membership = ['contact_id' => $contactId];
+ $membershipValues = [];
CRM_Member_BAO_Membership::getValues($membership, $membershipValues, TRUE);
$this->assertEquals($membershipValues[$membershipId1]['membership_id'], $membershipId1, 'Verify membership record 1 is fetched.');
public function testRetrieve() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
'contact_id', 'Database check for created membership.'
);
- $params = array('id' => $membershipId);
- $values = array();
+ $params = ['id' => $membershipId];
+ $values = [];
CRM_Member_BAO_Membership::retrieve($params, $values);
$this->assertEquals($values['id'], $membershipId, 'Verify membership record is retrieved.');
public function testActiveMembers() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId1 = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
'contact_id', 'Database check for created membership.'
);
- $params = array('id' => $membershipId1);
- $values1 = array();
+ $params = ['id' => $membershipId1];
+ $values1 = [];
CRM_Member_BAO_Membership::retrieve($params, $values1);
- $membership = array($membershipId1 => $values1);
+ $membership = [$membershipId1 => $values1];
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'PaySource',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId2 = $this->assertDBNotNull('CRM_Member_BAO_Membership', 'PaySource', 'id',
'source', 'Database check for created membership.'
);
- $params = array('id' => $membershipId2);
- $values2 = array();
+ $params = ['id' => $membershipId2];
+ $values2 = [];
CRM_Member_BAO_Membership::retrieve($params, $values2);
$membership[$membershipId2] = $values2;
public function testDeleteMembership() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
public function testGetContactMembership() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
public function testgetContributionPageId() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
public function testgetMembershipStarts() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
public function testGetMembershipCount() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
public function testSortName() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2006-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$membership = $this->callAPISuccess('Membership', 'create', $params);
public function testdeleteRelatedMemberships() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', strtotime('2006-01-21')),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
CRM_Member_BAO_Membership::create($params, $ids);
$contactId = $this->individualCreate();
$joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -6 month"));
$endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day"));
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => $joinDate,
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
'contact_id', 'Database check for created membership.'
$contactId = $this->individualCreate();
$joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -1 year -15 days"));
$endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day"));
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => $joinDate,
'end_date' => $endDate,
'source' => 'Payment',
'status_id' => $statusId,
- );
+ ];
- $ids = array();
+ $ids = [];
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
);
//verify all dates.
- $dates = array(
+ $dates = [
'startDate' => 'start_date',
'joinDate' => 'join_date',
'endDate' => 'end_date',
- );
+ ];
foreach ($dates as $date => $dbDate) {
$this->assertEquals($membership->$dbDate, $$date,
}
public function testUpdateAllMembershipStatusConvertExpiredOverriddenStatusToNormal() {
- $params = array(
+ $params = [
'contact_id' => $this->individualCreate(),
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', time()),
'is_override' => 1,
'status_override_end_date' => date('Ymd', strtotime('-1 day')),
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
$createdMembership = CRM_Member_BAO_Membership::create($params, $ids);
CRM_Member_BAO_Membership::updateAllMembershipStatus();
- $membershipAfterProcess = civicrm_api3('Membership', 'get', array(
+ $membershipAfterProcess = civicrm_api3('Membership', 'get', [
'sequential' => 1,
'id' => $createdMembership->id,
- 'return' => array('id', 'is_override', 'status_override_end_date'),
- ))['values'][0];
+ 'return' => ['id', 'is_override', 'status_override_end_date'],
+ ])['values'][0];
$this->assertEquals($createdMembership->id, $membershipAfterProcess['id']);
$this->assertArrayNotHasKey('is_override', $membershipAfterProcess);
}
public function testUpdateAllMembershipStatusHandleOverriddenWithEndOverrideDateEqualTodayAsExpired() {
- $params = array(
+ $params = [
'contact_id' => $this->individualCreate(),
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', time()),
'is_override' => 1,
'status_override_end_date' => date('Ymd', time()),
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
$createdMembership = CRM_Member_BAO_Membership::create($params, $ids);
CRM_Member_BAO_Membership::updateAllMembershipStatus();
- $membershipAfterProcess = civicrm_api3('Membership', 'get', array(
+ $membershipAfterProcess = civicrm_api3('Membership', 'get', [
'sequential' => 1,
'id' => $createdMembership->id,
- 'return' => array('id', 'is_override', 'status_override_end_date'),
- ))['values'][0];
+ 'return' => ['id', 'is_override', 'status_override_end_date'],
+ ])['values'][0];
$this->assertEquals($createdMembership->id, $membershipAfterProcess['id']);
$this->assertArrayNotHasKey('is_override', $membershipAfterProcess);
}
public function testUpdateAllMembershipStatusDoesNotConvertOverridenMembershipWithoutEndOverrideDateToNormal() {
- $params = array(
+ $params = [
'contact_id' => $this->individualCreate(),
'membership_type_id' => $this->_membershipTypeID,
'join_date' => date('Ymd', time()),
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
$createdMembership = CRM_Member_BAO_Membership::create($params, $ids);
CRM_Member_BAO_Membership::updateAllMembershipStatus();
- $membershipAfterProcess = civicrm_api3('Membership', 'get', array(
+ $membershipAfterProcess = civicrm_api3('Membership', 'get', [
'sequential' => 1,
'id' => $createdMembership->id,
- 'return' => array('id', 'is_override', 'status_override_end_date'),
- ))['values'][0];
+ 'return' => ['id', 'is_override', 'status_override_end_date'],
+ ])['values'][0];
$this->assertEquals($createdMembership->id, $membershipAfterProcess['id']);
$this->assertEquals(1, $membershipAfterProcess['is_override']);
parent::setUp();
//create relationship
- $params = array(
+ $params = [
'name_a_b' => 'Relation 1',
'name_b_a' => 'Relation 2',
'contact_type_a' => 'Individual',
'contact_type_b' => 'Organization',
'is_reserved' => 1,
'is_active' => 1,
- );
+ ];
$this->_relationshipTypeId = $this->relationshipTypeCreate($params);
$this->_orgContactID = $this->organizationCreate();
$this->_indiviContactID = $this->individualCreate();
*
*/
public function testAdd() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'test type',
'domain_id' => 1,
'description' => NULL,
'financial_type_id' => $this->_financialTypeId,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
- );
+ ];
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
);
$this->assertEquals($membership, 'test type', 'Verify membership type name.');
- $this->membershipTypeDelete(array('id' => $membershipType->id));
+ $this->membershipTypeDelete(['id' => $membershipType->id]);
}
/**
*
*/
public function testRetrieve() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'General',
'description' => NULL,
'domain_id' => 1,
'financial_type_id' => $this->_financialTypeId,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
- );
+ ];
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
- $params = array('name' => 'General');
- $default = array();
+ $params = ['name' => 'General'];
+ $default = [];
$result = CRM_Member_BAO_MembershipType::retrieve($params, $default);
$this->assertEquals($result->name, 'General', 'Verify membership type name.');
- $this->membershipTypeDelete(array('id' => $membershipType->id));
+ $this->membershipTypeDelete(['id' => $membershipType->id]);
}
/**
*
*/
public function testSetIsActive() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'General',
'description' => NULL,
'domain_id' => 1,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
'is_active' => 1,
- );
+ ];
$membership = CRM_Member_BAO_MembershipType::add($params, $ids);
CRM_Member_BAO_MembershipType::setIsActive($membership->id, 0);
);
$this->assertEquals($isActive, 0, 'Verify membership type status.');
- $this->membershipTypeDelete(array('id' => $membership->id));
+ $this->membershipTypeDelete(['id' => $membership->id]);
}
/**
*
*/
public function testdel() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'General',
'description' => NULL,
'minimum_fee' => 100,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
'is_active' => 1,
- );
+ ];
$membership = CRM_Member_BAO_MembershipType::add($params, $ids);
$result = CRM_Member_BAO_MembershipType::del($membership->id);
*
*/
public function testConvertDayFormat() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'General',
'description' => NULL,
'minimum_fee' => 100,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
'is_active' => 1,
- );
+ ];
$membership = CRM_Member_BAO_MembershipType::add($params, $ids);
$membershipType[$membership->id] = $params;
CRM_Member_BAO_MembershipType::convertDayFormat($membershipType);
$this->assertEquals($membershipType[$membership->id]['fixed_period_rollover_day'], 'Dec 14', 'Verify memberFixed Period Rollover Day.');
- $this->membershipTypeDelete(array('id' => $membership->id));
+ $this->membershipTypeDelete(['id' => $membership->id]);
}
/**
*
*/
public function testGetMembershipTypes() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'General',
'description' => NULL,
'minimum_fee' => 100,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
'is_active' => 1,
- );
+ ];
$membership = CRM_Member_BAO_MembershipType::add($params, $ids);
$result = CRM_Member_BAO_MembershipType::getMembershipTypes();
$this->assertEquals($result[$membership->id], 'General', 'Verify membership types.');
- $this->membershipTypeDelete(array('id' => $membership->id));
+ $this->membershipTypeDelete(['id' => $membership->id]);
}
/**
*
*/
public function testGetMembershipTypeDetails() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'General',
'description' => NULL,
'minimum_fee' => 100,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
'is_active' => 1,
- );
+ ];
$membership = CRM_Member_BAO_MembershipType::add($params, $ids);
$result = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membership->id);
$this->assertEquals($result['name'], 'General', 'Verify membership type details.');
$this->assertEquals($result['duration_unit'], 'year', 'Verify membership types details.');
- $this->membershipTypeDelete(array('id' => $membership->id));
+ $this->membershipTypeDelete(['id' => $membership->id]);
}
/**
*
*/
public function testGetDatesForMembershipType() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'General',
'description' => NULL,
'minimum_fee' => 100,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
'is_active' => 1,
- );
+ ];
$membership = CRM_Member_BAO_MembershipType::add($params, $ids);
$membershipDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->id);
$this->assertEquals($membershipDates['start_date'], date('Ymd'), 'Verify membership types details.');
- $this->membershipTypeDelete(array('id' => $membership->id));
+ $this->membershipTypeDelete(['id' => $membership->id]);
}
/**
*
*/
public function testGetRenewalDatesForMembershipType() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'General',
'domain_id' => 1,
'description' => NULL,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
'is_active' => 1,
- );
+ ];
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
- $params = array(
+ $params = [
'contact_id' => $this->_indiviContactID,
'membership_type_id' => $membershipType->id,
'join_date' => '20060121000000',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
- $ids = array();
+ ];
+ $ids = [];
$membership = CRM_Member_BAO_Membership::create($params, $ids);
$membershipRenewDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id);
$this->assertEquals($membershipRenewDates['end_date'], '20080120', 'Verify membership renewal end date.');
$this->membershipDelete($membership->id);
- $this->membershipTypeDelete(array('id' => $membershipType->id));
+ $this->membershipTypeDelete(['id' => $membershipType->id]);
}
/**
*
*/
public function testGetMembershipTypesByOrg() {
- $ids = array();
- $params = array(
+ $ids = [];
+ $params = [
'name' => 'General',
'description' => NULL,
'domain_id' => 1,
'relationship_type_id' => $this->_relationshipTypeId,
'visibility' => 'Public',
'is_active' => 1,
- );
+ ];
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
- $membershipTypesResult = civicrm_api3('MembershipType', 'get', array(
+ $membershipTypesResult = civicrm_api3('MembershipType', 'get', [
'member_of_contact_id' => $this->_orgContactID,
- 'options' => array(
+ 'options' => [
'limit' => 0,
- ),
- ));
+ ],
+ ]);
$result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL);
$this->assertEquals(empty($result), FALSE, 'Verify membership types for organization.');
- $membershipTypesResult = civicrm_api3('MembershipType', 'get', array(
+ $membershipTypesResult = civicrm_api3('MembershipType', 'get', [
'member_of_contact_id' => 501,
- 'options' => array(
+ 'options' => [
'limit' => 0,
- ),
- ));
+ ],
+ ]);
$result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL);
$this->assertEquals(empty($result), TRUE, 'Verify membership types for organization.');
- $this->membershipTypeDelete(array('id' => $membershipType->id));
+ $this->membershipTypeDelete(['id' => $membershipType->id]);
}
}
* 1) membership_type_id => 1
*/
public function testConvertEntityFieldSingleValue() {
- $formValues = array('membership_type_id' => 2);
- $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, array('membership_type_id'));
- $this->assertEquals(array('membership_type_id', '=', 2, 0, 0), $params[0]);
+ $formValues = ['membership_type_id' => 2];
+ $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, ['membership_type_id']);
+ $this->assertEquals(['membership_type_id', '=', 2, 0, 0], $params[0]);
$obj = new CRM_Contact_BAO_Query($params);
- $this->assertEquals(array('civicrm_membership.membership_type_id = 2'), $obj->_where[0]);
+ $this->assertEquals(['civicrm_membership.membership_type_id = 2'], $obj->_where[0]);
}
/**
* The last of these is the format used prior to converting membership_type_id to an entity reference field.
*/
public function testConvertEntityFieldMultipleValueEntityRef() {
- $formValues = array('membership_type_id' => '1,2');
- $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, array('membership_type_id'));
- $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]);
+ $formValues = ['membership_type_id' => '1,2'];
+ $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, ['membership_type_id']);
+ $this->assertEquals(['membership_type_id', 'IN', [1, 2], 0, 0], $params[0]);
$obj = new CRM_Contact_BAO_Query($params);
- $this->assertEquals(array('civicrm_membership.membership_type_id IN ("1", "2")'), $obj->_where[0]);
+ $this->assertEquals(['civicrm_membership.membership_type_id IN ("1", "2")'], $obj->_where[0]);
}
/**
* be used by pre-existing smart groups.
*/
public function testConvertEntityFieldMultipleValueLegacy() {
- $formValues = array('membership_type_id' => array(1, 2));
- $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, array('membership_type_id'));
- $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]);
+ $formValues = ['membership_type_id' => [1, 2]];
+ $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, ['membership_type_id']);
+ $this->assertEquals(['membership_type_id', 'IN', [1, 2], 0, 0], $params[0]);
$obj = new CRM_Contact_BAO_Query($params);
- $this->assertEquals(array('civicrm_membership.membership_type_id IN ("1", "2")'), $obj->_where[0]);
+ $this->assertEquals(['civicrm_membership.membership_type_id IN ("1", "2")'], $obj->_where[0]);
}
/**
* The convertFormValues function should cope with this until such time as we can rationalise that.
*/
public function testConvertEntityFieldMultipleValueEntityRefDoubleRun() {
- $formValues = array('membership_type_id' => '1,2');
- $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, array('membership_type_id'));
- $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]);
- $params = CRM_Contact_BAO_Query::convertFormValues($params, 0, FALSE, NULL, array('membership_type_id'));
- $this->assertEquals(array('membership_type_id', 'IN', array(1, 2), 0, 0), $params[0]);
+ $formValues = ['membership_type_id' => '1,2'];
+ $params = CRM_Contact_BAO_Query::convertFormValues($formValues, 0, FALSE, NULL, ['membership_type_id']);
+ $this->assertEquals(['membership_type_id', 'IN', [1, 2], 0, 0], $params[0]);
+ $params = CRM_Contact_BAO_Query::convertFormValues($params, 0, FALSE, NULL, ['membership_type_id']);
+ $this->assertEquals(['membership_type_id', 'IN', [1, 2], 0, 0], $params[0]);
$obj = new CRM_Contact_BAO_Query($params);
- $this->assertEquals(array('civicrm_membership.membership_type_id IN ("1", "2")'), $obj->_where[0]);
+ $this->assertEquals(['civicrm_membership.membership_type_id IN ("1", "2")'], $obj->_where[0]);
}
}
$this->_paymentProcessorID = $this->processorCreate();
$this->loadXMLDataSet(dirname(__FILE__) . '/dataset/data.xml');
- $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array(
+ $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', [
'domain_id' => 1,
'name' => "AnnualFixed",
'member_of_contact_id' => 23,
'fixed_period_rollover_day' => "1231",
'relationship_type_id' => 20,
'financial_type_id' => 2,
- ));
+ ]);
$this->membershipTypeAnnualFixedID = $membershipTypeAnnualFixed['id'];
- $membership = $this->callAPISuccess('Membership', 'create', array(
+ $membership = $this->callAPISuccess('Membership', 'create', [
'contact_id' => $this->_individualId,
'membership_type_id' => $this->membershipTypeAnnualFixedID,
- ));
+ ]);
$this->_membershipID = $membership['id'];
$instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
public function tearDown() {
$this->quickCleanUpFinancialEntities();
$this->quickCleanup(
- array(
+ [
'civicrm_relationship',
'civicrm_membership_type',
'civicrm_membership',
'civicrm_uf_match',
'civicrm_address',
- )
+ ]
);
- foreach (array(17, 18, 23, 32) as $contactID) {
- $this->callAPISuccess('contact', 'delete', array('id' => $contactID, 'skip_undelete' => TRUE));
+ foreach ([17, 18, 23, 32] as $contactID) {
+ $this->callAPISuccess('contact', 'delete', ['id' => $contactID, 'skip_undelete' => TRUE]);
}
- $this->callAPISuccess('relationship_type', 'delete', array('id' => 20));
+ $this->callAPISuccess('relationship_type', 'delete', ['id' => 20]);
}
/**
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '1',
'payment_processor_id' => $this->_paymentProcessorID,
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => '9',
// TODO: Future proof
'Y' => '2024',
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
'billing_middlename' => 'Last',
$form->testSubmit($params);
$form->setRenewalMessage();
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
- $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 0);
- $contribution = $this->callAPISuccess('Contribution', 'get', array(
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
+ $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 0);
+ $contribution = $this->callAPISuccess('Contribution', 'get', [
'contact_id' => $this->_individualId,
'is_test' => TRUE,
- ));
+ ]);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
- $this->_checkFinancialRecords(array(
+ ], 1);
+ $this->_checkFinancialRecords([
'id' => $contribution['id'],
'total_amount' => 50,
'financial_account_id' => 2,
- 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array(
+ 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
- )),
- ), 'online');
+ ]),
+ ], 'online');
$this->assertEquals([
[
'text' => 'AnnualFixed membership for Mr. Anthony Anderson II has been renewed.',
public function testSubmitRecur() {
$form = $this->getForm();
- $this->callAPISuccess('MembershipType', 'create', array(
+ $this->callAPISuccess('MembershipType', 'create', [
'id' => $this->membershipTypeAnnualFixedID,
'duration_unit' => 'month',
'duration_interval' => 1,
'auto_renew' => TRUE,
- ));
+ ]);
$form->preProcess();
$this->createLoggedInUser();
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'price_set_id' => 0,
'join_date' => date('m/d/Y', time()),
'end_date' => '',
'campaign_id' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'auto_renew' => '1',
'is_recur' => 1,
'max_related' => 0,
'payment_processor_id' => $this->_paymentProcessorID,
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => '9',
// TODO: Future proof
'Y' => '2019',
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
'billing_middlename' => 'Last',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
'send_receipt' => 1,
- );
+ ];
$form->_mode = 'test';
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
- $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
+ $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]);
$this->assertEquals(1, $contributionRecur['is_email_receipt']);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date'])));
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date'])));
$this->assertNotEmpty($contributionRecur['invoice_id']);
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id',
'Pending'), $contributionRecur['contribution_status_id']);
- $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', array(
+ $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', [
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
- )), $contributionRecur['payment_instrument_id']);
+ ]), $contributionRecur['payment_instrument_id']);
- $contribution = $this->callAPISuccess('Contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('Contribution', 'getsingle', [
'contact_id' => $this->_individualId,
'is_test' => TRUE,
- ));
+ ]);
- $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', array(
+ $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', [
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
- )), $contribution['payment_instrument_id']);
+ ]), $contribution['payment_instrument_id']);
$this->assertEquals($contributionRecur['id'], $contribution['contribution_recur_id']);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
+ ], 1);
- $this->callAPISuccessGetSingle('address', array(
+ $this->callAPISuccessGetSingle('address', [
'contact_id' => $this->_individualId,
'street_address' => '10 Test St',
'postal_code' => 90210,
- ));
+ ]);
}
/**
$form = $this->getForm();
/** @var \CRM_Core_Payment_Dummy $processor */
$processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
- $processor->setDoDirectPaymentResult(array(
+ $processor->setDoDirectPaymentResult([
'payment_status_id' => 1,
'trxn_id' => 'kettles boil water',
'fee_amount' => .29,
- ));
+ ]);
- $this->callAPISuccess('MembershipType', 'create', array(
+ $this->callAPISuccess('MembershipType', 'create', [
'id' => $this->membershipTypeAnnualFixedID,
'duration_unit' => 'month',
'duration_interval' => 1,
'auto_renew' => TRUE,
- ));
+ ]);
$this->createLoggedInUser();
$form->preProcess();
$form->_mode = 'test';
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
- $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
+ $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]);
$this->assertEquals($contributionRecur['id'], $membership['contribution_recur_id']);
$this->assertEquals(0, $contributionRecur['is_email_receipt']);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date'])));
'In Progress'), $contributionRecur['contribution_status_id']);
$this->assertNotEmpty($contributionRecur['next_sched_contribution_date']);
*/
- $paymentInstrumentID = $this->callAPISuccessGetValue('PaymentProcessor', array(
+ $paymentInstrumentID = $this->callAPISuccessGetValue('PaymentProcessor', [
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
- ));
+ ]);
$this->assertEquals($paymentInstrumentID, $contributionRecur['payment_instrument_id']);
- $contribution = $this->callAPISuccess('Contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('Contribution', 'getsingle', [
'contact_id' => $this->_individualId,
'is_test' => TRUE,
- ));
+ ]);
$this->assertEquals($paymentInstrumentID, $contribution['payment_instrument_id']);
$this->assertEquals('kettles boil water', $contribution['trxn_id']);
$this->assertEquals(7800.90, $contribution['total_amount']);
$this->assertEquals(7800.61, $contribution['net_amount']);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
+ ], 1);
}
/**
$this->mut = new CiviMailUtils($this, TRUE);
/** @var \CRM_Core_Payment_Dummy $processor */
$processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
- $processor->setDoDirectPaymentResult(array(
+ $processor->setDoDirectPaymentResult([
'payment_status_id' => 1,
'trxn_id' => 'kettles boil water',
'fee_amount' => .29,
- ));
+ ]);
- $this->callAPISuccess('MembershipType', 'create', array(
+ $this->callAPISuccess('MembershipType', 'create', [
'id' => $this->membershipTypeAnnualFixedID,
'duration_unit' => 'month',
'duration_interval' => 1,
'auto_renew' => TRUE,
- ));
+ ]);
$this->createLoggedInUser();
$form->preProcess();
$form->_mode = 'test';
$form->testSubmit($params);
- $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array('contact_id' => $this->_individualId));
+ $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]);
$this->assertEquals(1, $contributionRecur['is_email_receipt']);
$this->mut->checkMailLog([
'$ ' . $this->formatMoneyInput(7800.90),
public function testSubmitPayLater() {
$form = $this->getForm(NULL);
$this->createLoggedInUser();
- $originalMembership = $this->callAPISuccessGetSingle('membership', array());
- $params = array(
+ $originalMembership = $this->callAPISuccessGetSingle('membership', []);
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('m/d/Y', time()),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '2',
'record_contribution' => TRUE,
'trxn_id' => 777,
'contribution_status_id' => 2,
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals(strtotime($membership['end_date']), strtotime($originalMembership['end_date']));
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 2,
- 'return' => array("tax_amount", "trxn_id"),
- ));
+ 'return' => ["tax_amount", "trxn_id"],
+ ]);
$this->assertEquals($contribution['trxn_id'], 777);
$this->assertEquals($contribution['tax_amount'], NULL);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
+ ], 1);
}
/**
public function testSubmitPayLaterWithBilling() {
$form = $this->getForm(NULL);
$this->createLoggedInUser();
- $originalMembership = $this->callAPISuccessGetSingle('membership', array());
- $params = array(
+ $originalMembership = $this->callAPISuccessGetSingle('membership', []);
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('m/d/Y', time()),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '2',
'billing_state_province_id-5' => '1003',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals(strtotime($membership['end_date']), strtotime($originalMembership['end_date']));
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 2,
- ));
+ ]);
$this->assertEquals($contribution['trxn_id'], 777);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
- $this->callAPISuccessGetSingle('address', array(
+ ], 1);
+ $this->callAPISuccessGetSingle('address', [
'contact_id' => $this->_individualId,
'street_address' => '10 Test St',
'postal_code' => 90210,
- ));
+ ]);
}
/**
public function testSubmitComplete() {
$form = $this->getForm(NULL);
$this->createLoggedInUser();
- $originalMembership = $this->callAPISuccessGetSingle('membership', array());
- $params = array(
+ $originalMembership = $this->callAPISuccessGetSingle('membership', []);
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('m/d/Y', time()),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '2',
'trxn_id' => 777,
'contribution_status_id' => 1,
'fee_amount' => .5,
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals(strtotime($membership['end_date']), strtotime('+ 2 years',
strtotime($originalMembership['end_date'])));
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 1,
- ));
+ ]);
$this->assertEquals($contribution['trxn_id'], 777);
$this->assertEquals(.5, $contribution['fee_amount']);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
+ ], 1);
}
/**
* @return array
*/
protected function getBaseSubmitParams() {
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'price_set_id' => 0,
'join_date' => date('m/d/Y', time()),
'end_date' => '',
'campaign_id' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'auto_renew' => '1',
'is_recur' => 1,
'max_related' => 0,
'payment_processor_id' => $this->_paymentProcessorID,
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => '9',
// TODO: Future proof
'Y' => '2019',
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
'billing_middlename' => 'Last',
'billing_state_province_id-5' => '1003',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
- );
+ ];
return $params;
}
protected $_apiversion;
protected $_entity = 'Membership';
protected $_params;
- protected $_ids = array();
+ protected $_ids = [];
protected $_paymentProcessorID;
/**
*
* @var array
*/
- protected $_processorParams = array();
+ protected $_processorParams = [];
/**
* ID of created membership.
*
* @var array
*/
- protected $paymentInstruments = array();
+ protected $paymentInstruments = [];
/**
* @var CiviMailUtils
$this->loadXMLDataSet(dirname(__FILE__) . '/dataset/data.xml');
- $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array(
+ $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', [
'domain_id' => 1,
'name' => "AnnualFixed",
'member_of_contact_id' => 23,
'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'));
+ $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
$this->paymentInstruments = $instruments['values'];
}
public function tearDown() {
$this->quickCleanUpFinancialEntities();
$this->quickCleanup(
- array(
+ [
'civicrm_relationship',
'civicrm_membership_type',
'civicrm_membership',
'civicrm_uf_match',
'civicrm_email',
- )
+ ]
);
- foreach (array(17, 18, 23, 32) as $contactID) {
- $this->callAPISuccess('contact', 'delete', array('id' => $contactID, 'skip_undelete' => TRUE));
+ foreach ([17, 18, 23, 32] as $contactID) {
+ $this->callAPISuccess('contact', 'delete', ['id' => $contactID, 'skip_undelete' => TRUE]);
}
- $this->callAPISuccess('relationship_type', 'delete', array('id' => 20));
+ $this->callAPISuccess('relationship_type', 'delete', ['id' => 20]);
}
/**
* that has an empty contact_select_id value
*/
public function testFormRuleEmptyContact() {
- $params = array(
+ $params = [
'contact_select_id' => 0,
- 'membership_type_id' => array(1 => NULL),
- );
- $files = array();
+ 'membership_type_id' => [1 => NULL],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
$this->assertType('array', $rc);
$this->assertTrue(array_key_exists('membership_type_id', $rc));
- $params['membership_type_id'] = array(1 => 3);
+ $params['membership_type_id'] = [1 => 3];
$rc = $obj->formRule($params, $files, $obj);
$this->assertType('array', $rc);
$this->assertTrue(array_key_exists('join_date', $rc));
$unixNow = time();
$unixYesterday = $unixNow - (24 * 60 * 60);
$ymdYesterday = date('Y-m-d', $unixYesterday);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d'),
'start_date' => $ymdYesterday,
'end_date' => '',
- 'membership_type_id' => array('23', '15'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '15'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
- $rc = call_user_func(array('CRM_Member_Form_Membership', 'formRule'),
+ $rc = call_user_func(['CRM_Member_Form_Membership', 'formRule'],
$params, $files, $obj
);
$this->assertType('array', $rc);
$unixNow = time();
$unixYesterday = $unixNow - (24 * 60 * 60);
$ymdYesterday = date('Y-m-d', $unixYesterday);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d'),
'start_date' => date('Y-m-d'),
'end_date' => $ymdYesterday,
- 'membership_type_id' => array('23', '15'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '15'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
$this->assertType('array', $rc);
$unixNow = time();
$unixYearFromNow = $unixNow + (365 * 24 * 60 * 60);
$ymdYearFromNow = date('Y-m-d', $unixYearFromNow);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => $ymdYearFromNow,
- 'membership_type_id' => array('23', '15'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '15'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
$this->assertType('array', $rc);
public function testFormRuleRollingLifetimeEnd() {
$unixNow = time();
$unixYearFromNow = $unixNow + (365 * 24 * 60 * 60);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d'),
'start_date' => date('Y-m-d'),
'end_date' => date('Y-m-d',
$unixYearFromNow
),
- 'membership_type_id' => array('23', '25'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '25'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
$this->assertType('array', $rc);
*/
public function testFormRulePermanentOverrideWithNoStatus() {
$unixNow = time();
- $params = array(
+ $params = [
'join_date' => date('Y-m-d'),
- 'membership_type_id' => array('23', '25'),
+ 'membership_type_id' => ['23', '25'],
'is_override' => TRUE,
- );
- $files = array();
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
$this->assertType('array', $rc);
}
public function testFormRuleUntilDateOverrideWithValidOverrideEndDate() {
- $params = array(
+ $params = [
'join_date' => date('Y-m-d'),
- 'membership_type_id' => array('23', '25'),
+ 'membership_type_id' => ['23', '25'],
'is_override' => TRUE,
'status_id' => 1,
'status_override_end_date' => date('Y-m-d'),
- );
- $files = array();
+ ];
+ $files = [];
$membershipForm = new CRM_Member_Form_Membership();
$validationResponse = $membershipForm->formRule($params, $files, $membershipForm);
$this->assertTrue($validationResponse);
}
public function testFormRuleUntilDateOverrideWithNoOverrideEndDate() {
- $params = array(
+ $params = [
'join_date' => date('Y-m-d'),
- 'membership_type_id' => array('23', '25'),
+ 'membership_type_id' => ['23', '25'],
'is_override' => CRM_Member_StatusOverrideTypes::UNTIL_DATE,
'status_id' => 1,
- );
- $files = array();
+ ];
+ $files = [];
$membershipForm = new CRM_Member_Form_Membership();
$validationResponse = $membershipForm->formRule($params, $files, $membershipForm);
$this->assertType('array', $validationResponse);
public function testFormRuleRollingJoin1MonthFromNow() {
$unixNow = time();
$unix1MFmNow = $unixNow + (31 * 24 * 60 * 60);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d', $unix1MFmNow),
'start_date' => '',
'end_date' => '',
- 'membership_type_id' => array('23', '15'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '15'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
* Test CRM_Member_Form_Membership::formRule() with a join date of today and a rolling membership type.
*/
public function testFormRuleRollingJoinToday() {
- $params = array(
+ $params = [
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
- 'membership_type_id' => array('23', '15'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '15'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
public function testFormRuleRollingJoin1MonthAgo() {
$unixNow = time();
$unix1MAgo = $unixNow - (31 * 24 * 60 * 60);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d', $unix1MAgo),
'start_date' => '',
'end_date' => '',
- 'membership_type_id' => array('23', '15'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '15'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
public function testFormRuleRollingJoin6MonthsAgo() {
$unixNow = time();
$unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d', $unix6MAgo),
'start_date' => '',
'end_date' => '',
- 'membership_type_id' => array('23', '15'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '15'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
public function testFormRuleRollingJoin1YearAgo() {
$unixNow = time();
$unix1YAgo = $unixNow - (370 * 24 * 60 * 60);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d', $unix1YAgo),
'start_date' => '',
'end_date' => '',
- 'membership_type_id' => array('23', '15'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '15'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
public function testFormRuleRollingJoin2YearsAgo() {
$unixNow = time();
$unix2YAgo = $unixNow - (2 * 365 * 24 * 60 * 60);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d', $unix2YAgo),
'start_date' => '',
'end_date' => '',
- 'membership_type_id' => array('23', '15'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '15'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
public function testFormRuleFixedJoin6MonthsAgo() {
$unixNow = time();
$unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
- $params = array(
+ $params = [
'join_date' => date('Y-m-d', $unix6MAgo),
'start_date' => '',
'end_date' => '',
- 'membership_type_id' => array('23', '7'),
- );
- $files = array();
+ 'membership_type_id' => ['23', '7'],
+ ];
+ $files = [];
$obj = new CRM_Member_Form_Membership();
$rc = $obj->formRule($params, $files, $obj);
$this->mut = new CiviMailUtils($this, TRUE);
$form->_mode = 'test';
$this->createLoggedInUser();
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('2/d/Y', time()),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '1',
'payment_processor_id' => $this->_paymentProcessorID,
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => '9',
// TODO: Future proof
'Y' => '2024',
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
'billing_middlename' => 'Last',
'billing_country_id-5' => '1228',
'send_receipt' => TRUE,
'receipt_text' => 'Receipt text',
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
- $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 0);
- $contribution = $this->callAPISuccess('Contribution', 'get', array(
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
+ $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 0);
+ $contribution = $this->callAPISuccess('Contribution', 'get', [
'contact_id' => $this->_individualId,
'is_test' => TRUE,
- ));
+ ]);
//CRM-20264 : Check that CC type and number (last 4 digit) is stored during backoffice membership payment
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('card_type_id', 'pan_truncation'),
- )
+ 'return' => ['card_type_id', 'pan_truncation'],
+ ]
);
$this->assertEquals(1, $financialTrxn['card_type_id']);
$this->assertEquals(1111, $financialTrxn['pan_truncation']);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
+ ], 1);
- $this->_checkFinancialRecords(array(
+ $this->_checkFinancialRecords([
'id' => $contribution['id'],
'total_amount' => 1234.56,
'financial_account_id' => 2,
- 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array(
+ 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [
'id' => $this->_paymentProcessorID,
'return' => 'payment_instrument_id',
- )),
- ), 'online');
- $this->mut->checkMailLog(array(
+ ]),
+ ], 'online');
+ $this->mut->checkMailLog([
CRM_Utils_Money::format('1234.56'),
'Receipt text',
- ));
+ ]);
$this->mut->stop();
$this->assertEquals([
[
$form->preProcess();
$this->mut = new CiviMailUtils($this, TRUE);
$this->createLoggedInUser();
- $priceSet = $this->callAPISuccess('PriceSet', 'Get', array("extends" => "CiviMember"));
+ $priceSet = $this->callAPISuccess('PriceSet', 'Get', ["extends" => "CiviMember"]);
$form->set('priceSetId', $priceSet['id']);
CRM_Price_BAO_PriceSet::buildPriceSet($form);
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'record_contribution' => 1,
'total_amount' => 50,
'receive_date' => date('Y-m-d', time()) . ' 20:36:00',
//Member dues, see data.xml
'financial_type_id' => '2',
'payment_processor_id' => $this->_paymentProcessorID,
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
// check the membership status after partial payment, if its Pending
$this->assertEquals(array_search('New', CRM_Member_PseudoConstant::membershipStatus()), $membership['status_id']);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
- ));
+ ]);
$this->assertEquals('Completed', $contribution['contribution_status']);
$this->assertEquals(50.00, $contribution['total_amount']);
$this->assertEquals(50.00, $contribution['net_amount']);
// Step 2: Change the membership type whose minimum free is less than earlier membership
- $secondMembershipType = $this->callAPISuccess('membership_type', 'create', array(
+ $secondMembershipType = $this->callAPISuccess('membership_type', 'create', [
'domain_id' => 1,
'name' => "Second Test Membership",
'member_of_contact_id' => 23,
'fixed_period_rollover_day' => "1231",
'relationship_type_id' => 20,
'financial_type_id' => 2,
- ));
+ ]);
Civi::settings()->set('update_contribution_on_membership_type_change', TRUE);
$form = $this->getForm();
$form->preProcess();
$form->set('priceSetId', $priceSet['id']);
CRM_Price_BAO_PriceSet::buildPriceSet($form);
$form->_action = CRM_Core_Action::UPDATE;
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $secondMembershipType['id']),
+ 'membership_type_id' => [23, $secondMembershipType['id']],
'record_contribution' => 1,
'status_id' => 1,
'total_amount' => 25,
//Member dues, see data.xml
'financial_type_id' => '2',
'payment_processor_id' => $this->_paymentProcessorID,
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
// check the membership status after partial payment, if its Pending
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
- ));
+ ]);
$payment = CRM_Contribute_BAO_Contribution::getPaymentInfo($membership['id'], 'membership', FALSE, TRUE);
// Check the contribution status on membership type change whose minimum fee was less than earlier memebership
$this->assertEquals('Pending refund', $contribution['contribution_status']);
$form->preProcess();
$this->mut = new CiviMailUtils($this, TRUE);
$this->createLoggedInUser();
- $priceSet = $this->callAPISuccess('PriceSet', 'Get', array("extends" => "CiviMember"));
+ $priceSet = $this->callAPISuccess('PriceSet', 'Get', ["extends" => "CiviMember"]);
$form->set('priceSetId', $priceSet['id']);
$partiallyPaidAmount = 25;
CRM_Price_BAO_PriceSet::buildPriceSet($form);
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'receive_date' => date('Y-m-d', time()) . ' 20:36:00',
'record_contribution' => 1,
'total_amount' => $this->formatMoneyInput($partiallyPaidAmount),
//Member dues, see data.xml
'financial_type_id' => '2',
'payment_processor_id' => $this->_paymentProcessorID,
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
// check the membership status after partial payment, if its Pending
$this->assertEquals(array_search('Pending', CRM_Member_PseudoConstant::membershipStatus()), $membership['status_id']);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
- ));
+ ]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
// $this->assertEquals(50.00, $contribution['total_amount']);
// $this->assertEquals(25.00, $contribution['net_amount']);
// Step 2: submit the other half of the partial payment
// via AdditionalPayment form to complete the related contribution
$form = new CRM_Contribute_Form_AdditionalPayment();
- $submitParams = array(
+ $submitParams = [
'contribution_id' => $contribution['contribution_id'],
'contact_id' => $this->_individualId,
'total_amount' => $this->formatMoneyInput($partiallyPaidAmount),
'payment_processor_id' => 0,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'check_number' => 'check-12345',
- );
+ ];
$form->cid = $this->_individualId;
$form->testSubmit($submitParams);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
// check the membership status after additional payment, if its changed to 'New'
$this->assertEquals(array_search('New', CRM_Member_PseudoConstant::membershipStatus()), $membership['status_id']);
// check the contribution status and net amount after additional payment
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
- ));
+ ]);
$this->assertEquals('Completed', $contribution['contribution_status']);
// $this->assertEquals(50.00, $contribution['net_amount']);
}
*/
public function testSubmitRecur() {
CRM_Core_Session::singleton()->getStatus(TRUE);
- $pendingVal = $this->callAPISuccessGetValue('OptionValue', array(
+ $pendingVal = $this->callAPISuccessGetValue('OptionValue', [
'return' => "id",
'option_group_id' => "contribution_status",
'label' => "Pending",
- ));
+ ]);
//Update label for Pending contribution status.
- $this->callAPISuccess('OptionValue', 'create', array(
+ $this->callAPISuccess('OptionValue', 'create', [
'id' => $pendingVal,
'label' => "PendingEdited",
- ));
+ ]);
$form = $this->getForm();
- $this->callAPISuccess('MembershipType', 'create', array(
+ $this->callAPISuccess('MembershipType', 'create', [
'id' => $this->membershipTypeAnnualFixedID,
'duration_unit' => 'month',
'duration_interval' => 1,
'auto_renew' => TRUE,
- ));
+ ]);
$form->preProcess();
$this->createLoggedInUser();
$params = $this->getBaseSubmitParams();
$form->_mode = 'test';
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
- $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
+ $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 1);
- $contribution = $this->callAPISuccess('Contribution', 'get', array(
+ $contribution = $this->callAPISuccess('Contribution', 'get', [
'contact_id' => $this->_individualId,
'is_test' => TRUE,
- ));
+ ]);
//Check if Membership Payment is recorded.
- $this->callAPISuccessGetCount('MembershipPayment', array(
+ $this->callAPISuccessGetCount('MembershipPayment', [
'membership_id' => $membership['id'],
'contribution_id' => $contribution['id'],
- ), 1);
+ ], 1);
// CRM-16992.
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
+ ], 1);
$this->assertEquals([
[
'text' => 'AnnualFixed membership for Mr. Anthony Anderson II has been added. The new membership End Date is ' . date('F jS, Y', strtotime('last day of this month')) . ' 12:00 AM.',
$this->createTwoMembershipsViaPriceSetInBackEnd($this->_individualId);
// cancel the related contribution via API
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 2,
- ));
- $this->callAPISuccess('Contribution', 'create', array(
+ ]);
+ $this->callAPISuccess('Contribution', 'create', [
'id' => $contribution['id'],
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Cancelled'),
- ));
+ ]);
// fetch financial_trxn ID of the related contribution
$sql = "SELECT financial_trxn_id
ORDER BY id DESC
LIMIT 1
";
- $financialTrxnID = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($contribution['id'], 'Int')));
+ $financialTrxnID = CRM_Core_DAO::singleValueQuery($sql, [1 => [$contribution['id'], 'Int']]);
// fetch entity_financial_trxn records and compare their cancelled records
- $result = $this->callAPISuccess('EntityFinancialTrxn', 'Get', array(
+ $result = $this->callAPISuccess('EntityFinancialTrxn', 'Get', [
'financial_trxn_id' => $financialTrxnID,
'entity_table' => 'civicrm_financial_item',
- ));
+ ]);
// compare the reversed amounts of respective memberships after cancelling contribution
- $cancelledMembershipAmounts = array(
+ $cancelledMembershipAmounts = [
-20.00,
-10.00,
- );
+ ];
$count = 0;
foreach ($result['values'] as $record) {
$this->assertEquals($cancelledMembershipAmounts[$count], $record['amount']);
$form = $this->getForm(NULL);
$form->preProcess();
$this->createLoggedInUser();
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '2',
'billing_state_province_id-5' => '1003',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
- $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', [
'contact_id' => $this->_individualId,
'contribution_status_id' => 2,
- ));
+ ]);
$this->assertEquals($contribution['trxn_id'], 777);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
- $this->callAPISuccessGetSingle('address', array(
+ ], 1);
+ $this->callAPISuccessGetSingle('address', [
'contact_id' => $this->_individualId,
'street_address' => '10 Test St',
'postal_code' => 90210,
- ));
+ ]);
}
/**
//Perform a pay later membership contribution.
$this->testSubmitPayLaterWithBilling();
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals($membership['status_id'], array_search('Pending', $memStatus));
- $contribution = $this->callAPISuccessGetSingle('MembershipPayment', array(
+ $contribution = $this->callAPISuccessGetSingle('MembershipPayment', [
'membership_id' => $membership['id'],
- ));
+ ]);
//Update contribution to Partially paid.
- $prevContribution = $this->callAPISuccess('Contribution', 'create', array(
+ $prevContribution = $this->callAPISuccess('Contribution', 'create', [
'id' => $contribution['contribution_id'],
'contribution_status_id' => 'Partially paid',
- ));
+ ]);
$prevContribution = $prevContribution['values'][1];
//Complete the contribution from offline form.
$form = new CRM_Contribute_Form_Contribution();
- $submitParams = array(
+ $submitParams = [
'id' => $contribution['contribution_id'],
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'),
'price_set_id' => 0,
- );
- $fields = array('total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'contact_id', 'payment_instrument_id');
+ ];
+ $fields = ['total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'contact_id', 'payment_instrument_id'];
foreach ($fields as $val) {
$submitParams[$val] = $prevContribution[$val];
}
$form->testSubmit($submitParams, CRM_Core_Action::UPDATE);
//Check if Membership is updated to New.
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals($membership['status_id'], array_search('New', $memStatus));
}
$form = $this->getForm();
$mut = new CiviMailUtils($this, TRUE);
$processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
- $processor->setDoDirectPaymentResult(array(
+ $processor->setDoDirectPaymentResult([
'payment_status_id' => 1,
'trxn_id' => 'kettles boil water',
'fee_amount' => .14,
- ));
+ ]);
$processorDetail = $processor->getPaymentProcessor();
- $this->callAPISuccess('MembershipType', 'create', array(
+ $this->callAPISuccess('MembershipType', 'create', [
'id' => $this->membershipTypeAnnualFixedID,
'duration_unit' => 'month',
'duration_interval' => 1,
'auto_renew' => TRUE,
- ));
+ ]);
$form->preProcess();
$this->createLoggedInUser();
$params = $this->getBaseSubmitParams();
$form->_mode = 'test';
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
- $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
+ $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 1);
- $contribution = $this->callAPISuccess('Contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('Contribution', 'getsingle', [
'contact_id' => $this->_individualId,
'is_test' => TRUE,
- ));
+ ]);
$this->assertEquals(.14, $contribution['fee_amount']);
$this->assertEquals('kettles boil water', $contribution['trxn_id']);
$this->assertEquals($processorDetail['payment_instrument_id'], $contribution['payment_instrument_id']);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
- ), 1);
- $mut->checkMailLog(array(
+ ], 1);
+ $mut->checkMailLog([
'===========================================================
Billing Name and Address
===========================================================
Visa
************1111
Expires: ',
- ));
+ ]);
$mut->stop();
}
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals($membership['status_id'], array_search('Pending', CRM_Member_PseudoConstant::membershipStatus()));
}
public function testTwoInheritedMembershipsViaPriceSetInBackend() {
// Create an organization and give it a "Member of" relationship to $this->_individualId.
$orgID = $this->organizationCreate();
- $relationship = $this->callAPISuccess('relationship', 'create', array(
+ $relationship = $this->callAPISuccess('relationship', 'create', [
'contact_id_a' => $this->_individualId,
'contact_id_b' => $orgID,
'relationship_type_id' => 20,
'is_active' => 1,
- ));
+ ]);
// Create two memberships for the organization, via a price set in the back end.
$this->createTwoMembershipsViaPriceSetInBackEnd($orgID);
// Check the primary memberships on the organization.
- $orgMembershipResult = $this->callAPISuccess('membership', 'get', array(
+ $orgMembershipResult = $this->callAPISuccess('membership', 'get', [
'contact_id' => $orgID,
- ));
+ ]);
$this->assertEquals(2, $orgMembershipResult['count'], "2 primary memberships should have been created on the organization.");
- $primaryMembershipIds = array();
+ $primaryMembershipIds = [];
foreach ($orgMembershipResult['values'] as $membership) {
$primaryMembershipIds[] = $membership['id'];
$this->assertTrue(empty($membership['owner_membership_id']), "Membership on the organization has owner_membership_id so is inherited.");
// CRM-20955: check that correct inherited memberships were created for the individual,
// for both of the primary memberships.
- $individualMembershipResult = $this->callAPISuccess('membership', 'get', array(
+ $individualMembershipResult = $this->callAPISuccess('membership', 'get', [
'contact_id' => $this->_individualId,
- ));
+ ]);
$this->assertEquals(2, $individualMembershipResult['count'], "2 inherited memberships should have been created on the individual.");
foreach ($individualMembershipResult['values'] as $membership) {
$this->assertNotEmpty($membership['owner_membership_id'], "Membership on the individual lacks owner_membership_id so is not inherited.");
// CRM-20966: check that the correct membership contribution, line items
// & membership_payment records were created for the organization.
- $contributionResult = $this->callAPISuccess('contribution', 'get', array(
+ $contributionResult = $this->callAPISuccess('contribution', 'get', [
'contact_id' => $orgID,
'sequential' => 1,
- 'api.line_item.get' => array(),
- 'api.membership_payment.get' => array(),
- ));
+ 'api.line_item.get' => [],
+ 'api.membership_payment.get' => [],
+ ]);
$this->assertEquals(1, $contributionResult['count'], "One contribution should have been created for the organization's memberships.");
$this->assertEquals(2, $contributionResult['values'][0]['api.line_item.get']['count'], "2 line items should have been created for the organization's memberships.");
}
// CRM-20966: check that deleting relationship used for inheritance does not delete contribution.
- $this->callAPISuccess('relationship', 'delete', array(
+ $this->callAPISuccess('relationship', 'delete', [
'id' => $relationship['id'],
- ));
+ ]);
- $contributionResultAfterRelationshipDelete = $this->callAPISuccess('contribution', 'get', array(
+ $contributionResultAfterRelationshipDelete = $this->callAPISuccess('contribution', 'get', [
'id' => $contributionResult['values'][0]['id'],
'contact_id' => $orgID,
- ));
+ ]);
$this->assertEquals(1, $contributionResultAfterRelationshipDelete['count'], "Contribution has been wrongly deleted.");
}
* @return array
*/
protected function getBaseSubmitParams() {
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'price_set_id' => 0,
'join_date' => date('Y-m-d'),
'end_date' => '',
'campaign_id' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'auto_renew' => '1',
'is_recur' => 1,
'max_related' => 0,
'payment_processor_id' => $this->_paymentProcessorID,
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
- 'credit_card_exp_date' => array(
+ 'credit_card_exp_date' => [
'M' => '9',
// TODO: Future proof
'Y' => '2019',
- ),
+ ],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
'billing_middlename' => 'Last',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
'send_receipt' => 1,
- );
+ ];
return $params;
}
$this->createLoggedInUser();
// create a price-set of price-field of type checkbox and each price-option corresponds to a membership type
- $priceSet = $this->callAPISuccess('price_set', 'create', array(
+ $priceSet = $this->callAPISuccess('price_set', 'create', [
'is_quick_config' => 0,
'extends' => 'CiviMember',
'financial_type_id' => 1,
'title' => 'my Page',
- ));
+ ]);
$priceSetID = $priceSet['id'];
// create respective checkbox price-field
- $priceField = $this->callAPISuccess('price_field', 'create', array(
+ $priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => $priceSetID,
'label' => 'Memberships',
'html_type' => 'Checkbox',
- ));
+ ]);
$priceFieldID = $priceField['id'];
// create two price options, each represent a membership type of amount 20 and 10 respectively
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Long Haired Goat',
'financial_type_id' => 'Donation',
'membership_type_id' => 15,
'membership_num_terms' => 1,
- ));
- $pfvIDs = array($priceFieldValue['id'] => 1);
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ ]);
+ $pfvIDs = [$priceFieldValue['id'] => 1];
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Shoe-eating Goat',
'financial_type_id' => 'Donation',
'membership_type_id' => 35,
'membership_num_terms' => 2,
- ));
+ ]);
$pfvIDs[$priceFieldValue['id']] = 1;
// register for both of these memberships via backoffice membership form submission
- $params = array(
+ $params = [
'cid' => $contactId,
'join_date' => date('Y-m-d'),
'start_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
"price_$priceFieldID" => $pfvIDs,
"price_set_id" => $priceSetID,
- 'membership_type_id' => array(1 => 0),
+ 'membership_type_id' => [1 => 0],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '2',
'billing_state_province_id-5' => '1003',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
- );
+ ];
$form->testSubmit($params);
}
//Create a membership with status = 'New'.
$this->_individualId = $this->createLoggedInUser();
- $memParams = array(
+ $memParams = [
'contact_id' => $this->_individualId,
'membership_type_id' => $this->membershipTypeAnnualFixedID,
'status_id' => array_search('New', CRM_Member_PseudoConstant::membershipStatus()),
- );
- $cancelledStatusId = $this->callAPISuccessGetValue('OptionValue', array(
+ ];
+ $cancelledStatusId = $this->callAPISuccessGetValue('OptionValue', [
'return' => "value",
'option_group_id' => "contribution_status",
'name' => "Cancelled",
- ));
- $params = array(
+ ]);
+ $params = [
'total_amount' => 50,
'financial_type_id' => 2,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => $cancelledStatusId,
- );
+ ];
$membershipId = $this->contactMembershipCreate($memParams);
- $contriParams = array(
+ $contriParams = [
'membership_id' => $membershipId,
'total_amount' => 50,
'financial_type_id' => 2,
'contact_id' => $this->_individualId,
- );
+ ];
$contribution = CRM_Member_BAO_Membership::recordMembershipContribution($contriParams);
//Update Contribution to Cancelled.
$form->_mode = NULL;
$form->_contactID = $this->_individualId;
$form->testSubmit($params, CRM_Core_Action::UPDATE);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
//Assert membership status overrides when the contribution cancelled.
$this->assertEquals($membership['is_override'], TRUE);
- $this->assertEquals($membership['status_id'], $this->callAPISuccessGetValue('MembershipStatus', array(
+ $this->assertEquals($membership['status_id'], $this->callAPISuccessGetValue('MembershipStatus', [
'return' => "id",
'name' => "Cancelled",
- )));
+ ]));
}
/**
$form->preProcess();
$this->mut = new CiviMailUtils($this, TRUE);
$this->createLoggedInUser();
- $priceSet = $this->callAPISuccess('PriceSet', 'Get', array("extends" => "CiviMember"));
+ $priceSet = $this->callAPISuccess('PriceSet', 'Get', ["extends" => "CiviMember"]);
$form->set('priceSetId', $priceSet['id']);
// we are simulating the creation of a Price Set in Administer -> CiviContribute -> Manage Price Sets so set is_quick_config = 0
- $this->callAPISuccess('PriceSet', 'Create', array("id" => $priceSet['id'], 'is_quick_config' => 0));
+ $this->callAPISuccess('PriceSet', 'Create', ["id" => $priceSet['id'], 'is_quick_config' => 0]);
// clean the price options static variable to repopulate the options, in order to fetch tax information
\Civi::$statics['CRM_Price_BAO_PriceField']['priceOptions'] = NULL;
CRM_Price_BAO_PriceSet::buildPriceSet($form);
// rebuild the price set form variable to include the tax information against each price options
$form->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSet['id']));
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
- 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+ 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID],
'record_contribution' => 1,
'total_amount' => 55,
'receive_date' => date('Y-m-d', time()) . ' 20:36:00',
//Member dues, see data.xml
'financial_type_id' => 2,
'payment_processor_id' => $this->_paymentProcessorID,
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
- $lineItem = $this->callAPISuccessGetSingle('LineItem', array('entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership'));
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
+ $lineItem = $this->callAPISuccessGetSingle('LineItem', ['entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership']);
$this->assertEquals(1, $lineItem['qty']);
$this->assertEquals(50.00, $lineItem['unit_price']);
$this->assertEquals(50.00, $lineItem['line_total']);
// Simply save the 'Edit Contribution' form
$form = new CRM_Contribute_Form_Contribution();
$form->_context = 'membership';
- $form->_values = $this->callAPISuccessGetSingle('Contribution', array('id' => $lineItem['contribution_id'], 'return' => array('total_amount', 'net_amount', 'fee_amount', 'tax_amount')));
- $form->testSubmit(array(
+ $form->_values = $this->callAPISuccessGetSingle('Contribution', ['id' => $lineItem['contribution_id'], 'return' => ['total_amount', 'net_amount', 'fee_amount', 'tax_amount']]);
+ $form->testSubmit([
'contact_id' => $this->_individualId,
'id' => $lineItem['contribution_id'],
'financial_type_id' => 2,
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'),
- ),
+ ],
CRM_Core_Action::UPDATE);
// ensure that the LineItem data remain the same
- $lineItem = $this->callAPISuccessGetSingle('LineItem', array('entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership'));
+ $lineItem = $this->callAPISuccessGetSingle('LineItem', ['entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership']);
$this->assertEquals(1, $lineItem['qty']);
$this->assertEquals(50.00, $lineItem['unit_price']);
$this->assertEquals(50.00, $lineItem['line_total']);
// ensure that the LineItem data add up to the data at the Contribution level
$contribution = $this->callAPISuccessGetSingle('Contribution',
- array(
+ [
'contribution_id' => 1,
- 'return' => array('tax_amount', 'total_amount'),
- )
+ 'return' => ['tax_amount', 'total_amount'],
+ ]
);
$this->assertEquals($contribution['total_amount'], $lineItem['line_total'] + $lineItem['tax_amount']);
$this->assertEquals($contribution['tax_amount'], $lineItem['tax_amount']);
- $financialItems = $this->callAPISuccess('FinancialItem', 'get', array());
+ $financialItems = $this->callAPISuccess('FinancialItem', 'get', []);
$financialItems_sum = 0;
foreach ($financialItems['values'] as $financialItem) {
$financialItems_sum += $financialItem['amount'];
* Test token replacement for Print/Merge Task
*/
public function testMembershipTokenReplacementInPDF() {
- $membershipIds = $returnProperties = $categories = $expected = array();
+ $membershipIds = $returnProperties = $categories = $expected = [];
list($tokens, $htmlMessage) = self::getSampleHTML();
- $membershipDates = array(
+ $membershipDates = [
date('Y-m-d'),
date('Y-m-d', strtotime('-1 month')),
- );
+ ];
// Create sample memberships with different dates.
foreach ($membershipDates as $date) {
$contactId = $this->individualCreate();
- $membershipTypeID = $this->membershipTypeCreate(array(
+ $membershipTypeID = $this->membershipTypeCreate([
'minimum_fee' => '100.00',
'member_of_contact_id' => $contactId,
- ));
- $params = array(
+ ]);
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $membershipTypeID,
'join_date' => $date,
'start_date' => $date,
'end_date' => date('Y-m-d', strtotime("{$date} +1 year")),
- );
+ ];
$result = $this->callAPISuccess('membership', 'create', $params);
$membershipIds[] = $result['id'];
$params = array_merge($params,
- array(
+ [
'fee' => '100.00',
'type' => 'General',
'status' => 'New',
- )
+ ]
);
// Form an expected array replacing tokens for each contact.
* Generate sample HTML for testing.
*/
public static function getSampleHTML() {
- $tokens = array(
+ $tokens = [
'Test Fee' => 'fee',
'Test Type' => 'type',
'Test Status' => 'status',
'Test Join Date' => 'join_date',
'Test Start Date' => 'start_date',
'Test End Date' => 'end_date',
- );
+ ];
$html = '';
foreach ($tokens as $key => $val) {
$html .= "<p>{$key} - {membership.{$val}}</p>";
}
- return array($tokens, $html);
+ return [$tokens, $html];
}
}
public function setUp() {
parent::setUp();
- $params = array(
+ $params = [
'contact_type_a' => 'Individual',
'contact_type_b' => 'Organization',
'name_a_b' => 'Test Employee of',
'name_b_a' => 'Test Employer of',
- );
+ ];
$this->_relationshipTypeId = $this->relationshipTypeCreate($params);
$this->_orgContactID = $this->organizationCreate();
$this->_financialTypeId = 1;
$this->_membershipTypeName = 'Mickey Mouse Club Member';
- $params = array(
+ $params = [
'name' => $this->_membershipTypeName,
'description' => NULL,
'minimum_fee' => 10,
'is_active' => 1,
'fixed_period_start_day' => 101,
'fixed_period_rollover_day' => 1231,
- );
- $ids = array();
+ ];
+ $ids = [];
$membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
$this->_membershipTypeID = $membershipType->id;
* This method is called after a test is executed.
*/
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_membership',
'civicrm_membership_log',
'civicrm_contribution',
'civicrm_membership_payment',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
$this->relationshipTypeDelete($this->_relationshipTypeId);
- $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
+ $this->membershipTypeDelete(['id' => $this->_membershipTypeID]);
$this->membershipStatusDelete($this->_mebershipStatusID);
$this->contactDelete($this->_orgContactID);
}
*/
public function testImport() {
$this->individualCreate();
- $contact2Params = array(
+ $contact2Params = [
'first_name' => 'Anthonita',
'middle_name' => 'J.',
'last_name' => 'Anderson',
'suffix_id' => 3,
'email' => 'b@c.com',
'contact_type' => 'Individual',
- );
+ ];
$this->individualCreate($contact2Params);
$year = date('Y') - 1;
$startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year));
- $params = array(
- array(
+ $params = [
+ [
'anthony_anderson@civicrm.org',
$this->_membershipTypeID,
date('Y-m-d'),
- ),
- array(
+ ],
+ [
$contact2Params['email'],
$this->_membershipTypeName,
$startDate2,
- ),
- );
- $fieldMapper = array(
+ ],
+ ];
+ $fieldMapper = [
'mapper[0][0]' => 'email',
'mapper[1][0]' => 'membership_type_id',
'mapper[2][0]' => 'membership_start_date',
- );
+ ];
$importObject = new CRM_Member_Import_Parser_Membership($fieldMapper);
$importObject->init();
foreach ($params as $values) {
$this->assertEquals(CRM_Import_Parser::VALID, $importObject->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), $values[0]);
}
- $result = $this->callAPISuccess('membership', 'get', array());
+ $result = $this->callAPISuccess('membership', 'get', []);
$this->assertEquals(2, $result['count']);
}
public function testImportOverriddenMembershipButWithoutStatus() {
- $this->individualCreate(array('email' => 'anthony_anderson2@civicrm.org'));
+ $this->individualCreate(['email' => 'anthony_anderson2@civicrm.org']);
- $fieldMapper = array(
+ $fieldMapper = [
'mapper[0][0]' => 'email',
'mapper[1][0]' => 'membership_type_id',
'mapper[2][0]' => 'membership_start_date',
'mapper[3][0]' => 'is_override',
- );
+ ];
$membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
$membershipImporter->init();
$membershipImporter->_contactType = 'Individual';
- $importValues = array(
+ $importValues = [
'anthony_anderson2@civicrm.org',
$this->_membershipTypeID,
date('Y-m-d'),
TRUE,
- );
+ ];
$importResponse = $membershipImporter->import(CRM_Import_Parser::DUPLICATE_UPDATE, $importValues);
$this->assertEquals(CRM_Import_Parser::ERROR, $importResponse);
}
public function testImportOverriddenMembershipWithStatus() {
- $this->individualCreate(array('email' => 'anthony_anderson3@civicrm.org'));
+ $this->individualCreate(['email' => 'anthony_anderson3@civicrm.org']);
- $fieldMapper = array(
+ $fieldMapper = [
'mapper[0][0]' => 'email',
'mapper[1][0]' => 'membership_type_id',
'mapper[2][0]' => 'membership_start_date',
'mapper[3][0]' => 'is_override',
'mapper[4][0]' => 'status_id',
- );
+ ];
$membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
$membershipImporter->init();
$membershipImporter->_contactType = 'Individual';
- $importValues = array(
+ $importValues = [
'anthony_anderson3@civicrm.org',
$this->_membershipTypeID,
date('Y-m-d'),
TRUE,
'New',
- );
+ ];
$importResponse = $membershipImporter->import(CRM_Import_Parser::DUPLICATE_UPDATE, $importValues);
$this->assertEquals(CRM_Import_Parser::VALID, $importResponse);
}
public function testImportOverriddenMembershipWithValidOverrideEndDate() {
- $this->individualCreate(array('email' => 'anthony_anderson4@civicrm.org'));
+ $this->individualCreate(['email' => 'anthony_anderson4@civicrm.org']);
- $fieldMapper = array(
+ $fieldMapper = [
'mapper[0][0]' => 'email',
'mapper[1][0]' => 'membership_type_id',
'mapper[2][0]' => 'membership_start_date',
'mapper[3][0]' => 'is_override',
'mapper[4][0]' => 'status_id',
'mapper[5][0]' => 'status_override_end_date',
- );
+ ];
$membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
$membershipImporter->init();
$membershipImporter->_contactType = 'Individual';
- $importValues = array(
+ $importValues = [
'anthony_anderson4@civicrm.org',
$this->_membershipTypeID,
date('Y-m-d'),
TRUE,
'New',
date('Y-m-d'),
- );
+ ];
$importResponse = $membershipImporter->import(CRM_Import_Parser::DUPLICATE_UPDATE, $importValues);
$this->assertEquals(CRM_Import_Parser::VALID, $importResponse);
}
public function testImportOverriddenMembershipWithInvalidOverrideEndDate() {
- $this->individualCreate(array('email' => 'anthony_anderson5@civicrm.org'));
+ $this->individualCreate(['email' => 'anthony_anderson5@civicrm.org']);
- $fieldMapper = array(
+ $fieldMapper = [
'mapper[0][0]' => 'email',
'mapper[1][0]' => 'membership_type_id',
'mapper[2][0]' => 'membership_start_date',
'mapper[3][0]' => 'is_override',
'mapper[4][0]' => 'status_id',
'mapper[5][0]' => 'status_override_end_date',
- );
+ ];
$membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
$membershipImporter->init();
$membershipImporter->_contactType = 'Individual';
- $importValues = array(
+ $importValues = [
'anthony_anderson5@civicrm.org',
'New',
date('Y-m-d'),
TRUE,
$this->_mebershipStatusID,
'abc',
- );
+ ];
$importResponse = $membershipImporter->import(CRM_Import_Parser::DUPLICATE_UPDATE, $importValues);
$this->assertEquals(CRM_Import_Parser::ERROR, $importResponse);
$this->assertEquals($params['link_text'], $pcpBlock->link_text, 'Check for link text.');
$this->assertEquals($params['is_active'], $pcpBlock->is_active, 'Check for is_active.');
// Delete our test object
- $delParams = array('id' => $pcpBlock->id);
+ $delParams = ['id' => $pcpBlock->id];
// FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 )
// CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCPBlock', $delParams );
}
$this->assertEquals($params['is_active'], $pcp->is_active, 'Check for is_active.');
// Delete our test object
- $delParams = array('id' => $pcp->id);
+ $delParams = ['id' => $pcp->id];
// FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 )
// CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCP', $delParams );
}
$this->assertEquals($params['is_active'], $pcp->is_active, 'Check for is_active.');
// Delete our test object
- $delParams = array('id' => $pcp->id);
+ $delParams = ['id' => $pcp->id];
// FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 )
// CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCP', $delParams );
}
*/
public function testCreateAndDeletePledgeBlock() {
- $pledgeFrequencyUnit = array(
+ $pledgeFrequencyUnit = [
'week' => 1,
'month' => 1,
'year' => 1,
- );
+ ];
- $params = array(
+ $params = [
'entity_id' => $this->_contributionPageId,
'entity_table' => 'civicrm_contribution_page',
'pledge_frequency_unit' => $pledgeFrequencyUnit,
'max_reminders' => 2,
'initial_reminder_day' => 2,
'additional_reminder_day' => 1,
- );
+ ];
//Checking for pledgeBlock id in the Pledge_block table.
$pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params);
*/
public function testAddPledgeBlock() {
- $pledgeFrequencyUnit = array(
+ $pledgeFrequencyUnit = [
'week' => 1,
'month' => 1,
'year' => 1,
- );
+ ];
- $params = array(
+ $params = [
'entity_id' => $this->_contributionPageId,
'entity_table' => 'civicrm_contribution_page',
'pledge_frequency_unit' => $pledgeFrequencyUnit,
'max_reminders' => 2,
'initial_reminder_day' => 2,
'additional_reminder_day' => 1,
- );
+ ];
// check for add pledge block
$pledgeBlock = CRM_Pledge_BAO_PledgeBlock::add($params);
$this->assertEquals($value, $pledgeBlock->$param);
}
- $params = array(
+ $params = [
'id' => $pledgeBlock->id,
'entity_id' => $this->_contributionPageId,
'entity_table' => 'civicrm_contribution_page',
'initial_reminder_day' => 3,
'additional_reminder_day' => 2,
'is_pledge_interval' => 1,
- );
+ ];
// also check for edit pledge block
$pledgeBlock = CRM_Pledge_BAO_PledgeBlock::add($params);
*/
public function testRetrieveAndGetPledgeBlock() {
- $pledgeFrequencyUnit = array(
+ $pledgeFrequencyUnit = [
'week' => 1,
'month' => 1,
'year' => 1,
- );
+ ];
- $params = array(
+ $params = [
'entity_id' => $this->_contributionPageId,
'entity_table' => 'civicrm_contribution_page',
'pledge_frequency_unit' => $pledgeFrequencyUnit,
'max_reminders' => 2,
'initial_reminder_day' => 2,
'additional_reminder_day' => 1,
- );
+ ];
$pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params);
// use retrieve() method
- $retrieveParams = array(
+ $retrieveParams = [
'entity_id' => $this->_contributionPageId,
'entity_table' => 'civicrm_contribution_page',
- );
- $default = array();
+ ];
+ $default = [];
$retrievePledgeBlock = CRM_Pledge_BAO_PledgeBlock::retrieve($retrieveParams, $default);
// use getPledgeBlock() method
*/
public function testAdd() {
$pledge = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_Pledge');
- $params = array(
+ $params = [
'pledge_id' => $pledge->id,
'scheduled_amount' => 100.55,
'currency' => 'USD',
'reminder_date' => '20100520000000',
'reminder_count' => 5,
'status_id' => 1,
- );
+ ];
//do test for normal add.
$payment = CRM_Pledge_BAO_PledgePayment::add($params);
}
//do test for update mode.
- $params = array(
+ $params = [
'id' => $payment->id,
'pledge_id' => $pledge->id,
'scheduled_amount' => 55.55,
'reminder_date' => '20100425000000',
'reminder_count' => 10,
'status_id' => 2,
- );
+ ];
$payment = CRM_Pledge_BAO_PledgePayment::add($params);
foreach ($params as $param => $value) {
*/
public function testRetrieveZeroPledeID() {
$payment = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_PledgePayment');
- $params = array('pledge_id' => 0);
- $defaults = array();
+ $params = ['pledge_id' => 0];
+ $defaults = [];
$paymentid = CRM_Pledge_BAO_PledgePayment::retrieve($params, $defaults);
$this->assertEquals(is_null($paymentid), 1, "Pledge Id must be greater than 0");
*/
public function testRetrieveStringPledgeID() {
$payment = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_PledgePayment');
- $params = array('pledge_id' => 'Test');
- $defaults = array();
+ $params = ['pledge_id' => 'Test'];
+ $defaults = [];
$paymentid = CRM_Pledge_BAO_PledgePayment::retrieve($params, $defaults);
$this->assertEquals(is_null($paymentid), 1, "Pledge Id cannot be a string");
public function testRetrieveKnownPledgeID() {
$payment = CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_PledgePayment');
$pledgeId = $payment->pledge_id;
- $params = array('pledge_id' => $pledgeId);
- $defaults = array();
+ $params = ['pledge_id' => $pledgeId];
+ $defaults = [];
$paymentid = CRM_Pledge_BAO_PledgePayment::retrieve($params, $defaults);
$this->assertEquals($paymentid->N, 1, "Pledge was retrieved");
*/
public function testDeletePledgePayments() {
$contactId = $this->individualCreate();
- $pledgeId = $this->pledgeCreate(array('contact_id' => $contactId));
+ $pledgeId = $this->pledgeCreate(['contact_id' => $contactId]);
CRM_Pledge_BAO_PledgePayment::deletePayments($pledgeId);
// No payments should be retrieved
* Test calculateBaseScheduleDate - should give 15th day of month
*/
public function testcalculateBaseScheduleDateMonth() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'month',
'frequency_day' => 15,
'frequency_interval' => 2,
- );
+ ];
$date = CRM_Pledge_BAO_PledgePayment::calculateBaseScheduleDate($params);
$this->assertEquals('20110515000000', $date);
* Test calculateBaseScheduleDate - should give original date
*/
public function testcalculateBaseScheduleDateDay() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'day',
'frequency_day' => 15,
'frequency_interval' => 2,
- );
+ ];
$date = CRM_Pledge_BAO_PledgePayment::calculateBaseScheduleDate($params);
$this->assertEquals('20110510000000', $date);
* testing each day as this is really the only unit that does anything
*/
public function testcalculateBaseScheduleDateWeek() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'week',
'frequency_day' => 1,
'frequency_interval' => 2,
- );
+ ];
$date = CRM_Pledge_BAO_PledgePayment::calculateBaseScheduleDate($params);
$this->assertEquals('20110509000000', $date);
* Test calculateBaseScheduleDate - should give original date
*/
public function testcalculateBaseScheduleDateYear() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'year',
'frequency_day' => 15,
'frequency_interval' => 2,
- );
+ ];
$date = CRM_Pledge_BAO_PledgePayment::calculateBaseScheduleDate($params);
$this->assertEquals('20110510000000', $date);
* Test calculateNextScheduledDate - no date provided
*/
public function testcalculateNextScheduledDateYear() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'year',
'frequency_day' => 15,
'frequency_interval' => 2,
- );
+ ];
$date = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 1);
$this->assertEquals('20130510000000', $date);
* Test culateNextScheduledDateMonth for months.
*/
public function testcalculateNextScheduledDateMonth() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'month',
'frequency_day' => 31,
'frequency_interval' => 1,
- );
+ ];
$nextScheduleDate = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 2);
$this->assertEquals('20110731000000', $nextScheduleDate);
// assert pledge scheduled date for month february.
* Test calculateNextScheduledDate - no date provided
*/
public function testcalculateNextScheduledDateYearDateProvided() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'year',
'frequency_day' => 15,
'frequency_interval' => 2,
- );
+ ];
$date = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 3, '20080510');
$this->assertEquals('20140510000000', $date);
$scheduled_date = date('Ymd', mktime(0, 0, 0, date("m"), date("d") + 2, date("y")));
$contact_id = 2;
- $pledge = $this->callAPISuccess('Pledge', 'create', array(
+ $pledge = $this->callAPISuccess('Pledge', 'create', [
'contact_id' => $contact_id,
'pledge_create_date' => date('Ymd'),
'start_date' => date('Ymd'),
'frequency_day' => 1,
'installments' => 12,
'sequential' => 1,
- ));
+ ]);
- $contributionID = $this->contributionCreate(array(
+ $contributionID = $this->contributionCreate([
'contact_id' => $contact_id,
'financial_type_id' => 1,
'invoice_id' => 46,
'net_amount' => 404.70,
'payment_instrument_id' => 1,
'non_deductible_amount' => 0.00,
- ));
+ ]);
// Fetch the first planned pledge payment/installment
- $pledgePayments = civicrm_api3('PledgePayment', 'get', array(
+ $pledgePayments = civicrm_api3('PledgePayment', 'get', [
'pledge_id' => $pledge['id'],
'sequential' => 1,
- ));
+ ]);
// Does all sorts of shenanigans if the amount was not the expected amount,
// and this is what we really want to test in this function.
// Fetch the pledge payments again to see if the amounts and statuses
// have been updated correctly.
- $pledgePayments = $this->callAPISuccess('pledge_payment', 'get', array(
+ $pledgePayments = $this->callAPISuccess('pledge_payment', 'get', [
'pledge_id' => $pledge['id'],
'sequential' => 1,
- ));
+ ]);
// The status of the first 3 pledges should be set to complete
$this->assertEquals($pledgePayments['values'][0]['status_id'], 1);
$this->assertEquals($pledgePayments['values'][3]['status_id'], 2);
// Cleanup
- civicrm_api3('Pledge', 'delete', array(
+ civicrm_api3('Pledge', 'delete', [
'id' => $pledge['id'],
- ));
+ ]);
}
/**
$scheduled_date = date('Ymd', mktime(0, 0, 0, date("m"), date("d") + 2, date("y")));
$contact_id = 2;
- $params = array(
+ $params = [
'contact_id' => $contact_id,
'pledge_create_date' => date('Ymd'),
'start_date' => date('Ymd'),
'frequency_day' => 1,
'installments' => 12,
'sequential' => 1,
- );
+ ];
$pledge = CRM_Pledge_BAO_Pledge::create($params);
- $contributionID = $this->contributionCreate(array(
+ $contributionID = $this->contributionCreate([
'contact_id' => $contact_id,
'financial_type_id' => 1,
'invoice_id' => 47,
'net_amount' => 100.00,
'payment_instrument_id' => 1,
'non_deductible_amount' => 0.00,
- ));
+ ]);
// Fetch the first planned pledge payment/installment
- $pledgePayments = civicrm_api3('PledgePayment', 'get', array(
+ $pledgePayments = civicrm_api3('PledgePayment', 'get', [
'pledge_id' => $pledge->id,
'sequential' => 1,
- ));
+ ]);
// The last pledge payment is 8.37 because 12*8.33 = 99.96
// So CiviCRM automatically creates a larger final pledge to catch the missing cents.
// Fetch the pledge payments again to see if the amounts and statuses
// have been updated correctly.
- $pledgePayments = $this->callAPISuccess('pledge_payment', 'get', array(
+ $pledgePayments = $this->callAPISuccess('pledge_payment', 'get', [
'pledge_id' => $pledge->id,
'sequential' => 1,
- ));
+ ]);
foreach ($pledgePayments['values'] as $key => $pp) {
if ($key == 0) {
$this->assertEquals(count($pledgePayments['values']), CRM_Pledge_BAO_Pledge::pledgeHasFinancialTransactions($pledge->id, 2));
// Cleanup
- civicrm_api3('Pledge', 'delete', array(
+ civicrm_api3('Pledge', 'delete', [
'id' => $pledge->id,
- ));
+ ]);
}
}
protected function setUp() {
parent::setUp();
$this->_contactId = $this->individualCreate();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_contactId,
'frequency_unit' => 'month',
'original_installment_amount' => 25.00,
'status_id' => 2,
'currency' => 'USD',
'amount' => 300,
- );
+ ];
}
/**
* Retrieve a pledge based on a pledge id = 0
*/
public function testRetrieveZeroPledeID() {
- $defaults = array();
- $params = array('pledge_id' => 0);
+ $defaults = [];
+ $params = ['pledge_id' => 0];
$pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults);
$this->assertEquals(is_null($pledgeId), 1, "Pledge Id must be greater than 0");
* Retrieve a payment based on a Null pledge id random string.
*/
public function testRetrieveStringPledgeID() {
- $defaults = array();
- $params = array('pledge_id' => 'random text');
+ $defaults = [];
+ $params = ['pledge_id' => 'random text'];
$pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults);
$this->assertEquals(is_null($pledgeId), 1, "Pledge Id must be a string");
* Test that payment retrieve wrks based on known pledge id.
*/
public function testRetrieveKnownPledgeID() {
- $params = array(
+ $params = [
'contact_id' => $this->_contactId,
'frequency_unit' => 'month',
'frequency_interval' => 1,
'status_id' => 2,
'currency' => 'USD',
'amount' => 300,
- );
+ ];
$pledge = CRM_Pledge_BAO_Pledge::add($params);
- $defaults = array();
- $pledgeParams = array('pledge_id' => $pledge->id);
+ $defaults = [];
+ $pledgeParams = ['pledge_id' => $pledge->id];
$pledgeId = CRM_Pledge_BAO_Pledge::retrieve($pledgeParams, $defaults);
* Test build recur params.
*/
public function testGetPledgeStartDate() {
- $startDate = json_encode(array('calendar_month' => 6));
+ $startDate = json_encode(['calendar_month' => 6]);
- $params = array(
+ $params = [
'pledge_start_date' => $startDate,
'is_pledge_start_date_editable' => TRUE,
'is_pledge_start_date_visible' => TRUE,
- );
+ ];
// Try with relative date
$date = CRM_Pledge_BAO_Pledge::getPledgeStartDate(6, $params);
// Try with fixed date
$date = NULL;
- $params = array(
- 'pledge_start_date' => json_encode(array('calendar_date' => '06/10/2016')),
+ $params = [
+ 'pledge_start_date' => json_encode(['calendar_date' => '06/10/2016']),
'is_pledge_start_date_visible' => FALSE,
- );
+ ];
$date = CRM_Pledge_BAO_Pledge::getPledgeStartDate($date, $params);
$this->assertEquals(date('m/d/Y', strtotime($date)), '06/10/2016', "The two dates do not match");
public function setUp() {
parent::setUp();
$this->individualID = $this->individualCreate();
- $this->pledgeCreate(array('contact_id' => $this->individualID));
+ $this->pledgeCreate(['contact_id' => $this->individualID]);
}
public function tearDown() {
parent::tearDown();
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_activity',
'civicrm_activity_contact',
'civicrm_pledge',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
}
$qfKey = $form->controller->_key;
$date = date('Y-m-d') . ' 00:00:00';
$rows = $form->controller->get('rows');
- $this->assertEquals(array(
+ $this->assertEquals([
'contact_id' => '3',
'sort_name' => 'Anderson, Anthony',
'display_name' => 'Mr. Anthony Anderson II',
'checkbox' => 'mark_x_1',
'action' => '<span><a href="/index.php?q=civicrm/contact/view/pledge&reset=1&id=1&cid=3&action=view&context=search&selectedChild=pledge&key=' . $qfKey . '" class="action-item crm-hover-button" title=' . "'" . 'View Pledge' . "'" . ' >View</a><a href="/index.php?q=civicrm/contact/view/pledge&reset=1&action=update&id=1&cid=3&context=search&key=' . $qfKey . '" class="action-item crm-hover-button" title=' . "'" . 'Edit Pledge' . "'" . ' >Edit</a></span><span class=' . "'" . 'btn-slide crm-hover-button' . "'" . '>more<ul class=' . "'" . 'panel' . "'" . '><li><a href="/index.php?q=civicrm/contact/view/pledge&reset=1&action=detach&id=1&cid=3&context=search&key=' . $qfKey . '" class="action-item crm-hover-button" title=' . "'" . 'Cancel Pledge' . "'" . ' onclick = "return confirm(' . "'" . 'Cancelling this pledge will also cancel any scheduled (and not completed) pledge payments. This action cannot be undone. Do you want to continue?' . "'" . ');">Cancel</a></li><li><a href="/index.php?q=civicrm/contact/view/pledge&reset=1&action=delete&id=1&cid=3&context=search&key=' . $qfKey . '" class="action-item crm-hover-button small-popup" title=' . "'" . 'Delete Pledge' . "'" . ' >Delete</a></li></ul></span>',
'contact_type' => '<a href="/index.php?q=civicrm/profile/view&reset=1&gid=7&id=3&snippet=4" class="crm-summary-link"><div class="icon crm-icon Individual-icon"></div></a>',
- ), $rows[0]);
+ ], $rows[0]);
}
}
$priceSetID = $this->eventPriceSetCreate(9);
$priceSet = CRM_Price_BAO_PriceSet::getCachedPriceSetDetail($priceSetID);
$field = reset($priceSet['fields']);
- $params = array('priceSetId' => $priceSetID, 'price_' . $field['id'] => 1);
+ $params = ['priceSetId' => $priceSetID, 'price_' . $field['id'] => 1];
$amountLevel = CRM_Price_BAO_PriceSet::getAmountLevelText($params);
$this->assertEquals(CRM_Core_DAO::VALUE_SEPARATOR . 'Price Field - 1' . CRM_Core_DAO::VALUE_SEPARATOR, $amountLevel);
- $priceFieldValue = $this->callAPISuccess('pricefieldvalue', 'getsingle', array('price_field_id' => $field['id']));
- $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $priceFieldValue['id']));
- $this->callAPISuccess('PriceField', 'delete', array('id' => $field['id']));
- $this->callAPISuccess('PriceSet', 'delete', array('id' => $priceSetID));
+ $priceFieldValue = $this->callAPISuccess('pricefieldvalue', 'getsingle', ['price_field_id' => $field['id']]);
+ $this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $priceFieldValue['id']]);
+ $this->callAPISuccess('PriceField', 'delete', ['id' => $field['id']]);
+ $this->callAPISuccess('PriceSet', 'delete', ['id' => $priceSetID]);
}
/**
*/
public function testCopyPriceSet() {
$priceSetID = $this->eventPriceSetCreate(9);
- $oldPriceSetInfo = $this->callAPISuccess('PriceSet', 'getsingle', array('id' => $priceSetID));
+ $oldPriceSetInfo = $this->callAPISuccess('PriceSet', 'getsingle', ['id' => $priceSetID]);
$newPriceSet = CRM_Price_BAO_PriceSet::copy($priceSetID);
$this->assertEquals(substr($oldPriceSetInfo['name'], 0, 20) . 'price_set_' . $newPriceSet->id, $newPriceSet->name);
$this->assertEquals($oldPriceSetInfo['title'] . ' [Copy id ' . $newPriceSet->id . ']', $newPriceSet->title);
$new2PriceSet = CRM_Price_BAO_PriceSet::copy($newPriceSet->id);
$this->assertEquals(substr($newPriceSet->name, 0, 20) . 'price_set_' . $new2PriceSet->id, $new2PriceSet->name);
$this->assertEquals($oldPriceSetInfo['title'] . ' [Copy id ' . $new2PriceSet->id . ']', $new2PriceSet->title);
- $oldPriceField = $this->callAPISuccess('priceField', 'getsingle', array('price_set_id' => $priceSetID));
- $oldPriceFieldValue = $this->callAPISuccess('priceFieldValue', 'getsingle', array('price_field_id' => $oldPriceField['id']));
- $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $oldPriceFieldValue['id']));
- $this->callAPISuccess('PriceField', 'delete', array('id' => $oldPriceField['id']));
- $this->callAPISuccess('PriceSet', 'delete', array('id' => $priceSetID));
- $newPriceField = $this->callAPISuccess('PriceField', 'getsingle', array('price_set_id' => $newPriceSet->id));
- $newPriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', array('price_field_id' => $newPriceField['id']));
- $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $newPriceFieldValue['id']));
- $this->callAPISuccess('PriceField', 'delete', array('id' => $newPriceField['id']));
- $this->callAPISuccess('PriceSet', 'delete', array('id' => $newPriceSet->id));
- $new2PriceField = $this->callAPISuccess('PriceField', 'getsingle', array('price_set_id' => $new2PriceSet->id));
- $new2PriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', array('price_field_id' => $new2PriceField['id']));
- $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $new2PriceFieldValue['id']));
- $this->callAPISuccess('PriceField', 'delete', array('id' => $new2PriceField['id']));
- $this->callAPISuccess('PriceSet', 'delete', array('id' => $new2PriceSet->id));
+ $oldPriceField = $this->callAPISuccess('priceField', 'getsingle', ['price_set_id' => $priceSetID]);
+ $oldPriceFieldValue = $this->callAPISuccess('priceFieldValue', 'getsingle', ['price_field_id' => $oldPriceField['id']]);
+ $this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $oldPriceFieldValue['id']]);
+ $this->callAPISuccess('PriceField', 'delete', ['id' => $oldPriceField['id']]);
+ $this->callAPISuccess('PriceSet', 'delete', ['id' => $priceSetID]);
+ $newPriceField = $this->callAPISuccess('PriceField', 'getsingle', ['price_set_id' => $newPriceSet->id]);
+ $newPriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $newPriceField['id']]);
+ $this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $newPriceFieldValue['id']]);
+ $this->callAPISuccess('PriceField', 'delete', ['id' => $newPriceField['id']]);
+ $this->callAPISuccess('PriceSet', 'delete', ['id' => $newPriceSet->id]);
+ $new2PriceField = $this->callAPISuccess('PriceField', 'getsingle', ['price_set_id' => $new2PriceSet->id]);
+ $new2PriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $new2PriceField['id']]);
+ $this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $new2PriceFieldValue['id']]);
+ $this->callAPISuccess('PriceField', 'delete', ['id' => $new2PriceField['id']]);
+ $this->callAPISuccess('PriceSet', 'delete', ['id' => $new2PriceSet->id]);
}
/**
$organization2 = $this->organizationCreate();
// create three membership type where first two belong to same organisation
- $membershipType1 = $this->membershipTypeCreate(array(
+ $membershipType1 = $this->membershipTypeCreate([
'name' => 'Membership Type 1',
'member_of_contact_id' => $organization1,
- ));
- $membershipType2 = $this->membershipTypeCreate(array(
+ ]);
+ $membershipType2 = $this->membershipTypeCreate([
'name' => 'Membership Type 2',
'member_of_contact_id' => $organization1,
- ));
- $membershipType3 = $this->membershipTypeCreate(array(
+ ]);
+ $membershipType3 = $this->membershipTypeCreate([
'name' => 'Membership Type 3',
'member_of_contact_id' => $organization2,
- ));
+ ]);
$priceDetails = CRM_Price_BAO_PriceSet::getSetDetail(CRM_Core_DAO::getFieldValue(
'CRM_Price_DAO_PriceSet',
'id', 'name'
));
// fetch price field value IDs in array('membership_type_id' => 'price_field_value_id') format
- $priceFieldValueIDs = array();
+ $priceFieldValueIDs = [];
foreach ($priceDetails as $priceFields) {
foreach ($priceFields['fields'] as $priceField) {
foreach ($priceField['options'] as $id => $priceFieldValue) {
- if (in_array($priceFieldValue['membership_type_id'], array($membershipType1, $membershipType2, $membershipType3))) {
+ if (in_array($priceFieldValue['membership_type_id'], [$membershipType1, $membershipType2, $membershipType3])) {
$priceFieldValueIDs[$priceFieldValue['membership_type_id']] = $id;
}
}
}
// CASE 1: when two price field value IDs of membership type that belong to same organization, are chosen
- $sameOrgPriceFieldIDs = implode(', ', array(
+ $sameOrgPriceFieldIDs = implode(', ', [
$priceFieldValueIDs[$membershipType1],
$priceFieldValueIDs[$membershipType2],
- ));
+ ]);
$occurences = CRM_Price_BAO_PriceSet::getMembershipCount($sameOrgPriceFieldIDs);
// total number of membership type occurences of same organisation is one
$this->assertEquals(1, count($occurences));
$this->assertEquals(2, $occurences[$organization1]);
// CASE 2: when two price field value IDs of membership type that belong to different organizations, are chosen
- $differentOrgPriceFieldIDs = implode(', ', array(
+ $differentOrgPriceFieldIDs = implode(', ', [
$priceFieldValueIDs[$membershipType1],
$priceFieldValueIDs[$membershipType3],
- ));
+ ]);
$occurences = CRM_Price_BAO_PriceSet::getMembershipCount($differentOrgPriceFieldIDs);
// total number of membership type occurences of different organisation is two
$this->assertEquals(2, count($occurences));
public function setUp() {
parent::setUp();
- $this->visibilityOptionsKeys = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, array(
+ $this->visibilityOptionsKeys = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, [
'labelColumn' => 'name',
'flip' => TRUE,
- ));
+ ]);
- $this->publicFieldParams = $this->initializeFieldParameters(array(
+ $this->publicFieldParams = $this->initializeFieldParameters([
'label' => 'Public Price Field',
'name' => 'public_price',
'visibility_id' => $this->visibilityOptionsKeys['public'],
- ));
+ ]);
- $this->adminFieldParams = $this->initializeFieldParameters(array(
+ $this->adminFieldParams = $this->initializeFieldParameters([
'label' => 'Public Price Field',
'name' => 'public_price',
'visibility_id' => $this->visibilityOptionsKeys['admin'],
- ));
+ ]);
}
public function testPublicFieldWithOnlyAdminOptionsIsNotAllowed() {
$form = new CRM_Price_Form_Field();
$form->_action = CRM_Core_Action::ADD;
- $files = array();
+ $files = [];
$validationResult = $form->formRule($this->publicFieldParams, $files, $form);
$this->assertType('array', $validationResult);
$form = new CRM_Price_Form_Field();
$form->_action = CRM_Core_Action::ADD;
- $files = array();
+ $files = [];
$validationResult = $form->formRule($this->adminFieldParams, $files, $form);
$this->assertType('array', $validationResult);
}
private function initializeFieldParameters($params) {
- $defaultParams = array(
+ $defaultParams = [
'label' => 'Price Field',
'name' => CRM_Utils_String::titleToVar('Price Field'),
'html_type' => 'Select',
'is_enter_qty' => 1,
'financial_type_id' => $this->getFinancialTypeId('Event Fee'),
'visibility_id' => $this->visibilityOptionsKeys['public'],
- );
+ ];
for ($index = 1; $index <= CRM_Price_Form_Field::NUM_OPTION; $index++) {
$defaultParams['option_label'][$index] = NULL;
* Return a list of persistent and transient queue providers.
*/
public function getQueueSpecs() {
- $queueSpecs = array();
- $queueSpecs[] = array(
- array(
+ $queueSpecs = [];
+ $queueSpecs[] = [
+ [
'type' => 'Sql',
'name' => 'test-queue',
- ),
- );
+ ],
+ ];
return $queueSpecs;
}
public function tearDown() {
CRM_Utils_Time::resetTime();
- $tablesToTruncate = array('civicrm_queue_item');
+ $tablesToTruncate = ['civicrm_queue_item'];
$this->quickCleanup($tablesToTruncate);
}
$this->queue = $this->queueService->create($queueSpec);
$this->assertTrue($this->queue instanceof CRM_Queue_Queue);
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'a',
- ));
- $this->queue->createItem(array(
+ ]);
+ $this->queue->createItem([
'test-key' => 'b',
- ));
- $this->queue->createItem(array(
+ ]);
+ $this->queue->createItem([
'test-key' => 'c',
- ));
+ ]);
$this->assertEquals(3, $this->queue->numberOfItems());
$item = $this->queue->claimItem();
$this->queue->deleteItem($item);
$this->queue->createItem(
- array(
+ [
'test-key' => 'start',
- ),
- array(
+ ],
+ [
'weight' => -1,
- )
+ ]
);
$this->queue->createItem(
- array(
+ [
'test-key' => 'end',
- ),
- array(
+ ],
+ [
'weight' => 1,
- )
+ ]
);
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'd',
- ));
+ ]);
$this->assertEquals(4, $this->queue->numberOfItems());
$item = $this->queue->claimItem();
* Return a list of persistent and transient queue providers.
*/
public function getQueueSpecs() {
- $queueSpecs = array();
- $queueSpecs[] = array(
- array(
+ $queueSpecs = [];
+ $queueSpecs[] = [
+ [
'type' => 'Sql',
'name' => 'test-queue',
- ),
- );
- $queueSpecs[] = array(
- array(
+ ],
+ ];
+ $queueSpecs[] = [
+ [
'type' => 'Memory',
'name' => 'test-queue',
- ),
- );
+ ],
+ ];
return $queueSpecs;
}
public function tearDown() {
CRM_Utils_Time::resetTime();
- $tablesToTruncate = array('civicrm_queue_item');
+ $tablesToTruncate = ['civicrm_queue_item'];
$this->quickCleanup($tablesToTruncate);
}
$this->queue = $this->queueService->create($queueSpec);
$this->assertTrue($this->queue instanceof CRM_Queue_Queue);
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'a',
- ));
- $this->queue->createItem(array(
+ ]);
+ $this->queue->createItem([
'test-key' => 'b',
- ));
- $this->queue->createItem(array(
+ ]);
+ $this->queue->createItem([
'test-key' => 'c',
- ));
+ ]);
$this->assertEquals(3, $this->queue->numberOfItems());
$item = $this->queue->claimItem();
$this->assertEquals('b', $item->data['test-key']);
$this->queue->deleteItem($item);
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'd',
- ));
+ ]);
$this->assertEquals(2, $this->queue->numberOfItems());
$item = $this->queue->claimItem();
$this->queue = $this->queueService->create($queueSpec);
$this->assertTrue($this->queue instanceof CRM_Queue_Queue);
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'a',
- ));
+ ]);
$item = $this->queue->claimItem();
$this->assertEquals('a', $item->data['test-key']);
$this->assertTrue($this->queue instanceof CRM_Queue_Queue);
CRM_Utils_Time::setTime('2012-04-01 1:00:00');
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'a',
- ));
+ ]);
$item = $this->queue->claimItem();
$this->assertEquals('a', $item->data['test-key']);
$this->assertTrue($this->queue instanceof CRM_Queue_Queue);
CRM_Utils_Time::setTime('2012-04-01 1:00:00');
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'a',
- ));
+ ]);
$item = $this->queue->claimItem();
$this->assertEquals('a', $item->data['test-key']);
*/
public function testCreateResetTrue($queueSpec) {
$this->queue = $this->queueService->create($queueSpec);
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'a',
- ));
- $this->queue->createItem(array(
+ ]);
+ $this->queue->createItem([
'test-key' => 'b',
- ));
+ ]);
$this->assertEquals(2, $this->queue->numberOfItems());
unset($this->queue);
$queue2 = $this->queueService->create(
- $queueSpec + array('reset' => TRUE)
+ $queueSpec + ['reset' => TRUE]
);
$this->assertEquals(0, $queue2->numberOfItems());
}
*/
public function testCreateResetFalse($queueSpec) {
$this->queue = $this->queueService->create($queueSpec);
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'a',
- ));
- $this->queue->createItem(array(
+ ]);
+ $this->queue->createItem([
'test-key' => 'b',
- ));
+ ]);
$this->assertEquals(2, $this->queue->numberOfItems());
unset($this->queue);
*/
public function testLoad($queueSpec) {
$this->queue = $this->queueService->create($queueSpec);
- $this->queue->createItem(array(
+ $this->queue->createItem([
'test-key' => 'a',
- ));
- $this->queue->createItem(array(
+ ]);
+ $this->queue->createItem([
'test-key' => 'b',
- ));
+ ]);
$this->assertEquals(2, $this->queue->numberOfItems());
unset($this->queue);
public function setUp() {
parent::setUp();
$this->queueService = CRM_Queue_Service::singleton(TRUE);
- $this->queue = $this->queueService->create(array(
+ $this->queue = $this->queueService->create([
'type' => 'Sql',
'name' => 'test-queue',
- ));
- self::$_recordedValues = array();
+ ]);
+ self::$_recordedValues = [];
}
public function tearDown() {
CRM_Utils_Time::resetTime();
- $tablesToTruncate = array('civicrm_queue_item');
+ $tablesToTruncate = ['civicrm_queue_item'];
$this->quickCleanup($tablesToTruncate);
}
public function testRunAllNormal() {
// prepare a list of tasks with an error in the middle
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('a'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['a'],
'Add "a"'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('b'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['b'],
'Add "b"'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('c'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['c'],
'Add "c"'
));
// run the list of tasks
- $runner = new CRM_Queue_Runner(array(
+ $runner = new CRM_Queue_Runner([
'queue' => $this->queue,
'errorMode' => CRM_Queue_Runner::ERROR_ABORT,
- ));
- $this->assertEquals(self::$_recordedValues, array());
+ ]);
+ $this->assertEquals(self::$_recordedValues, []);
$this->assertEquals(3, $this->queue->numberOfItems());
$result = $runner->runAll();
$this->assertEquals(TRUE, $result);
- $this->assertEquals(self::$_recordedValues, array('a', 'b', 'c'));
+ $this->assertEquals(self::$_recordedValues, ['a', 'b', 'c']);
$this->assertEquals(0, $this->queue->numberOfItems());
}
public function testRunAll_AddMore() {
// Prepare a list of tasks with an error in the middle.
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('a'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['a'],
'Add "a"'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_enqueueNumbers'),
- array(1, 3),
+ ['CRM_Queue_RunnerTest', '_enqueueNumbers'],
+ [1, 3],
'Add more'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('b'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['b'],
'Add "b"'
));
// run the list of tasks
- $runner = new CRM_Queue_Runner(array(
+ $runner = new CRM_Queue_Runner([
'queue' => $this->queue,
'errorMode' => CRM_Queue_Runner::ERROR_ABORT,
- ));
- $this->assertEquals(self::$_recordedValues, array());
+ ]);
+ $this->assertEquals(self::$_recordedValues, []);
$this->assertEquals(3, $this->queue->numberOfItems());
$result = $runner->runAll();
$this->assertEquals(TRUE, $result);
- $this->assertEquals(self::$_recordedValues, array('a', 1, 2, 3, 'b'));
+ $this->assertEquals(self::$_recordedValues, ['a', 1, 2, 3, 'b']);
$this->assertEquals(0, $this->queue->numberOfItems());
}
public function testRunAll_Continue_Exception() {
// prepare a list of tasks with an error in the middle
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('a'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['a'],
'Add "a"'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_throwException'),
- array('b'),
+ ['CRM_Queue_RunnerTest', '_throwException'],
+ ['b'],
'Throw exception'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('c'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['c'],
'Add "c"'
));
// run the list of tasks
- $runner = new CRM_Queue_Runner(array(
+ $runner = new CRM_Queue_Runner([
'queue' => $this->queue,
'errorMode' => CRM_Queue_Runner::ERROR_CONTINUE,
- ));
- $this->assertEquals(self::$_recordedValues, array());
+ ]);
+ $this->assertEquals(self::$_recordedValues, []);
$this->assertEquals(3, $this->queue->numberOfItems());
$result = $runner->runAll();
// FIXME useless return
$this->assertEquals(TRUE, $result);
- $this->assertEquals(self::$_recordedValues, array('a', 'c'));
+ $this->assertEquals(self::$_recordedValues, ['a', 'c']);
$this->assertEquals(0, $this->queue->numberOfItems());
}
public function testRunAll_Abort_Exception() {
// prepare a list of tasks with an error in the middle
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('a'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['a'],
'Add "a"'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_throwException'),
- array('b'),
+ ['CRM_Queue_RunnerTest', '_throwException'],
+ ['b'],
'Throw exception'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('c'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['c'],
'Add "c"'
));
// run the list of tasks
- $runner = new CRM_Queue_Runner(array(
+ $runner = new CRM_Queue_Runner([
'queue' => $this->queue,
'errorMode' => CRM_Queue_Runner::ERROR_ABORT,
- ));
- $this->assertEquals(self::$_recordedValues, array());
+ ]);
+ $this->assertEquals(self::$_recordedValues, []);
$this->assertEquals(3, $this->queue->numberOfItems());
$result = $runner->runAll();
$this->assertEquals(1, $result['is_error']);
// nothing from 'c'
- $this->assertEquals(self::$_recordedValues, array('a'));
+ $this->assertEquals(self::$_recordedValues, ['a']);
// 'b' and 'c' remain
$this->assertEquals(2, $this->queue->numberOfItems());
}
public function testRunAll_Abort_False() {
// prepare a list of tasks with an error in the middle
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('a'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['a'],
'Add "a"'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_returnFalse'),
- array(),
+ ['CRM_Queue_RunnerTest', '_returnFalse'],
+ [],
'Return false'
));
$this->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array('c'),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ ['c'],
'Add "c"'
));
// run the list of tasks
- $runner = new CRM_Queue_Runner(array(
+ $runner = new CRM_Queue_Runner([
'queue' => $this->queue,
'errorMode' => CRM_Queue_Runner::ERROR_ABORT,
- ));
- $this->assertEquals(self::$_recordedValues, array());
+ ]);
+ $this->assertEquals(self::$_recordedValues, []);
$this->assertEquals(3, $this->queue->numberOfItems());
$result = $runner->runAll();
$this->assertEquals(1, $result['is_error']);
// nothing from 'c'
- $this->assertEquals(self::$_recordedValues, array('a'));
+ $this->assertEquals(self::$_recordedValues, ['a']);
// 'b' and 'c' remain
$this->assertEquals(2, $this->queue->numberOfItems());
}
public static function _enqueueNumbers($taskCtx, $low, $high) {
for ($i = $low; $i <= $high; $i++) {
$taskCtx->queue->createItem(new CRM_Queue_Task(
- array('CRM_Queue_RunnerTest', '_recordValue'),
- array($i),
+ ['CRM_Queue_RunnerTest', '_recordValue'],
+ [$i],
sprintf('Add number "%d"', $i)
- ), array(
+ ), [
'weight' => -1,
- ));
+ ]);
}
return TRUE;
}
* @package CiviCRM
*/
class CRM_Report_Form_ActivityTest extends CiviReportTestCase {
- protected $_tablesToTruncate = array(
+ protected $_tablesToTruncate = [
'civicrm_contact',
'civicrm_email',
'civicrm_phone',
'civicrm_address',
'civicrm_contribution',
- );
+ ];
public function setUp() {
parent::setUp();
public function testLongCustomFieldNames() {
// Create custom group with long name and custom field with long name.
$long_name = 'this is a very very very very long name with 65 characters in it';
- $group_params = array(
+ $group_params = [
'title' => $long_name,
'extends' => 'Activity',
- );
+ ];
$result = $this->customGroupCreate($group_params);
$custom_group_id = $result['id'];
- $field_params = array(
+ $field_params = [
'custom_group_id' => $custom_group_id,
'label' => $long_name,
- );
+ ];
$result = $this->customFieldCreate($field_params);
$custom_field_id = $result['id'];
- $input = array(
- 'fields' => array(
+ $input = [
+ 'fields' => [
'custom_' . $custom_field_id,
- ),
- );
+ ],
+ ];
$obj = $this->getReportObject('CRM_Report_Form_Activity', $input);
//$params = $obj->_params;
//$params['fields'] = array('custom_' . $custom_field_id);
public function testTargetAddressFields() {
$countryNames = array_flip(CRM_Core_PseudoConstant::country());
// Create contact 1 and 2 with address fields, later considered as target contacts for activity
- $contactID1 = $this->individualCreate(array(
- 'api.Address.create' => array(
+ $contactID1 = $this->individualCreate([
+ 'api.Address.create' => [
'contact_id' => '$value.id',
'location_type_id' => 'Home',
'city' => 'ABC',
'country_id' => $countryNames['India'],
- ),
- ));
- $contactID2 = $this->individualCreate(array(
- 'api.Address.create' => array(
+ ],
+ ]);
+ $contactID2 = $this->individualCreate([
+ 'api.Address.create' => [
'contact_id' => '$value.id',
'location_type_id' => 'Home',
'city' => 'DEF',
'country_id' => $countryNames['United States'],
- ),
- ));
+ ],
+ ]);
// Create Contact 3 later considered as assignee contact of activity
- $contactID3 = $this->individualCreate(array(
- 'api.Address.create' => array(
+ $contactID3 = $this->individualCreate([
+ 'api.Address.create' => [
'contact_id' => '$value.id',
'location_type_id' => 'Home',
'city' => 'GHI',
'country_id' => $countryNames['China'],
- ),
- ));
+ ],
+ ]);
// create dummy activity type
- $activityTypeID = CRM_Utils_Array::value('id', $this->callAPISuccess('option_value', 'create', array(
+ $activityTypeID = CRM_Utils_Array::value('id', $this->callAPISuccess('option_value', 'create', [
'option_group_id' => 'activity_type',
'name' => 'Test activity type',
'label' => 'Test activity type',
- )));
+ ]));
// create activity
- $result = $this->callAPISuccess('activity', 'create', array(
+ $result = $this->callAPISuccess('activity', 'create', [
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'duration' => 120,
'status_id' => 1,
'activity_type_id' => 'Test activity type',
'source_contact_id' => $this->individualCreate(),
- 'target_contact_id' => array($contactID1, $contactID2),
+ 'target_contact_id' => [$contactID1, $contactID2],
'assignee_contact_id' => $contactID3,
- ));
+ ]);
// display city and country field so that we can check its value
- $input = array(
- 'fields' => array(
+ $input = [
+ 'fields' => [
'city',
'country_id',
- ),
- 'order_bys' => array(
- 'city' => array(),
- 'country_id' => array('default' => TRUE),
- ),
- );
+ ],
+ 'order_bys' => [
+ 'city' => [],
+ 'country_id' => ['default' => TRUE],
+ ],
+ ];
// generate result
$obj = $this->getReportObject('CRM_Report_Form_Activity', $input);
$rows = $obj->getResultSet();
* @package CiviCRM
*/
class CRM_Report_Form_ContactSummaryTest extends CiviReportTestCase {
- protected $_tablesToTruncate = array(
+ protected $_tablesToTruncate = [
'civicrm_contact',
'civicrm_email',
'civicrm_phone',
'civicrm_address',
- );
+ ];
public function setUp() {
parent::setUp();
* @package CiviCRM
*/
class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase {
- protected $_tablesToTruncate = array(
+ protected $_tablesToTruncate = [
'civicrm_contact',
'civicrm_email',
'civicrm_phone',
'civicrm_address',
'civicrm_contribution',
- );
+ ];
/**
* @return array
*/
public function dataProvider() {
- return array(
- array(
+ return [
+ [
'CRM_Report_Form_Contribute_Detail',
- array(
- 'fields' => array(
+ [
+ 'fields' => [
'sort_name',
'first_name',
'email',
'total_amount',
- ),
- 'filters' => array(
+ ],
+ 'filters' => [
'total_amount_op' => 'gte',
'total_amount_value' => 50,
- ),
+ ],
// FIXME: add filters
- ),
+ ],
'fixtures/dataset-ascii.sql',
'fixtures/report-ascii.csv',
- ),
- );
+ ],
+ ];
}
public function setUp() {
* @return array
*/
public function postalCodeDataProvider() {
- return array(
- array(
+ return [
+ [
'CRM_Report_Form_Contribute_Detail',
- array(
- 'fields' => array(
+ [
+ 'fields' => [
'sort_name',
'first_name',
'email',
'total_amount',
'postal_code',
- ),
- 'filters' => array(
+ ],
+ 'filters' => [
'postal_code_value' => 'B10 G56',
'postal_code_op' => 'has',
- ),
- ),
+ ],
+ ],
'fixtures/dataset-ascii.sql',
'fixtures/DetailPostalCodeTest-ascii.csv',
- ),
- );
+ ],
+ ];
}
/**
public function testMultipleSoftCredits() {
$this->quickCleanup($this->_tablesToTruncate);
- $solParams = array(
+ $solParams = [
'first_name' => 'Solicitor 1',
'last_name' => 'User ' . rand(),
'contact_type' => 'Individual',
- );
+ ];
$solicitor1Id = $this->individualCreate($solParams);
$solParams['first_name'] = 'Solicitor 2';
$solicitor2Id = $this->individualCreate($solParams);
* @package CiviCRM
*/
class CRM_Report_Form_TestCaseTest extends CiviReportTestCase {
- protected $_tablesToTruncate = array(
+ protected $_tablesToTruncate = [
'civicrm_contact',
'civicrm_email',
'civicrm_phone',
'civicrm_address',
'civicrm_contribution',
- );
+ ];
/**
* @return array
*/
public function dataProvider() {
- $testCaseA = array(
+ $testCaseA = [
'CRM_Report_Form_Contribute_Detail',
- array(
- 'fields' => array(
+ [
+ 'fields' => [
'sort_name',
'first_name',
'email',
'total_amount',
- ),
- 'filters' => array(
+ ],
+ 'filters' => [
'total_amount_op' => 'gte',
'total_amount_value' => 50,
- ),
+ ],
// FIXME: add filters
- ),
+ ],
'Contribute/fixtures/dataset-ascii.sql',
'Contribute/fixtures/report-ascii.csv',
- );
+ ];
- return array(
+ return [
$testCaseA,
$testCaseA,
$testCaseA,
// ensure that CiviReportTestCase can
// clean up sufficiently to run
// multiple tests.
- );
+ ];
}
/**
* @return array
*/
public function badDataProvider() {
- return array(
+ return [
// This test-case is bad because the dataset-ascii.sql does not match the
// report.csv (due to differences in international chars)
- array(
+ [
'CRM_Report_Form_Contribute_Detail',
- array(
- 'fields' => array(
+ [
+ 'fields' => [
'sort_name',
'first_name',
'email',
'total_amount',
- ),
- 'filters' => array(
+ ],
+ 'filters' => [
'total_amount_op' => 'gte',
'total_amount_value' => 50,
- ),
+ ],
// FIXME: add filters
- ),
+ ],
'Contribute/fixtures/dataset-ascii.sql',
'Contribute/fixtures/report.csv',
- ),
+ ],
// This test-case is bad because the filters check for
// an amount >= $100, but the test data includes records
// for $50.
- array(
+ [
'CRM_Report_Form_Contribute_Detail',
- array(
- 'fields' => array(
+ [
+ 'fields' => [
'sort_name',
'first_name',
'email',
'total_amount',
- ),
- 'filters' => array(
+ ],
+ 'filters' => [
'total_amount_op' => 'gte',
'total_amount_value' => 100,
- ),
+ ],
// FIXME: add filters
- ),
+ ],
'Contribute/fixtures/dataset-ascii.sql',
'Contribute/fixtures/report.csv',
- ),
- );
+ ],
+ ];
}
public function setUp() {
$outputMode = $clazz->getProperty('_outputMode');
$outputMode->setAccessible(TRUE);
- $params->setValue($reportForm, array('groups' => 4));
+ $params->setValue($reportForm, ['groups' => 4]);
$reportForm->processReportMode();
$this->assertEquals('group', $outputMode->getValue($reportForm));
- $params->setValue($reportForm, array('task' => 'copy'));
+ $params->setValue($reportForm, ['task' => 'copy']);
$reportForm->processReportMode();
$this->assertEquals('copy', $outputMode->getValue($reportForm));
- $params->setValue($reportForm, array('task' => 'print'));
+ $params->setValue($reportForm, ['task' => 'print']);
$reportForm->processReportMode();
$this->assertEquals('print', $outputMode->getValue($reportForm));
}
}
public function fromToData() {
- $cases = array();
+ $cases = [];
// Absolute dates
- $cases[] = array('20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017');
+ $cases[] = ['20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017'];
// "Today" relative date filter
$date = new DateTime();
$expectedFrom = $date->format('Ymd') . '000000';
$expectedTo = $date->format('Ymd') . '235959';
- $cases[] = array($expectedFrom, $expectedTo, 'this.day', '', '');
+ $cases[] = [$expectedFrom, $expectedTo, 'this.day', '', ''];
// "yesterday" relative date filter
$date = new DateTime();
$date->sub(new DateInterval('P1D'));
$expectedFrom = $date->format('Ymd') . '000000';
$expectedTo = $date->format('Ymd') . '235959';
- $cases[] = array($expectedFrom, $expectedTo, 'previous.day', '', '');
+ $cases[] = [$expectedFrom, $expectedTo, 'previous.day', '', ''];
return $cases;
}
*/
public function setUp() {
parent::setUp();
- $option = $this->callAPISuccess('option_value', 'create', array('option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1));
+ $option = $this->callAPISuccess('option_value', 'create', ['option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1]);
$this->option_value = $option['id'];
}
*/
public function tearDown() {
parent::tearDown();
- $this->callAPISuccess('option_value', 'delete', array('id' => $this->option_value));
+ $this->callAPISuccess('option_value', 'delete', ['id' => $this->option_value]);
}
/**
* CRM-19961 Check that when saving and updating a SMS provider with domain as NULL that it stays null
*/
public function testCreateAndUpdateProvider() {
- $values = array(
+ $values = [
'domain_id' => NULL,
'title' => 'test SMS provider',
'username' => 'test',
'name' => 1,
'is_active' => 1,
'api_type' => 1,
- );
+ ];
$this->callAPISuccess('SmsProvider', 'create', $values);
- $provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('title' => 'test SMS provider'));
+ $provider = $this->callAPISuccess('SmsProvider', 'getsingle', ['title' => 'test SMS provider']);
$domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id');
$this->assertNull($domain_id);
- $values2 = array('title' => 'Test SMS Provider2', 'id' => $provider['id']);
+ $values2 = ['title' => 'Test SMS Provider2', 'id' => $provider['id']];
$this->callAPISuccess('SmsProvider', 'create', $values2);
- $provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('id' => $provider['id']));
+ $provider = $this->callAPISuccess('SmsProvider', 'getsingle', ['id' => $provider['id']]);
$this->assertEquals('Test SMS Provider2', $provider['title']);
$domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id');
$this->assertNull($domain_id);
* Add unit test to ensure that filtering by domain works in get Active Providers
*/
public function testActiveProviderCount() {
- $values = array(
+ $values = [
'domain_id' => NULL,
'title' => 'test SMS provider',
'username' => 'test',
'name' => 1,
'is_active' => 1,
'api_type' => 1,
- );
+ ];
$provider = $this->callAPISuccess('SmsProvider', 'create', $values);
- $provider2 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, array('domain_id' => 2)));
+ $provider2 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, ['domain_id' => 2]));
$result = CRM_SMS_BAO_Provider::activeProviderCount();
$this->assertEquals(1, $result);
- $provider3 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, array('domain_id' => 1)));
+ $provider3 = $this->callAPISuccess('SmsProvider', 'create', array_merge($values, ['domain_id' => 1]));
$result = CRM_SMS_BAO_Provider::activeProviderCount();
$this->assertEquals(2, $result);
CRM_SMS_BAO_Provider::del($provider['id']);
* CRM-19961 Check that when a domain is not passed when saving it defaults to current domain when create
*/
public function testCreateWithoutDomain() {
- $values = array(
+ $values = [
'title' => 'test SMS provider',
'username' => 'test',
'password' => 'dummpy password',
'name' => 1,
'is_active' => 1,
'api_type' => 1,
- );
+ ];
$this->callAPISuccess('SmsProvider', 'create', $values);
- $provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('title' => 'test SMS provider'));
+ $provider = $this->callAPISuccess('SmsProvider', 'getsingle', ['title' => 'test SMS provider']);
$domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id');
$this->assertEquals(CRM_Core_Config::domainID(), $domain_id);
CRM_SMS_BAO_Provider::del($provider['id']);
*/
public function setUp() {
parent::setUp();
- $option = $this->callAPISuccess('option_value', 'create', array('option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1));
+ $option = $this->callAPISuccess('option_value', 'create', ['option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1]);
$this->option_value = $option['id'];
}
*/
public function tearDown() {
parent::tearDown();
- $this->quickCleanup(array('civicrm_email', 'civicrm_phone', 'civicrm_activity', 'civicrm_activity_contact'));
- $this->callAPISuccess('option_value', 'delete', array('id' => $this->option_value));
+ $this->quickCleanup(['civicrm_email', 'civicrm_phone', 'civicrm_activity', 'civicrm_activity_contact']);
+ $this->callAPISuccess('option_value', 'delete', ['id' => $this->option_value]);
}
/**
* CRM-20238 Add test of the processInbound function for SMSs
*/
public function testProcessInbound() {
- $testSourceContact = $this->individualCreate(array('phone' => array(1 => array('phone_type_id' => 'Phone', 'location_type_id' => 'Home', 'phone' => '+61487654321'))));
+ $testSourceContact = $this->individualCreate(['phone' => [1 => ['phone_type_id' => 'Phone', 'location_type_id' => 'Home', 'phone' => '+61487654321']]]);
$provider = new CiviTestSMSProvider('CiviTestSMSProvider');
$result = $provider->processInbound('+61412345678', 'This is a test message', '+61487654321');
$this->assertEquals('This is a test message', $result->details);
$this->assertEquals('This is a test message', $result->details);
$this->assertEquals('+61412345678', $result->phone_number);
$this->assertEquals('12345', $result->result);
- $activity = $this->callAPISuccess('activity', 'getsingle', array('id' => $result->id, 'return' => array('source_contact_id', 'target_contact_id', 'assignee_contact_id')));
- $contact = $this->callAPISuccess('contact', 'getsingle', array('phone' => '61412345678'));
+ $activity = $this->callAPISuccess('activity', 'getsingle', ['id' => $result->id, 'return' => ['source_contact_id', 'target_contact_id', 'assignee_contact_id']]);
+ $contact = $this->callAPISuccess('contact', 'getsingle', ['phone' => '61412345678']);
// Verify that when no to is passed in by default the same contact is used for the source and target.
$this->assertEquals($contact['id'], $activity['source_contact_id']);
$this->assertEquals($contact['id'], $activity['target_contact_id'][0]);
*/
public function testProcessInboundSetToContactIDUsingHook() {
$provider = new CiviTestSMSProvider('CiviTestSMSProvider');
- $this->hookClass->setHook('civicrm_inboundSMS', array($this, 'smsHookTest'));
+ $this->hookClass->setHook('civicrm_inboundSMS', [$this, 'smsHookTest']);
$result = $provider->processInbound('+61412345678', 'This is a test message', NULL, '12345');
$this->assertEquals('This is a test message', $result->details);
$this->assertEquals('+61412345678', $result->phone_number);
$this->assertEquals('12345', $result->result);
- $contact = $this->callAPISuccess('contact', 'getsingle', array('phone' => '+61487654321'));
- $activity = $this->callAPISuccess('activity', 'getsingle', array('id' => $result->id, 'return' => array('source_contact_id', 'target_contact_id', 'assignee_contact_id')));
+ $contact = $this->callAPISuccess('contact', 'getsingle', ['phone' => '+61487654321']);
+ $activity = $this->callAPISuccess('activity', 'getsingle', ['id' => $result->id, 'return' => ['source_contact_id', 'target_contact_id', 'assignee_contact_id']]);
$this->assertEquals($contact['id'], $activity['source_contact_id']);
}
public function smsHookTest(&$message) {
- $testSourceContact = $this->individualCreate(array('phone' => array(1 => array('phone' => '+61487654321'))));
+ $testSourceContact = $this->individualCreate(['phone' => [1 => ['phone' => '+61487654321']]]);
$message->toContactID = $testSourceContact;
}
* Spot check a few fields that should appear in schema.
*/
public function testGetSchema() {
- $schema = CRM_UF_Page_ProfileEditor::getSchema(array('IndividualModel', 'ActivityModel'));
+ $schema = CRM_UF_Page_ProfileEditor::getSchema(['IndividualModel', 'ActivityModel']);
foreach ($schema as $entityName => $entityDef) {
foreach ($entityDef['schema'] as $fieldName => $fieldDef) {
$this->assertNotEmpty($fieldDef['type']);
$this->assertDBQuery(0, "SELECT count(*) FROM civicrm_contact WHERE first_name='Jeffrey' and last_name='Lebowski'");
// Create noise to ensure we don't accidentally/coincidentally match the first record
- $this->noise['individual'] = $this->individualCreate(array(
+ $this->noise['individual'] = $this->individualCreate([
'email' => 'ignore1@example.com',
// 'street_address-1' => 'Irrelevant'
- 'api.Address.create' => array(
+ 'api.Address.create' => [
'location_type_id' => 1,
'street_address' => '123 Irrelevant Str',
'supplemental_address_1' => 'Room 987',
- ),
- ));
+ ],
+ ]);
}
public function tearDown() {
- $noise = $this->callAPISuccess('Contact', 'get', array(
+ $noise = $this->callAPISuccess('Contact', 'get', [
'id' => $this->noise['individual'],
- 'return' => array('email'),
+ 'return' => ['email'],
'api.Address.get' => 1,
- ));
+ ]);
$this->assertEquals(1, count($noise['values']));
foreach ($noise['values'] as $value) {
$this->assertEquals('ignore1@example.com', $value['email']);
$this->assertEquals(1, count($value['api.Address.get']['values']));
}
- CRM_core_DAO::executeQuery('DELETE FROM civicrm_address WHERE contact_id=%1', array(
- 1 => array($this->noise['individual'], 'Positive'),
- ));
- $this->callAPISuccess('Contact', 'delete', array(
+ CRM_core_DAO::executeQuery('DELETE FROM civicrm_address WHERE contact_id=%1', [
+ 1 => [$this->noise['individual'], 'Positive'],
+ ]);
+ $this->callAPISuccess('Contact', 'delete', [
'id' => $this->noise['individual'],
- ));
+ ]);
parent::tearDown();
}
* If there's no pre-existing record, then insert a new one.
*/
public function testCreateMatch_none() {
- $result = $this->callAPISuccess('contact', 'create', array(
- 'options' => array(
- 'match' => array('first_name', 'last_name'),
- ),
+ $result = $this->callAPISuccess('contact', 'create', [
+ 'options' => [
+ 'match' => ['first_name', 'last_name'],
+ ],
'contact_type' => 'Individual',
'first_name' => 'Jeffrey',
'last_name' => 'Lebowski',
'nick_name' => '',
'external_identifier' => '1',
- ));
+ ]);
$this->assertEquals('Jeffrey', $result['values'][$result['id']]['first_name']);
$this->assertEquals('Lebowski', $result['values'][$result['id']]['last_name']);
}
* If there's no pre-existing record, then throw an error.
*/
public function testCreateMatchMandatory_none() {
- $this->callAPIFailure('contact', 'create', array(
- 'options' => array(
- 'match-mandatory' => array('first_name', 'last_name'),
- ),
+ $this->callAPIFailure('contact', 'create', [
+ 'options' => [
+ 'match-mandatory' => ['first_name', 'last_name'],
+ ],
'contact_type' => 'Individual',
'first_name' => 'Jeffrey',
'last_name' => 'Lebowski',
'nick_name' => '',
'external_identifier' => '1',
- ), 'Failed to match existing record');
+ ], 'Failed to match existing record');
}
/**
* @return array
*/
public function apiOptionNames() {
- return array(
- array('match'),
- array('match-mandatory'),
- );
+ return [
+ ['match'],
+ ['match-mandatory'],
+ ];
}
/**
*/
public function testCreateMatch_one($apiOptionName) {
// create basic record
- $result1 = $this->callAPISuccess('contact', 'create', array(
+ $result1 = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'Jeffrey',
'last_name' => 'Lebowski',
'nick_name' => '',
'external_identifier' => '1',
- ));
+ ]);
// more noise!
- $this->individualCreate(array('email' => 'ignore2@example.com'));
+ $this->individualCreate(['email' => 'ignore2@example.com']);
// update the record by matching first/last name
- $result2 = $this->callAPISuccess('contact', 'create', array(
- 'options' => array(
- $apiOptionName => array('first_name', 'last_name'),
- ),
+ $result2 = $this->callAPISuccess('contact', 'create', [
+ 'options' => [
+ $apiOptionName => ['first_name', 'last_name'],
+ ],
'contact_type' => 'Individual',
'first_name' => 'Jeffrey',
'last_name' => 'Lebowski',
'nick_name' => 'The Dude',
'external_identifier' => '2',
- ));
+ ]);
$this->assertEquals($result1['id'], $result2['id']);
$this->assertEquals('Jeffrey', $result2['values'][$result2['id']]['first_name']);
*/
public function testCreateMatch_many($apiOptionName) {
// create the first Lebowski
- $result1 = $this->callAPISuccess('contact', 'create', array(
+ $result1 = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'Jeffrey',
'last_name' => 'Lebowski',
'nick_name' => 'The Dude',
'external_identifier' => '1',
- ));
+ ]);
// create the second Lebowski
- $result2 = $this->callAPISuccess('contact', 'create', array(
+ $result2 = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'Jeffrey',
'last_name' => 'Lebowski',
'nick_name' => 'The Big Lebowski',
'external_identifier' => '2',
- ));
+ ]);
// more noise!
- $this->individualCreate(array('email' => 'ignore2@example.com'));
+ $this->individualCreate(['email' => 'ignore2@example.com']);
// Try to update - but fail due to ambiguity
- $result3 = $this->callAPIFailure('contact', 'create', array(
- 'options' => array(
- $apiOptionName => array('first_name', 'last_name'),
- ),
+ $result3 = $this->callAPIFailure('contact', 'create', [
+ 'options' => [
+ $apiOptionName => ['first_name', 'last_name'],
+ ],
'contact_type' => 'Individual',
'first_name' => 'Jeffrey',
'last_name' => 'Lebowski',
'nick_name' => '',
'external_identifier' => 'new',
- ), 'Ambiguous match criteria');
+ ], 'Ambiguous match criteria');
}
/**
*/
public function testReplaceMatch_Email() {
// Create contact with two emails (j1,j2)
- $createResult = $this->callAPISuccess('contact', 'create', array(
+ $createResult = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'Jeffrey',
'last_name' => 'Lebowski',
- 'api.Email.replace' => array(
- 'options' => array('match' => 'location_type_id'),
- 'values' => array(
- array('location_type_id' => 1, 'email' => 'j1-a@example.com', 'signature_text' => 'The Dude abides.'),
- array(
+ 'api.Email.replace' => [
+ 'options' => ['match' => 'location_type_id'],
+ 'values' => [
+ ['location_type_id' => 1, 'email' => 'j1-a@example.com', 'signature_text' => 'The Dude abides.'],
+ [
'location_type_id' => 2,
'email' => 'j2@example.com',
'signature_text' => 'You know, a lotta ins, a lotta outs, a lotta what-have-yous.',
- ),
- ),
- ),
- ));
+ ],
+ ],
+ ],
+ ]);
$this->assertEquals(1, $createResult['count']);
foreach ($createResult['values'] as $value) {
$this->assertAPISuccess($value['api.Email.replace']);
}
// Update contact's emails -- specifically, modify j1, delete j2, add j3
- $updateResult = $this->callAPISuccess('contact', 'create', array(
+ $updateResult = $this->callAPISuccess('contact', 'create', [
'id' => $createResult['id'],
'nick_name' => 'The Dude',
- 'api.Email.replace' => array(
- 'options' => array('match' => 'location_type_id'),
- 'values' => array(
- array('location_type_id' => 1, 'email' => 'j1-b@example.com'),
- array('location_type_id' => 3, 'email' => 'j3@example.com'),
- ),
- ),
- ));
+ 'api.Email.replace' => [
+ 'options' => ['match' => 'location_type_id'],
+ 'values' => [
+ ['location_type_id' => 1, 'email' => 'j1-b@example.com'],
+ ['location_type_id' => 3, 'email' => 'j3@example.com'],
+ ],
+ ],
+ ]);
$this->assertEquals(1, $updateResult['count']);
foreach ($updateResult['values'] as $value) {
$this->assertAPISuccess($value['api.Email.replace']);
}
// Re-read from DB
- $getResult = $this->callAPISuccess('Email', 'get', array(
+ $getResult = $this->callAPISuccess('Email', 'get', [
'contact_id' => $createResult['id'],
- ));
+ ]);
$this->assertEquals(2, $getResult['count']);
$getValues = array_values($getResult['values']);
*/
public function testReplaceMatch_Address() {
// Create contact with two addresses (j1,j2)
- $createResult = $this->callAPISuccess('contact', 'create', array(
+ $createResult = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'Jeffrey',
'last_name' => 'Lebowski',
- 'api.Address.replace' => array(
- 'options' => array('match' => 'location_type_id'),
- 'values' => array(
- array(
+ 'api.Address.replace' => [
+ 'options' => ['match' => 'location_type_id'],
+ 'values' => [
+ [
'location_type_id' => 1,
'street_address' => 'j1-a Example Ave',
'supplemental_address_1' => 'The Dude abides.',
- ),
- array(
+ ],
+ [
'location_type_id' => 2,
'street_address' => 'j2 Example Ave',
'supplemental_address_1' => 'You know, a lotta ins, a lotta outs, a lotta what-have-yous.',
- ),
- ),
- ),
- ));
+ ],
+ ],
+ ],
+ ]);
$this->assertEquals(1, $createResult['count']);
foreach ($createResult['values'] as $value) {
$this->assertAPISuccess($value['api.Address.replace']);
}
// Update contact's addresses -- specifically, modify j1, delete j2, add j3
- $updateResult = $this->callAPISuccess('contact', 'create', array(
+ $updateResult = $this->callAPISuccess('contact', 'create', [
'id' => $createResult['id'],
'nick_name' => 'The Dude',
- 'api.Address.replace' => array(
- 'options' => array('match' => 'location_type_id'),
- 'values' => array(
- array('location_type_id' => 1, 'street_address' => 'j1-b Example Ave'),
- array('location_type_id' => 3, 'street_address' => 'j3 Example Ave'),
- ),
- ),
- ));
+ 'api.Address.replace' => [
+ 'options' => ['match' => 'location_type_id'],
+ 'values' => [
+ ['location_type_id' => 1, 'street_address' => 'j1-b Example Ave'],
+ ['location_type_id' => 3, 'street_address' => 'j3 Example Ave'],
+ ],
+ ],
+ ]);
$this->assertEquals(1, $updateResult['count']);
foreach ($updateResult['values'] as $value) {
$this->assertAPISuccess($value['api.Address.replace']);
}
// Re-read from DB
- $getResult = $this->callAPISuccess('Address', 'get', array(
+ $getResult = $this->callAPISuccess('Address', 'get', [
'contact_id' => $createResult['id'],
- ));
+ ]);
$this->assertEquals(2, $getResult['count']);
$getValues = array_values($getResult['values']);
public function setUp() {
parent::setUp();
- CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_post', array($this, 'onPost'));
+ CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_post', [$this, 'onPost']);
}
/**
* fact that the hook manipulated the actual DB content.
*/
public function testNoReload() {
- $result = $this->callAPISuccess('contact', 'create', array(
+ $result = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'First',
'last_name' => 'Last',
'nick_name' => 'Firstie',
- ));
+ ]);
$this->assertEquals('First', $result['values'][$result['id']]['first_name']);
// munged by hook, but we haven't realized it
$this->assertEquals('Firstie', $result['values'][$result['id']]['nick_name']);
* When the reload option is unrecognized, generate an error
*/
public function testReloadInvalid() {
- $this->callAPIFailure('contact', 'create', array(
+ $this->callAPIFailure('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'First',
'last_name' => 'Last',
'nick_name' => 'Firstie',
- 'options' => array(
+ 'options' => [
'reload' => 'invalid',
- ),
- ));
+ ],
+ ]);
}
/**
* differs from the inputted nick_name.
*/
public function testReloadDefault() {
- $result = $this->callAPISuccess('contact', 'create', array(
+ $result = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'First',
'last_name' => 'Last',
'nick_name' => 'Firstie',
- 'options' => array(
+ 'options' => [
'reload' => 1,
- ),
- ));
+ ],
+ ]);
$this->assertEquals('First', $result['values'][$result['id']]['first_name']);
$this->assertEquals('munged', $result['values'][$result['id']]['nick_name']);
}
* the chain results.
*/
public function testReloadNoChainInterference() {
- $result = $this->callAPISuccess('contact', 'create', array(
+ $result = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'First',
'last_name' => 'Last',
'nick_name' => 'Firstie',
- 'api.Email.create' => array(
+ 'api.Email.create' => [
'email' => 'test@example.com',
- ),
- 'options' => array(
+ ],
+ 'options' => [
'reload' => 1,
- ),
- ));
+ ],
+ ]);
$this->assertEquals('First', $result['values'][$result['id']]['first_name']);
$this->assertEquals('munged', $result['values'][$result['id']]['nick_name']);
$this->assertAPISuccess($result['values'][$result['id']]['api.Email.create']);
* the chain results, even if sequential=1.
*/
public function testReloadNoChainInterferenceSequential() {
- $result = $this->callAPISuccess('contact', 'create', array(
+ $result = $this->callAPISuccess('contact', 'create', [
'sequential' => 1,
'contact_type' => 'Individual',
'first_name' => 'First',
'last_name' => 'Last',
'nick_name' => 'Firstie',
- 'api.Email.create' => array(
+ 'api.Email.create' => [
'email' => 'test@example.com',
- ),
- 'options' => array(
+ ],
+ 'options' => [
'reload' => 1,
- ),
- ));
+ ],
+ ]);
$this->assertEquals('First', $result['values'][0]['first_name']);
$this->assertEquals('munged', $result['values'][0]['nick_name']);
$this->assertAPISuccess($result['values'][0]['api.Email.create']);
}
public function testAddressFormat() {
- $contact = $this->callAPISuccess('contact', 'create', array(
+ $contact = $this->callAPISuccess('contact', 'create', [
'first_name' => 'Micky',
'last_name' => 'mouse',
'contact_type' => 'Individual',
- ));
- $address = $this->callAPISuccess('address', 'create', array(
+ ]);
+ $address = $this->callAPISuccess('address', 'create', [
'street_address' => '1 Happy Place',
'city' => 'Miami',
'state_province' => 'Flordia',
'contact_id' => $contact['id'],
'location_type_id' => 5,
'is_primary' => 1,
- ));
+ ]);
$addressDetails = $address['values'][$address['id']];
$countries = CRM_Core_PseudoConstant::country();
$addressDetails['country'] = $countries[$addressDetails['country_id']];
* and test using alternate names for state_province field
*/
public function testStateProvinceFormattedBillingAddress() {
- $params = array(
+ $params = [
'billing_street_address-99' => '123 Happy Place',
'billing_city-99' => 'Miami',
'billing_postal_code-99' => 33101,
// 1000 => Alabama (AL)
'state_province-99' => '1000',
'country-99' => 'United States',
- );
+ ];
// set address_format (we are only interested in state_province & state_province_name)
$addFormat = '{contact.state_province}';
class CRM_Utils_ArrayTest extends CiviUnitTestCase {
public function testIndexArray() {
- $inputs = array();
- $inputs[] = array(
+ $inputs = [];
+ $inputs[] = [
'lang' => 'en',
'msgid' => 'greeting',
'familiar' => FALSE,
'value' => 'Hello',
- );
- $inputs[] = array(
+ ];
+ $inputs[] = [
'lang' => 'en',
'msgid' => 'parting',
'value' => 'Goodbye',
- );
- $inputs[] = array(
+ ];
+ $inputs[] = [
'lang' => 'fr',
'msgid' => 'greeting',
'value' => 'Bon jour',
- );
- $inputs[] = array(
+ ];
+ $inputs[] = [
'lang' => 'fr',
'msgid' => 'parting',
'value' => 'Au revoir',
- );
- $inputs[] = array(
+ ];
+ $inputs[] = [
'lang' => 'en',
'msgid' => 'greeting',
'familiar' => TRUE,
'value' => 'Hey',
- );
- $inputs[] = array(
+ ];
+ $inputs[] = [
'msgid' => 'greeting',
'familiar' => TRUE,
'value' => 'Universal greeting',
- );
+ ];
- $byLangMsgid = CRM_Utils_Array::index(array('lang', 'msgid'), $inputs);
+ $byLangMsgid = CRM_Utils_Array::index(['lang', 'msgid'], $inputs);
$this->assertEquals($inputs[4], $byLangMsgid['en']['greeting']);
$this->assertEquals($inputs[1], $byLangMsgid['en']['parting']);
$this->assertEquals($inputs[2], $byLangMsgid['fr']['greeting']);
}
public function testCollect() {
- $arr = array(
- array('catWord' => 'cat', 'dogWord' => 'dog'),
- array('catWord' => 'chat', 'dogWord' => 'chien'),
- array('catWord' => 'gato'),
- );
- $expected = array('cat', 'chat', 'gato');
+ $arr = [
+ ['catWord' => 'cat', 'dogWord' => 'dog'],
+ ['catWord' => 'chat', 'dogWord' => 'chien'],
+ ['catWord' => 'gato'],
+ ];
+ $expected = ['cat', 'chat', 'gato'];
$this->assertEquals($expected, CRM_Utils_Array::collect('catWord', $arr));
- $arr = array();
- $arr['en'] = (object) array('catWord' => 'cat', 'dogWord' => 'dog');
- $arr['fr'] = (object) array('catWord' => 'chat', 'dogWord' => 'chien');
- $arr['es'] = (object) array('catWord' => 'gato');
- $expected = array('en' => 'cat', 'fr' => 'chat', 'es' => 'gato');
+ $arr = [];
+ $arr['en'] = (object) ['catWord' => 'cat', 'dogWord' => 'dog'];
+ $arr['fr'] = (object) ['catWord' => 'chat', 'dogWord' => 'chien'];
+ $arr['es'] = (object) ['catWord' => 'gato'];
+ $expected = ['en' => 'cat', 'fr' => 'chat', 'es' => 'gato'];
$this->assertEquals($expected, CRM_Utils_Array::collect('catWord', $arr));
}
public function testProduct0() {
$actual = CRM_Utils_Array::product(
- array(),
- array('base data' => 1)
+ [],
+ ['base data' => 1]
);
- $this->assertEquals(array(
- array('base data' => 1),
- ), $actual);
+ $this->assertEquals([
+ ['base data' => 1],
+ ], $actual);
}
public function testProduct1() {
$actual = CRM_Utils_Array::product(
- array('dim1' => array('a', 'b')),
- array('base data' => 1)
+ ['dim1' => ['a', 'b']],
+ ['base data' => 1]
);
- $this->assertEquals(array(
- array('base data' => 1, 'dim1' => 'a'),
- array('base data' => 1, 'dim1' => 'b'),
- ), $actual);
+ $this->assertEquals([
+ ['base data' => 1, 'dim1' => 'a'],
+ ['base data' => 1, 'dim1' => 'b'],
+ ], $actual);
}
public function testProduct3() {
$actual = CRM_Utils_Array::product(
- array('dim1' => array('a', 'b'), 'dim2' => array('alpha', 'beta'), 'dim3' => array('one', 'two')),
- array('base data' => 1)
+ ['dim1' => ['a', 'b'], 'dim2' => ['alpha', 'beta'], 'dim3' => ['one', 'two']],
+ ['base data' => 1]
);
- $this->assertEquals(array(
- array('base data' => 1, 'dim1' => 'a', 'dim2' => 'alpha', 'dim3' => 'one'),
- array('base data' => 1, 'dim1' => 'a', 'dim2' => 'alpha', 'dim3' => 'two'),
- array('base data' => 1, 'dim1' => 'a', 'dim2' => 'beta', 'dim3' => 'one'),
- array('base data' => 1, 'dim1' => 'a', 'dim2' => 'beta', 'dim3' => 'two'),
- array('base data' => 1, 'dim1' => 'b', 'dim2' => 'alpha', 'dim3' => 'one'),
- array('base data' => 1, 'dim1' => 'b', 'dim2' => 'alpha', 'dim3' => 'two'),
- array('base data' => 1, 'dim1' => 'b', 'dim2' => 'beta', 'dim3' => 'one'),
- array('base data' => 1, 'dim1' => 'b', 'dim2' => 'beta', 'dim3' => 'two'),
- ), $actual);
+ $this->assertEquals([
+ ['base data' => 1, 'dim1' => 'a', 'dim2' => 'alpha', 'dim3' => 'one'],
+ ['base data' => 1, 'dim1' => 'a', 'dim2' => 'alpha', 'dim3' => 'two'],
+ ['base data' => 1, 'dim1' => 'a', 'dim2' => 'beta', 'dim3' => 'one'],
+ ['base data' => 1, 'dim1' => 'a', 'dim2' => 'beta', 'dim3' => 'two'],
+ ['base data' => 1, 'dim1' => 'b', 'dim2' => 'alpha', 'dim3' => 'one'],
+ ['base data' => 1, 'dim1' => 'b', 'dim2' => 'alpha', 'dim3' => 'two'],
+ ['base data' => 1, 'dim1' => 'b', 'dim2' => 'beta', 'dim3' => 'one'],
+ ['base data' => 1, 'dim1' => 'b', 'dim2' => 'beta', 'dim3' => 'two'],
+ ], $actual);
}
public function testIsSubset() {
- $this->assertTrue(CRM_Utils_Array::isSubset(array(), array()));
- $this->assertTrue(CRM_Utils_Array::isSubset(array('a'), array('a')));
- $this->assertTrue(CRM_Utils_Array::isSubset(array('a'), array('b', 'a', 'c')));
- $this->assertTrue(CRM_Utils_Array::isSubset(array('b', 'd'), array('a', 'b', 'c', 'd')));
- $this->assertFalse(CRM_Utils_Array::isSubset(array('a'), array()));
- $this->assertFalse(CRM_Utils_Array::isSubset(array('a'), array('b')));
- $this->assertFalse(CRM_Utils_Array::isSubset(array('a'), array('b', 'c', 'd')));
+ $this->assertTrue(CRM_Utils_Array::isSubset([], []));
+ $this->assertTrue(CRM_Utils_Array::isSubset(['a'], ['a']));
+ $this->assertTrue(CRM_Utils_Array::isSubset(['a'], ['b', 'a', 'c']));
+ $this->assertTrue(CRM_Utils_Array::isSubset(['b', 'd'], ['a', 'b', 'c', 'd']));
+ $this->assertFalse(CRM_Utils_Array::isSubset(['a'], []));
+ $this->assertFalse(CRM_Utils_Array::isSubset(['a'], ['b']));
+ $this->assertFalse(CRM_Utils_Array::isSubset(['a'], ['b', 'c', 'd']));
}
public function testRemove() {
- $data = array(
+ $data = [
'one' => 1,
'two' => 2,
'three' => 3,
'four' => 4,
'five' => 5,
'six' => 6,
- );
- CRM_Utils_Array::remove($data, 'one', 'two', array('three', 'four'), 'five');
- $this->assertEquals($data, array('six' => 6));
+ ];
+ CRM_Utils_Array::remove($data, 'one', 'two', ['three', 'four'], 'five');
+ $this->assertEquals($data, ['six' => 6]);
}
public function testGetSetPathParts() {
- $arr = array(
+ $arr = [
'one' => '1',
- 'two' => array(
+ 'two' => [
'half' => 2,
- ),
- );
- $this->assertEquals('1', CRM_Utils_Array::pathGet($arr, array('one')));
- $this->assertEquals('2', CRM_Utils_Array::pathGet($arr, array('two', 'half')));
- $this->assertEquals(NULL, CRM_Utils_Array::pathGet($arr, array('zoo', 'half')));
- CRM_Utils_Array::pathSet($arr, array('zoo', 'half'), '3');
- $this->assertEquals(3, CRM_Utils_Array::pathGet($arr, array('zoo', 'half')));
+ ],
+ ];
+ $this->assertEquals('1', CRM_Utils_Array::pathGet($arr, ['one']));
+ $this->assertEquals('2', CRM_Utils_Array::pathGet($arr, ['two', 'half']));
+ $this->assertEquals(NULL, CRM_Utils_Array::pathGet($arr, ['zoo', 'half']));
+ CRM_Utils_Array::pathSet($arr, ['zoo', 'half'], '3');
+ $this->assertEquals(3, CRM_Utils_Array::pathGet($arr, ['zoo', 'half']));
$this->assertEquals(3, $arr['zoo']['half']);
}
public function getSortExamples() {
- $red = array('label' => 'Red', 'id' => 1, 'weight' => '90');
- $orange = array('label' => 'Orange', 'id' => 2, 'weight' => '70');
- $yellow = array('label' => 'Yellow', 'id' => 3, 'weight' => '10');
- $green = array('label' => 'Green', 'id' => 4, 'weight' => '70');
- $blue = array('label' => 'Blue', 'id' => 5, 'weight' => '70');
+ $red = ['label' => 'Red', 'id' => 1, 'weight' => '90'];
+ $orange = ['label' => 'Orange', 'id' => 2, 'weight' => '70'];
+ $yellow = ['label' => 'Yellow', 'id' => 3, 'weight' => '10'];
+ $green = ['label' => 'Green', 'id' => 4, 'weight' => '70'];
+ $blue = ['label' => 'Blue', 'id' => 5, 'weight' => '70'];
- $examples = array();
- $examples[] = array(
- array(
+ $examples = [];
+ $examples[] = [
+ [
'r' => $red,
'y' => $yellow,
'g' => $green,
'o' => $orange,
'b' => $blue,
- ),
+ ],
'id',
- array(
+ [
'r' => $red,
'o' => $orange,
'y' => $yellow,
'g' => $green,
'b' => $blue,
- ),
- );
- $examples[] = array(
- array(
+ ],
+ ];
+ $examples[] = [
+ [
'r' => $red,
'y' => $yellow,
'g' => $green,
'o' => $orange,
'b' => $blue,
- ),
+ ],
'label',
- array(
+ [
'b' => $blue,
'g' => $green,
'o' => $orange,
'r' => $red,
'y' => $yellow,
- ),
- );
- $examples[] = array(
- array(
+ ],
+ ];
+ $examples[] = [
+ [
'r' => $red,
'g' => $green,
'y' => $yellow,
'o' => $orange,
'b' => $blue,
- ),
- array('weight', 'id'),
- array(
+ ],
+ ['weight', 'id'],
+ [
'y' => $yellow,
'o' => $orange,
'g' => $green,
'b' => $blue,
'r' => $red,
- ),
- );
+ ],
+ ];
return $examples;
}
public function nestedWithArrayCb() {
$this->foo = 'arraycb';
- $ac = CRM_Utils_AutoClean::with(array($this, 'setFoo'), 'orig');
+ $ac = CRM_Utils_AutoClean::with([$this, 'setFoo'], 'orig');
$this->assertEquals('arraycb', $this->foo);
}
}
public function nestedSwap() {
- $ac = CRM_Utils_AutoClean::swap(array($this, 'getFoo'), array($this, 'setFoo'), 'tmp');
+ $ac = CRM_Utils_AutoClean::swap([$this, 'getFoo'], [$this, 'setFoo'], 'tmp');
$this->assertEquals('tmp', $this->foo);
}
* Add and remove two items from the same cache instance.
*/
public function testSameInstance() {
- $a = new CRM_Utils_Cache_SqlGroup(array(
+ $a = new CRM_Utils_Cache_SqlGroup([
'group' => 'testSameInstance',
- ));
+ ]);
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_cache WHERE group_name = "testSameInstance"');
- $fooValue = array('whiz' => 'bang', 'bar' => 2);
+ $fooValue = ['whiz' => 'bang', 'bar' => 2];
$a->set('foo', $fooValue);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_cache WHERE group_name = "testSameInstance"');
- $this->assertEquals($a->get('foo'), array('whiz' => 'bang', 'bar' => 2));
+ $this->assertEquals($a->get('foo'), ['whiz' => 'bang', 'bar' => 2]);
$barValue = 45.78;
$a->set('bar', $barValue);
* Add item to one cache instance then read with another.
*/
public function testTwoInstance() {
- $a = new CRM_Utils_Cache_SqlGroup(array(
+ $a = new CRM_Utils_Cache_SqlGroup([
'group' => 'testTwoInstance',
- ));
- $fooValue = array('whiz' => 'bang', 'bar' => 3);
+ ]);
+ $fooValue = ['whiz' => 'bang', 'bar' => 3];
$a->set('foo', $fooValue);
$getValue = $a->get('foo');
- $expectValue = array('whiz' => 'bang', 'bar' => 3);
+ $expectValue = ['whiz' => 'bang', 'bar' => 3];
$this->assertEquals($getValue, $expectValue);
- $b = new CRM_Utils_Cache_SqlGroup(array(
+ $b = new CRM_Utils_Cache_SqlGroup([
'group' => 'testTwoInstance',
'prefetch' => FALSE,
- ));
- $this->assertEquals($b->get('foo'), array('whiz' => 'bang', 'bar' => 3));
+ ]);
+ $this->assertEquals($b->get('foo'), ['whiz' => 'bang', 'bar' => 3]);
}
/**
*/
public function testPrefetch() {
// 1. put data in cache
- $a = new CRM_Utils_Cache_SqlGroup(array(
+ $a = new CRM_Utils_Cache_SqlGroup([
'group' => 'testPrefetch',
'prefetch' => FALSE,
- ));
- $fooValue = array('whiz' => 'bang', 'bar' => 4);
+ ]);
+ $fooValue = ['whiz' => 'bang', 'bar' => 4];
$a->set('foo', $fooValue);
- $this->assertEquals($a->get('foo'), array('whiz' => 'bang', 'bar' => 4));
+ $this->assertEquals($a->get('foo'), ['whiz' => 'bang', 'bar' => 4]);
// 2. see what happens when prefetch is TRUE
- $b = new CRM_Utils_Cache_SqlGroup(array(
+ $b = new CRM_Utils_Cache_SqlGroup([
'group' => 'testPrefetch',
'prefetch' => TRUE,
- ));
+ ]);
// should work b/c value was prefetched
$this->assertEquals($fooValue, $b->getFromFrontCache('foo'));
// should work b/c value was prefetched
$this->assertEquals($fooValue, $b->get('foo'));
// 3. see what happens when prefetch is FALSE
- $c = new CRM_Utils_Cache_SqlGroup(array(
+ $c = new CRM_Utils_Cache_SqlGroup([
'group' => 'testPrefetch',
'prefetch' => FALSE,
- ));
+ ]);
// should be NULL b/c value was NOT prefetched
$this->assertEquals(NULL, $c->getFromFrontCache('foo'));
// should work b/c value is fetched on demand
}
public function fromToData() {
- $cases = array();
+ $cases = [];
// Absolute dates
- $cases[] = array('20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017');
+ $cases[] = ['20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017'];
// "Today" relative date filter
$date = new DateTime();
$expectedFrom = $date->format('Ymd') . '000000';
$expectedTo = $date->format('Ymd') . '235959';
- $cases[] = array($expectedFrom, $expectedTo, 'this.day', '', '');
+ $cases[] = [$expectedFrom, $expectedTo, 'this.day', '', ''];
// "yesterday" relative date filter
$date = new DateTime();
$date->sub(new DateInterval('P1D'));
$expectedFrom = $date->format('Ymd') . '000000';
$expectedTo = $date->format('Ymd') . '235959';
- $cases[] = array($expectedFrom, $expectedTo, 'previous.day', '', '');
+ $cases[] = [$expectedFrom, $expectedTo, 'previous.day', '', ''];
return $cases;
}
public function tearDown() {
// truncate a few tables
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contact',
'civicrm_email',
'civicrm_contribution',
'civicrm_website',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
}
* Test civicrm_contact_check_params with no contact type.
*/
public function testCheckParamsWithNoContactType() {
- $params = array('foo' => 'bar');
+ $params = ['foo' => 'bar'];
$contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
$this->assertEquals(1, $contact['is_error']);
}
* params and no params
*/
public function testCheckParamsWithNoParams() {
- $params = array();
+ $params = [];
$contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
$this->assertEquals(1, $contact['is_error']);
}
* Test is child path.
*/
public function testIsChildPath() {
- $testCases = array();
- $testCases[] = array('/ab/cd/ef', '/ab/cd', FALSE);
- $testCases[] = array('/ab/cd', '/ab/cd/ef', TRUE);
- $testCases[] = array('/ab/cde', '/ab/cd/ef', FALSE);
- $testCases[] = array('/ab/cde', '/ab/cd', FALSE);
- $testCases[] = array('/ab/cd', 'ab/cd/ef', FALSE);
+ $testCases = [];
+ $testCases[] = ['/ab/cd/ef', '/ab/cd', FALSE];
+ $testCases[] = ['/ab/cd', '/ab/cd/ef', TRUE];
+ $testCases[] = ['/ab/cde', '/ab/cd/ef', FALSE];
+ $testCases[] = ['/ab/cde', '/ab/cd', FALSE];
+ $testCases[] = ['/ab/cd', 'ab/cd/ef', FALSE];
foreach ($testCases as $testCase) {
$actual = CRM_Utils_File::isChildPath($testCase[0], $testCase[1], FALSE);
$this->assertEquals($testCase[2], $actual, sprintf("parent=[%s] child=[%s] expected=[%s] actual=[%s]",
}
public function testStripComment() {
- $strings = array(
+ $strings = [
"\nab\n-- cd\nef" => "\nab\nef",
"ab\n-- cd\nef" => "ab\nef",
"ab\n-- cd\nef\ngh" => "ab\nef\ngh",
"ab\r\n--cd\r\nef" => "ab\r\nef",
"ab\r\n#cd\r\nef" => "ab\r\nef",
"ab\r\nfoo#cd\r\nef" => "ab\r\nfoo#cd\r\nef",
- );
+ ];
foreach ($strings as $string => $check) {
$test = CRM_Utils_File::stripComments($string);
$this->assertEquals($test,
}
public function fileExtensions() {
- return array(
- array('txt'),
- array('danger'),
- );
+ return [
+ ['txt'],
+ ['danger'],
+ ];
}
/**
$this->assertFalse(isset($_FOO['bang']));
$this->assertEquals(1, $_EXTRA);
- CRM_Utils_GlobalStack::singleton()->push(array(
- '_FOO' => array(
+ CRM_Utils_GlobalStack::singleton()->push([
+ '_FOO' => [
'bar' => 2,
'bang' => 2,
- ),
+ ],
'_EXTRA' => 2,
- ));
+ ]);
$this->assertEquals(2, $_FOO['bar']);
$this->assertEquals(1, $_FOO['whiz']);
* @return array
*/
public function translateExamples() {
- $cases = array();
- $cases[] = array(
+ $cases = [];
+ $cases[] = [
'',
- array(),
- );
+ [],
+ ];
// missing ts
- $cases[] = array(
+ $cases[] = [
'<div>Hello world</div>',
- array(),
- );
+ [],
+ ];
// text, no arg
- $cases[] = array(
+ $cases[] = [
'<div>{{ts("Hello world")}}</div>',
- array('Hello world'),
- );
+ ['Hello world'],
+ ];
// text, no arg, alternate text
- $cases[] = array(
+ $cases[] = [
'<div>{{ts("Good morning, Dave")}}</div>',
- array('Good morning, Dave'),
- );
+ ['Good morning, Dave'],
+ ];
// text, with arg
- $cases[] = array(
+ $cases[] = [
'<div>{{ts("Hello world", {1: "whiz"})}}</div>',
- array('Hello world'),
- );
+ ['Hello world'],
+ ];
// text, not really ts(), no arg
- $cases[] = array(
+ $cases[] = [
'<div>{{clients("Hello world")}}</div>',
- array(),
- );
+ [],
+ ];
// text, not really ts(), with arg
- $cases[] = array(
+ $cases[] = [
'<div>{{clients("Hello world", {1: "whiz"})}}</div>',
- array(),
- );
+ [],
+ ];
// two strings, duplicate
- $cases[] = array(
+ $cases[] = [
'<div>{{ts("Hello world")}}</div> <p>{{ts("Hello world")}}</p>',
- array('Hello world'),
- );
+ ['Hello world'],
+ ];
// two strings, addition
- $cases[] = array(
+ $cases[] = [
'<div>{{ts("Hello world") + "-" + ts("How do you do?")}}</p>',
- array('Hello world', 'How do you do?'),
- );
+ ['Hello world', 'How do you do?'],
+ ];
// two strings, separate calls
- $cases[] = array(
+ $cases[] = [
'<div>{{ts("Hello world")}}</div> <p>{{ts("How do you do?")}}</p>',
- array('Hello world', 'How do you do?'),
- );
+ ['Hello world', 'How do you do?'],
+ ];
// single quoted
- $cases[] = array(
+ $cases[] = [
'<div>{{ts(\'Hello world\')}}</div>',
- array('Hello world'),
- );
+ ['Hello world'],
+ ];
// unclear string
- $cases[] = array(
+ $cases[] = [
'<div>{{ts(message)}}</div>',
- array(),
- );
+ [],
+ ];
// ts() within a string
- $cases[] = array(
+ $cases[] = [
'<div>{{ts("Does the ts(\'example\') notation work?")}}</div>',
- array('Does the ts(\'example\') notation work?'),
- );
+ ['Does the ts(\'example\') notation work?'],
+ ];
// attribute, no arg
- $cases[] = array(
+ $cases[] = [
'<div crm-title="ts("Hello world")"></div>',
- array('Hello world'),
- );
+ ['Hello world'],
+ ];
// attribute, with arg
- $cases[] = array(
+ $cases[] = [
'<div crm-title="ts("Hello world", {1: "whiz"})"></div>',
- array('Hello world'),
- );
+ ['Hello world'],
+ ];
// attribute, two strings, with arg
- $cases[] = array(
+ $cases[] = [
'<div crm-title="ts("Hello world", {1: "whiz"}) + ts("How do you do, %1?", {2: "funky"})"></div>',
- array('Hello world', 'How do you do, %1?'),
- );
+ ['Hello world', 'How do you do, %1?'],
+ ];
// trick question! Not used on Smarty templates.
- $cases[] = array(
+ $cases[] = [
'<div>{ts}Hello world{/ts}</div>',
- array(),
- );
+ [],
+ ];
return $cases;
}
public function setUp() {
parent::setUp();
- $this->fakeModules = array(
+ $this->fakeModules = [
'hooktesta',
'hooktestb',
'hooktestc',
'hooktestd',
'hookteste',
- );
+ ];
// our goal is to test a helper in CRM_Utils_Hook, but we need a concrete class
$this->hook = new CRM_Utils_Hook_UnitTests();
- $this->log = array();
+ $this->log = [];
self::$activeTest = $this;
}
$arg1 = 'whatever';
$this->hook->runHooks($this->fakeModules, 'civicrm_testRunHooks_outer', 1, $arg1, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject);
$this->assertEquals(
- array(
+ [
'a-outer',
'b-outer-1',
'a-inner',
'b-inner',
'b-outer-2',
'c-outer',
- ),
+ ],
$this->log
);
}
public function testRunHooks_merge() {
$result = $this->hook->runHooks($this->fakeModules, 'civicrm_testRunHooks_merge', 0, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject);
$this->assertEquals(
- array(
+ [
'from-module-a1',
'from-module-a2',
'from-module-e',
- ),
+ ],
$result
);
}
* @return array
*/
function hooktesta_civicrm_testRunHooks_merge() {
- return array('from-module-a1', 'from-module-a2');
+ return ['from-module-a1', 'from-module-a2'];
}
// OMIT: function hooktestb_civicrm_testRunHooks_merge
* Implements hook_civicrm_testRunHooks_merge().
*/
function hooktestc_civicrm_testRunHooks_merge() {
- return array();
+ return [];
}
/**
* @return array
*/
function hookteste_civicrm_testRunHooks_merge() {
- return array('from-module-e');
+ return ['from-module-e'];
}
*/
public function htmlToTextExamples() {
// array(0 => string $html, 1 => string $text)
- $cases = array();
+ $cases = [];
- $cases[] = array(
+ $cases[] = [
'<br/><p>',
'',
- );
+ ];
- $cases[] = array(
+ $cases[] = [
"\n<p>\n" .
"This is a paragraph with <b>Bold</b> and <i>italics</i>\n" .
"Also some <a href=\"http://www.example.com\">hrefs</a> and a\n" .
"------\n" .
"[1] http://www.example.com\n" .
"",
- );
+ ];
- $cases[] = array(
+ $cases[] = [
"<p>\nA <a href=\"{action.do_something}\">token</a>\nis not treated as a relative URL",
"A token [1] is not treated as a relative URL\n" .
"\n" .
"Links:\n" .
"------\n" .
"[1] {action.do_something}\n",
- );
+ ];
return $cases;
}
$this->tmpFile = $this->createTempDir() . '/example.txt';
- $result = civicrm_api('Setting', 'create', array(
+ $result = civicrm_api('Setting', 'create', [
'version' => 3,
'verifySSL' => TRUE,
- ));
+ ]);
$this->assertAPISuccess($result);
$this->client = new CRM_Utils_HttpClient();
}
}
public function testFetchHttps_invalid_noVerify() {
- $result = civicrm_api('Setting', 'create', array(
+ $result = civicrm_api('Setting', 'create', [
'version' => 3,
'verifySSL' => FALSE,
- ));
+ ]);
$this->assertAPISuccess($result);
$result = $this->client->fetch(self::SELF_SIGNED_HTTPS_URL, $this->tmpFile);
}
public function testGetHttps_invalid_noVerify() {
- $result = civicrm_api('Setting', 'create', array(
+ $result = civicrm_api('Setting', 'create', [
'version' => 3,
'verifySSL' => FALSE,
- ));
+ ]);
$this->assertAPISuccess($result);
list($status, $data) = $this->client->get(self::SELF_SIGNED_HTTPS_URL);
* @return array
*/
public function escapeExamples() {
- $cases = array();
- $cases[] = array("Hello
+ $cases = [];
+ $cases[] = ["Hello
this is, a test!",
- );
- $cases[] = array("Hello!!
+ ];
+ $cases[] = ["Hello!!
this is, a \"test\"!",
- );
+ ];
return $cases;
}
* @return array
*/
public function translateExamples() {
- $cases = array();
- $cases[] = array(
+ $cases = [];
+ $cases[] = [
'',
- array(),
- );
+ [],
+ ];
// missing ts
- $cases[] = array(
+ $cases[] = [
'alert("Hello world")',
- array(),
- );
+ [],
+ ];
// basic function call
- $cases[] = array(
+ $cases[] = [
'alert(ts("Hello world"));',
- array('Hello world'),
- );
+ ['Hello world'],
+ ];
// with arg
- $cases[] = array(
+ $cases[] = [
'alert(ts("Hello world", {1: "whiz"}));',
- array('Hello world'),
- );
+ ['Hello world'],
+ ];
// not really ts()
- $cases[] = array(
+ $cases[] = [
'alert(clients("Hello world"));',
- array(),
- );
+ [],
+ ];
// not really ts()
- $cases[] = array(
+ $cases[] = [
'alert(clients("Hello world", {1: "whiz"}));',
- array(),
- );
+ [],
+ ];
// with arg
- $cases[] = array(
+ $cases[] = [
"\n" .
"public function whits() {\n" .
" for (a in b) {\n" .
" });\n" .
" }\n" .
"}\n",
- array('Hello'),
- );
+ ['Hello'],
+ ];
// duplicate
- $cases[] = array(
+ $cases[] = [
'alert(ts("Hello world") + "-" + ts("Hello world"));',
- array('Hello world'),
- );
+ ['Hello world'],
+ ];
// two strings, addition
- $cases[] = array(
+ $cases[] = [
'alert(ts("Hello world") + "-" + ts("How do you do?"));',
- array('Hello world', 'How do you do?'),
- );
+ ['Hello world', 'How do you do?'],
+ ];
// two strings, separate calls
- $cases[] = array(
+ $cases[] = [
'alert(ts("Hello world");\nalert(ts("How do you do?"));',
- array('Hello world', 'How do you do?'),
- );
- $cases[] = array(
+ ['Hello world', 'How do you do?'],
+ ];
+ $cases[] = [
'alert(ts(\'Single quoted\'));',
- array('Single quoted'),
- );
+ ['Single quoted'],
+ ];
// unclear string
- $cases[] = array(
+ $cases[] = [
'alert(ts(message));',
- array(),
- );
+ [],
+ ];
// ts() within a string
- $cases[] = array(
+ $cases[] = [
'alert(ts("Does the ts(\'example\') notation work?"));',
- array('Does the ts(\'example\') notation work?'),
- );
+ ['Does the ts(\'example\') notation work?'],
+ ];
return $cases;
}
$abc = "(function (angular, $, _) {\na();\n\nb();\n\nc();\n})(angular,CRM.$, CRM._);";
$cb = "(function( angular, $,_) {\nc();\n\nb();\n})(angular,CRM.$,CRM._);";
- $cases = array();
- $cases[] = array(array($a), "$a");
- $cases[] = array(array($b), "$b");
- $cases[] = array(array($c), "$c");
- $cases[] = array(array($d), "$d");
- $cases[] = array(array($m), "$m");
- $cases[] = array(array($a, $b), "$ab");
- $cases[] = array(array($a, $m, $b), "$a$m$b");
- $cases[] = array(array($a, $d), "$a$d");
- $cases[] = array(array($a, $d, $b), "$a$d$b");
- $cases[] = array(array($a, $b, $c), "$abc");
- $cases[] = array(array($a, $b, $d, $c, $b), "$ab$d$cb");
+ $cases = [];
+ $cases[] = [[$a], "$a"];
+ $cases[] = [[$b], "$b"];
+ $cases[] = [[$c], "$c"];
+ $cases[] = [[$d], "$d"];
+ $cases[] = [[$m], "$m"];
+ $cases[] = [[$a, $b], "$ab"];
+ $cases[] = [[$a, $m, $b], "$a$m$b"];
+ $cases[] = [[$a, $d], "$a$d"];
+ $cases[] = [[$a, $d, $b], "$a$d$b"];
+ $cases[] = [[$a, $b, $c], "$abc"];
+ $cases[] = [[$a, $b, $d, $c, $b], "$ab$d$cb"];
return $cases;
}
public function testDedupeClosure($scripts, $expectedOutput) {
$actualOutput = CRM_Utils_JS::dedupeClosures(
$scripts,
- array('angular', '$', '_'),
- array('angular', 'CRM.$', 'CRM._')
+ ['angular', '$', '_'],
+ ['angular', 'CRM.$', 'CRM._']
);
$this->assertEquals($expectedOutput, implode("", $actualOutput));
}
public function stripCommentsExamples() {
- $cases = array();
- $cases[] = array(
+ $cases = [];
+ $cases[] = [
"a();\n//# sourceMappingURL=../foo/bar/baz.js\nb();",
"a();\n\nb();",
- );
- $cases[] = array(
+ ];
+ $cases[] = [
"// foo\na();",
"\na();",
- );
- $cases[] = array(
+ ];
+ $cases[] = [
"b();\n // foo",
"b();\n",
- );
- $cases[] = array(
+ ];
+ $cases[] = [
"/// foo\na();\n\t \t//bar\nb();\n// whiz",
"\na();\n\nb();\n",
- );
- $cases[] = array(
+ ];
+ $cases[] = [
"alert('//# sourceMappingURL=../foo/bar/baz.js');\n//zoop\na();",
"alert('//# sourceMappingURL=../foo/bar/baz.js');\n\na();",
- );
+ ];
return $cases;
}
*
* @var array
*/
- protected $eventQueue = array();
+ protected $eventQueue = [];
/**
* ID of our sample contact.
parent::setUp();
CRM_Utils_File::cleanDir(__DIR__ . '/data/mail');
mkdir(__DIR__ . '/data/mail');
- $this->callAPISuccess('MailSettings', 'get', array(
- 'api.MailSettings.create' => array(
+ $this->callAPISuccess('MailSettings', 'get', [
+ 'api.MailSettings.create' => [
'name' => 'local',
'protocol' => 'Localdir',
'source' => __DIR__ . '/data/mail',
'domain' => 'example.com',
- ),
- ));
+ ],
+ ]);
}
public function tearDown() {
CRM_Utils_File::cleanDir(__DIR__ . '/data/mail');
parent::tearDown();
- $this->quickCleanup(array('civicrm_group', 'civicrm_group_contact', 'civicrm_mailing', 'civicrm_mailing_job', 'civicrm_mailing_event_bounce', 'civicrm_mailing_event_queue', 'civicrm_mailing_group', 'civicrm_mailing_recipients', 'civicrm_contact', 'civicrm_email'));
+ $this->quickCleanup(['civicrm_group', 'civicrm_group_contact', 'civicrm_mailing', 'civicrm_mailing_job', 'civicrm_mailing_event_bounce', 'civicrm_mailing_event_queue', 'civicrm_mailing_group', 'civicrm_mailing_recipients', 'civicrm_contact', 'civicrm_email']);
}
/**
copy(__DIR__ . '/data/bounces/bounce_no_verp.txt', __DIR__ . '/data/mail/bounce_no_verp.txt');
$this->assertTrue(file_exists(__DIR__ . '/data/mail/bounce_no_verp.txt'));
- $this->callAPISuccess('job', 'fetch_bounces', array());
+ $this->callAPISuccess('job', 'fetch_bounces', []);
$this->assertFalse(file_exists(__DIR__ . '/data/mail/bounce_no_verp.txt'));
$this->checkMailingBounces(1);
}
$mail = 'test_invalid_character.eml';
copy(__DIR__ . '/data/bounces/' . $mail, __DIR__ . '/data/mail/' . $mail);
- $this->callAPISuccess('job', 'fetch_bounces', array());
+ $this->callAPISuccess('job', 'fetch_bounces', []);
$this->assertFalse(file_exists(__DIR__ . '/data/mail/' . $mail));
$this->checkMailingBounces(1);
}
$mail = 'test_utf8mb4_character.txt';
copy(__DIR__ . '/data/bounces/' . $mail, __DIR__ . '/data/mail/' . $mail);
- $this->callAPISuccess('job', 'fetch_bounces', array());
+ $this->callAPISuccess('job', 'fetch_bounces', []);
$this->assertFalse(file_exists(__DIR__ . '/data/mail/' . $mail));
$this->checkMailingBounces(1);
}
$mail = 'test_sample_message.eml';
copy(__DIR__ . '/data/bounces/' . $mail, __DIR__ . '/data/mail/' . $mail);
- $this->callAPISuccess('job', 'fetch_bounces', array());
+ $this->callAPISuccess('job', 'fetch_bounces', []);
$this->assertFalse(file_exists(__DIR__ . '/data/mail/' . $mail));
$this->checkMailingBounces(1);
}
$mail = 'test_nested_message.eml';
copy(__DIR__ . '/data/bounces/' . $mail, __DIR__ . '/data/mail/' . $mail);
- $this->callAPISuccess('job', 'fetch_bounces', array());
+ $this->callAPISuccess('job', 'fetch_bounces', []);
$this->assertFalse(file_exists(__DIR__ . '/data/mail/' . $mail));
$this->checkMailingBounces(1);
}
*/
public function testBounceProcessingDeletedEmail() {
$this->setUpMailing();
- $this->callAPISuccess('Email', 'get', array(
+ $this->callAPISuccess('Email', 'get', [
'contact_id' => $this->contactID,
'api.email.delete' => 1,
- ));
+ ]);
copy(__DIR__ . '/data/bounces/bounce_no_verp.txt', __DIR__ . '/data/mail/bounce_no_verp.txt');
$this->assertTrue(file_exists(__DIR__ . '/data/mail/bounce_no_verp.txt'));
- $this->callAPISuccess('job', 'fetch_bounces', array());
+ $this->callAPISuccess('job', 'fetch_bounces', []);
$this->assertFalse(file_exists(__DIR__ . '/data/mail/bounce_no_verp.txt'));
$this->checkMailingBounces(1);
}
* Set up a mailing.
*/
public function setUpMailing() {
- $this->contactID = $this->individualCreate(array('email' => 'undeliverable@example.com'));
- $groupID = $this->callAPISuccess('Group', 'create', array(
+ $this->contactID = $this->individualCreate(['email' => 'undeliverable@example.com']);
+ $groupID = $this->callAPISuccess('Group', 'create', [
'title' => 'Mailing group',
- 'api.GroupContact.create' => array(
+ 'api.GroupContact.create' => [
'contact_id' => $this->contactID,
- ),
- ));
- $this->createMailing(array('scheduled_date' => 'now', 'groups' => array('include' => array($groupID))));
- $this->callAPISuccess('job', 'process_mailing', array());
- $this->eventQueue = $this->callAPISuccess('MailingEventQueue', 'get', array('api.MailingEventQueue.create' => array('hash' => 'aaaaaaaaaaaaaaaa')));
+ ],
+ ]);
+ $this->createMailing(['scheduled_date' => 'now', 'groups' => ['include' => [$groupID]]]);
+ $this->callAPISuccess('job', 'process_mailing', []);
+ $this->eventQueue = $this->callAPISuccess('MailingEventQueue', 'get', ['api.MailingEventQueue.create' => ['hash' => 'aaaaaaaaaaaaaaaa']]);
}
}
*/
public function testFormatRFC822() {
- $values = array(
- array(
+ $values = [
+ [
'name' => "Test User",
'email' => "foo@bar.com",
'result' => "Test User <foo@bar.com>",
- ),
- array(
+ ],
+ [
'name' => '"Test User"',
'email' => "foo@bar.com",
'result' => "Test User <foo@bar.com>",
- ),
- array(
+ ],
+ [
'name' => "User, Test",
'email' => "foo@bar.com",
'result' => '"User, Test" <foo@bar.com>',
- ),
- array(
+ ],
+ [
'name' => '"User, Test"',
'email' => "foo@bar.com",
'result' => '"User, Test" <foo@bar.com>',
- ),
- array(
+ ],
+ [
'name' => '"Test User"',
'email' => "foo@bar.com",
'result' => '"Test User" <foo@bar.com>',
'useQuote' => TRUE,
- ),
- array(
+ ],
+ [
'name' => "User, Test",
'email' => "foo@bar.com",
'result' => '"User, Test" <foo@bar.com>',
'useQuote' => TRUE,
- ),
- );
+ ],
+ ];
foreach ($values as $value) {
$result = CRM_Utils_Mail::formatRFC822Email($value['name'],
$value['email'],
}
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_custom_group',
'civicrm_custom_field',
- );
+ ];
$this->quickCleanup($tablesToTruncate, TRUE);
}
*/
public function basicXmlTestCases() {
// a small library which we use to describe test cases
- $fixtures = array();
- $fixtures['textField'] = array(
+ $fixtures = [];
+ $fixtures['textField'] = [
'name' => 'test_textfield',
'label' => 'Name1',
'html_type' => 'Text',
'is_required' => 1,
'is_searchable' => 0,
'is_active' => 1,
- );
- $fixtures['selectField'] = array(
+ ];
+ $fixtures['selectField'] = [
// custom_group_id
'label' => 'Our select field',
'html_type' => 'Select',
'is_searchable' => 0,
'is_active' => 1,
// 'option_group_name' => 'our_select_field_20130818044104',
- 'option_values' => array(
- array(
+ 'option_values' => [
+ [
'weight' => 1,
'label' => 'Label1',
'value' => 1,
'is_active' => 1,
- ),
- array(
+ ],
+ [
'weight' => 2,
'label' => 'Label2',
'value' => 2,
'is_active' => 1,
- ),
- ),
- );
+ ],
+ ],
+ ];
// the actual test cases
- $cases = array();
+ $cases = [];
- $cases[] = array(
+ $cases[] = [
// CustomGroup params
- array(
+ [
'extends' => 'Contact',
'title' => 'example',
- ),
+ ],
// CustomField params
$fixtures['textField'],
// expectedXmlFilePath
__DIR__ . '/fixtures/Contact-text.xml',
- );
+ ];
/* @codingStandardsIgnoreStart
$cases[] = array(
);
@codingStandardsIgnoreEnd */
- $cases[] = array(
+ $cases[] = [
// CustomGroup params
- array(
+ [
'extends' => 'Individual',
'title' => 'example',
- ),
+ ],
// CustomField params
$fixtures['textField'],
// expectedXmlFilePath
__DIR__ . '/fixtures/Individual-text.xml',
- );
+ ];
- $cases[] = array(
+ $cases[] = [
// CustomGroup params
- array(
+ [
'extends' => 'Individual',
- 'extends_entity_column_value' => array('Student'),
+ 'extends_entity_column_value' => ['Student'],
'title' => 'example',
- ),
+ ],
// CustomField params
$fixtures['textField'],
// expectedXmlFilePath
__DIR__ . '/fixtures/IndividualStudent-text.xml',
- );
+ ];
- $cases[] = array(
+ $cases[] = [
// CustomGroup params
- array(
+ [
'extends' => 'Activity',
'title' => 'example',
- ),
+ ],
// CustomField params
$fixtures['textField'],
// expectedXmlFilePath
__DIR__ . '/fixtures/Activity-text.xml',
- );
+ ];
- $cases[] = array(
+ $cases[] = [
// CustomGroup params
- array(
+ [
'extends' => 'Activity',
'extends_entity_column_value' => [1],
'title' => 'example',
- ),
+ ],
// CustomField params
$fixtures['textField'],
// expectedXmlFilePath
__DIR__ . '/fixtures/ActivityMeeting-text.xml',
- );
+ ];
return $cases;
}
* @dataProvider basicXmlTestCases
*/
public function testBasicXMLExports($customGroupParams, $fieldParams, $expectedXmlFilePath) {
- $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', array(
- 1 => array($customGroupParams['title'], 'String'),
- ));
+ $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', [
+ 1 => [$customGroupParams['title'], 'String'],
+ ]);
$customGroup = $this->customGroupCreate($customGroupParams);
$fieldParams['custom_group_id'] = $customGroup['id'];
$customField = $this->callAPISuccess('custom_field', 'create', $fieldParams);
$exporter = new CRM_Utils_Migrate_Export();
- $exporter->buildCustomGroups(array($customGroup['id']));
+ $exporter->buildCustomGroups([$customGroup['id']]);
// print $exporter->toXML();
$this->assertEquals(file_get_contents($expectedXmlFilePath), $exporter->toXML());
- $this->callAPISuccess('custom_field', 'delete', array('id' => $customField['id']));
- $this->callAPISuccess('custom_group', 'delete', array('id' => $customGroup['id']));
+ $this->callAPISuccess('custom_field', 'delete', ['id' => $customField['id']]);
+ $this->callAPISuccess('custom_group', 'delete', ['id' => $customGroup['id']]);
}
/**
* @dataProvider basicXmlTestCases
*/
public function testBasicXMLImports($expectCustomGroup, $expectCustomField, $inputXmlFilePath) {
- $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', array(
- 1 => array($expectCustomGroup['title'], 'String'),
- ));
+ $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', [
+ 1 => [$expectCustomGroup['title'], 'String'],
+ ]);
$importer = new CRM_Utils_Migrate_Import();
$importer->run($inputXmlFilePath);
- $customGroups = $this->callAPISuccess('custom_group', 'get', array('title' => $expectCustomGroup['title']));
+ $customGroups = $this->callAPISuccess('custom_group', 'get', ['title' => $expectCustomGroup['title']]);
$this->assertEquals(1, $customGroups['count']);
$customGroup = array_shift($customGroups['values']);
foreach ($expectCustomGroup as $expectKey => $expectValue) {
$this->assertEquals($expectValue, $customGroup[$expectKey]);
}
- $customFields = $this->callAPISuccess('custom_field', 'get', array('label' => $expectCustomField['label']));
+ $customFields = $this->callAPISuccess('custom_field', 'get', ['label' => $expectCustomField['label']]);
$this->assertEquals(1, $customFields['count']);
$customField = array_shift($customFields['values']);
foreach ($expectCustomField as $expectKey => $expectValue) {
* @return array
*/
public function subtractCurrenciesDataProvider() {
- return array(
- array(number_format(300.00, 2), number_format(299.99, 2), 'USD', number_format(0.01, 2)),
- array(2, 1, 'USD', 1),
- array(0, 0, 'USD', 0),
- array(1, 2, 'USD', -1),
- array(number_format(19.99, 2), number_format(20.00, 2), 'USD', number_format(-0.01, 2)),
- array('notanumber', 5.00, 'USD', NULL),
- );
+ return [
+ [number_format(300.00, 2), number_format(299.99, 2), 'USD', number_format(0.01, 2)],
+ [2, 1, 'USD', 1],
+ [0, 0, 'USD', 0],
+ [1, 2, 'USD', -1],
+ [number_format(19.99, 2), number_format(20.00, 2), 'USD', number_format(-0.01, 2)],
+ ['notanumber', 5.00, 'USD', NULL],
+ ];
}
/**
* @return array
*/
public function randomDecimalCases() {
- $cases = array();
+ $cases = [];
// array(array $precision, int $expectedMinInclusive, int $expectedMaxExclusive)
- $cases[] = array(array(1, 0), 0, 10);
- $cases[] = array(array(5, 2), 0, 1000);
- $cases[] = array(array(10, 8), 0, 100);
+ $cases[] = [[1, 0], 0, 10];
+ $cases[] = [[5, 2], 0, 1000];
+ $cases[] = [[10, 8], 0, 100];
return $cases;
}
* @return array
*/
public function truncDecimalCases() {
- $cases = array();
+ $cases = [];
// array($value, $precision, $expectedValue)
- $cases[] = array(523, array(1, 0), 5);
- $cases[] = array(523, array(5, 2), 523);
- $cases[] = array(523, array(10, 8), 52.3);
- $cases[] = array(12345, array(3, 3), 0.123);
- $cases[] = array(0.12345, array(10, 0), 12345);
- $cases[] = array(-123.45, array(4, 2), -12.34);
+ $cases[] = [523, [1, 0], 5];
+ $cases[] = [523, [5, 2], 523];
+ $cases[] = [523, [10, 8], 52.3];
+ $cases[] = [12345, [3, 3], 0.123];
+ $cases[] = [0.12345, [10, 0], 12345];
+ $cases[] = [-123.45, [4, 2], -12.34];
return $cases;
}
PRIMARY KEY (id)
)
');
- $idx = new CRM_Core_InnoDBIndexer(self::supportsFts(), array(
- 'civicrm_contact' => array(
- array('first_name', 'last_name'),
- ),
- ));
+ $idx = new CRM_Core_InnoDBIndexer(self::supportsFts(), [
+ 'civicrm_contact' => [
+ ['first_name', 'last_name'],
+ ],
+ ]);
$idx->fixSchemaDifferences();
- $rows = array(
- array(1, 'someone@example.com'),
- array(2, 'this is someone@example.com!'),
- array(3, 'first second'),
- array(4, 'zeroth first second'),
- array(5, 'zeroth first second third'),
- array(6, 'never say never'),
- array(7, 'first someone@example.com second'),
- array(8, 'first someone'),
- array(9, 'firstly someone'),
- );
+ $rows = [
+ [1, 'someone@example.com'],
+ [2, 'this is someone@example.com!'],
+ [3, 'first second'],
+ [4, 'zeroth first second'],
+ [5, 'zeroth first second third'],
+ [6, 'never say never'],
+ [7, 'first someone@example.com second'],
+ [8, 'first someone'],
+ [9, 'firstly someone'],
+ ];
foreach ($rows as $row) {
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_fts_example (id,name) VALUES (%1, %2)",
- array(
- 1 => array($row[0], 'Int'),
- 2 => array($row[1], 'String'),
- ));
+ [
+ 1 => [$row[0], 'Int'],
+ 2 => [$row[1], 'String'],
+ ]);
}
}
*/
public function dataProvider() {
// Array(0=>$inputText, 1=>$language, 2=>$options, 3=>$expectedText, 4=>$matchingIds).
- $cases = array();
-
- $allEmailRows = array(1, 2, 7);
-
- $cases[] = array('someone@example.com', 'like', 'simple', '%someone@example.com%', $allEmailRows);
- $cases[] = array('someone@example.com', 'like', 'phrase', '%someone@example.com%', $allEmailRows);
- $cases[] = array('someone@example.com', 'like', 'wildphrase', '%someone@example.com%', $allEmailRows);
- $cases[] = array('someone@example.com', 'like', 'wildwords', '%someone@example.com%', $allEmailRows);
- $cases[] = array('someone@example.com', 'like', 'wildwords-suffix', '%someone@example.com%', $allEmailRows);
-
- $cases[] = array('someone@example.com', 'fts', 'simple', 'someone@example.com', $allEmailRows);
- $cases[] = array('someone@example.com', 'fts', 'phrase', '"someone@example.com"', $allEmailRows);
- $cases[] = array('someone@example.com', 'fts', 'wildphrase', '"*someone@example.com*"', $allEmailRows);
- $cases[] = array('someone@example.com', 'fts', 'wildwords', '*someone* *example*', $allEmailRows);
- $cases[] = array('someone@example.com', 'fts', 'wildwords-suffix', 'someone* example*', $allEmailRows);
-
- $cases[] = array('someone@example.com', 'ftsbool', 'simple', '+"someone" +"example"', $allEmailRows);
- $cases[] = array('someone@example.com', 'ftsbool', 'phrase', '+"someone@example.com"', $allEmailRows);
- $cases[] = array('someone@example.com', 'ftsbool', 'wildphrase', '+"*someone@example.com*"', $allEmailRows);
- $cases[] = array('someone@example.com', 'ftsbool', 'wildwords', '+*someone* +*example*', $allEmailRows);
- $cases[] = array('someone@example.com', 'ftsbool', 'wildwords-suffix', '+someone* +example*', $allEmailRows);
-
- $cases[] = array('first second', 'like', 'simple', '%first second%', array(3, 4, 5));
- $cases[] = array('first second', 'like', 'phrase', '%first second%', array(3, 4, 5));
- $cases[] = array('first second', 'like', 'wildphrase', '%first second%', array(3, 4, 5));
- $cases[] = array('first second', 'like', 'wildwords', '%first%second%', array(3, 4, 5, 7));
- $cases[] = array('first second', 'like', 'wildwords-suffix', '%first%second%', array(3, 4, 5, 7));
-
- $cases[] = array('first second', 'fts', 'simple', 'first second', array(3, 4, 5));
- $cases[] = array('first second', 'fts', 'phrase', '"first second"', array(3, 4, 5));
- $cases[] = array('first second', 'fts', 'wildphrase', '"*first second*"', array(3, 4, 5));
- $cases[] = array('first second', 'fts', 'wildwords', '*first* *second*', array(3, 4, 5, 7));
- $cases[] = array('first second', 'fts', 'wildwords-suffix', 'first* second*', array(3, 4, 5, 7));
-
- $cases[] = array('first second', 'ftsbool', 'simple', '+"first" +"second"', array(3, 4, 5));
- $cases[] = array('first second', 'ftsbool', 'phrase', '+"first second"', array(3, 4, 5));
- $cases[] = array('first second', 'ftsbool', 'wildphrase', '+"*first second*"', array(3, 4, 5));
- $cases[] = array('first second', 'ftsbool', 'wildwords', '+*first* +*second*', array(3, 4, 5, 7));
- $cases[] = array('first second', 'ftsbool', 'wildwords-suffix', '+first* +second*', array(3, 4, 5, 7));
-
- $cases[] = array('first second', 'solr', 'simple', 'first second', NULL);
- $cases[] = array('first second', 'solr', 'phrase', '"first second"', NULL);
- $cases[] = array('first second', 'solr', 'wildphrase', '"*first second*"', NULL);
- $cases[] = array('first second', 'solr', 'wildwords', '*first* *second*', NULL);
- $cases[] = array('first second', 'solr', 'wildwords-suffix', 'first* second*', NULL);
-
- $cases[] = array('someone@', 'ftsbool', 'simple', '+"someone"', $allEmailRows);
- $cases[] = array('@example.com', 'ftsbool', 'simple', '+"example.com"', $allEmailRows);
+ $cases = [];
+
+ $allEmailRows = [1, 2, 7];
+
+ $cases[] = ['someone@example.com', 'like', 'simple', '%someone@example.com%', $allEmailRows];
+ $cases[] = ['someone@example.com', 'like', 'phrase', '%someone@example.com%', $allEmailRows];
+ $cases[] = ['someone@example.com', 'like', 'wildphrase', '%someone@example.com%', $allEmailRows];
+ $cases[] = ['someone@example.com', 'like', 'wildwords', '%someone@example.com%', $allEmailRows];
+ $cases[] = ['someone@example.com', 'like', 'wildwords-suffix', '%someone@example.com%', $allEmailRows];
+
+ $cases[] = ['someone@example.com', 'fts', 'simple', 'someone@example.com', $allEmailRows];
+ $cases[] = ['someone@example.com', 'fts', 'phrase', '"someone@example.com"', $allEmailRows];
+ $cases[] = ['someone@example.com', 'fts', 'wildphrase', '"*someone@example.com*"', $allEmailRows];
+ $cases[] = ['someone@example.com', 'fts', 'wildwords', '*someone* *example*', $allEmailRows];
+ $cases[] = ['someone@example.com', 'fts', 'wildwords-suffix', 'someone* example*', $allEmailRows];
+
+ $cases[] = ['someone@example.com', 'ftsbool', 'simple', '+"someone" +"example"', $allEmailRows];
+ $cases[] = ['someone@example.com', 'ftsbool', 'phrase', '+"someone@example.com"', $allEmailRows];
+ $cases[] = ['someone@example.com', 'ftsbool', 'wildphrase', '+"*someone@example.com*"', $allEmailRows];
+ $cases[] = ['someone@example.com', 'ftsbool', 'wildwords', '+*someone* +*example*', $allEmailRows];
+ $cases[] = ['someone@example.com', 'ftsbool', 'wildwords-suffix', '+someone* +example*', $allEmailRows];
+
+ $cases[] = ['first second', 'like', 'simple', '%first second%', [3, 4, 5]];
+ $cases[] = ['first second', 'like', 'phrase', '%first second%', [3, 4, 5]];
+ $cases[] = ['first second', 'like', 'wildphrase', '%first second%', [3, 4, 5]];
+ $cases[] = ['first second', 'like', 'wildwords', '%first%second%', [3, 4, 5, 7]];
+ $cases[] = ['first second', 'like', 'wildwords-suffix', '%first%second%', [3, 4, 5, 7]];
+
+ $cases[] = ['first second', 'fts', 'simple', 'first second', [3, 4, 5]];
+ $cases[] = ['first second', 'fts', 'phrase', '"first second"', [3, 4, 5]];
+ $cases[] = ['first second', 'fts', 'wildphrase', '"*first second*"', [3, 4, 5]];
+ $cases[] = ['first second', 'fts', 'wildwords', '*first* *second*', [3, 4, 5, 7]];
+ $cases[] = ['first second', 'fts', 'wildwords-suffix', 'first* second*', [3, 4, 5, 7]];
+
+ $cases[] = ['first second', 'ftsbool', 'simple', '+"first" +"second"', [3, 4, 5]];
+ $cases[] = ['first second', 'ftsbool', 'phrase', '+"first second"', [3, 4, 5]];
+ $cases[] = ['first second', 'ftsbool', 'wildphrase', '+"*first second*"', [3, 4, 5]];
+ $cases[] = ['first second', 'ftsbool', 'wildwords', '+*first* +*second*', [3, 4, 5, 7]];
+ $cases[] = ['first second', 'ftsbool', 'wildwords-suffix', '+first* +second*', [3, 4, 5, 7]];
+
+ $cases[] = ['first second', 'solr', 'simple', 'first second', NULL];
+ $cases[] = ['first second', 'solr', 'phrase', '"first second"', NULL];
+ $cases[] = ['first second', 'solr', 'wildphrase', '"*first second*"', NULL];
+ $cases[] = ['first second', 'solr', 'wildwords', '*first* *second*', NULL];
+ $cases[] = ['first second', 'solr', 'wildwords-suffix', 'first* second*', NULL];
+
+ $cases[] = ['someone@', 'ftsbool', 'simple', '+"someone"', $allEmailRows];
+ $cases[] = ['@example.com', 'ftsbool', 'simple', '+"example.com"', $allEmailRows];
// If user supplies wildcards, then ignore mode.
- foreach (array(
+ foreach ([
'simple',
'wildphrase',
'wildwords',
'wildwords-suffix',
- ) as $mode) {
- $cases[] = array('first% second', 'like', $mode, 'first% second', array(3, 7));
- $cases[] = array('first% second', 'fts', $mode, 'first* second', array(3, 7));
- $cases[] = array('first% second', 'ftsbool', $mode, '+first* +second', array(3, 7));
- $cases[] = array('first% second', 'solr', $mode, 'first* second', NULL);
- $cases[] = array('first second%', 'like', $mode, 'first second%', array(3));
- $cases[] = array('first second%', 'fts', $mode, 'first second*', array(3));
- $cases[] = array('first second%', 'ftsbool', $mode, '+first +second*', array(3));
- $cases[] = array('first second%', 'solr', $mode, 'first second*', NULL);
+ ] as $mode) {
+ $cases[] = ['first% second', 'like', $mode, 'first% second', [3, 7]];
+ $cases[] = ['first% second', 'fts', $mode, 'first* second', [3, 7]];
+ $cases[] = ['first% second', 'ftsbool', $mode, '+first* +second', [3, 7]];
+ $cases[] = ['first% second', 'solr', $mode, 'first* second', NULL];
+ $cases[] = ['first second%', 'like', $mode, 'first second%', [3]];
+ $cases[] = ['first second%', 'fts', $mode, 'first second*', [3]];
+ $cases[] = ['first second%', 'ftsbool', $mode, '+first +second*', [3]];
+ $cases[] = ['first second%', 'solr', $mode, 'first second*', NULL];
}
return $cases;
$this->createExampleTable();
$this->assertSqlIds($expectedRowIds, "SELECT id FROM civicrm_fts_example WHERE " . $formatter->formatSql('civicrm_fts_example', 'name', $text));
}
- elseif (in_array($language, array('fts', 'ftsbool'))) {
+ elseif (in_array($language, ['fts', 'ftsbool'])) {
if ($this->supportsFts()) {
$this->createExampleTable();
$this->assertSqlIds($expectedRowIds, "SELECT id FROM civicrm_fts_example WHERE " . $formatter->formatSql('civicrm_fts_example', 'name', $text));
public function testProcessMultiple() {
$_SERVER['REQUEST_METHOD'] = 'POST';
- $input = array(
- 'cow' => array(
+ $input = [
+ 'cow' => [
'contact',
'create',
- array(
+ [
'contact_type' => 'Individual',
'first_name' => 'Cow',
- ),
- ),
- 'sheep' => array(
+ ],
+ ],
+ 'sheep' => [
'contact',
'create',
- array(
+ [
'contact_type' => 'Individual',
'first_name' => 'Sheep',
- ),
- ),
- );
+ ],
+ ],
+ ];
$_REQUEST['json'] = json_encode($input);
$output = CRM_Utils_REST::processMultiple();
$this->assertGreaterThan(0, $output['cow']['id']);
* @return array
*/
public function integerDataProvider() {
- return array(
- array(10, TRUE),
- array('145E+3', FALSE),
- array('10', TRUE),
- array(-10, TRUE),
- array('-10', TRUE),
- array('-10foo', FALSE),
- );
+ return [
+ [10, TRUE],
+ ['145E+3', FALSE],
+ ['10', TRUE],
+ [-10, TRUE],
+ ['-10', TRUE],
+ ['-10foo', FALSE],
+ ];
}
/**
* @return array
*/
public function positiveDataProvider() {
- return array(
- array(10, TRUE),
- array('145.0E+3', FALSE),
- array('10', TRUE),
- array(-10, FALSE),
- array('-10', FALSE),
- array('-10foo', FALSE),
- );
+ return [
+ [10, TRUE],
+ ['145.0E+3', FALSE],
+ ['10', TRUE],
+ [-10, FALSE],
+ ['-10', FALSE],
+ ['-10foo', FALSE],
+ ];
}
/**
* @return array
*/
public function numericDataProvider() {
- return array(
- array(10, TRUE),
- array('145.0E+3', FALSE),
- array('10', TRUE),
- array(-10, TRUE),
- array('-10', TRUE),
- array('-10foo', FALSE),
- );
+ return [
+ [10, TRUE],
+ ['145.0E+3', FALSE],
+ ['10', TRUE],
+ [-10, TRUE],
+ ['-10', TRUE],
+ ['-10foo', FALSE],
+ ];
}
/**
* @return array
*/
public function moneyDataProvider() {
- return array(
- array(10, TRUE),
- array('145.0E+3', FALSE),
- array('10', TRUE),
- array(-10, TRUE),
- array('-10', TRUE),
- array('-10foo', FALSE),
- array('-10.0345619', TRUE),
- array('-10.010,4345619', TRUE),
- array('10.0104345619', TRUE),
- array('-0', TRUE),
- array('-.1', TRUE),
- array('.1', TRUE),
+ return [
+ [10, TRUE],
+ ['145.0E+3', FALSE],
+ ['10', TRUE],
+ [-10, TRUE],
+ ['-10', TRUE],
+ ['-10foo', FALSE],
+ ['-10.0345619', TRUE],
+ ['-10.010,4345619', TRUE],
+ ['10.0104345619', TRUE],
+ ['-0', TRUE],
+ ['-.1', TRUE],
+ ['.1', TRUE],
// Test currency symbols too, default locale uses $, so if we wanted to test others we'd need to reconfigure locale
- array('$500.3333', TRUE),
- array('-$500.3333', TRUE),
- array('$-500.3333', TRUE),
- );
+ ['$500.3333', TRUE],
+ ['-$500.3333', TRUE],
+ ['$-500.3333', TRUE],
+ ];
}
/**
* @return array
*/
public function extenionKeyTests() {
- $keys = array();
- $keys[] = array('org.civicrm.multisite', TRUE);
- $keys[] = array('au.org.contribute2016', TRUE);
- $keys[] = array('%3Csvg%20onload=alert(0)%3E', FALSE);
+ $keys = [];
+ $keys[] = ['org.civicrm.multisite', TRUE];
+ $keys[] = ['au.org.contribute2016', TRUE];
+ $keys[] = ['%3Csvg%20onload=alert(0)%3E', FALSE];
return $keys;
}
public function testWherePlain() {
$del = CRM_Utils_SQL_Delete::from('foo')
->where('foo = bar')
- ->where(array('whiz = bang', 'frob > nicate'));
+ ->where(['whiz = bang', 'frob > nicate']);
$this->assertLike('DELETE FROM foo WHERE (foo = bar) AND (whiz = bang) AND (frob > nicate)', $del->toSQL());
}
public function testWhereArg() {
$del = CRM_Utils_SQL_Delete::from('foo')
- ->where('foo = @value', array('@value' => 'not"valid'))
- ->where(array('whiz > @base', 'frob != @base'), array('@base' => 'in"valid'));
+ ->where('foo = @value', ['@value' => 'not"valid'])
+ ->where(['whiz > @base', 'frob != @base'], ['@base' => 'in"valid']);
$this->assertLike('DELETE FROM foo WHERE (foo = "not\\"valid") AND (whiz > "in\\"valid") AND (frob != "in\\"valid")', $del->toSQL());
}
public function testWhereNullArg() {
$del = CRM_Utils_SQL_Delete::from('foo')
- ->where('foo IS @value', array('@value' => NULL))
+ ->where('foo IS @value', ['@value' => NULL])
->where('nonexistent IS @nonexistent', [])
->where('morenonexistent IS @nonexistent', NULL)
- ->where('bar IS @value', array('@value' => 'null'));
+ ->where('bar IS @value', ['@value' => 'null']);
$this->assertLike('DELETE FROM foo WHERE (foo IS NULL) AND (nonexistent IS @nonexistent) AND (morenonexistent IS @nonexistent) AND (bar IS "null")', $del->toSQL());
}
public function testRow_twice() {
$insert = CRM_Utils_SQL_Insert::into('foo')
- ->row(array('first' => '1', 'second' => '2'))
- ->row(array('second' => '2b', 'first' => '1b'));
+ ->row(['first' => '1', 'second' => '2'])
+ ->row(['second' => '2b', 'first' => '1b']);
$expected = '
INSERT INTO foo (`first`,`second`) VALUES
("1","2"),
public function testRows() {
$insert = CRM_Utils_SQL_Insert::into('foo')
- ->row(array('first' => '1', 'second' => '2'))
- ->rows(array(
- array('second' => '2b', 'first' => '1b'),
- array('first' => '1c', 'second' => '2c'),
- ))
- ->row(array('second' => '2d', 'first' => '1d'))
- ->row(array('first' => NULL, 'second' => '2e'));
+ ->row(['first' => '1', 'second' => '2'])
+ ->rows([
+ ['second' => '2b', 'first' => '1b'],
+ ['first' => '1c', 'second' => '2c'],
+ ])
+ ->row(['second' => '2d', 'first' => '1d'])
+ ->row(['first' => NULL, 'second' => '2e']);
$expected = '
INSERT INTO foo (`first`,`second`) VALUES
("1","2"),
public function testGetFields() {
$select = CRM_Utils_SQL_Select::from('foo')
->select('bar')
- ->select(array('whiz', 'bang'));
+ ->select(['whiz', 'bang']);
$this->assertLike('SELECT bar, whiz, bang FROM foo', $select->toSQL());
}
public function testWherePlain() {
$select = CRM_Utils_SQL_Select::from('foo')
->where('foo = bar')
- ->where(array('whiz = bang', 'frob > nicate'));
+ ->where(['whiz = bang', 'frob > nicate']);
$this->assertLike('SELECT * FROM foo WHERE (foo = bar) AND (whiz = bang) AND (frob > nicate)', $select->toSQL());
}
public function testWhereArg() {
$select = CRM_Utils_SQL_Select::from('foo')
- ->where('foo = @value', array('@value' => 'not"valid'))
- ->where(array('whiz > @base', 'frob != @base'), array('@base' => 'in"valid'));
+ ->where('foo = @value', ['@value' => 'not"valid'])
+ ->where(['whiz > @base', 'frob != @base'], ['@base' => 'in"valid']);
$this->assertLike('SELECT * FROM foo WHERE (foo = "not\\"valid") AND (whiz > "in\\"valid") AND (frob != "in\\"valid")', $select->toSQL());
}
public function testWhereNullArg() {
$select = CRM_Utils_SQL_Select::from('foo')
- ->where('foo IS @value', array('@value' => NULL))
+ ->where('foo IS @value', ['@value' => NULL])
->where('nonexistent IS @nonexistent', [])
->where('morenonexistent IS @nonexistent', NULL)
- ->where('bar IS @value', array('@value' => 'null'));
+ ->where('bar IS @value', ['@value' => 'null']);
$this->assertLike('SELECT * FROM foo WHERE (foo IS NULL) AND (nonexistent IS @nonexistent) AND (morenonexistent IS @nonexistent) AND (bar IS "null")', $select->toSQL());
}
public function testGroupByPlain() {
$select = CRM_Utils_SQL_Select::from('foo')
->groupBy("bar_id")
- ->groupBy(array('whiz_id*2', 'lower(bang)'));
+ ->groupBy(['whiz_id*2', 'lower(bang)']);
$this->assertLike('SELECT * FROM foo GROUP BY bar_id, whiz_id*2, lower(bang)', $select->toSQL());
}
$select = CRM_Utils_SQL_Select::from('foo')
->groupBy("bar_id")
->having('count(id) > 2')
- ->having(array('sum(id) > 10', 'avg(id) < 200'));
+ ->having(['sum(id) > 10', 'avg(id) < 200']);
$this->assertLike('SELECT * FROM foo GROUP BY bar_id HAVING (count(id) > 2) AND (sum(id) > 10) AND (avg(id) < 200)', $select->toSQL());
}
public function testHavingArg() {
$select = CRM_Utils_SQL_Select::from('foo')
->groupBy("bar_id")
- ->having('count(id) > #mincnt', array('#mincnt' => 2))
- ->having(array('sum(id) > #whiz', 'avg(id) < #whiz'), array('#whiz' => 10));
+ ->having('count(id) > #mincnt', ['#mincnt' => 2])
+ ->having(['sum(id) > #whiz', 'avg(id) < #whiz'], ['#whiz' => 10]);
$this->assertLike('SELECT * FROM foo GROUP BY bar_id HAVING (count(id) > 2) AND (sum(id) > 10) AND (avg(id) < 10)', $select->toSQL());
}
public function testOrderByPlain() {
$select = CRM_Utils_SQL_Select::from('foo bar')
->orderBy('first asc')
- ->orderBy(array('second desc', 'third'));
+ ->orderBy(['second desc', 'third']);
$this->assertLike('SELECT * FROM foo bar ORDER BY first asc, second desc, third', $select->toSQL());
}
}
public function testModeOutput() {
- $select = CRM_Utils_SQL_Select::from('foo', array('mode' => 'out'))
+ $select = CRM_Utils_SQL_Select::from('foo', ['mode' => 'out'])
->where('foo = @value')
- ->where(array(
+ ->where([
'whiz > @base',
'frob != @base',
- ))
+ ])
->param('@value', 'not"valid')
- ->param(array(
+ ->param([
'@base' => 'in"valid',
- ));
+ ]);
$this->assertLike('SELECT * FROM foo WHERE (foo = "not\\"valid") AND (whiz > "in\\"valid") AND (frob != "in\\"valid")', $select->toSQL());
try {
- CRM_Utils_SQL_Select::from('foo', array('mode' => 'out'))
- ->where('foo = @value', array('@value' => 'not"valid'));
+ CRM_Utils_SQL_Select::from('foo', ['mode' => 'out'])
+ ->where('foo = @value', ['@value' => 'not"valid']);
$this->fail('In output mode, we should reject requests to interpolate inputs.');
}
catch (Exception $e) {
$outputModeFragment = CRM_Utils_SQL_Select::fragment()
->param('value', 'whatever');
$inputModeFragment = CRM_Utils_SQL_Select::fragment()
- ->where('foo = @value', array('@value' => 'not"valid'));
+ ->where('foo = @value', ['@value' => 'not"valid']);
try {
$outputModeFragment->merge($inputModeFragment);
$this->fail('In output-mode, we should reject requests to merge from input-mode.');
->select('foo.id')
->join('rel1', 'INNER JOIN rel1_table rel1 ON foo.id = rel1.foo_id')
->join('rel2', 'LEFT JOIN rel2_table rel2 ON foo.id = rel2.foo_id')
- ->where('foo.type = @theType', array('@theType' => 'mytype'))
+ ->where('foo.type = @theType', ['@theType' => 'mytype'])
->groupBy("foo.id")
->having('sum(rel1.stat) > 10')
->orderBy('rel2.whiz')
*/
public function testNoIterativeInterpolation() {
$select = CRM_Utils_SQL_Select::from('foo')
- ->where('a = @a and b = @b and c = @c', array(
+ ->where('a = @a and b = @b and c = @c', [
'a' => '@b',
'b' => '@c',
'c' => '@a',
- ));
+ ]);
$this->assertLike('SELECT * FROM foo WHERE (a = "@b" and b = "@c" and c = "@a")', $select->toSQL());
}
public function testInterpolate() {
$actual = CRM_Utils_SQL_Select::from('ignore')->interpolate(
'@escaped !unescaped #validated',
- array(
+ [
'@escaped' => 'foo"bar',
'!unescaped' => 'concat(foo,bar)',
'#validated' => 15.2,
- )
+ ]
);
$this->assertLike('"foo\"bar" concat(foo,bar) 15.2', $actual);
}
public function testInterpolateWildcard() {
$actual = CRM_Utils_SQL_Select::from('ignore')->interpolate(
'escaped @escaped unescaped !unescaped validated #validated',
- array(
+ [
'escaped' => 'foo"bar',
'unescaped' => 'concat(foo,bar)',
'validated' => 15.2,
- )
+ ]
);
$this->assertLike('escaped "foo\"bar" unescaped concat(foo,bar) validated 15.2', $actual);
}
public function testInterpolateUnknown() {
$actual = CRM_Utils_SQL_Select::from('ignore')->interpolate(
'escaped @escaped unescaped !unescaped validated #validated',
- array(
+ [
'irrelevant' => 'foo',
- )
+ ]
);
$this->assertLike('escaped @escaped unescaped !unescaped validated #validated', $actual);
}
CRM_Utils_SQL_Select::from('ignore')
->strict()
->interpolate('@johnMcClane',
- array(
+ [
'irrelevant' => 'foo',
- )
+ ]
);
$this->fail('Unknown variables should throw errors in strict mode.');
}
public function testInterpolateArray() {
$actual = CRM_Utils_SQL_Select::from('ignore')->interpolate(
'(@escaped) (!unescaped) (#validated)',
- array(
- '@escaped' => array('foo"bar', "whiz", "null", NULL, "bang"),
- '!unescaped' => array('foo"bar', 'bar'),
- '#validated' => array(1, 10, NULL, 100.1),
- )
+ [
+ '@escaped' => ['foo"bar', "whiz", "null", NULL, "bang"],
+ '!unescaped' => ['foo"bar', 'bar'],
+ '#validated' => [1, 10, NULL, 100.1],
+ ]
);
$this->assertLike('("foo\\"bar", "whiz", "null", NULL, "bang") (foo"bar, bar) (1, 10, NULL, 100.1)', $actual);
}
public function testInterpolateBadNumber() {
try {
- $result = CRM_Utils_SQL_Select::from('ignore')->interpolate('#num', array(
+ $result = CRM_Utils_SQL_Select::from('ignore')->interpolate('#num', [
'#num' => '5not-a-number5',
- ));
+ ]);
$this->fail('Expected exception; got: ' . var_export($result, TRUE));
}
catch (CRM_Core_Exception $e) {
}
try {
- $result = CRM_Utils_SQL_Select::from('ignore')->interpolate('#num', array(
- '#num' => array(1, '5not-a-number5', 2),
- ));
+ $result = CRM_Utils_SQL_Select::from('ignore')->interpolate('#num', [
+ '#num' => [1, '5not-a-number5', 2],
+ ]);
$this->fail('Expected exception; got: ' . var_export($result, TRUE));
}
catch (CRM_Core_Exception $e) {
public function testMerge() {
$fragmentOutMode = CRM_Utils_SQL_Select::fragment()
- ->select(array('a', 'b'))
+ ->select(['a', 'b'])
->where('a = #two')
->param('two', 2);
$fragmentAutoMode = CRM_Utils_SQL_Select::fragment()
->select('e')
->where('whipit()');
$query = CRM_Utils_SQL_Select::from('foo')
- ->select(array('c', 'd'))
+ ->select(['c', 'd'])
->where('c = @four')
->param('four', 4)
->merge($fragmentOutMode)
public function testInsertInto_WithDupes() {
$select = CRM_Utils_SQL_Select::from('foo')
- ->insertInto('bar', array('first', 'second', 'third', 'fourth'))
+ ->insertInto('bar', ['first', 'second', 'third', 'fourth'])
->select('fid')
->select('1')
->select('fid')
->select('1')
- ->where('!field = #value', array('field' => 'zoo', 'value' => 3))
- ->where('!field = #value', array('field' => 'aviary', 'value' => 3))
- ->where('!field = #value', array('field' => 'zoo', 'value' => 3))
- ->groupBy('!colName', array('colName' => 'noodle'))
- ->groupBy('!colName', array('colName' => 'sauce'))
- ->groupBy('!colName', array('colName' => 'noodle'));
+ ->where('!field = #value', ['field' => 'zoo', 'value' => 3])
+ ->where('!field = #value', ['field' => 'aviary', 'value' => 3])
+ ->where('!field = #value', ['field' => 'zoo', 'value' => 3])
+ ->groupBy('!colName', ['colName' => 'noodle'])
+ ->groupBy('!colName', ['colName' => 'sauce'])
+ ->groupBy('!colName', ['colName' => 'noodle']);
$this->assertLike('INSERT INTO bar (first, second, third, fourth) SELECT fid, 1, fid, 1 FROM foo WHERE (zoo = 3) AND (aviary = 3) GROUP BY noodle, sauce', $select->toSQL());
}
}
public function testSignValidate() {
- $cases = array();
- $cases[] = array(
- 'signParams' => array(
+ $cases = [];
+ $cases[] = [
+ 'signParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => NULL,
- ),
- 'validateParams' => array(
+ ],
+ 'validateParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => NULL,
- ),
+ ],
'isValid' => TRUE,
- );
- $cases[] = array(
- 'signParams' => array(
+ ];
+ $cases[] = [
+ 'signParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => NULL,
- ),
- 'validateParams' => array(
+ ],
+ 'validateParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => NULL,
'irrelevant' => 'totally-irrelevant',
- ),
+ ],
'isValid' => TRUE,
- );
- $cases[] = array(
- 'signParams' => array(
+ ];
+ $cases[] = [
+ 'signParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => NULL,
- ),
- 'validateParams' => array(
+ ],
+ 'validateParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => '',
- ),
+ ],
'isValid' => TRUE,
- );
- $cases[] = array(
- 'signParams' => array(
+ ];
+ $cases[] = [
+ 'signParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => NULL,
- ),
- 'validateParams' => array(
+ ],
+ 'validateParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => 0,
- ),
+ ],
'isValid' => FALSE,
- );
- $cases[] = array(
- 'signParams' => array(
+ ];
+ $cases[] = [
+ 'signParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => 0,
- ),
- 'validateParams' => array(
+ ],
+ 'validateParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => NULL,
- ),
+ ],
'isValid' => FALSE,
- );
- $cases[] = array(
- 'signParams' => array(
+ ];
+ $cases[] = [
+ 'signParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => NULL,
- ),
- 'validateParams' => array(
+ ],
+ 'validateParams' => [
'a' => 'eh',
'b' => 'bay',
'c' => NULL,
- ),
+ ],
'isValid' => FALSE,
- );
- $cases[] = array(
- 'signParams' => array(
+ ];
+ $cases[] = [
+ 'signParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => NULL,
- ),
- 'validateParams' => array(
+ ],
+ 'validateParams' => [
'a' => 'eh',
'b' => 'bee',
'c' => FALSE,
- ),
+ ],
'isValid' => FALSE,
- );
- $cases[] = array(
- 'signParams' => array(
+ ];
+ $cases[] = [
+ 'signParams' => [
// int
'a' => 1,
'b' => 'bee',
- ),
- 'validateParams' => array(
+ ],
+ 'validateParams' => [
// string
'a' => '1',
'b' => 'bee',
- ),
+ ],
'isValid' => TRUE,
- );
+ ];
foreach ($cases as $caseId => $case) {
- $signer = new CRM_Utils_Signer('secret', array('a', 'b', 'c'));
+ $signer = new CRM_Utils_Signer('secret', ['a', 'b', 'c']);
$signature = $signer->sign($case['signParams']);
// arbitrary
$this->assertTrue(!empty($signature) && is_string($signature));
// same as $signer but physically separate
- $validator = new CRM_Utils_Signer('secret', array('a', 'b', 'c'));
+ $validator = new CRM_Utils_Signer('secret', ['a', 'b', 'c']);
$isValid = $validator->validate($signature, $case['validateParams']);
if ($isValid !== $case['isValid']) {
}
public function testStripPathChars() {
- $testSet = array(
+ $testSet = [
'' => '',
NULL => NULL,
'civicrm' => 'civicrm',
'civicrm/contribute/transact' => 'civicrm/contribute/transact',
'civicrm/<hack>attempt</hack>' => 'civicrm/_hack_attempt_/hack_',
'civicrm dashboard & force = 1,;' => 'civicrm_dashboard___force___1__',
- );
+ ];
foreach ($testSet as $in => $expected) {
$out = CRM_Utils_String::stripPathChars($in);
}
public function testExtractName() {
- $cases = array(
- array(
+ $cases = [
+ [
'full_name' => 'Alan',
'first_name' => 'Alan',
- ),
- array(
+ ],
+ [
'full_name' => 'Alan Arkin',
'first_name' => 'Alan',
'last_name' => 'Arkin',
- ),
- array(
+ ],
+ [
'full_name' => '"Alan Arkin"',
'first_name' => 'Alan',
'last_name' => 'Arkin',
- ),
- array(
+ ],
+ [
'full_name' => 'Alan A Arkin',
'first_name' => 'Alan',
'middle_name' => 'A',
'last_name' => 'Arkin',
- ),
- array(
+ ],
+ [
'full_name' => 'Adams, Amy',
'first_name' => 'Amy',
'last_name' => 'Adams',
- ),
- array(
+ ],
+ [
'full_name' => 'Adams, Amy A',
'first_name' => 'Amy',
'middle_name' => 'A',
'last_name' => 'Adams',
- ),
- array(
+ ],
+ [
'full_name' => '"Adams, Amy A"',
'first_name' => 'Amy',
'middle_name' => 'A',
'last_name' => 'Adams',
- ),
- );
+ ],
+ ];
foreach ($cases as $case) {
- $actual = array();
+ $actual = [];
CRM_Utils_String::extractName($case['full_name'], $actual);
$this->assertEquals($actual['first_name'], $case['first_name']);
$this->assertEquals(CRM_Utils_Array::value('last_name', $actual), CRM_Utils_Array::value('last_name', $case));
public function testEllipsify() {
$maxLen = 5;
- $cases = array(
+ $cases = [
'1' => '1',
'12345' => '12345',
'123456' => '12...',
- );
+ ];
foreach ($cases as $input => $expected) {
$this->assertEquals($expected, CRM_Utils_String::ellipsify($input, $maxLen));
}
* @return array
*/
public function parsePrefixData() {
- $cases = array();
- $cases[] = array('administer CiviCRM', NULL, array(NULL, 'administer CiviCRM'));
- $cases[] = array('administer CiviCRM', 'com_civicrm', array('com_civicrm', 'administer CiviCRM'));
- $cases[] = array('Drupal:access user profiles', NULL, array('Drupal', 'access user profiles'));
- $cases[] = array('Joomla:component:perm', NULL, array('Joomla', 'component:perm'));
+ $cases = [];
+ $cases[] = ['administer CiviCRM', NULL, [NULL, 'administer CiviCRM']];
+ $cases[] = ['administer CiviCRM', 'com_civicrm', ['com_civicrm', 'administer CiviCRM']];
+ $cases[] = ['Drupal:access user profiles', NULL, ['Drupal', 'access user profiles']];
+ $cases[] = ['Joomla:component:perm', NULL, ['Joomla', 'component:perm']];
return $cases;
}
*/
public function booleanDataProvider() {
// array(0 => $input, 1 => $expectedOutput)
- $cases = array();
- $cases[] = array(TRUE, TRUE);
- $cases[] = array(FALSE, FALSE);
- $cases[] = array(1, TRUE);
- $cases[] = array(0, FALSE);
- $cases[] = array('1', TRUE);
- $cases[] = array('0', FALSE);
- $cases[] = array(TRUE, TRUE);
- $cases[] = array(FALSE, FALSE);
- $cases[] = array('Y', TRUE);
- $cases[] = array('N', FALSE);
- $cases[] = array('y', TRUE);
- $cases[] = array('n', FALSE);
- $cases[] = array('Yes', TRUE);
- $cases[] = array('No', FALSE);
- $cases[] = array('True', TRUE);
- $cases[] = array('False', FALSE);
- $cases[] = array('yEs', TRUE);
- $cases[] = array('nO', FALSE);
- $cases[] = array('tRuE', TRUE);
- $cases[] = array('FaLsE', FALSE);
+ $cases = [];
+ $cases[] = [TRUE, TRUE];
+ $cases[] = [FALSE, FALSE];
+ $cases[] = [1, TRUE];
+ $cases[] = [0, FALSE];
+ $cases[] = ['1', TRUE];
+ $cases[] = ['0', FALSE];
+ $cases[] = [TRUE, TRUE];
+ $cases[] = [FALSE, FALSE];
+ $cases[] = ['Y', TRUE];
+ $cases[] = ['N', FALSE];
+ $cases[] = ['y', TRUE];
+ $cases[] = ['n', FALSE];
+ $cases[] = ['Yes', TRUE];
+ $cases[] = ['No', FALSE];
+ $cases[] = ['True', TRUE];
+ $cases[] = ['False', FALSE];
+ $cases[] = ['yEs', TRUE];
+ $cases[] = ['nO', FALSE];
+ $cases[] = ['tRuE', TRUE];
+ $cases[] = ['FaLsE', FALSE];
return $cases;
}
}
public function startEndCases() {
- $cases = array();
- $cases[] = array('startsWith', 'foo', '', TRUE);
- $cases[] = array('startsWith', 'foo', 'f', TRUE);
- $cases[] = array('startsWith', 'foo', 'fo', TRUE);
- $cases[] = array('startsWith', 'foo', 'foo', TRUE);
- $cases[] = array('startsWith', 'foo', 'fooo', FALSE);
- $cases[] = array('startsWith', 'foo', 'o', FALSE);
- $cases[] = array('endsWith', 'foo', 'f', FALSE);
- $cases[] = array('endsWith', 'foo', '', TRUE);
- $cases[] = array('endsWith', 'foo', 'o', TRUE);
- $cases[] = array('endsWith', 'foo', 'oo', TRUE);
- $cases[] = array('endsWith', 'foo', 'foo', TRUE);
- $cases[] = array('endsWith', 'foo', 'fooo', FALSE);
- $cases[] = array('endsWith', 'foo*', '*', TRUE);
+ $cases = [];
+ $cases[] = ['startsWith', 'foo', '', TRUE];
+ $cases[] = ['startsWith', 'foo', 'f', TRUE];
+ $cases[] = ['startsWith', 'foo', 'fo', TRUE];
+ $cases[] = ['startsWith', 'foo', 'foo', TRUE];
+ $cases[] = ['startsWith', 'foo', 'fooo', FALSE];
+ $cases[] = ['startsWith', 'foo', 'o', FALSE];
+ $cases[] = ['endsWith', 'foo', 'f', FALSE];
+ $cases[] = ['endsWith', 'foo', '', TRUE];
+ $cases[] = ['endsWith', 'foo', 'o', TRUE];
+ $cases[] = ['endsWith', 'foo', 'oo', TRUE];
+ $cases[] = ['endsWith', 'foo', 'foo', TRUE];
+ $cases[] = ['endsWith', 'foo', 'fooo', FALSE];
+ $cases[] = ['endsWith', 'foo*', '*', TRUE];
return $cases;
}
}
public function wildcardCases() {
- $cases = array();
- $cases[] = array('*', array('foo.bar.1', 'foo.bar.2', 'foo.whiz', 'bang.bang'));
- $cases[] = array('foo.*', array('foo.bar.1', 'foo.bar.2', 'foo.whiz'));
- $cases[] = array('foo.bar.*', array('foo.bar.1', 'foo.bar.2'));
- $cases[] = array(array('foo.bar.*', 'foo.bar.2'), array('foo.bar.1', 'foo.bar.2'));
- $cases[] = array(array('foo.bar.2', 'foo.w*'), array('foo.bar.2', 'foo.whiz'));
+ $cases = [];
+ $cases[] = ['*', ['foo.bar.1', 'foo.bar.2', 'foo.whiz', 'bang.bang']];
+ $cases[] = ['foo.*', ['foo.bar.1', 'foo.bar.2', 'foo.whiz']];
+ $cases[] = ['foo.bar.*', ['foo.bar.1', 'foo.bar.2']];
+ $cases[] = [['foo.bar.*', 'foo.bar.2'], ['foo.bar.1', 'foo.bar.2']];
+ $cases[] = [['foo.bar.2', 'foo.w*'], ['foo.bar.2', 'foo.whiz']];
return $cases;
}
* @dataProvider wildcardCases
*/
public function testFilterByWildCards($patterns, $expectedResults) {
- $data = array('foo.bar.1', 'foo.bar.2', 'foo.whiz', 'bang.bang');
+ $data = ['foo.bar.1', 'foo.bar.2', 'foo.whiz', 'bang.bang'];
$actualResults = CRM_Utils_String::filterByWildcards($patterns, $data);
$this->assertEquals($expectedResults, $actualResults);
$this->assertEquals($expectedResults, $actualResults);
$actualResults = CRM_Utils_String::filterByWildcards($patterns, $data, TRUE);
- $this->assertEquals(array_merge($expectedResults, array('noise')), $actualResults);
+ $this->assertEquals(array_merge($expectedResults, ['noise']), $actualResults);
}
/**
$externalDomain = 'example.net';
}
- return array(
- 'prototypical example' => array(
+ return [
+ 'prototypical example' => [
"https://$localDomain/sites/default/files/coffee-mug.jpg",
FALSE,
'/sites/default/files/coffee-mug.jpg',
- ),
- 'external domain with https' => array(
+ ],
+ 'external domain with https' => [
"https://$externalDomain/sites/default/files/coffee-mug.jpg",
FALSE,
"https://$externalDomain/sites/default/files/coffee-mug.jpg",
- ),
- 'external domain with http forced to https' => array(
+ ],
+ 'external domain with http forced to https' => [
"http://$externalDomain/sites/default/files/coffee-mug.jpg",
TRUE,
"https://$externalDomain/sites/default/files/coffee-mug.jpg",
- ),
- 'external domain with http not forced' => array(
+ ],
+ 'external domain with http not forced' => [
"http://$externalDomain/sites/default/files/coffee-mug.jpg",
FALSE,
"http://$externalDomain/sites/default/files/coffee-mug.jpg",
- ),
- 'local URL' => array(
+ ],
+ 'local URL' => [
"/sites/default/files/coffee-mug.jpg",
FALSE,
"/sites/default/files/coffee-mug.jpg",
- ),
- 'local URL without a forward slash' => array(
+ ],
+ 'local URL without a forward slash' => [
"sites/default/files/coffee-mug.jpg",
FALSE,
"/sites/default/files/coffee-mug.jpg",
- ),
- 'empty input' => array(
+ ],
+ 'empty input' => [
'',
FALSE,
'',
- ),
- );
+ ],
+ ];
}
/**
* @return array
*/
public function parseURLProvider() {
- return array(
- "prototypical example" => array(
+ return [
+ "prototypical example" => [
"https://example.com:8000/foo/bar/?id=1#fragment",
- array(
+ [
'host+port' => "example.com:8000",
'path+query' => "/foo/bar/?id=1",
- ),
- ),
- "default port example" => array(
+ ],
+ ],
+ "default port example" => [
"https://example.com/foo/bar/?id=1#fragment",
- array(
+ [
'host+port' => "example.com",
'path+query' => "/foo/bar/?id=1",
- ),
- ),
- "empty" => array(
+ ],
+ ],
+ "empty" => [
"",
- array(
+ [
'host+port' => "",
'path+query' => "",
- ),
- ),
- "path only" => array(
+ ],
+ ],
+ "path only" => [
"/foo/bar/image.png",
- array(
+ [
'host+port' => "",
'path+query' => "/foo/bar/image.png",
- ),
- ),
- );
+ ],
+ ],
+ ];
}
public function purifyHTMLProvider() {
$config = CRM_Core_Config::singleton();
$this->assertTrue($config->userSystem instanceof CRM_Utils_System_UnitTests);
$expected = '/index.php?q=civicrm/foo/bar&foo=ab&bar=cd%26ef';
- $actual = CRM_Utils_System::url('civicrm/foo/bar', array(
+ $actual = CRM_Utils_System::url('civicrm/foo/bar', [
'foo' => 'ab',
'bar' => 'cd&ef',
- ), FALSE, NULL, FALSE);
+ ], FALSE, NULL, FALSE);
$this->assertEquals($expected, $actual);
}
* @dataProvider getURLs
*/
public function testRedirectHook($url, $parsedUrl) {
- $this->hookClass->setHook('civicrm_alterRedirect', array($this, 'hook_civicrm_alterRedirect'));
+ $this->hookClass->setHook('civicrm_alterRedirect', [$this, 'hook_civicrm_alterRedirect']);
try {
CRM_Utils_System::redirect($url, [
'expected' => $parsedUrl,
*/
public function equalCases() {
// array(0 => $timeA, 1 => $timeB, 2 => $threshold, 3 => $expectedResult)
- $cases = array();
- $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:00:00', 0, 1);
- $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:00:01', 0, 0);
- $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:00:50', 60, 1);
- $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:01:02', 60, 0);
- $cases[] = array('2012-04-01 12:00', '2012-04-01 12:01', 0, 0);
- $cases[] = array('2012-04-01 12:00', '2012-04-01 12:01', 60, 1);
- $cases[] = array('2012-04-01 12:00', '2012-04-01 12:01', 120, 1);
+ $cases = [];
+ $cases[] = ['2012-04-01 12:00:00', '2012-04-01 12:00:00', 0, 1];
+ $cases[] = ['2012-04-01 12:00:00', '2012-04-01 12:00:01', 0, 0];
+ $cases[] = ['2012-04-01 12:00:00', '2012-04-01 12:00:50', 60, 1];
+ $cases[] = ['2012-04-01 12:00:00', '2012-04-01 12:01:02', 60, 0];
+ $cases[] = ['2012-04-01 12:00', '2012-04-01 12:01', 0, 0];
+ $cases[] = ['2012-04-01 12:00', '2012-04-01 12:01', 60, 1];
+ $cases[] = ['2012-04-01 12:00', '2012-04-01 12:01', 120, 1];
return $cases;
}
* Basic test on getTokenDetails function.
*/
public function testGetTokenDetails() {
- $contactID = $this->individualCreate(array('preferred_communication_method' => array('Phone', 'Fax')));
- $resolvedTokens = CRM_Utils_Token::getTokenDetails(array($contactID));
+ $contactID = $this->individualCreate(['preferred_communication_method' => ['Phone', 'Fax']]);
+ $resolvedTokens = CRM_Utils_Token::getTokenDetails([$contactID]);
$this->assertEquals('Phone, Fax', $resolvedTokens[0][$contactID]['preferred_communication_method']);
}
// create a contact with multiple email address and among which one is primary
$contactID = $this->individualCreate();
$primaryEmail = uniqid() . '@primary.com';
- $this->callAPISuccess('Email', 'create', array(
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => $primaryEmail,
'location_type_id' => 'Other',
'is_primary' => 1,
- ));
- $this->callAPISuccess('Email', 'create', array(
+ ]);
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => uniqid() . '@galaxy.com',
'location_type_id' => 'Work',
'is_primary' => 0,
- ));
- $this->callAPISuccess('Email', 'create', array(
+ ]);
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => uniqid() . '@galaxy.com',
'location_type_id' => 'Work',
'is_primary' => 0,
- ));
+ ]);
- $contactIDs = array($contactID);
+ $contactIDs = [$contactID];
// when we are fetching contact details ON basis of primary address fields
$contactDetails = CRM_Utils_Token::getTokenDetails($contactIDs);
*/
public function testReplaceGreetingTokens() {
$tokenString = 'First Name: {contact.first_name} Last Name: {contact.last_name} Birth Date: {contact.birth_date} Prefix: {contact.prefix_id} Suffix: {contact.individual_suffix}';
- $contactDetails = array(
- array(
- 2811 => array(
+ $contactDetails = [
+ [
+ 2811 => [
'id' => '2811',
'contact_type' => 'Individual',
'first_name' => 'Morticia',
'last_name' => 'Addams',
'prefix_id' => 2,
- ),
- ),
- );
+ ],
+ ],
+ ];
$contactId = 2811;
$className = 'CRM_Contact_BAO_Contact';
$escapeSmarty = TRUE;
public function testGetTokenDetailsMultipleEmails() {
$i = 0;
- $params = array(
+ $params = [
'do_not_phone' => 1,
'do_not_email' => 0,
'do_not_mail' => 1,
'gender_id' => '1',
'birth_date' => '2017-01-01',
// 'city' => 'Metropolis',
- );
- $contactIDs = array();
+ ];
+ $contactIDs = [];
while ($i < 27) {
$contactIDs[] = $contactID = $this->individualCreate($params);
- $this->callAPISuccess('Email', 'create', array(
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => 'goodguy@galaxy.com',
'location_type_id' => 'Other',
'is_primary' => 0,
- ));
- $this->callAPISuccess('Email', 'create', array(
+ ]);
+ $this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'email' => 'villain@galaxy.com',
'location_type_id' => 'Work',
'is_primary' => 1,
- ));
+ ]);
$i++;
}
unset($params['email']);
* @return array
*/
public function validateDataProvider() {
- return array(
- array(10, 'Int', 10),
- array('145E+3', 'Int', NULL),
- array('10', 'Integer', 10),
- array(-10, 'Int', -10),
- array('-10', 'Integer', -10),
- array('-10foo', 'Int', NULL),
- array(10, 'Positive', 10),
- array('145.0E+3', 'Positive', NULL),
- array('10', 'Positive', 10),
- array(-10, 'Positive', NULL),
- array('-10', 'Positive', NULL),
- array('-10foo', 'Positive', NULL),
- array('civicrm_column_name', 'MysqlColumnNameOrAlias', 'civicrm_column_name'),
- array('table.civicrm_column_name', 'MysqlColumnNameOrAlias', 'table.civicrm_column_name'),
- array('table.civicrm_column_name.toomanydots', 'MysqlColumnNameOrAlias', NULL),
- array('Home-street_address', 'MysqlColumnNameOrAlias', 'Home-street_address'),
- array('`Home-street_address`', 'MysqlColumnNameOrAlias', '`Home-street_address`'),
- array('`Home-street_address', 'MysqlColumnNameOrAlias', NULL),
- array('table.`Home-street_address`', 'MysqlColumnNameOrAlias', 'table.`Home-street_address`'),
- array('`table-alias`.`Home-street_address`', 'MysqlColumnNameOrAlias', '`table-alias`.`Home-street_address`'),
- array('`table-alias`.column', 'MysqlColumnNameOrAlias', '`table-alias`.column'),
+ return [
+ [10, 'Int', 10],
+ ['145E+3', 'Int', NULL],
+ ['10', 'Integer', 10],
+ [-10, 'Int', -10],
+ ['-10', 'Integer', -10],
+ ['-10foo', 'Int', NULL],
+ [10, 'Positive', 10],
+ ['145.0E+3', 'Positive', NULL],
+ ['10', 'Positive', 10],
+ [-10, 'Positive', NULL],
+ ['-10', 'Positive', NULL],
+ ['-10foo', 'Positive', NULL],
+ ['civicrm_column_name', 'MysqlColumnNameOrAlias', 'civicrm_column_name'],
+ ['table.civicrm_column_name', 'MysqlColumnNameOrAlias', 'table.civicrm_column_name'],
+ ['table.civicrm_column_name.toomanydots', 'MysqlColumnNameOrAlias', NULL],
+ ['Home-street_address', 'MysqlColumnNameOrAlias', 'Home-street_address'],
+ ['`Home-street_address`', 'MysqlColumnNameOrAlias', '`Home-street_address`'],
+ ['`Home-street_address', 'MysqlColumnNameOrAlias', NULL],
+ ['table.`Home-street_address`', 'MysqlColumnNameOrAlias', 'table.`Home-street_address`'],
+ ['`table-alias`.`Home-street_address`', 'MysqlColumnNameOrAlias', '`table-alias`.`Home-street_address`'],
+ ['`table-alias`.column', 'MysqlColumnNameOrAlias', '`table-alias`.column'],
// Spaces also permitted, only when enclosed in backticks.
- array('`column alias`', 'MysqlColumnNameOrAlias', '`column alias`'),
- array('`table alias`.column', 'MysqlColumnNameOrAlias', '`table alias`.column'),
- array('`table alias`.`column alias`', 'MysqlColumnNameOrAlias', '`table alias`.`column alias`'),
- array('table alias.column alias', 'MysqlColumnNameOrAlias', NULL),
- array('table alias.column_alias', 'MysqlColumnNameOrAlias', NULL),
- array('table_alias.column alias', 'MysqlColumnNameOrAlias', NULL),
+ ['`column alias`', 'MysqlColumnNameOrAlias', '`column alias`'],
+ ['`table alias`.column', 'MysqlColumnNameOrAlias', '`table alias`.column'],
+ ['`table alias`.`column alias`', 'MysqlColumnNameOrAlias', '`table alias`.`column alias`'],
+ ['table alias.column alias', 'MysqlColumnNameOrAlias', NULL],
+ ['table alias.column_alias', 'MysqlColumnNameOrAlias', NULL],
+ ['table_alias.column alias', 'MysqlColumnNameOrAlias', NULL],
// Functions are not permitted.
- array('column_name, sleep(5)', 'MysqlColumnNameOrAlias', NULL),
+ ['column_name, sleep(5)', 'MysqlColumnNameOrAlias', NULL],
// Length checking permits only 64 chars.
- array(str_repeat('a', 64), 'MysqlColumnNameOrAlias', str_repeat('a', 64)),
- array(str_repeat('a', 65), 'MysqlColumnNameOrAlias', NULL),
- array(str_repeat('a', 64) . '.' . str_repeat('a', 64), 'MysqlColumnNameOrAlias', str_repeat('a', 64) . '.' . str_repeat('a', 64)),
- array('`' . str_repeat('a', 64) . '`.`' . str_repeat('b', 64) . '`', 'MysqlColumnNameOrAlias', '`' . str_repeat('a', 64) . '`.`' . str_repeat('b', 64) . '`'),
- array(str_repeat('a', 64) . '.' . str_repeat('a', 65), 'MysqlColumnNameOrAlias', NULL),
- array(str_repeat('a', 65) . '.' . str_repeat('a', 64), 'MysqlColumnNameOrAlias', NULL),
+ [str_repeat('a', 64), 'MysqlColumnNameOrAlias', str_repeat('a', 64)],
+ [str_repeat('a', 65), 'MysqlColumnNameOrAlias', NULL],
+ [str_repeat('a', 64) . '.' . str_repeat('a', 64), 'MysqlColumnNameOrAlias', str_repeat('a', 64) . '.' . str_repeat('a', 64)],
+ ['`' . str_repeat('a', 64) . '`.`' . str_repeat('b', 64) . '`', 'MysqlColumnNameOrAlias', '`' . str_repeat('a', 64) . '`.`' . str_repeat('b', 64) . '`'],
+ [str_repeat('a', 64) . '.' . str_repeat('a', 65), 'MysqlColumnNameOrAlias', NULL],
+ [str_repeat('a', 65) . '.' . str_repeat('a', 64), 'MysqlColumnNameOrAlias', NULL],
// ORDER BY can be ASC or DESC, case not significant.
- array('asc', 'MysqlOrderByDirection', 'asc'),
- array('DESC', 'MysqlOrderByDirection', 'desc'),
- array('DESCc', 'MysqlOrderByDirection', NULL),
- array('table.civicrm_column_name desc', 'MysqlOrderBy', 'table.civicrm_column_name desc'),
- array('field(civicrm_column_name,4,5,6)', 'MysqlOrderBy', 'field(civicrm_column_name,4,5,6)'),
- array('field(table.civicrm_column_name,4,5,6)', 'MysqlOrderBy', 'field(table.civicrm_column_name,4,5,6)'),
- array('table.civicrm_column_name desc,other_column, another_column desc', 'MysqlOrderBy', 'table.civicrm_column_name desc,other_column, another_column desc'),
- array('table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column', 'MysqlOrderBy', 'table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column'),
+ ['asc', 'MysqlOrderByDirection', 'asc'],
+ ['DESC', 'MysqlOrderByDirection', 'desc'],
+ ['DESCc', 'MysqlOrderByDirection', NULL],
+ ['table.civicrm_column_name desc', 'MysqlOrderBy', 'table.civicrm_column_name desc'],
+ ['field(civicrm_column_name,4,5,6)', 'MysqlOrderBy', 'field(civicrm_column_name,4,5,6)'],
+ ['field(table.civicrm_column_name,4,5,6)', 'MysqlOrderBy', 'field(table.civicrm_column_name,4,5,6)'],
+ ['table.civicrm_column_name desc,other_column, another_column desc', 'MysqlOrderBy', 'table.civicrm_column_name desc,other_column, another_column desc'],
+ ['table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column', 'MysqlOrderBy', 'table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column'],
// Lab issue dev/core#93 allow for 3 column orderby
- array('contact_id.gender_id.label', 'MysqlOrderBy', 'contact_id.gender_id.label'),
- array('a string', 'String', 'a string'),
- array('{"contact":{"contact_id":205}}', 'Json', '{"contact":{"contact_id":205}}'),
- array('{"contact":{"contact_id":!n†rude®}}', 'Json', NULL),
- );
+ ['contact_id.gender_id.label', 'MysqlOrderBy', 'contact_id.gender_id.label'],
+ ['a string', 'String', 'a string'],
+ ['{"contact":{"contact_id":205}}', 'Json', '{"contact":{"contact_id":205}}'],
+ ['{"contact":{"contact_id":!n†rude®}}', 'Json', NULL],
+ ];
}
/**
* @return array
*/
public function escapeDataProvider() {
- return array(
- array(10, 'Int', 10),
- array('145E+3', 'Int', NULL),
- array('10', 'Integer', 10),
- array(-10, 'Int', -10),
- array(array(), 'Integer', NULL),
- array('-10foo', 'Int', NULL),
- array(10, 'Positive', 10),
- array('145.0E+3', 'Positive', NULL),
- array('10', 'Positive', 10),
- array(-10, 'Positive', NULL),
- array('-10', 'Positive', NULL),
- array('-10foo', 'Positive', NULL),
- array(array('10', 20), 'Country', array('10', 20)),
- array(array('10', '-10foo'), 'Country', NULL),
- array('', 'Timestamp', ''),
- array('', 'ContactReference', ''),
- array('3', 'ContactReference', 3),
- array('-3', 'ContactReference', NULL),
+ return [
+ [10, 'Int', 10],
+ ['145E+3', 'Int', NULL],
+ ['10', 'Integer', 10],
+ [-10, 'Int', -10],
+ [[], 'Integer', NULL],
+ ['-10foo', 'Int', NULL],
+ [10, 'Positive', 10],
+ ['145.0E+3', 'Positive', NULL],
+ ['10', 'Positive', 10],
+ [-10, 'Positive', NULL],
+ ['-10', 'Positive', NULL],
+ ['-10foo', 'Positive', NULL],
+ [['10', 20], 'Country', ['10', 20]],
+ [['10', '-10foo'], 'Country', NULL],
+ ['', 'Timestamp', ''],
+ ['', 'ContactReference', ''],
+ ['3', 'ContactReference', 3],
+ ['-3', 'ContactReference', NULL],
// Escape function is meant for sql, not xss
- array('<p onclick="alert(\'xss\');">Hello</p>', 'Memo', '<p onclick=\\"alert(\\\'xss\\\');\\">Hello</p>'),
- array('civicrm_column_name', 'MysqlColumnNameOrAlias', '`civicrm_column_name`'),
- array('table.civicrm_column_name', 'MysqlColumnNameOrAlias', '`table`.`civicrm_column_name`'),
- array('table.civicrm_column_name.toomanydots', 'MysqlColumnNameOrAlias', NULL),
- array('Home-street_address', 'MysqlColumnNameOrAlias', '`Home-street_address`'),
- array('`Home-street_address`', 'MysqlColumnNameOrAlias', '`Home-street_address`'),
- array('`Home-street_address', 'MysqlColumnNameOrAlias', NULL),
- array('column_name, sleep(5)', 'MysqlColumnNameOrAlias', NULL),
- array('asc', 'MysqlOrderByDirection', 'asc'),
- array('DESC', 'MysqlOrderByDirection', 'desc'),
- array('DESCc', 'MysqlOrderByDirection', NULL),
- array('table.civicrm_column_name desc', 'MysqlOrderBy', '`table`.`civicrm_column_name` desc'),
- array('field(contribution_status_id,4,5,6) asc', 'MysqlOrderBy', 'field(`contribution_status_id`,4,5,6) asc'),
- array('field(contribution_status_id,4,5,6) asc, contact_id asc', 'MysqlOrderBy', 'field(`contribution_status_id`,4,5,6) asc, `contact_id` asc'),
- array('table.civicrm_column_name desc,other_column,another_column desc', 'MysqlOrderBy', '`table`.`civicrm_column_name` desc, `other_column`, `another_column` desc'),
- array('table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column', 'MysqlOrderBy', '`table`.`Home-street_address` asc, `table-alias`.`Home-street_address` desc, `table-alias`.`column`'),
- );
+ ['<p onclick="alert(\'xss\');">Hello</p>', 'Memo', '<p onclick=\\"alert(\\\'xss\\\');\\">Hello</p>'],
+ ['civicrm_column_name', 'MysqlColumnNameOrAlias', '`civicrm_column_name`'],
+ ['table.civicrm_column_name', 'MysqlColumnNameOrAlias', '`table`.`civicrm_column_name`'],
+ ['table.civicrm_column_name.toomanydots', 'MysqlColumnNameOrAlias', NULL],
+ ['Home-street_address', 'MysqlColumnNameOrAlias', '`Home-street_address`'],
+ ['`Home-street_address`', 'MysqlColumnNameOrAlias', '`Home-street_address`'],
+ ['`Home-street_address', 'MysqlColumnNameOrAlias', NULL],
+ ['column_name, sleep(5)', 'MysqlColumnNameOrAlias', NULL],
+ ['asc', 'MysqlOrderByDirection', 'asc'],
+ ['DESC', 'MysqlOrderByDirection', 'desc'],
+ ['DESCc', 'MysqlOrderByDirection', NULL],
+ ['table.civicrm_column_name desc', 'MysqlOrderBy', '`table`.`civicrm_column_name` desc'],
+ ['field(contribution_status_id,4,5,6) asc', 'MysqlOrderBy', 'field(`contribution_status_id`,4,5,6) asc'],
+ ['field(contribution_status_id,4,5,6) asc, contact_id asc', 'MysqlOrderBy', 'field(`contribution_status_id`,4,5,6) asc, `contact_id` asc'],
+ ['table.civicrm_column_name desc,other_column,another_column desc', 'MysqlOrderBy', '`table`.`civicrm_column_name` desc, `other_column`, `another_column` desc'],
+ ['table.`Home-street_address` asc, `table-alias`.`Home-street_address` desc,`table-alias`.column', 'MysqlOrderBy', '`table`.`Home-street_address` asc, `table-alias`.`Home-street_address` desc, `table-alias`.`column`'],
+ ];
}
}
public function testFindBaseDirName_normal() {
$this->_doFindBaseDirName('author-com.example.foo-random/',
- array('author-com.example.foo-random'),
- array('author-com.example.foo-random/README.txt' => 'hello')
+ ['author-com.example.foo-random'],
+ ['author-com.example.foo-random/README.txt' => 'hello']
);
}
public function testFindBaseDirName_0() {
$this->_doFindBaseDirName('0/',
- array('0'),
- array()
+ ['0'],
+ []
);
}
public function testFindBaseDirName_plainfile() {
$this->_doFindBaseDirName(FALSE,
- array(),
- array('README.txt' => 'hello')
+ [],
+ ['README.txt' => 'hello']
);
}
public function testFindBaseDirName_twodir() {
$this->_doFindBaseDirName(FALSE,
- array('dir-1', 'dir-2'),
- array('dir-1/README.txt' => 'hello')
+ ['dir-1', 'dir-2'],
+ ['dir-1/README.txt' => 'hello']
);
}
public function testFindBaseDirName_dirfile() {
$this->_doFindBaseDirName(FALSE,
- array('dir-1'),
- array('dir-1/README.txt' => 'hello', 'MANIFEST.MF' => 'extra')
+ ['dir-1'],
+ ['dir-1/README.txt' => 'hello', 'MANIFEST.MF' => 'extra']
);
}
public function testFindBaseDirName_dot() {
$this->_doFindBaseDirName(FALSE,
- array('.'),
- array('./README.txt' => 'hello')
+ ['.'],
+ ['./README.txt' => 'hello']
);
}
public function testFindBaseDirName_dots() {
$this->_doFindBaseDirName(FALSE,
- array('..'),
- array('../README.txt' => 'hello')
+ ['..'],
+ ['../README.txt' => 'hello']
);
}
public function testFindBaseDirName_weird() {
$this->_doFindBaseDirName(FALSE,
- array('foo/../'),
- array('foo/../README.txt' => 'hello')
+ ['foo/../'],
+ ['foo/../README.txt' => 'hello']
);
}
public function testGuessBaseDir_normal() {
$this->_doGuessBaseDir('author-com.example.foo-random',
- array('author-com.example.foo-random'),
- array('author-com.example.foo-random/README.txt' => 'hello'),
+ ['author-com.example.foo-random'],
+ ['author-com.example.foo-random/README.txt' => 'hello'],
'com.example.foo'
);
}
public function testGuessBaseDir_MACOSX() {
$this->_doGuessBaseDir('com.example.foo',
- array('com.example.foo', '__MACOSX'),
- array('author-com.example.foo-random/README.txt' => 'hello', '__MACOSX/foo' => 'bar'),
+ ['com.example.foo', '__MACOSX'],
+ ['author-com.example.foo-random/README.txt' => 'hello', '__MACOSX/foo' => 'bar'],
'com.example.foo'
);
}
public function testGuessBaseDir_0() {
$this->_doGuessBaseDir('0',
- array('0'),
- array(),
+ ['0'],
+ [],
'com.example.foo'
);
}
public function testGuessBaseDir_plainfile() {
$this->_doGuessBaseDir(FALSE,
- array(),
- array('README.txt' => 'hello'),
+ [],
+ ['README.txt' => 'hello'],
'com.example.foo'
);
}
public function testGuessBaseDirTwoDir() {
$this->_doGuessBaseDir(FALSE,
- array('dir-1', 'dir-2'),
- array('dir-1/README.txt' => 'hello'),
+ ['dir-1', 'dir-2'],
+ ['dir-1/README.txt' => 'hello'],
'com.example.foo'
);
}
public function testGuessBaseDirWeird() {
$this->_doGuessBaseDir(FALSE,
- array('foo/../'),
- array('foo/../README.txt' => 'hello'),
+ ['foo/../'],
+ ['foo/../README.txt' => 'hello'],
'com.example.foo'
);
}
/**
* @var array
*/
- protected $sampleVersionInfo = array(
- '4.2' => array(
+ protected $sampleVersionInfo = [
+ '4.2' => [
'status' => 'eol',
- 'releases' => array(
- array('version' => '4.2.0', 'date' => '2012-08-20'),
- array('version' => '4.2.1', 'date' => '2012-09-12'),
- array('version' => '4.2.2', 'date' => '2012-09-27'),
- array('version' => '4.2.4', 'date' => '2012-10-18'),
- array('version' => '4.2.6', 'date' => '2012-11-01', 'security' => TRUE),
- array('version' => '4.2.7', 'date' => '2013-01-02', 'security' => TRUE),
- array('version' => '4.2.8', 'date' => '2013-02-20'),
- array('version' => '4.2.9', 'date' => '2013-04-03'),
- array('version' => '4.2.10', 'date' => '2013-07-29', 'security' => TRUE),
- array('version' => '4.2.11', 'date' => '2013-09-25'),
- array('version' => '4.2.12', 'date' => '2013-10-02', 'security' => TRUE),
- array('version' => '4.2.13', 'date' => '2013-11-06', 'security' => TRUE),
- array('version' => '4.2.14', 'date' => '2013-11-20'),
- array('version' => '4.2.15', 'date' => '2014-02-07', 'security' => TRUE),
- array('version' => '4.2.16', 'date' => '2014-02-18'),
- array('version' => '4.2.17', 'date' => '2014-07-01', 'security' => TRUE),
- array('version' => '4.2.18', 'date' => '2014-08-06'),
- array('version' => '4.2.19', 'date' => '2014-09-17', 'security' => TRUE),
- ),
- ),
- '4.3' => array(
+ 'releases' => [
+ ['version' => '4.2.0', 'date' => '2012-08-20'],
+ ['version' => '4.2.1', 'date' => '2012-09-12'],
+ ['version' => '4.2.2', 'date' => '2012-09-27'],
+ ['version' => '4.2.4', 'date' => '2012-10-18'],
+ ['version' => '4.2.6', 'date' => '2012-11-01', 'security' => TRUE],
+ ['version' => '4.2.7', 'date' => '2013-01-02', 'security' => TRUE],
+ ['version' => '4.2.8', 'date' => '2013-02-20'],
+ ['version' => '4.2.9', 'date' => '2013-04-03'],
+ ['version' => '4.2.10', 'date' => '2013-07-29', 'security' => TRUE],
+ ['version' => '4.2.11', 'date' => '2013-09-25'],
+ ['version' => '4.2.12', 'date' => '2013-10-02', 'security' => TRUE],
+ ['version' => '4.2.13', 'date' => '2013-11-06', 'security' => TRUE],
+ ['version' => '4.2.14', 'date' => '2013-11-20'],
+ ['version' => '4.2.15', 'date' => '2014-02-07', 'security' => TRUE],
+ ['version' => '4.2.16', 'date' => '2014-02-18'],
+ ['version' => '4.2.17', 'date' => '2014-07-01', 'security' => TRUE],
+ ['version' => '4.2.18', 'date' => '2014-08-06'],
+ ['version' => '4.2.19', 'date' => '2014-09-17', 'security' => TRUE],
+ ],
+ ],
+ '4.3' => [
'status' => 'lts',
- 'releases' => array(
- array('version' => '4.3.0', 'date' => '2013-04-10'),
- array('version' => '4.3.1', 'date' => '2013-04-18'),
- array('version' => '4.3.2', 'date' => '2013-05-02'),
- array('version' => '4.3.3', 'date' => '2013-05-08'),
- array('version' => '4.3.4', 'date' => '2013-06-10', 'security' => TRUE),
- array('version' => '4.3.5', 'date' => '2013-07-08', 'security' => TRUE),
- array('version' => '4.3.6', 'date' => '2013-09-25'),
- array('version' => '4.3.7', 'date' => '2013-10-02', 'security' => TRUE),
- array('version' => '4.3.8', 'date' => '2013-11-06', 'security' => TRUE),
- array('version' => '4.3.9', 'date' => '2014-09-07', 'security' => TRUE),
- ),
- ),
- '4.4' => array(
+ 'releases' => [
+ ['version' => '4.3.0', 'date' => '2013-04-10'],
+ ['version' => '4.3.1', 'date' => '2013-04-18'],
+ ['version' => '4.3.2', 'date' => '2013-05-02'],
+ ['version' => '4.3.3', 'date' => '2013-05-08'],
+ ['version' => '4.3.4', 'date' => '2013-06-10', 'security' => TRUE],
+ ['version' => '4.3.5', 'date' => '2013-07-08', 'security' => TRUE],
+ ['version' => '4.3.6', 'date' => '2013-09-25'],
+ ['version' => '4.3.7', 'date' => '2013-10-02', 'security' => TRUE],
+ ['version' => '4.3.8', 'date' => '2013-11-06', 'security' => TRUE],
+ ['version' => '4.3.9', 'date' => '2014-09-07', 'security' => TRUE],
+ ],
+ ],
+ '4.4' => [
'status' => 'lts',
- 'releases' => array(
- array('version' => '4.4.0', 'date' => '2013-10-23'),
- array('version' => '4.4.1', 'date' => '2013-11-06', 'security' => TRUE),
- array('version' => '4.4.2', 'date' => '2013-11-20'),
- array('version' => '4.4.3', 'date' => '2013-12-05'),
- array('version' => '4.4.4', 'date' => '2014-02-07', 'security' => TRUE),
- array('version' => '4.4.5', 'date' => '2014-04-17'),
- array('version' => '4.4.6', 'date' => '2014-07-01', 'security' => TRUE),
- array('version' => '4.4.7', 'date' => '2014-09-17', 'security' => TRUE),
- array('version' => '4.4.8', 'date' => '2014-10-14'),
- array('version' => '4.4.9', 'date' => '2014-11-05'),
- array('version' => '4.4.10', 'date' => '2014-11-19'),
- array('version' => '4.4.11', 'date' => '2014-12-17', 'security' => TRUE),
- ),
- ),
- '4.5' => array(
+ 'releases' => [
+ ['version' => '4.4.0', 'date' => '2013-10-23'],
+ ['version' => '4.4.1', 'date' => '2013-11-06', 'security' => TRUE],
+ ['version' => '4.4.2', 'date' => '2013-11-20'],
+ ['version' => '4.4.3', 'date' => '2013-12-05'],
+ ['version' => '4.4.4', 'date' => '2014-02-07', 'security' => TRUE],
+ ['version' => '4.4.5', 'date' => '2014-04-17'],
+ ['version' => '4.4.6', 'date' => '2014-07-01', 'security' => TRUE],
+ ['version' => '4.4.7', 'date' => '2014-09-17', 'security' => TRUE],
+ ['version' => '4.4.8', 'date' => '2014-10-14'],
+ ['version' => '4.4.9', 'date' => '2014-11-05'],
+ ['version' => '4.4.10', 'date' => '2014-11-19'],
+ ['version' => '4.4.11', 'date' => '2014-12-17', 'security' => TRUE],
+ ],
+ ],
+ '4.5' => [
'status' => 'stable',
- 'releases' => array(
- array('version' => '4.5.0', 'date' => '2014-09-18'),
- array('version' => '4.5.1', 'date' => '2014-10-09'),
- array('version' => '4.5.2', 'date' => '2014-10-14'),
- array('version' => '4.5.3', 'date' => '2014-11-05'),
- array('version' => '4.5.4', 'date' => '2014-11-19'),
- array('version' => '4.5.5', 'date' => '2014-12-17', 'security' => TRUE),
- ),
- ),
- '4.6' => array(
+ 'releases' => [
+ ['version' => '4.5.0', 'date' => '2014-09-18'],
+ ['version' => '4.5.1', 'date' => '2014-10-09'],
+ ['version' => '4.5.2', 'date' => '2014-10-14'],
+ ['version' => '4.5.3', 'date' => '2014-11-05'],
+ ['version' => '4.5.4', 'date' => '2014-11-19'],
+ ['version' => '4.5.5', 'date' => '2014-12-17', 'security' => TRUE],
+ ],
+ ],
+ '4.6' => [
'status' => 'testing',
- 'releases' => array(
- array('version' => '4.6.alpha1', 'date' => '2015-02-01'),
- array('version' => '4.6.beta1', 'date' => '2015-03-01'),
- ),
- ),
- );
+ 'releases' => [
+ ['version' => '4.6.alpha1', 'date' => '2015-02-01'],
+ ['version' => '4.6.beta1', 'date' => '2015-03-01'],
+ ],
+ ],
+ ];
public function tearDown() {
parent::tearDown();
unset($vc);
// Update "remote" source data
- $remoteData = array('4.3' => $this->sampleVersionInfo['4.3']);
+ $remoteData = ['4.3' => $this->sampleVersionInfo['4.3']];
file_put_contents($tmpSrc, json_encode($remoteData));
// Cache was just updated, so fallback should not happen - assert we are still using cached data
public function testGetSiteStats() {
// Create domain address so the domain country will come up in the stats.
- $country_params = array(
+ $country_params = [
'sequential' => 1,
- 'options' => array(
+ 'options' => [
'limit' => 1,
- ),
- );
+ ],
+ ];
$country_result = civicrm_api3('country', 'get', $country_params);
$country = $country_result['values'][0];
- $domain_params = array(
+ $domain_params = [
'id' => CRM_Core_Config::domainID(),
- );
+ ];
CRM_Core_BAO_Domain::retrieve($domain_params, $domain_defaults);
$location_type = CRM_Core_BAO_LocationType::getDefault();
- $address_params = array(
+ $address_params = [
'contact_id' => $domain_defaults['contact_id'],
'location_type_id' => $location_type->id,
'is_primary' => '1',
'city' => 'Anywhere',
'postal_code' => '99999',
'country_id' => $country['id'],
- );
+ ];
$address_result = civicrm_api3('address', 'create', $address_params);
// Build stats and test them.
// Assert $stats['domain_isoCode'] is correct.
$this->assertEquals($country['iso_code'], $stats['domain_isoCode']);
- $entity_names = array();
+ $entity_names = [];
foreach ($stats['entities'] as $entity) {
$entity_names[] = $entity['name'];
$this->assertType('int', $entity['size'], "Stats entity {$entity['name']} has integer size?");
}
- $expected_entity_names = array(
+ $expected_entity_names = [
'Activity',
'Case',
'Contact',
'Pledge',
'PledgeBlock',
'Delivered',
- );
+ ];
sort($entity_names);
sort($expected_entity_names);
$this->assertEquals($expected_entity_names, $entity_names);
protected function setUp() {
parent::setUp();
- $this->actualEventSequence = array();
+ $this->actualEventSequence = [];
$this->dispatcher = new EventDispatcher();
$this->monitorEvents(Events::allEvents());
$this->kernel = new Kernel($this->dispatcher);
public function testNormalEvents() {
$this->kernel->registerApiProvider($this->createWidgetFrobnicateProvider());
- $result = $this->kernel->run('Widget', 'frobnicate', array(
+ $result = $this->kernel->run('Widget', 'frobnicate', [
'version' => self::MOCK_VERSION,
- ));
+ ]);
- $expectedEventSequence = array(
- array('name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'),
- array('name' => Events::AUTHORIZE, 'class' => 'Civi\API\Event\AuthorizeEvent'),
- array('name' => Events::PREPARE, 'class' => 'Civi\API\Event\PrepareEvent'),
- array('name' => Events::RESPOND, 'class' => 'Civi\API\Event\RespondEvent'),
- );
+ $expectedEventSequence = [
+ ['name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'],
+ ['name' => Events::AUTHORIZE, 'class' => 'Civi\API\Event\AuthorizeEvent'],
+ ['name' => Events::PREPARE, 'class' => 'Civi\API\Event\PrepareEvent'],
+ ['name' => Events::RESPOND, 'class' => 'Civi\API\Event\RespondEvent'],
+ ];
$this->assertEquals($expectedEventSequence, $this->actualEventSequence);
$this->assertEquals('frob', $result['values'][98]);
}
public function testResolveException() {
$test = $this;
$this->dispatcher->addListener(Events::RESOLVE, function () {
- throw new \API_Exception('Oh My God', 'omg', array('the' => 'badzes'));
+ throw new \API_Exception('Oh My God', 'omg', ['the' => 'badzes']);
}, Events::W_EARLY);
$this->dispatcher->addListener(Events::EXCEPTION, function (\Civi\API\Event\ExceptionEvent $event) use ($test) {
$test->assertEquals('Oh My God', $event->getException()->getMessage());
});
$this->kernel->registerApiProvider($this->createWidgetFrobnicateProvider());
- $result = $this->kernel->run('Widget', 'frobnicate', array(
+ $result = $this->kernel->run('Widget', 'frobnicate', [
'version' => self::MOCK_VERSION,
- ));
+ ]);
- $expectedEventSequence = array(
- array('name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'),
- array('name' => Events::EXCEPTION, 'class' => 'Civi\API\Event\ExceptionEvent'),
- );
+ $expectedEventSequence = [
+ ['name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'],
+ ['name' => Events::EXCEPTION, 'class' => 'Civi\API\Event\ExceptionEvent'],
+ ];
$this->assertEquals($expectedEventSequence, $this->actualEventSequence);
$this->assertEquals('Oh My God', $result['error_message']);
$this->assertEquals('omg', $result['error_code']);
public function createWidgetFrobnicateProvider() {
$provider = new \Civi\API\Provider\AdhocProvider(self::MOCK_VERSION, 'Widget');
$provider->addAction('frobnicate', 'access CiviCRM', function ($apiRequest) {
- return civicrm_api3_create_success(array(98 => 'frob'));
+ return civicrm_api3_create_success([98 => 'frob']);
});
return $provider;
}
foreach ($monitoredEvents as $monitoredEvent) {
$test = $this;
$this->dispatcher->addListener($monitoredEvent, function ($event) use ($monitoredEvent, &$test) {
- $test->actualEventSequence[] = array(
+ $test->actualEventSequence[] = [
'name' => $monitoredEvent,
'class' => get_class($event),
- );
+ ];
}, 2 * Events::W_EARLY);
}
}
* @return array
*/
public function validEntityActionPairs() {
- $cases = array();
- $cases[] = array(
- array('MyEntity', 'MyAction', 3),
- array('MyEntity', 'myaction', 3),
- );
- $cases[] = array(
- array('my+entity', 'MyAction', 3),
- array('MyEntity', 'myaction', 3),
- );
- $cases[] = array(
- array('my entity with under_scores', 'My_Action', 3),
- array('MyEntityWithUnderScores', 'my_action', 3),
- );
- $cases[] = array(
- array('u_f_match', 'get Something', 3),
- array('UFMatch', 'get_something', 3),
- );
+ $cases = [];
+ $cases[] = [
+ ['MyEntity', 'MyAction', 3],
+ ['MyEntity', 'myaction', 3],
+ ];
+ $cases[] = [
+ ['my+entity', 'MyAction', 3],
+ ['MyEntity', 'myaction', 3],
+ ];
+ $cases[] = [
+ ['my entity with under_scores', 'My_Action', 3],
+ ['MyEntityWithUnderScores', 'my_action', 3],
+ ];
+ $cases[] = [
+ ['u_f_match', 'get Something', 3],
+ ['UFMatch', 'get_something', 3],
+ ];
return $cases;
}
*/
public function testCreateRequest_EntityActionMunging($input, $expected) {
list ($inEntity, $inAction, $inVersion) = $input;
- $apiRequest = Request::create($inEntity, $inAction, array('version' => $inVersion), NULL);
- $this->assertEquals($expected, array($apiRequest['entity'], $apiRequest['action'], $apiRequest['version']));
+ $apiRequest = Request::create($inEntity, $inAction, ['version' => $inVersion], NULL);
+ $this->assertEquals($expected, [$apiRequest['entity'], $apiRequest['action'], $apiRequest['version']]);
}
/**
* @return array
*/
public function invalidEntityActionPairs() {
- $cases = array();
- $cases[] = array('Not!Valid', 'create', 4);
- $cases[] = array('My+Entity', 'MyAction', 4);
- $cases[] = array('My Entity', 'MyAction', 4);
- $cases[] = array('2MyEntity', 'MyAction', 4);
- $cases[] = array('MyEntity', 'My+Action', 4);
- $cases[] = array('MyEntity', 'My Action', 4);
- $cases[] = array('MyEntity', '2Action', 4);
+ $cases = [];
+ $cases[] = ['Not!Valid', 'create', 4];
+ $cases[] = ['My+Entity', 'MyAction', 4];
+ $cases[] = ['My Entity', 'MyAction', 4];
+ $cases[] = ['2MyEntity', 'MyAction', 4];
+ $cases[] = ['MyEntity', 'My+Action', 4];
+ $cases[] = ['MyEntity', 'My Action', 4];
+ $cases[] = ['MyEntity', '2Action', 4];
return $cases;
}
* @throws \Civi\API\Exception\NotImplementedException
*/
public function testCreateRequest_InvalidEntityAction($inEntity, $inAction, $inVersion) {
- Request::create($inEntity, $inAction, array('version' => $inVersion), NULL);
+ Request::create($inEntity, $inAction, ['version' => $inVersion], NULL);
}
}
$fileProvider = new \Civi\API\Provider\StaticProvider(
3,
'FakeFile',
- array('id', 'entity_table', 'entity_id'),
- array(),
- array(
- array('id' => self::FILE_WIDGET_ID, 'entity_table' => 'fake_widget', 'entity_id' => self::WIDGET_ID),
- array('id' => self::FILE_FORBIDDEN_ID, 'entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID),
- )
+ ['id', 'entity_table', 'entity_id'],
+ [],
+ [
+ ['id' => self::FILE_WIDGET_ID, 'entity_table' => 'fake_widget', 'entity_id' => self::WIDGET_ID],
+ ['id' => self::FILE_FORBIDDEN_ID, 'entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID],
+ ]
);
\CRM_Core_DAO_AllCoreTables::registerEntityType('Widget', 'CRM_Fake_DAO_Widget', 'fake_widget');
$widgetProvider = new \Civi\API\Provider\StaticProvider(3, 'Widget',
- array('id', 'title'),
- array(),
- array(
- array('id' => self::WIDGET_ID, 'title' => 'my widget'),
- )
+ ['id', 'title'],
+ [],
+ [
+ ['id' => self::WIDGET_ID, 'title' => 'my widget'],
+ ]
);
\CRM_Core_DAO_AllCoreTables::registerEntityType('Forbidden', 'CRM_Fake_DAO_Forbidden', 'fake_forbidden');
$forbiddenProvider = new \Civi\API\Provider\StaticProvider(
3,
'Forbidden',
- array('id', 'label'),
- array(
+ ['id', 'label'],
+ [
'create' => \CRM_Core_Permission::ALWAYS_DENY_PERMISSION,
'get' => \CRM_Core_Permission::ALWAYS_DENY_PERMISSION,
'delete' => \CRM_Core_Permission::ALWAYS_DENY_PERMISSION,
- ),
- array(
- array('id' => self::FORBIDDEN_ID, 'label' => 'my forbidden'),
- )
+ ],
+ [
+ ['id' => self::FORBIDDEN_ID, 'label' => 'my forbidden'],
+ ]
);
$this->dispatcher = new EventDispatcher();
$this->dispatcher->addSubscriber(new DynamicFKAuthorization(
$this->kernel,
'FakeFile',
- array('create', 'get'),
+ ['create', 'get'],
// Given a file ID, determine the entity+table it's attached to.
"select
case %1
",
// Get a list of custom fields (field_name,table_name,extends)
"select",
- array('fake_widget', 'fake_forbidden')
+ ['fake_widget', 'fake_forbidden']
));
}
* @return array
*/
public function okDataProvider() {
- $cases = array();
+ $cases = [];
- $cases[] = array('Widget', 'create', array('id' => self::WIDGET_ID));
- $cases[] = array('Widget', 'get', array('id' => self::WIDGET_ID));
+ $cases[] = ['Widget', 'create', ['id' => self::WIDGET_ID]];
+ $cases[] = ['Widget', 'get', ['id' => self::WIDGET_ID]];
- $cases[] = array('FakeFile', 'create', array('id' => self::FILE_WIDGET_ID));
- $cases[] = array('FakeFile', 'get', array('id' => self::FILE_WIDGET_ID));
- $cases[] = array(
+ $cases[] = ['FakeFile', 'create', ['id' => self::FILE_WIDGET_ID]];
+ $cases[] = ['FakeFile', 'get', ['id' => self::FILE_WIDGET_ID]];
+ $cases[] = [
'FakeFile',
'create',
- array('entity_table' => 'fake_widget', 'entity_id' => self::WIDGET_ID),
- );
+ ['entity_table' => 'fake_widget', 'entity_id' => self::WIDGET_ID],
+ ];
return $cases;
}
* @return array
*/
public function badDataProvider() {
- $cases = array();
+ $cases = [];
- $cases[] = array('Forbidden', 'create', array('id' => self::FORBIDDEN_ID), '/Authorization failed/');
- $cases[] = array('Forbidden', 'get', array('id' => self::FORBIDDEN_ID), '/Authorization failed/');
+ $cases[] = ['Forbidden', 'create', ['id' => self::FORBIDDEN_ID], '/Authorization failed/'];
+ $cases[] = ['Forbidden', 'get', ['id' => self::FORBIDDEN_ID], '/Authorization failed/'];
- $cases[] = array('FakeFile', 'create', array('id' => self::FILE_FORBIDDEN_ID), '/Authorization failed/');
- $cases[] = array('FakeFile', 'get', array('id' => self::FILE_FORBIDDEN_ID), '/Authorization failed/');
+ $cases[] = ['FakeFile', 'create', ['id' => self::FILE_FORBIDDEN_ID], '/Authorization failed/'];
+ $cases[] = ['FakeFile', 'get', ['id' => self::FILE_FORBIDDEN_ID], '/Authorization failed/'];
- $cases[] = array('FakeFile', 'create', array('entity_table' => 'fake_forbidden'), '/Authorization failed/');
- $cases[] = array('FakeFile', 'get', array('entity_table' => 'fake_forbidden'), '/Authorization failed/');
+ $cases[] = ['FakeFile', 'create', ['entity_table' => 'fake_forbidden'], '/Authorization failed/'];
+ $cases[] = ['FakeFile', 'get', ['entity_table' => 'fake_forbidden'], '/Authorization failed/'];
- $cases[] = array(
+ $cases[] = [
'FakeFile',
'create',
- array('entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID),
+ ['entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID],
'/Authorization failed/',
- );
- $cases[] = array(
+ ];
+ $cases[] = [
'FakeFile',
'get',
- array('entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID),
+ ['entity_table' => 'fake_forbidden', 'entity_id' => self::FORBIDDEN_ID],
'/Authorization failed/',
- );
+ ];
- $cases[] = array(
+ $cases[] = [
'FakeFile',
'create',
- array(),
+ [],
"/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table/",
- );
- $cases[] = array(
+ ];
+ $cases[] = [
'FakeFile',
'get',
- array(),
+ [],
"/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table/",
- );
+ ];
- $cases[] = array('FakeFile', 'create', array('entity_table' => 'unknown'), '/Unrecognized target entity/');
- $cases[] = array('FakeFile', 'get', array('entity_table' => 'unknown'), '/Unrecognized target entity/');
+ $cases[] = ['FakeFile', 'create', ['entity_table' => 'unknown'], '/Unrecognized target entity/'];
+ $cases[] = ['FakeFile', 'get', ['entity_table' => 'unknown'], '/Unrecognized target entity/'];
// We should be allowed to lookup files for fake_widgets, but we need an ID.
- $cases[] = array('FakeFile', 'get', array('entity_table' => 'fake_widget'), '/Missing entity_id/');
+ $cases[] = ['FakeFile', 'get', ['entity_table' => 'fake_widget'], '/Missing entity_id/'];
return $cases;
}
$params['debug'] = 1;
$params['check_permissions'] = 1;
$result = $this->kernel->run($entity, $action, $params);
- $this->assertFalse((bool) $result['is_error'], print_r(array(
+ $this->assertFalse((bool) $result['is_error'], print_r([
'$entity' => $entity,
'$action' => $action,
'$params' => $params,
'$result' => $result,
- ), TRUE));
+ ], TRUE));
}
/**
$params['debug'] = 1;
$params['check_permissions'] = 1;
$result = $this->kernel->run($entity, $action, $params);
- $this->assertTrue((bool) $result['is_error'], print_r(array(
+ $this->assertTrue((bool) $result['is_error'], print_r([
'$entity' => $entity,
'$action' => $action,
'$params' => $params,
'$result' => $result,
- ), TRUE));
+ ], TRUE));
$this->assertRegExp($expectedError, $result['error_message']);
}
* @return array
*/
public function transactionOptions() {
- $r = array();
+ $r = [];
// $r[] = array(string $entity, string $action, array $params, bool $isTransactional, bool $isForceRollback, bool $isNested);
- $r[] = array(3, 'Widget', 'get', array(), FALSE, FALSE, FALSE);
- $r[] = array(3, 'Widget', 'create', array(), TRUE, FALSE, FALSE);
- $r[] = array(3, 'Widget', 'delete', array(), TRUE, FALSE, FALSE);
- $r[] = array(3, 'Widget', 'submit', array(), TRUE, FALSE, FALSE);
+ $r[] = [3, 'Widget', 'get', [], FALSE, FALSE, FALSE];
+ $r[] = [3, 'Widget', 'create', [], TRUE, FALSE, FALSE];
+ $r[] = [3, 'Widget', 'delete', [], TRUE, FALSE, FALSE];
+ $r[] = [3, 'Widget', 'submit', [], TRUE, FALSE, FALSE];
- $r[] = array(3, 'Widget', 'get', array('is_transactional' => TRUE), TRUE, FALSE, FALSE);
- $r[] = array(3, 'Widget', 'get', array('is_transactional' => FALSE), FALSE, FALSE, FALSE);
- $r[] = array(3, 'Widget', 'get', array('is_transactional' => 'nest'), TRUE, FALSE, TRUE);
+ $r[] = [3, 'Widget', 'get', ['is_transactional' => TRUE], TRUE, FALSE, FALSE];
+ $r[] = [3, 'Widget', 'get', ['is_transactional' => FALSE], FALSE, FALSE, FALSE];
+ $r[] = [3, 'Widget', 'get', ['is_transactional' => 'nest'], TRUE, FALSE, TRUE];
- $r[] = array(3, 'Widget', 'create', array('is_transactional' => TRUE), TRUE, FALSE, FALSE);
- $r[] = array(3, 'Widget', 'create', array('is_transactional' => FALSE), FALSE, FALSE, FALSE);
- $r[] = array(3, 'Widget', 'create', array('is_transactional' => 'nest'), TRUE, FALSE, TRUE);
+ $r[] = [3, 'Widget', 'create', ['is_transactional' => TRUE], TRUE, FALSE, FALSE];
+ $r[] = [3, 'Widget', 'create', ['is_transactional' => FALSE], FALSE, FALSE, FALSE];
+ $r[] = [3, 'Widget', 'create', ['is_transactional' => 'nest'], TRUE, FALSE, TRUE];
- $r[] = array(3, 'Widget', 'create', array('options' => array('force_rollback' => TRUE)), TRUE, TRUE, TRUE);
- $r[] = array(3, 'Widget', 'create', array('options' => array('force_rollback' => FALSE)), TRUE, FALSE, FALSE);
+ $r[] = [3, 'Widget', 'create', ['options' => ['force_rollback' => TRUE]], TRUE, TRUE, TRUE];
+ $r[] = [3, 'Widget', 'create', ['options' => ['force_rollback' => FALSE]], TRUE, FALSE, FALSE];
- $r[] = array(
+ $r[] = [
3,
'Widget',
'create',
- array('is_transactional' => TRUE, 'options' => array('force_rollback' => TRUE)),
+ ['is_transactional' => TRUE, 'options' => ['force_rollback' => TRUE]],
TRUE,
TRUE,
TRUE,
- );
- $r[] = array(
+ ];
+ $r[] = [
3,
'Widget',
'create',
- array('is_transactional' => TRUE, 'options' => array('force_rollback' => FALSE)),
+ ['is_transactional' => TRUE, 'options' => ['force_rollback' => FALSE]],
TRUE,
FALSE,
FALSE,
- );
- $r[] = array(
+ ];
+ $r[] = [
3,
'Widget',
'create',
- array('is_transactional' => FALSE, 'options' => array('force_rollback' => TRUE)),
+ ['is_transactional' => FALSE, 'options' => ['force_rollback' => TRUE]],
TRUE,
TRUE,
TRUE,
- );
- $r[] = array(
+ ];
+ $r[] = [
3,
'Widget',
'create',
- array('is_transactional' => FALSE, 'options' => array('force_rollback' => FALSE)),
+ ['is_transactional' => FALSE, 'options' => ['force_rollback' => FALSE]],
FALSE,
FALSE,
FALSE,
- );
+ ];
// $r[] = array(4, 'Widget', 'get', array(), FALSE, FALSE, FALSE);
// $r[] = array(4, 'Widget', 'create', array(), TRUE, FALSE, FALSE);
$apiProvider = NULL;
$params['version'] = $version;
- $apiRequest = \Civi\API\Request::create($entity, $action, $params, array());
+ $apiRequest = \Civi\API\Request::create($entity, $action, $params, []);
$this->assertEquals($isTransactional, $txs->isTransactional($apiProvider, $apiRequest), 'check isTransactional');
$this->assertEquals($isForceRollback, $txs->isForceRollback($apiProvider, $apiRequest), 'check isForceRollback');
}
public function testForceRollback() {
- $result = $this->callAPISuccess('contact', 'create', array(
+ $result = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'Me',
'last_name' => 'Myself',
- 'options' => array(
+ 'options' => [
'force_rollback' => TRUE,
- ),
- ));
+ ],
+ ]);
$this->assertTrue(is_numeric($result['id']));
- $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', array(
- 1 => array($result['id'], 'Integer'),
- ));
+ $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_contact WHERE id = %1', [
+ 1 => [$result['id'], 'Integer'],
+ ]);
}
}
class WhitelistSubscriberTest extends \CiviUnitTestCase {
protected function getFixtures() {
- $recs = array();
+ $recs = [];
- $recs['widget'] = array(
- 1 => array(
+ $recs['widget'] = [
+ 1 => [
'id' => 1,
'widget_type' => 'foo',
'provider' => 'george jetson',
'title' => 'first widget',
'comments' => 'this widget is the bomb',
- ),
- 2 => array(
+ ],
+ 2 => [
'id' => 2,
'widget_type' => 'bar',
'provider' => 'george jetson',
'title' => 'second widget',
'comments' => 'this widget is a bomb',
- ),
- 3 => array(
+ ],
+ 3 => [
'id' => 3,
'widget_type' => 'foo',
'provider' => 'cosmo spacely',
'title' => 'third widget',
'comments' => 'omg, that thing is a bomb! widgets are bombs! get out!',
- ),
- 8 => array(
+ ],
+ 8 => [
'id' => 8,
'widget_type' => 'bax',
'provider' => 'cosmo spacely',
'title' => 'fourth widget',
'comments' => 'todo: rebuild garage',
- ),
- );
+ ],
+ ];
- $recs['sprocket'] = array(
- 1 => array(
+ $recs['sprocket'] = [
+ 1 => [
'id' => 1,
'sprocket_type' => 'whiz',
'provider' => 'cosmo spacely',
'title' => 'first sprocket',
'comment' => 'this sprocket is so good i could eat it up',
'widget_id' => 2,
- ),
- 5 => array(
+ ],
+ 5 => [
'id' => 5,
'sprocket_type' => 'bang',
'provider' => 'george jetson',
'title' => 'second sprocket',
'comment' => 'this green sprocket was made by soylent',
'widget_id' => 2,
- ),
- 7 => array(
+ ],
+ 7 => [
'id' => 7,
'sprocket_type' => 'quux',
'provider' => 'cosmo spacely',
'title' => 'third sprocket',
'comment' => 'sprocket green is people! sprocket green is people!',
'widget_id' => 3,
- ),
- 8 => array(
+ ],
+ 8 => [
'id' => 8,
'sprocket_type' => 'baz',
'provider' => 'george jetson',
'title' => 'fourth sprocket',
'comment' => 'see also: cooking.com/hannibal/1981420-sprocket-fava',
'widget_id' => 3,
- ),
- );
+ ],
+ ];
return $recs;
}
public function restrictionCases() {
- $calls = $rules = array();
+ $calls = $rules = [];
$recs = $this->getFixtures();
- $calls['Widget.get-all'] = array(
+ $calls['Widget.get-all'] = [
'entity' => 'Widget',
'action' => 'get',
- 'params' => array('version' => 3),
+ 'params' => ['version' => 3],
'expectedResults' => $recs['widget'],
- );
- $calls['Widget.get-foo'] = array(
+ ];
+ $calls['Widget.get-foo'] = [
'entity' => 'Widget',
'action' => 'get',
- 'params' => array('version' => 3, 'widget_type' => 'foo'),
- 'expectedResults' => array(1 => $recs['widget'][1], 3 => $recs['widget'][3]),
- );
- $calls['Widget.get-spacely'] = array(
+ 'params' => ['version' => 3, 'widget_type' => 'foo'],
+ 'expectedResults' => [1 => $recs['widget'][1], 3 => $recs['widget'][3]],
+ ];
+ $calls['Widget.get-spacely'] = [
'entity' => 'Widget',
'action' => 'get',
- 'params' => array('version' => 3, 'provider' => 'cosmo spacely'),
- 'expectedResults' => array(3 => $recs['widget'][3], 8 => $recs['widget'][8]),
- );
- $calls['Widget.get-spacely=>title'] = array(
+ 'params' => ['version' => 3, 'provider' => 'cosmo spacely'],
+ 'expectedResults' => [3 => $recs['widget'][3], 8 => $recs['widget'][8]],
+ ];
+ $calls['Widget.get-spacely=>title'] = [
'entity' => 'Widget',
'action' => 'get',
- 'params' => array('version' => 3, 'provider' => 'cosmo spacely', 'return' => array('title')),
- 'expectedResults' => array(
- 3 => array('id' => 3, 'title' => 'third widget'),
- 8 => array('id' => 8, 'title' => 'fourth widget'),
- ),
- );
- $calls['Widget.get-spacely-foo'] = array(
+ 'params' => ['version' => 3, 'provider' => 'cosmo spacely', 'return' => ['title']],
+ 'expectedResults' => [
+ 3 => ['id' => 3, 'title' => 'third widget'],
+ 8 => ['id' => 8, 'title' => 'fourth widget'],
+ ],
+ ];
+ $calls['Widget.get-spacely-foo'] = [
'entity' => 'Widget',
'action' => 'get',
- 'params' => array('version' => 3, 'provider' => 'cosmo spacely', 'widget_type' => 'foo'),
- 'expectedResults' => array(3 => $recs['widget'][3]),
- );
- $calls['Sprocket.get-all'] = array(
+ 'params' => ['version' => 3, 'provider' => 'cosmo spacely', 'widget_type' => 'foo'],
+ 'expectedResults' => [3 => $recs['widget'][3]],
+ ];
+ $calls['Sprocket.get-all'] = [
'entity' => 'Sprocket',
'action' => 'get',
- 'params' => array('version' => 3),
+ 'params' => ['version' => 3],
'expectedResults' => $recs['sprocket'],
- );
- $calls['Widget.get-bar=>title + Sprocket.get=>provider'] = array(
+ ];
+ $calls['Widget.get-bar=>title + Sprocket.get=>provider'] = [
'entity' => 'Widget',
'action' => 'get',
- 'params' => array(
+ 'params' => [
'version' => 3,
'widget_type' => 'bar',
- 'return' => array('title'),
- 'api.Sprocket.get' => array(
+ 'return' => ['title'],
+ 'api.Sprocket.get' => [
'widget_id' => '$value.id',
- 'return' => array('provider'),
- ),
- ),
- 'expectedResults' => array(
- 2 => array(
+ 'return' => ['provider'],
+ ],
+ ],
+ 'expectedResults' => [
+ 2 => [
'id' => 2,
'title' => 'second widget',
- 'api.Sprocket.get' => array(
+ 'api.Sprocket.get' => [
'is_error' => 0,
'count' => 2,
'version' => 3,
- 'values' => array(
- 0 => array('id' => 1, 'provider' => 'cosmo spacely'),
- 1 => array('id' => 5, 'provider' => 'george jetson'),
- ),
+ 'values' => [
+ 0 => ['id' => 1, 'provider' => 'cosmo spacely'],
+ 1 => ['id' => 5, 'provider' => 'george jetson'],
+ ],
// This is silly:
- 'undefined_fields' => array('entity_id', 'entity_table', 'widget_id', 'api.has_parent'),
- ),
- ),
- ),
- );
+ 'undefined_fields' => ['entity_id', 'entity_table', 'widget_id', 'api.has_parent'],
+ ],
+ ],
+ ],
+ ];
- $rules['*.*'] = array(
+ $rules['*.*'] = [
'version' => 3,
'entity' => '*',
'actions' => '*',
- 'required' => array(),
+ 'required' => [],
'fields' => '*',
- );
- $rules['Widget.*'] = array(
+ ];
+ $rules['Widget.*'] = [
'version' => 3,
'entity' => 'Widget',
'actions' => '*',
- 'required' => array(),
+ 'required' => [],
'fields' => '*',
- );
- $rules['Sprocket.*'] = array(
+ ];
+ $rules['Sprocket.*'] = [
'version' => 3,
'entity' => 'Sprocket',
'actions' => '*',
- 'required' => array(),
+ 'required' => [],
'fields' => '*',
- );
- $rules['Widget.get'] = array(
+ ];
+ $rules['Widget.get'] = [
'version' => 3,
'entity' => 'Widget',
'actions' => 'get',
- 'required' => array(),
+ 'required' => [],
'fields' => '*',
- );
- $rules['Sprocket.get'] = array(
+ ];
+ $rules['Sprocket.get'] = [
'version' => 3,
'entity' => 'Sprocket',
'actions' => 'get',
- 'required' => array(),
+ 'required' => [],
'fields' => '*',
- );
- $rules['Sprocket.get=>title,misc'] = array(
+ ];
+ $rules['Sprocket.get=>title,misc'] = [
'version' => 3,
'entity' => 'Sprocket',
'actions' => 'get',
- 'required' => array(),
+ 'required' => [],
// To call api.Sprocket.get via chaining, you must accept superfluous fields.
// It would be a mistake for the whitelist mechanism to approve these
// automatically, so instead we have to enumerate them. Ideally, ChainSubscriber
// wouldn't generate superfluous fields.
- 'fields' => array('id', 'title', 'widget_id', 'entity_id', 'entity_table'),
- );
- $rules['Sprocket.get=>provider,misc'] = array(
+ 'fields' => ['id', 'title', 'widget_id', 'entity_id', 'entity_table'],
+ ];
+ $rules['Sprocket.get=>provider,misc'] = [
'version' => 3,
'entity' => 'Sprocket',
'actions' => 'get',
- 'required' => array(),
+ 'required' => [],
// To call api.Sprocket.get via chaining, you must accept superfluous fields.
// It would be a mistake for the whitelist mechanism to approve these
// automatically, so instead we have to enumerate them. Ideally, ChainSubscriber
// wouldn't generate superfluous fields.
- 'fields' => array('id', 'provider', 'widget_id', 'entity_id', 'entity_table'),
- );
- $rules['Widget.get-foo'] = array(
+ 'fields' => ['id', 'provider', 'widget_id', 'entity_id', 'entity_table'],
+ ];
+ $rules['Widget.get-foo'] = [
'version' => 3,
'entity' => 'Widget',
'actions' => 'get',
- 'required' => array('widget_type' => 'foo'),
+ 'required' => ['widget_type' => 'foo'],
'fields' => '*',
- );
- $rules['Widget.get-spacely'] = array(
+ ];
+ $rules['Widget.get-spacely'] = [
'version' => 3,
'entity' => 'Widget',
'actions' => 'get',
- 'required' => array('provider' => 'cosmo spacely'),
+ 'required' => ['provider' => 'cosmo spacely'],
'fields' => '*',
- );
- $rules['Widget.get-bar=>title'] = array(
+ ];
+ $rules['Widget.get-bar=>title'] = [
'version' => 3,
'entity' => 'Widget',
'actions' => 'get',
- 'required' => array('widget_type' => 'bar'),
- 'fields' => array('id', 'title'),
- );
- $rules['Widget.get-spacely=>title'] = array(
+ 'required' => ['widget_type' => 'bar'],
+ 'fields' => ['id', 'title'],
+ ];
+ $rules['Widget.get-spacely=>title'] = [
'version' => 3,
'entity' => 'Widget',
'actions' => 'get',
- 'required' => array('provider' => 'cosmo spacely'),
- 'fields' => array('id', 'title'),
- );
- $rules['Widget.get-spacely=>widget_type'] = array(
+ 'required' => ['provider' => 'cosmo spacely'],
+ 'fields' => ['id', 'title'],
+ ];
+ $rules['Widget.get-spacely=>widget_type'] = [
'version' => 3,
'entity' => 'Widget',
'actions' => 'get',
- 'required' => array('provider' => 'cosmo spacely'),
- 'fields' => array('id', 'widget_type'),
- );
- $rules['Widget.getcreate'] = array(
+ 'required' => ['provider' => 'cosmo spacely'],
+ 'fields' => ['id', 'widget_type'],
+ ];
+ $rules['Widget.getcreate'] = [
'version' => 3,
'entity' => 'Widget',
- 'actions' => array('get', 'create'),
- 'required' => array(),
+ 'actions' => ['get', 'create'],
+ 'required' => [],
'fields' => '*',
- );
- $rules['Widget.create'] = array(
+ ];
+ $rules['Widget.create'] = [
'version' => 3,
'entity' => 'Widget',
'actions' => 'create',
- 'required' => array(),
+ 'required' => [],
'fields' => '*',
- );
+ ];
- $c = array();
+ $c = [];
- $c[] = array($calls['Widget.get-all'], array($rules['*.*']), TRUE);
- $c[] = array($calls['Widget.get-all'], array($rules['Widget.*']), TRUE);
- $c[] = array($calls['Widget.get-all'], array($rules['Widget.get']), TRUE);
- $c[] = array($calls['Widget.get-all'], array($rules['Widget.create']), FALSE);
- $c[] = array($calls['Widget.get-all'], array($rules['Widget.getcreate']), TRUE);
- $c[] = array($calls['Widget.get-all'], array($rules['Sprocket.*']), FALSE);
+ $c[] = [$calls['Widget.get-all'], [$rules['*.*']], TRUE];
+ $c[] = [$calls['Widget.get-all'], [$rules['Widget.*']], TRUE];
+ $c[] = [$calls['Widget.get-all'], [$rules['Widget.get']], TRUE];
+ $c[] = [$calls['Widget.get-all'], [$rules['Widget.create']], FALSE];
+ $c[] = [$calls['Widget.get-all'], [$rules['Widget.getcreate']], TRUE];
+ $c[] = [$calls['Widget.get-all'], [$rules['Sprocket.*']], FALSE];
- $c[] = array($calls['Sprocket.get-all'], array($rules['*.*']), TRUE);
- $c[] = array($calls['Sprocket.get-all'], array($rules['Sprocket.*']), TRUE);
- $c[] = array($calls['Sprocket.get-all'], array($rules['Widget.*']), FALSE);
- $c[] = array($calls['Sprocket.get-all'], array($rules['Widget.get']), FALSE);
+ $c[] = [$calls['Sprocket.get-all'], [$rules['*.*']], TRUE];
+ $c[] = [$calls['Sprocket.get-all'], [$rules['Sprocket.*']], TRUE];
+ $c[] = [$calls['Sprocket.get-all'], [$rules['Widget.*']], FALSE];
+ $c[] = [$calls['Sprocket.get-all'], [$rules['Widget.get']], FALSE];
- $c[] = array($calls['Widget.get-spacely'], array($rules['Widget.*']), TRUE);
- $c[] = array($calls['Widget.get-spacely'], array($rules['Widget.get-spacely']), TRUE);
- $c[] = array($calls['Widget.get-spacely'], array($rules['Widget.get-foo']), FALSE);
- $c[] = array($calls['Widget.get-spacely'], array($rules['Widget.get-foo'], $rules['Sprocket.*']), FALSE);
- $c[] = array(
+ $c[] = [$calls['Widget.get-spacely'], [$rules['Widget.*']], TRUE];
+ $c[] = [$calls['Widget.get-spacely'], [$rules['Widget.get-spacely']], TRUE];
+ $c[] = [$calls['Widget.get-spacely'], [$rules['Widget.get-foo']], FALSE];
+ $c[] = [$calls['Widget.get-spacely'], [$rules['Widget.get-foo'], $rules['Sprocket.*']], FALSE];
+ $c[] = [
// we do a broad get, but 'fields' filtering kicks in and restricts the results
- array_merge($calls['Widget.get-spacely'], array(
+ array_merge($calls['Widget.get-spacely'], [
'expectedResults' => $calls['Widget.get-spacely=>title']['expectedResults'],
- )),
- array($rules['Widget.get-spacely=>title']),
+ ]),
+ [$rules['Widget.get-spacely=>title']],
TRUE,
- );
+ ];
- $c[] = array($calls['Widget.get-foo'], array($rules['Widget.*']), TRUE);
- $c[] = array($calls['Widget.get-foo'], array($rules['Widget.get-foo']), TRUE);
- $c[] = array($calls['Widget.get-foo'], array($rules['Widget.get-spacely']), FALSE);
+ $c[] = [$calls['Widget.get-foo'], [$rules['Widget.*']], TRUE];
+ $c[] = [$calls['Widget.get-foo'], [$rules['Widget.get-foo']], TRUE];
+ $c[] = [$calls['Widget.get-foo'], [$rules['Widget.get-spacely']], FALSE];
- $c[] = array($calls['Widget.get-spacely=>title'], array($rules['*.*']), TRUE);
- $c[] = array($calls['Widget.get-spacely=>title'], array($rules['Widget.*']), TRUE);
- $c[] = array($calls['Widget.get-spacely=>title'], array($rules['Widget.get-spacely']), TRUE);
- $c[] = array($calls['Widget.get-spacely=>title'], array($rules['Widget.get-spacely=>title']), TRUE);
+ $c[] = [$calls['Widget.get-spacely=>title'], [$rules['*.*']], TRUE];
+ $c[] = [$calls['Widget.get-spacely=>title'], [$rules['Widget.*']], TRUE];
+ $c[] = [$calls['Widget.get-spacely=>title'], [$rules['Widget.get-spacely']], TRUE];
+ $c[] = [$calls['Widget.get-spacely=>title'], [$rules['Widget.get-spacely=>title']], TRUE];
// We request returning title field, but the rule doesn't allow title to be returned.
// Need it to fail so that control could pass to another rule which does allow it.
- $c[] = array($calls['Widget.get-spacely=>title'], array($rules['Widget.get-spacely=>widget_type']), FALSE);
+ $c[] = [$calls['Widget.get-spacely=>title'], [$rules['Widget.get-spacely=>widget_type']], FALSE];
// One rule would allow, one would be irrelevant. The order of the two rules shouldn't matter.
- $c[] = array(
+ $c[] = [
$calls['Widget.get-spacely=>title'],
- array($rules['Widget.get-spacely=>widget_type'], $rules['Widget.get-spacely=>title']),
+ [$rules['Widget.get-spacely=>widget_type'], $rules['Widget.get-spacely=>title']],
TRUE,
- );
- $c[] = array(
+ ];
+ $c[] = [
$calls['Widget.get-spacely=>title'],
- array($rules['Widget.get-spacely=>title'], $rules['Widget.get-spacely=>widget_type']),
+ [$rules['Widget.get-spacely=>title'], $rules['Widget.get-spacely=>widget_type']],
TRUE,
- );
+ ];
- $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['*.*']), TRUE);
- $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get-bar=>title'], $rules['Sprocket.get']), TRUE);
- $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get'], $rules['Sprocket.get=>title,misc']), FALSE);
- $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get'], $rules['Sprocket.get=>provider,misc']), TRUE);
- $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get-foo'], $rules['Sprocket.get']), FALSE);
- $c[] = array($calls['Widget.get-bar=>title + Sprocket.get=>provider'], array($rules['Widget.get']), FALSE);
+ $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['*.*']], TRUE];
+ $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get-bar=>title'], $rules['Sprocket.get']], TRUE];
+ $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get'], $rules['Sprocket.get=>title,misc']], FALSE];
+ $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get'], $rules['Sprocket.get=>provider,misc']], TRUE];
+ $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get-foo'], $rules['Sprocket.get']], FALSE];
+ $c[] = [$calls['Widget.get-bar=>title + Sprocket.get=>provider'], [$rules['Widget.get']], FALSE];
return $c;
}
\CRM_Core_DAO_AllCoreTables::registerEntityType('Widget', 'CRM_Fake_DAO_Widget', 'fake_widget');
$widgetProvider = new \Civi\API\Provider\StaticProvider(3, 'Widget',
- array('id', 'widget_type', 'provider', 'title'),
- array(),
+ ['id', 'widget_type', 'provider', 'title'],
+ [],
$recs['widget']
);
$sprocketProvider = new \Civi\API\Provider\StaticProvider(
3,
'Sprocket',
- array('id', 'sprocket_type', 'widget_id', 'provider', 'title', 'comment'),
- array(),
+ ['id', 'sprocket_type', 'widget_id', 'provider', 'title', 'comment'],
+ [],
$recs['sprocket']
);
$this->mut = new \CiviMailUtils($this, TRUE);
- $this->cronSchedule = array(
+ $this->cronSchedule = [
'start' => '2015-01-20 00:00:00',
'end' => '2015-03-01 00:00:00',
// seconds
'interval' => 24 * 60 * 60,
- );
+ ];
$this->schedule = new \CRM_Core_DAO_ActionSchedule();
$this->schedule->title = $this->getName(TRUE);
$this->schedule->msg_template_id = NULL;
$this->schedule->record_activity = NULL;
- $this->contacts['alice'] = $this->callAPISuccess('Contact', 'create', array(
+ $this->contacts['alice'] = $this->callAPISuccess('Contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'Alice',
'last_name' => 'Exemplar',
'email' => 'alice@example.org',
- ));
- $this->contacts['bob'] = $this->callAPISuccess('Contact', 'create', array(
+ ]);
+ $this->contacts['bob'] = $this->callAPISuccess('Contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'Bob',
'last_name' => 'Exemplar',
'email' => 'bob@example.org',
- ));
- $this->contacts['carol'] = $this->callAPISuccess('Contact', 'create', array(
+ ]);
+ $this->contacts['carol'] = $this->callAPISuccess('Contact', 'create', [
'contact_type' => 'Individual',
'first_name' => 'Carol',
'last_name' => 'Exemplar',
'email' => 'carol@example.org',
- ));
+ ]);
}
/**
}
$this->schedule->save();
- $actualMessages = array();
+ $actualMessages = [];
foreach ($this->cronTimes() as $time) {
\CRM_Utils_Time::setTime($time);
- $this->callAPISuccess('job', 'send_reminder', array());
+ $this->callAPISuccess('job', 'send_reminder', []);
foreach ($this->mut->getAllMessages('ezc') as $message) {
/** @var \ezcMail $message */
- $simpleMessage = array(
+ $simpleMessage = [
'time' => $time,
'to' => \CRM_Utils_Array::collect('email', $message->to),
'subject' => $message->subject,
- );
+ ];
sort($simpleMessage['to']);
$actualMessages[] = $simpleMessage;
$this->mut->clearMessages();
}
}
- $errorText = "Incorrect messages: " . print_r(array(
+ $errorText = "Incorrect messages: " . print_r([
'actualMessages' => $actualMessages,
'expectMessages' => $expectMessages,
- ), 1);
+ ], 1);
$this->assertEquals(count($expectMessages), count($actualMessages), $errorText);
- usort($expectMessages, array(__CLASS__, 'compareSimpleMsgs'));
- usort($actualMessages, array(__CLASS__, 'compareSimpleMsgs'));
+ usort($expectMessages, [__CLASS__, 'compareSimpleMsgs']);
+ usort($actualMessages, [__CLASS__, 'compareSimpleMsgs']);
foreach ($expectMessages as $offset => $expectMessage) {
$actualMessage = $actualMessages[$offset];
$this->assertApproxEquals(strtotime($expectMessage['time']), strtotime($actualMessage['time']), $this->dateTolerance, $errorText);
protected function cronTimes() {
$skew = 0;
- $times = array();
+ $times = [];
$end = strtotime($this->cronSchedule['end']);
for ($time = strtotime($this->cronSchedule['start']); $time < $end; $time += $this->cronSchedule['interval']) {
$times[] = date('Y-m-d H:i:s', $time + $skew);
*/
public function testInsertAfter() {
$changeSet = ChangeSet::create(__FUNCTION__);
- $counts = array('~/foo.html' => 0);
+ $counts = ['~/foo.html' => 0];
$changeSet->alterHtml('~/foo.html', function (\phpQueryObject $doc, $file) use (&$counts) {
$counts[$file]++;
throw new \Exception("This should not be called. The file does not exist!");
});
- $results = ChangeSet::applyResourceFilters(array($changeSet), 'partials', array(
+ $results = ChangeSet::applyResourceFilters([$changeSet], 'partials', [
'~/foo.html' => '<span><p class="foo">Hello</p><p class="bar">Goodbye</p></span>',
- ));
+ ]);
$this->assertHtmlEquals(
'<span><p class="foo">Hello</p><p ng-if="alpha.beta() && true">world</p><p class="bar">Goodbye</p><p>cruel world</p></span>',
*/
public function testAppendPrepend() {
$changeSet = ChangeSet::create(__FUNCTION__);
- $counts = array('~/foo.html' => 0);
+ $counts = ['~/foo.html' => 0];
$changeSet->alterHtml('~/foo.html', function (\phpQueryObject $doc, $file) use (&$counts) {
$counts[$file]++;
throw new \Exception("This should not be called. The file does not exist!");
});
- $originals = array(
+ $originals = [
'~/foo.html' => '<span><p class="foo">Hello</p><p class="bar">Goodbye</p></span>',
- );
- $results = ChangeSet::applyResourceFilters(array($changeSet), 'partials', $originals);
+ ];
+ $results = ChangeSet::applyResourceFilters([$changeSet], 'partials', $originals);
$this->assertHtmlEquals(
'<span><p class="foo">Hello<p ng-if="!!gamma()">world</p></p><p class="bar"><span>Cruel world,</span>Goodbye</p></span>',
public function testGetModules() {
$modules = $this->angular->getModules();
- $counts = array(
+ $counts = [
'js' => 0,
'css' => 0,
'partials' => 0,
'settings' => 0,
- );
+ ];
foreach ($modules as $module) {
$this->assertTrue(is_array($module));
* Get HTML fragments from an example module. The HTML is modified via hook.
*/
public function testGetPartials_Hooked() {
- \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', array($this, 'hook_civicrm_alterAngular'));
+ \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', [$this, 'hook_civicrm_alterAngular']);
$partials = $this->angular->getPartials('crmMailing');
$this->assertRegExp('/ng-form="crmMailingSubform" cat-stevens="ts\\(\'wild world\'\\)">/', $partials['~/crmMailing/EditMailingCtrl/2step.html']);
}
public function testGetJs_Asset() {
- \CRM_Utils_Hook::singleton()->setHook('civicrm_angularModules', array($this, 'hook_civicrm_angularModules_fooBar'));
+ \CRM_Utils_Hook::singleton()->setHook('civicrm_angularModules', [$this, 'hook_civicrm_angularModules_fooBar']);
- $paths = $this->angular->getResources(array('fooBar'), 'js', 'path');
+ $paths = $this->angular->getResources(['fooBar'], 'js', 'path');
$this->assertRegExp('/visual-bundle.[a-z0-9]+.js/', $paths[0]);
$this->assertRegExp('/crossfilter/', file_get_contents($paths[0]));
* Get a translatable string from an example module. The HTML is modified via hook.
*/
public function testGetStrings_Hooked() {
- \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', array($this, 'hook_civicrm_alterAngular'));
+ \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', [$this, 'hook_civicrm_alterAngular']);
$strings = $this->angular->getStrings('crmMailing');
$this->assertTrue(in_array('wild world', $strings));
* Get the list of dependencies for an Angular module.
*/
public function testGetRequires() {
- $requires = $this->angular->getResources(array('crmMailing'), 'requires', 'requires');
+ $requires = $this->angular->getResources(['crmMailing'], 'requires', 'requires');
$this->assertTrue(in_array('ngRoute', $requires['crmMailing']));
$this->assertFalse(in_array('crmCatStevens', $requires['crmMailing']));
// If crmMailing changes, feel free to use a different example.
* Get the list of dependencies for an Angular module. It can be modified via hook.
*/
public function testGetRequires_Hooked() {
- \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', array($this, 'hook_civicrm_alterAngular'));
+ \CRM_Utils_Hook::singleton()->setHook('civicrm_alterAngular', [$this, 'hook_civicrm_alterAngular']);
- $requires = $this->angular->getResources(array('crmMailing'), 'requires', 'requires');
+ $requires = $this->angular->getResources(['crmMailing'], 'requires', 'requires');
$this->assertTrue(in_array('ngRoute', $requires['crmMailing']));
$this->assertTrue(in_array('crmCatStevens', $requires['crmMailing']));
// If crmMailing changes, feel free to use a different example.
*/
public function testResolveDeps() {
// If crmMailing changes, feel free to use a different example.
- $expected = array(
+ $expected = [
'angularFileUpload',
'crmAttachment',
'crmAutosave',
'ngRoute',
'ngSanitize',
'ui.utils',
- );
- $input = array('crmMailing', 'crmCxn');
+ ];
+ $input = ['crmMailing', 'crmCxn'];
$actual = $this->angular->resolveDependencies($input);
sort($expected);
sort($actual);
}
public function hook_civicrm_angularModules_fooBar(&$angularModules) {
- $angularModules['fooBar'] = array(
+ $angularModules['fooBar'] = [
'ext' => 'civicrm',
- 'js' => array(
+ 'js' => [
'assetBuilder://visual-bundle.js',
'ext://civicrm/js/Common.js',
- ),
- );
+ ],
+ ];
}
}
}
public function basicConsistencyExamples() {
- $cases = array();
+ $cases = [];
- $cases[0] = array(
+ $cases[0] = [
'<div foo="bar"></div>',
'<div foo="bar"></div>',
- );
- $cases[1] = array(
+ ];
+ $cases[1] = [
'<div foo="bar"/>',
'<div foo="bar"></div>',
- );
- $cases[2] = array(
+ ];
+ $cases[2] = [
'<div foo=\'bar\'></div>',
'<div foo="bar"></div>',
- );
- $cases[3] = array(
+ ];
+ $cases[3] = [
'<div foo=\'ts("Hello world")\'></div>',
'<div foo=\'ts("Hello world")\'></div>',
- );
- $cases[4] = array(
+ ];
+ $cases[4] = [
'<div foo="ts(\'Hello world\')\"></div>',
'<div foo="ts(\'Hello world\')\"></div>',
- );
- $cases[5] = array(
+ ];
+ $cases[5] = [
'<a href="{{foo}}" title="{{bar}}"></a>',
'<a href="{{foo}}" title="{{bar}}"></a>',
- );
- $cases[6] = array(
+ ];
+ $cases[6] = [
'<div ng-if="a && b"></div>',
'<div ng-if="a && b"></div>',
- );
+ ];
return $cases;
}
*/
public function testAllPartials() {
$coder = new \Civi\Angular\Coder();
- $errors = array();
+ $errors = [];
$count = 0;
foreach ($this->angular->getModules() as $module => $moduleDefn) {
$partials = $this->angular->getPartials($module);
public function setUp() {
parent::setUp();
- $this->_params = array(
+ $this->_params = [
'case_type' => $this->caseType,
'subject' => 'Test case',
'contact_id' => 17,
- );
+ ];
//Add an activity status with Type = Completed
- $this->callAPISuccess('OptionValue', 'create', array(
+ $this->callAPISuccess('OptionValue', 'create', [
'option_group_id' => "activity_status",
'filter' => \CRM_Activity_BAO_Activity::COMPLETED,
'label' => "Skip Activity",
- ));
+ ]);
}
public function testSequence() {
// Edit details of first activity -- but don't finish it yet!
\CRM_Utils_Time::setTime('2013-11-30 01:30:00');
- $this->callApiSuccess('Activity', 'create', array(
+ $this->callApiSuccess('Activity', 'create', [
'id' => self::ag($analyzer->getSingleActivity('Medical evaluation'), 'id'),
'subject' => 'This is the new subject',
- ));
+ ]);
$analyzer = new \Civi\CCase\Analyzer($case['id']);
$this->assertEquals($caseStatuses['Open'], self::ag($analyzer->getCase(), 'status_id'));
$this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time'));
// Complete first activity; schedule second
\CRM_Utils_Time::setTime('2013-11-30 02:00:00');
- $this->callApiSuccess('Activity', 'create', array(
+ $this->callApiSuccess('Activity', 'create', [
'id' => self::ag($analyzer->getSingleActivity('Medical evaluation'), 'id'),
'status_id' => $actStatuses['Completed'],
- ));
+ ]);
$analyzer->flush();
$this->assertEquals($caseStatuses['Open'], self::ag($analyzer->getCase(), 'status_id'));
$this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time'));
//Complete second activity using "Skip Activity"(Completed); schedule third
\CRM_Utils_Time::setTime('2013-11-30 03:00:00');
- $this->callApiSuccess('Activity', 'create', array(
+ $this->callApiSuccess('Activity', 'create', [
'id' => self::ag($analyzer->getSingleActivity('Mental health evaluation'), 'id'),
'status_id' => $actStatuses['Skip Activity'],
- ));
+ ]);
$analyzer->flush();
$this->assertEquals($caseStatuses['Open'], self::ag($analyzer->getCase(), 'status_id'));
$this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time'));
//Add an Activity before the case is closed
\CRM_Utils_Time::setTime('2013-11-30 04:00:00');
- $this->callApiSuccess('Activity', 'create', array(
+ $this->callApiSuccess('Activity', 'create', [
'activity_name' => 'Follow up',
'activity_type_id' => $actTypes['Follow up'],
'status_id' => $actStatuses['Scheduled'],
'case_id' => $case['id'],
'activity_date_time' => \CRM_Utils_Time::getTime(),
- ));
+ ]);
$analyzer->flush();
$this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time'));
$this->assertEquals($actStatuses['Completed'], self::ag($analyzer->getSingleActivity('Medical evaluation'), 'status_id'));
// Complete third activity; Case should remain open because of the Follow up activity
\CRM_Utils_Time::setTime('2013-11-30 04:00:00');
- $this->callApiSuccess('Activity', 'create', array(
+ $this->callApiSuccess('Activity', 'create', [
'id' => self::ag($analyzer->getSingleActivity('Secure temporary housing'), 'id'),
'status_id' => $actStatuses['Completed'],
- ));
+ ]);
$analyzer->flush();
$this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time'));
$this->assertEquals($actStatuses['Completed'], self::ag($analyzer->getSingleActivity('Medical evaluation'), 'status_id'));
// Complete the additional Activity; Case closed
\CRM_Utils_Time::setTime('2013-11-30 04:00:00');
- $this->callApiSuccess('Activity', 'create', array(
+ $this->callApiSuccess('Activity', 'create', [
'id' => self::ag($analyzer->getSingleActivity('Follow up'), 'id'),
'status_id' => $actStatuses['Completed'],
- ));
+ ]);
$analyzer->flush();
$this->assertApproxTime('2013-11-30 01:00:00', self::ag($analyzer->getSingleActivity('Medical evaluation'), 'activity_date_time'));
$this->assertEquals($actStatuses['Completed'], self::ag($analyzer->getSingleActivity('Medical evaluation'), 'status_id'));
* @see \CRM_Utils_Hook::caseTypes
*/
public function hook_caseTypes(&$caseTypes) {
- $caseTypes[$this->caseType] = array(
+ $caseTypes[$this->caseType] = [
'module' => 'org.civicrm.hrcase',
'name' => $this->caseType,
'file' => __DIR__ . '/HousingSupportWithSequence.xml',
- );
+ ];
}
/**
$inspector = new CiviEventInspector();
$eventDef = $inspector->get('hook_civicrm_alterSettingsMetaData');
$this->assertEquals('hook_civicrm_alterSettingsMetaData', $eventDef['name']);
- $this->assertEquals(array('settingsMetaData', 'domainID', 'profile'), array_keys($eventDef['fields']));
+ $this->assertEquals(['settingsMetaData', 'domainID', 'profile'], array_keys($eventDef['fields']));
$this->assertEquals('hook', $eventDef['type']);
$this->assertNotEmpty($eventDef['description_html']);
$this->assertTrue($eventDef['fields']['settingsMetaData']['ref']);
parent::setUp();
$this->useTransaction(TRUE);
- $this->mandates = array();
+ $this->mandates = [];
}
public function tearDown() {
}
public function testConstructParams() {
- $event = GenericHookEvent::create(array(
+ $event = GenericHookEvent::create([
'ab' => 123,
- 'cd' => array('foo' => 'bar'),
+ 'cd' => ['foo' => 'bar'],
'nothingNull' => NULL,
'nothingZero' => 0,
- ));
+ ]);
$this->assertEquals(123, $event->ab);
$this->assertEquals('bar', $event->cd['foo']);
$this->assertTrue($event->hasField('ab'));
public function testConstructOrdered() {
$event = GenericHookEvent::createOrdered(
- array('alpha', 'beta', 'nothingNull', 'nothingZero'),
- array(456, array('whiz' => 'bang'), NULL, 0, \CRM_Utils_Hook::$_nullObject)
+ ['alpha', 'beta', 'nothingNull', 'nothingZero'],
+ [456, ['whiz' => 'bang'], NULL, 0, \CRM_Utils_Hook::$_nullObject]
);
$this->assertEquals(456, $event->alpha);
$this->assertEquals('bang', $event->beta['whiz']);
public function testDispatch() {
\CRM_Utils_Hook::singleton()->setHook('civicrm_ghet',
- array($this, 'hook_civicrm_ghet'));
+ [$this, 'hook_civicrm_ghet']);
\Civi::service('dispatcher')->addListener('hook_civicrm_ghet',
- array($this, 'onGhet'));
+ [$this, 'onGhet']);
$roString = 'readonly';
$rwString = 'readwrite';
- $roArray = array('readonly');
- $rwArray = array('readwrite');
+ $roArray = ['readonly'];
+ $rwArray = ['readwrite'];
$plainObj = new \stdClass();
$refObj = new \stdClass();
$this->assertEquals('readonly', $roString);
$this->assertEquals('readwrite added-string-via-event added-string-via-hook', $rwString);
- $this->assertEquals(array('readonly'), $roArray);
- $this->assertEquals(array('readwrite', 'added-to-array-via-event', 'added-to-array-via-hook'), $rwArray);
+ $this->assertEquals(['readonly'], $roArray);
+ $this->assertEquals(['readwrite', 'added-to-array-via-event', 'added-to-array-via-hook'], $rwArray);
$this->assertEquals('added-to-object-via-hook', $plainObj->prop1);
$this->assertEquals('added-to-object-via-hook', $refObj->prop2);
- $this->assertEquals(array('early-running-result', 'late-running-result'), $returnValue);
+ $this->assertEquals(['early-running-result', 'late-running-result'], $returnValue);
}
/**
*/
public function hookStub($roString, &$rwString, $roArray, &$rwArray, $plainObj, &$refObj) {
return \CRM_Utils_Hook::singleton()->invoke(
- array('roString', 'rwString', 'roArray', 'rwArray', 'plainObj', 'refObj'),
+ ['roString', 'rwString', 'roArray', 'rwArray', 'plainObj', 'refObj'],
$roString, $rwString, $roArray, $rwArray, $plainObj, $refObj,
'civicrm_ghet'
);
$rwArray[] = 'added-to-array-via-hook';
$plainObj->prop1 = 'added-to-object-via-hook';
$refObj->prop2 = 'added-to-object-via-hook';
- return array('late-running-result');
+ return ['late-running-result'];
}
public function onGhet(GenericHookEvent $e) {
$e->rwArray[] = 'added-to-array-via-event';
$e->plainObj->prop1 = 'added-to-object-via-event';
$e->refObj->prop2 = 'added-to-object-via-event';
- $e->addReturnValues(array('early-running-result'));
+ $e->addReturnValues(['early-running-result']);
}
}
*/
public function testStatic() {
$cb = $this->resolver->get('Civi\Core\ResolverTest::dummy');
- $this->assertEquals(array('Civi\Core\ResolverTest', 'dummy'), $cb);
+ $this->assertEquals(['Civi\Core\ResolverTest', 'dummy'], $cb);
$expected = 'static dummy received foo';
$actual = call_user_func($cb, 'foo');
parent::setUp();
$this->useTransaction(TRUE);
- $this->mandates = array();
+ $this->mandates = [];
}
public function tearDown() {
parent::setUp();
$this->useTransaction(TRUE);
- $this->domainDefaults = array(
+ $this->domainDefaults = [
'd1' => 'alpha',
'd2' => 'beta',
'd3' => 'gamma',
'myabspath' => '/tmp/bar',
'myrelurl' => 'sites/foo',
'myabsurl' => 'http://example.com/bar',
- );
- $this->contactDefaults = array(
+ ];
+ $this->contactDefaults = [
'c1' => 'alpha',
'c2' => 'beta',
'c3' => 'gamma',
- );
- $this->mandates = array(
- 'Mailing Preferences' => array(
+ ];
+ $this->mandates = [
+ 'Mailing Preferences' => [
'd3' => 'GAMMA!',
- ),
- 'contact' => array(
+ ],
+ 'contact' => [
'c3' => 'GAMMA MAN!',
- ),
- );
+ ],
+ ];
}
public function tearDown() {
* @return SettingsManager
*/
protected function createManager() {
- $cache = new \CRM_Utils_Cache_Arraycache(array());
+ $cache = new \CRM_Utils_Cache_Arraycache([]);
$cache->set('defaults_domain', $this->domainDefaults);
$cache->set('defaults_contact', $this->contactDefaults);
foreach ($this->mandates as $entity => $keyValues) {
}
protected function setUp() {
- $this->contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', array(
+ $this->contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', [
'contact_type' => 'Individual',
- ));
+ ]);
$session = \CRM_Core_Session::singleton();
$session->set('userID', $this->contact->id);
}
* @var array
* Array(int $id).
*/
- protected static $contactIds = array();
+ protected static $contactIds = [];
public function setUpHeadless() {
return \Civi\Test::headless()->apply();
protected function setUp() {
/** @var \CRM_Contact_DAO_Contact $contact */
- $contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', array(
+ $contact = \CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact', [
'contact_type' => 'Individual',
- ));
+ ]);
self::$contactIds[$this->getName()] = $contact->id;
}
$this->useTransaction(TRUE);
parent::setUp();
$this->dispatcher = new EventDispatcher();
- $this->dispatcher->addListener(Events::TOKEN_REGISTER, array($this, 'onListTokens'));
- $this->dispatcher->addListener(Events::TOKEN_EVALUATE, array($this, 'onEvalTokens'));
- $this->counts = array(
+ $this->dispatcher->addListener(Events::TOKEN_REGISTER, [$this, 'onListTokens']);
+ $this->dispatcher->addListener(Events::TOKEN_EVALUATE, [$this, 'onEvalTokens']);
+ $this->counts = [
'onListTokens' => 0,
'onEvalTokens' => 0,
- );
+ ];
}
/**
* values.
*/
public function testRowContext() {
- $p = new TokenProcessor($this->dispatcher, array(
+ $p = new TokenProcessor($this->dispatcher, [
'controller' => __CLASS__,
'omega' => '99',
- ));
+ ]);
$createdRow = $p->addRow()
->context('one', 1)
- ->context('two', array(2 => 3))
- ->context(array(
- 'two' => array(4 => 5),
- 'three' => array(6 => 7),
+ ->context('two', [2 => 3])
+ ->context([
+ 'two' => [4 => 5],
+ 'three' => [6 => 7],
'omega' => '98',
- ));
+ ]);
$gotRow = $p->getRow(0);
- foreach (array($createdRow, $gotRow) as $row) {
+ foreach ([$createdRow, $gotRow] as $row) {
$this->assertEquals(1, $row->context['one']);
$this->assertEquals(3, $row->context['two'][2]);
$this->assertEquals(5, $row->context['two'][4]);
* Check that getContextValues() returns the correct data
*/
public function testGetContextValues() {
- $p = new TokenProcessor($this->dispatcher, array(
+ $p = new TokenProcessor($this->dispatcher, [
'controller' => __CLASS__,
'omega' => '99',
- ));
+ ]);
$p->addRow()->context('id', 10)->context('omega', '98');
$p->addRow()->context('id', 10)->context('contact', (object) ['cid' => 10]);
$p->addRow()->context('id', 11)->context('contact', (object) ['cid' => 11]);
* values.
*/
public function testRowTokens() {
- $p = new TokenProcessor($this->dispatcher, array(
+ $p = new TokenProcessor($this->dispatcher, [
'controller' => __CLASS__,
- ));
+ ]);
$createdRow = $p->addRow()
->tokens('one', 1)
- ->tokens('two', array(2 => 3))
- ->tokens(array(
- 'two' => array(4 => 5),
- 'three' => array(6 => 7),
- ))
+ ->tokens('two', [2 => 3])
+ ->tokens([
+ 'two' => [4 => 5],
+ 'three' => [6 => 7],
+ ])
->tokens('four', 8, 9);
$gotRow = $p->getRow(0);
- foreach (array($createdRow, $gotRow) as $row) {
+ foreach ([$createdRow, $gotRow] as $row) {
$this->assertEquals(1, $row->tokens['one']);
$this->assertEquals(3, $row->tokens['two'][2]);
$this->assertEquals(5, $row->tokens['two'][4]);
}
public function testGetMessageTokens() {
- $p = new TokenProcessor($this->dispatcher, array(
+ $p = new TokenProcessor($this->dispatcher, [
'controller' => __CLASS__,
- ));
+ ]);
$p->addMessage('greeting_html', 'Good morning, <p>{contact.display_name}</p>. {custom.foobar}!', 'text/html');
$p->addMessage('greeting_text', 'Good morning, {contact.display_name}. {custom.whizbang}, {contact.first_name}!', 'text/plain');
- $expected = array(
- 'contact' => array('display_name', 'first_name'),
- 'custom' => array('foobar', 'whizbang'),
- );
+ $expected = [
+ 'contact' => ['display_name', 'first_name'],
+ 'custom' => ['foobar', 'whizbang'],
+ ];
$this->assertEquals($expected, $p->getMessageTokens());
}
public function testListTokens() {
- $p = new TokenProcessor($this->dispatcher, array(
+ $p = new TokenProcessor($this->dispatcher, [
'controller' => __CLASS__,
- ));
- $p->addToken(array('entity' => 'MyEntity', 'field' => 'myField', 'label' => 'My Label'));
- $this->assertEquals(array('{MyEntity.myField}' => 'My Label'), $p->listTokens());
+ ]);
+ $p->addToken(['entity' => 'MyEntity', 'field' => 'myField', 'label' => 'My Label']);
+ $this->assertEquals(['{MyEntity.myField}' => 'My Label'], $p->listTokens());
}
/**
* contacts in multiple messages.
*/
public function testFull() {
- $p = new TokenProcessor($this->dispatcher, array(
+ $p = new TokenProcessor($this->dispatcher, [
'controller' => __CLASS__,
- ));
+ ]);
$p->addMessage('greeting_html', 'Good morning, <p>{contact.display_name}</p>. {custom.foobar} Bye!', 'text/html');
$p->addMessage('greeting_text', 'Good morning, {contact.display_name}. {custom.foobar} Bye!', 'text/plain');
$p->addRow()
- ->context(array('contact_id' => 123))
- ->format('text/plain')->tokens(array(
- 'contact' => array('display_name' => 'What'),
- ));
+ ->context(['contact_id' => 123])
+ ->format('text/plain')->tokens([
+ 'contact' => ['display_name' => 'What'],
+ ]);
$p->addRow()
- ->context(array('contact_id' => 4))
- ->format('text/plain')->tokens(array(
- 'contact' => array('display_name' => 'Who'),
- ));
+ ->context(['contact_id' => 4])
+ ->format('text/plain')->tokens([
+ 'contact' => ['display_name' => 'Who'],
+ ]);
$p->addRow()
- ->context(array('contact_id' => 10))
- ->format('text/plain')->tokens(array(
- 'contact' => array('display_name' => 'Darth Vader'),
- ));
+ ->context(['contact_id' => 10])
+ ->format('text/plain')->tokens([
+ 'contact' => ['display_name' => 'Darth Vader'],
+ ]);
- $expectHtml = array(
+ $expectHtml = [
0 => 'Good morning, <p>What</p>. #0123 is a good number. Trickster {contact.display_name}. Bye!',
1 => 'Good morning, <p>Who</p>. #0004 is a good number. Trickster {contact.display_name}. Bye!',
2 => 'Good morning, <p>Darth Vader</p>. #0010 is a good number. Trickster {contact.display_name}. Bye!',
- );
+ ];
- $expectText = array(
+ $expectText = [
0 => 'Good morning, What. #0123 is a good number. Trickster {contact.display_name}. Bye!',
1 => 'Good morning, Who. #0004 is a good number. Trickster {contact.display_name}. Bye!',
2 => 'Good morning, Darth Vader. #0010 is a good number. Trickster {contact.display_name}. Bye!',
- );
+ ];
$rowCount = 0;
foreach ($p->evaluate()->getRows() as $key => $row) {
public function onListTokens(TokenRegisterEvent $e) {
$this->counts[__FUNCTION__]++;
- $e->register('custom', array(
+ $e->register('custom', [
'foobar' => 'A special message about foobar',
- ));
+ ]);
}
public function onEvalTokens(TokenValueEvent $e) {
* @see CiviUnitTestCase::tearDown()
*/
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_activity',
- );
+ ];
$this->quickCleanup($tablesToTruncate, TRUE);
}
*/
public function testActivityCreateCustomBefore($version) {
$this->_apiversion = $version;
- $values = $this->callAPISuccess('custom_field', 'getoptions', array('field' => 'custom_group_id'));
+ $values = $this->callAPISuccess('custom_field', 'getoptions', ['field' => 'custom_group_id']);
$this->assertTrue($values['count'] == 0);
- $this->CustomGroupCreate(array('extends' => 'Activity'));
- $groupCount = $this->callAPISuccess('custom_group', 'getcount', array('extends' => 'activity'));
+ $this->CustomGroupCreate(['extends' => 'Activity']);
+ $groupCount = $this->callAPISuccess('custom_group', 'getcount', ['extends' => 'activity']);
$this->assertEquals($groupCount, 1, 'one group should now exist');
- $values = $this->callAPISuccess('custom_field', 'getoptions', array('field' => 'custom_group_id'));
+ $values = $this->callAPISuccess('custom_field', 'getoptions', ['field' => 'custom_group_id']);
$this->assertTrue($values['count'] == 1, 'check that cached value is not retained for custom_group_id');
}
protected $_apiversion = 3;
public function testAPIReplaceVariables() {
- $result = array();
+ $result = [];
$result['testfield'] = 6;
$result['api.tag.get'] = 999;
$result['api.tag.create']['id'] = 8;
$result['api.tag.create']['values']['0']['display'] = 'batman';
$result['api.tag.create.api.tag.create']['values']['0']['display'] = 'krypton';
$result['api.tag.create']['values']['0']['api_tag_get'] = 'darth vader';
- $params = array(
+ $params = [
'activity_type_id' => '$value.testfield',
'tag_id' => '$value.api.tag.create.id',
'tag1_id' => '$value.api.entity.create.0.id',
'number' => '$value.api.tag.get',
'big_rock' => '$value.api.tag.create.api.tag.create.values.0.display',
'villain' => '$value.api.tag.create.values.0.api_tag_get.display',
- );
+ ];
_civicrm_api_replace_variables($params, $result);
$this->assertEquals(999, $params['number']);
$this->assertEquals(8, $params['tag_id']);
$this->callAPIFailure(
'RandomFile',
'get',
- array(),
+ [],
'API (RandomFile, get) does not exist (join the API team and implement it!)'
);
}
public function testAPIWrapperCamelCaseFunction() {
- $this->callAPISuccess('OptionGroup', 'Get', array());
+ $this->callAPISuccess('OptionGroup', 'Get', []);
}
public function testAPIWrapperLcaseFunction() {
- $this->callAPISuccess('OptionGroup', 'get', array());
+ $this->callAPISuccess('OptionGroup', 'get', []);
}
/**
$oldPath = get_include_path();
set_include_path($oldPath . PATH_SEPARATOR . dirname(__FILE__) . '/dataset/resolver');
- $result = $this->callAPISuccess('contact', 'example_action1', array());
+ $result = $this->callAPISuccess('contact', 'example_action1', []);
$this->assertEquals($result['values'][0], 'civicrm_api3_generic_example_action1 is ok');
- $result = $this->callAPISuccess('contact', 'example_action2', array());
+ $result = $this->callAPISuccess('contact', 'example_action2', []);
$this->assertEquals($result['values'][0], 'civicrm_api3_contact_example_action2 is ok');
- $result = $this->callAPISuccess('test_entity', 'example_action3', array());
+ $result = $this->callAPISuccess('test_entity', 'example_action3', []);
$this->assertEquals($result['values'][0], 'civicrm_api3_test_entity_example_action3 is ok');
set_include_path($oldPath);
}
public function testFromCamel() {
- $cases = array(
+ $cases = [
'Contribution' => 'contribution',
'contribution' => 'contribution',
'OptionValue' => 'option_value',
'UFJoin' => 'uf_join',
'ufJoin' => 'uf_join',
'uf_join' => 'uf_join',
- );
+ ];
foreach ($cases as $input => $expected) {
$actual = _civicrm_api_get_entity_name_from_camel($input);
$this->assertEquals($expected, $actual, sprintf('input=%s expected=%s actual=%s', $input, $expected, $actual));
}
public function testToCamel() {
- $cases = array(
+ $cases = [
'Contribution' => 'Contribution',
'contribution' => 'Contribution',
'OptionValue' => 'OptionValue',
'option_value' => 'OptionValue',
'UFJoin' => 'UFJoin',
'uf_join' => 'UFJoin',
- );
+ ];
foreach ($cases as $input => $expected) {
$actual = _civicrm_api_get_camel_name($input);
$this->assertEquals($expected, $actual, sprintf('input=%s expected=%s actual=%s', $input, $expected, $actual));
*/
public function testv3Wrapper() {
try {
- $result = civicrm_api3('contact', 'get', array());
+ $result = civicrm_api3('contact', 'get', []);
}
catch (CRM_Exception $e) {
$this->fail("This should have been a success test");
*/
public function testV3WrapperException() {
try {
- civicrm_api3('contact', 'create', array('debug' => 1));
+ civicrm_api3('contact', 'create', ['debug' => 1]);
}
catch (CiviCRM_API3_Exception $e) {
$this->assertEquals('mandatory_missing', $e->getErrorCode());
public function testCreateNoStringNullResult() {
// create an example contact
// $contact = CRM_Core_DAO::createTestObject('CRM_Contribute_DAO_ContributionPage')->toArray();
- $result = $this->callAPISuccess('ContributionPage', 'create', array(
+ $result = $this->callAPISuccess('ContributionPage', 'create', [
'title' => "Test Contribution Page",
'financial_type_id' => 1,
'currency' => 'USD',
'goal_amount' => 100,
- ));
+ ]);
$contact = array_shift($result['values']);
$this->assertTrue(is_numeric($contact['id']));
$this->assertNotEmpty($contact['currency']);
// update the contact
- $result = $this->callAPISuccess('ContributionPage', 'create', array(
+ $result = $this->callAPISuccess('ContributionPage', 'create', [
'id' => $contact['id'],
'title' => 'New title',
'currency' => '',
- ));
+ ]);
// Check return format.
$this->assertEquals(1, $result['count']);
protected function setUp() {
parent::setUp();
$this->useTransaction(TRUE);
- CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_apiWrappers', array($this, 'onApiWrappers'));
+ CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_apiWrappers', [$this, 'onApiWrappers']);
}
/**
// the wrapper intervenes (fromApiInput)
// Note: The output would define "display_name", but the wrapper
// intervenes (toApiOutput) and replaces with "display_name_munged".
- $result = $this->callAPISuccess('contact', 'create', array(
+ $result = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Invalid',
'first_name' => 'First',
'last_name' => 'Last',
- ));
+ ]);
$this->assertEquals('First', $result['values'][$result['id']]['first_name']);
$this->assertEquals('MUNGE! First Last', $result['values'][$result['id']]['display_name_munged']);
}
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
$title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7);
- $params = array(
+ $params = [
'title' => $title,
'recipient' => $assigneeID,
'limit_to' => 1,
'record_activity' => 1,
'start_action_date' => 'activity_date_time',
'mapping_id' => CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID,
- );
+ ];
$actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
$this->assertTrue(is_numeric($actionSchedule['id']));
$this->assertTrue($actionSchedule['id'] > 0);
*/
public function testActionScheduleCreateWithoutRequired($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'subject' => 'this case should fail',
'scheduled_date_time' => date('Ymd'),
- );
+ ];
$this->callAPIFailure('activity', 'create', $params);
}
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
$title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7);
- $params = array(
+ $params = [
'title' => $title,
'recipient' => $assigneeID,
'limit_to' => 1,
'end_date' => 'activity_date_time',
'body_html' => 'Test description',
'subject' => 'Test subject',
- );
+ ];
$actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
$this->assertTrue(is_numeric($actionSchedule['id']));
$this->assertTrue($actionSchedule['id'] > 0);
$this->_cid = $this->individualCreate();
- $this->_case = $this->callAPISuccess('case', 'create', array(
+ $this->_case = $this->callAPISuccess('case', 'create', [
'case_type_id' => $this->caseTypeId,
'subject' => __CLASS__,
'contact_id' => $this->_cid,
- ));
+ ]);
- $this->_otherActivity = $this->callAPISuccess('Activity', 'create', array(
+ $this->_otherActivity = $this->callAPISuccess('Activity', 'create', [
'source_contact_id' => $this->_cid,
'activity_type_id' => 'Phone Call',
'subject' => 'Ask not what your API can do for you, but what you can do for your API.',
- ));
+ ]);
}
/**
*/
public function testActivityCreateOnCase() {
$hash = substr(sha1(CIVICRM_SITE_KEY . $this->_case['id']), 0, 7);
- $subjectArr = array(
+ $subjectArr = [
"[case #{$this->_case['id']}] test activity recording under case with id",
"[case #{$hash}] test activity recording under case with id",
- );
+ ];
foreach ($subjectArr as $subject) {
- $activity = $this->callAPISuccess('Activity', 'create', array(
+ $activity = $this->callAPISuccess('Activity', 'create', [
'source_contact_id' => $this->_cid,
'activity_type_id' => 'Phone Call',
'subject' => $subject,
- ));
- $case = $this->callAPISuccessGetSingle('Activity', array('return' => array("case_id"), 'id' => $activity['id']));
+ ]);
+ $case = $this->callAPISuccessGetSingle('Activity', ['return' => ["case_id"], 'id' => $activity['id']]);
//Check if case id is present for the activity.
$this->assertEquals($this->_case['id'], $case['case_id'][0]);
}
$this->assertTrue(is_numeric($this->_case['id']));
$this->assertTrue(is_numeric($this->_otherActivity['id']));
- $getByCaseId = $this->callAPIAndDocument('Activity', 'get', array(
+ $getByCaseId = $this->callAPIAndDocument('Activity', 'get', [
'case_id' => $this->_case['id'],
- ), __FUNCTION__, __FILE__);
+ ], __FUNCTION__, __FILE__);
$this->assertNotEmpty($getByCaseId['values']);
$getByCaseId_ids = array_keys($getByCaseId['values']);
- $getByCaseNotNull = $this->callAPIAndDocument('Activity', 'get', array(
- 'case_id' => array('IS NOT NULL' => 1),
- ), __FUNCTION__, __FILE__);
+ $getByCaseNotNull = $this->callAPIAndDocument('Activity', 'get', [
+ 'case_id' => ['IS NOT NULL' => 1],
+ ], __FUNCTION__, __FILE__);
$this->assertNotEmpty($getByCaseNotNull['values']);
$getByCaseNotNull_ids = array_keys($getByCaseNotNull['values']);
- $getByCaseNull = $this->callAPIAndDocument('Activity', 'get', array(
- 'case_id' => array('IS NULL' => 1),
- ), __FUNCTION__, __FILE__);
+ $getByCaseNull = $this->callAPIAndDocument('Activity', 'get', [
+ 'case_id' => ['IS NULL' => 1],
+ ], __FUNCTION__, __FILE__);
$this->assertNotEmpty($getByCaseNull['values']);
$getByCaseNull_ids = array_keys($getByCaseNull['values']);
$this->assertTrue(in_array($this->_otherActivity['id'], $getByCaseNull_ids));
$this->assertNotTrue(in_array($this->_otherActivity['id'], $getByCaseId_ids));
$this->assertEquals($getByCaseId_ids, $getByCaseNotNull_ids);
- $this->assertEquals(array(), array_intersect($getByCaseId_ids, $getByCaseNull_ids));
+ $this->assertEquals([], array_intersect($getByCaseId_ids, $getByCaseNull_ids));
}
public function testActivityGetWithCaseInfo() {
- $activities = $this->callAPISuccess('Activity', 'get', array(
+ $activities = $this->callAPISuccess('Activity', 'get', [
'sequential' => 1,
'case_id' => $this->_case['id'],
- 'return' => array('case_id', 'case_id.subject'),
- ));
+ 'return' => ['case_id', 'case_id.subject'],
+ ]);
$this->assertEquals(__CLASS__, $activities['values'][0]['case_id.subject']);
// Note - case_id is always an array
$this->assertEquals($this->_case['id'], $activities['values'][0]['case_id'][0]);
$activity = $this->activityCreate();
$this->_activityID = $activity['id'];
CRM_Core_PseudoConstant::flush();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_contactID,
'activity_id' => $this->_activityID,
'record_type_id' => 2,
- );
+ ];
}
/**
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->callAPISuccess('activity_contact', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('activity_contact', 'delete', ['id' => $result['id']]);
}
/**
//create one
$create = $this->callAPISuccess('activity_contact', 'create', $this->_params);
- $result = $this->callAPIAndDocument('activity_contact', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('activity_contact', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
- $get = $this->callAPISuccess('activity_contact', 'get', array(
+ $get = $this->callAPISuccess('activity_contact', 'get', [
'id' => $create['id'],
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'ActivityContact not successfully deleted');
}
*/
public function testGetActivitiesByContact($version) {
$this->_apiversion = $version;
- $this->callAPISuccess('ActivityContact', 'Get', array('contact_id' => $this->_contactID));
+ $this->callAPISuccess('ActivityContact', 'Get', ['contact_id' => $this->_contactID]);
}
/**
*/
public function testGetActivitiesByActivity($version) {
$this->_apiversion = $version;
- $this->callAPISuccess('ActivityContact', 'Get', array('activity_id' => $this->_activityID));
+ $this->callAPISuccess('ActivityContact', 'Get', ['activity_id' => $this->_activityID]);
}
/**
*/
public function testGetEmptyParams($version) {
$this->_apiversion = $version;
- $this->callAPISuccess('ActivityContact', 'Get', array());
+ $this->callAPISuccess('ActivityContact', 'Get', []);
}
/**
* FIXME: Api4
*/
public function testGetWrongParams() {
- $this->callAPIFailure('ActivityContact', 'Get', array('contact_id' => 'abc'));
- $this->callAPIFailure('ActivityContact', 'Get', array('activity_id' => 'abc'));
- $this->callAPIFailure('ActivityContact', 'Get', array('record_type_id' => 'abc'));
+ $this->callAPIFailure('ActivityContact', 'Get', ['contact_id' => 'abc']);
+ $this->callAPIFailure('ActivityContact', 'Get', ['activity_id' => 'abc']);
+ $this->callAPIFailure('ActivityContact', 'Get', ['record_type_id' => 'abc']);
}
}
$this->_contactID = $this->individualCreate();
//create activity types
$this->test_activity_type_value = 9999;
- $activityTypes = $this->callAPISuccess('option_value', 'create', array(
+ $activityTypes = $this->callAPISuccess('option_value', 'create', [
'option_group_id' => 2,
'name' => 'Test activity type',
'label' => 'Test activity type',
'value' => $this->test_activity_type_value,
'sequential' => 1,
- ));
+ ]);
$this->test_activity_type_id = $activityTypes['id'];
- $this->_params = array(
+ $this->_params = [
'source_contact_id' => $this->_contactID,
'activity_type_id' => 'Test activity type',
'subject' => 'test activity type id',
'duration' => 120,
'location' => 'Pennsylvania',
'details' => 'a test activity',
- );
- $this->_params2 = array(
+ ];
+ $this->_params2 = [
'source_contact_id' => $this->_contactID,
'subject' => 'Eat & drink',
'activity_date_time' => date('Ymd'),
'details' => 'discuss & eat',
'status_id' => 1,
'activity_type_id' => $this->test_activity_type_value,
- );
+ ];
// create a logged in USER since the code references it for source_contact_id
$this->createLoggedInUser();
}
* This method is called after a test is executed.
*/
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contact',
'civicrm_activity',
'civicrm_activity_contact',
'civicrm_uf_match',
- );
+ ];
$this->quickCleanup($tablesToTruncate, TRUE);
- $type = $this->callAPISuccess('optionValue', 'get', array('id' => $this->test_activity_type_id));
+ $type = $this->callAPISuccess('optionValue', 'get', ['id' => $this->test_activity_type_id]);
if (!empty($type['count'])) {
- $this->callAPISuccess('option_value', 'delete', array('id' => $this->test_activity_type_id));
+ $this->callAPISuccess('option_value', 'delete', ['id' => $this->test_activity_type_id]);
}
}
*/
public function testActivityCreateEmpty($version) {
$this->_apiversion = $version;
- $this->callAPIFailure('activity', 'create', array());
+ $this->callAPIFailure('activity', 'create', []);
}
/**
*/
public function testActivityCreateWithoutRequired($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'subject' => 'this case should fail',
'scheduled_date_time' => date('Ymd'),
- );
+ ];
$this->callAPIFailure('activity', 'create', $params);
}
* and activity_name.
*/
public function testActivityCreateMismatchNameType() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Test activity',
'activity_date_time' => date('Ymd'),
'activity_name' => 'Fubar activity type',
'activity_type_id' => 5,
'scheduled_date_time' => date('Ymd'),
- );
+ ];
$this->callAPIFailure('activity', 'create', $params);
}
* Test civicrm_activity_id() with missing source_contact_id is put with the current user.
*/
public function testActivityCreateWithMissingContactId() {
- $params = array(
+ $params = [
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'duration' => 120,
'details' => 'a test activity',
'status_id' => 1,
'activity_name' => 'Test activity type',
- );
+ ];
$this->callAPISuccess('activity', 'create', $params);
}
*/
public function testActivityCreateWithMissingContactIdNoLoggedInUser() {
CRM_Core_Session::singleton()->set('userID', NULL);
- $params = array(
+ $params = [
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'duration' => 120,
'details' => 'a test activity',
'status_id' => 1,
'activity_name' => 'Test activity type',
- );
+ ];
$this->callAPIFailure('activity', 'create', $params, 'source_contact_id is not a valid integer');
}
*/
public function testActivityCreateWithNonNumericContactId($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'source_contact_id' => 'fubar',
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'details' => 'a test activity',
'status_id' => 1,
'activity_name' => 'Test activity type',
- );
+ ];
$this->callAPIFailure('activity', 'create', $params);
}
* got added to the set up routine. Probably a mis-fix on a test
*/
public function testActivityCreateWithNonNumericActivityTypeId() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'details' => 'a test activity',
'status_id' => 1,
'activity_type_id' => 'Invalid Test activity type',
- );
+ ];
$this->callAPIFailure('activity', 'create', $params);
}
}
public function testActivityCreateWithInvalidPriority() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'status_id' => 1,
'priority_id' => 44,
'activity_type_id' => 1,
- );
+ ];
$result = $this->callAPIFailure('activity', 'create', $params,
"'44' is not a valid option for field priority_id");
* Test create succeeds with valid string for priority.
*/
public function testActivityCreateWithValidStringPriority() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'status_id' => 1,
'priority_id' => 'Urgent',
'activity_type_id' => 1,
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
$this->assertEquals(1, $result['values'][$result['id']]['priority_id']);
* Test create fails with invalid priority string.
*/
public function testActivityCreateWithInValidStringPriority() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'status_id' => 1,
'priority_id' => 'ergUrgent',
'activity_type_id' => 1,
- );
+ ];
$this->callAPIFailure('activity', 'create', $params,
"'ergUrgent' is not a valid option for field priority_id");
$this->_apiversion = $version;
$this->enableCiviCampaign();
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => '20110316',
'details' => 'a test activity',
'status_id' => 1,
'activity_type_id' => 29,
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
- $result = $this->callAPISuccess('activity', 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess('activity', 'getsingle', ['id' => $result['id']]);
$this->assertEquals($result['duration'], 120);
$this->assertEquals($result['subject'], 'Make-it-Happen Meeting');
$this->assertEquals($result['activity_date_time'], '2011-03-16 00:00:00');
$this->assertEquals($result['details'], 'a test activity');
$this->assertEquals($result['status_id'], 1);
- $priorities = $this->callAPISuccess('activity', 'getoptions', array('field' => 'priority_id'));
+ $priorities = $this->callAPISuccess('activity', 'getoptions', ['field' => 'priority_id']);
$this->assertEquals($result['priority_id'], array_search('Normal', $priorities['values']));
}
$description = "Demonstrates setting & retrieving activity target & source.";
$subfile = "GetTargetandAssignee";
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => '20110316',
'priority_id' => 1,
'target_contact_id' => $this->_contactID,
'assignee_contact_id' => $this->_contactID,
- );
+ ];
$result = $this->callAPIAndDocument('activity', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $result = $this->callAPISuccess('activity', 'get', array(
+ $result = $this->callAPISuccess('activity', 'get', [
'id' => $result['id'],
'version' => $this->_apiversion,
'return.assignee_contact_id' => 1,
'return.target_contact_id' => 1,
- ));
+ ]);
$this->assertEquals($this->_contactID, $result['values'][$result['id']]['assignee_contact_id'][0]);
$this->assertEquals($this->_contactID, $result['values'][$result['id']]['target_contact_id'][0]);
$description = "Demonstrates retrieving activity target & source contact names.";
$subfile = "GetTargetandAssigneeName";
- $target1 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'A', 'last_name' => 'Cat'));
- $target2 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'B', 'last_name' => 'Good'));
- $assignee = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'C', 'last_name' => 'Shore'));
- $source = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'D', 'last_name' => 'Bug'));
+ $target1 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'A', 'last_name' => 'Cat']);
+ $target2 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'B', 'last_name' => 'Good']);
+ $assignee = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'C', 'last_name' => 'Shore']);
+ $source = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'D', 'last_name' => 'Bug']);
- $params = array(
+ $params = [
'source_contact_id' => $source['id'],
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => '20170316',
'status_id' => 1,
'activity_type_id' => 1,
- 'target_contact_id' => array($target1['id'], $target2['id']),
+ 'target_contact_id' => [$target1['id'], $target2['id']],
'assignee_contact_id' => $assignee['id'],
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
- $result = $this->callAPIAndDocument('activity', 'getsingle', array(
+ $result = $this->callAPIAndDocument('activity', 'getsingle', [
'id' => $result['id'],
- 'return' => array('source_contact_name', 'target_contact_name', 'assignee_contact_name', 'subject'),
- ), __FUNCTION__, __FILE__, $description, $subfile);
+ 'return' => ['source_contact_name', 'target_contact_name', 'assignee_contact_name', 'subject'],
+ ], __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($params['subject'], $result['subject']);
$this->assertEquals($source['id'], $result['source_contact_id']);
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
- $result = $this->callAPISuccess($this->_entity, 'get', array(
+ $result = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
$this->customFieldDelete($ids['custom_field_id']);
*/
public function testActivityCreateCustomSubType() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
- $this->callAPISuccess('CustomGroup', 'create', array(
+ $this->callAPISuccess('CustomGroup', 'create', [
'extends_entity_column_value' => $this->test_activity_type_value,
'id' => $ids['custom_group_id'],
'extends' => 'Activity',
'is_active' => TRUE,
- ));
+ ]);
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
- $result = $this->callAPISuccess($this->_entity, 'get', array(
+ $result = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]);
$this->customFieldDelete($ids['custom_field_id']);
*/
public function testActivityCreateCustomContactRefField() {
- $this->callAPISuccess('contact', 'create', array('id' => $this->_contactID, 'sort_name' => 'Contact, Test'));
+ $this->callAPISuccess('contact', 'create', ['id' => $this->_contactID, 'sort_name' => 'Contact, Test']);
$subfile = 'ContactRefCustomField';
$description = "Demonstrates create with Contact Reference Custom Field.";
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
- $params = array(
+ $params = [
'custom_group_id' => $ids['custom_group_id'],
'name' => 'Worker_Lookup',
'label' => 'Worker Lookup',
'weight' => 4,
'is_searchable' => 1,
'is_active' => 1,
- );
+ ];
$customField = $this->callAPISuccess('custom_field', 'create', $params);
$params = $this->_params;
$params['custom_' . $customField['id']] = "$this->_contactID";
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $result = $this->callAPIAndDocument($this->_entity, 'get', array(
+ $result = $this->callAPIAndDocument($this->_entity, 'get', [
'return.custom_' . $customField['id'] => 1,
'id' => $result['id'],
- ), __FUNCTION__, __FILE__, 'Get with Contact Ref Custom Field', 'ContactRefCustomFieldGet');
+ ], __FUNCTION__, __FILE__, 'Get with Contact Ref Custom Field', 'ContactRefCustomFieldGet');
$this->assertEquals('Anderson, Anthony', $result['values'][$result['id']]['custom_' . $customField['id']]);
$this->assertEquals($this->_contactID, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__);
*/
public function testActivityCreateBadTextStatus() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Discussion on Apis for v3',
'activity_date_time' => date('Ymd'),
'details' => 'a test activity',
'status_id' => 'Invalid',
'activity_name' => 'Test activity type',
- );
+ ];
$this->callAPIFailure('activity', 'create', $params);
}
*/
public function testActivityCreateSupportActivityStatus() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Discussion on Apis for v3',
'activity_date_time' => date('Ymd'),
'details' => 'a test activity',
'activity_status_id' => 'Invalid',
'activity_name' => 'Test activity type',
- );
+ ];
$this->callAPIFailure('activity', 'create', $params,
"'Invalid' is not a valid option for field status_id");
*/
public function testActivityCreateTextStatus() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'details' => 'a test activity',
'status_id' => 'Scheduled',
'activity_name' => 'Test activity type',
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
$this->assertEquals($result['values'][$result['id']]['duration'], 120);
* Test civicrm_activity_get() with no params
*/
public function testActivityGetEmpty() {
- $this->callAPISuccess('activity', 'get', array());
+ $this->callAPISuccess('activity', 'get', []);
}
/**
$subfile = 'ReturnAssigneeContact';
$activity = $this->callAPISuccess('activity', 'create', $this->_params);
- $contact = $this->callAPISuccess('Contact', 'Create', array(
+ $contact = $this->callAPISuccess('Contact', 'Create', [
'first_name' => "The Rock",
'last_name' => 'roccky',
'contact_type' => 'Individual',
'version' => 3,
- 'api.activity.create' => array(
+ 'api.activity.create' => [
'id' => $activity['id'],
'assignee_contact_id' => '$value.id',
- ),
- ));
+ ],
+ ]);
- $params = array(
+ $params = [
'activity_id' => $activity['id'],
'version' => $this->_apiversion,
'sequential' => 1,
'return.assignee_contact_id' => 1,
- 'api.contact.get' => array(
+ 'api.contact.get' => [
'id' => '$value.source_contact_id',
- ),
- );
+ ],
+ ];
$result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
* test that get functioning does filtering.
*/
public function testGetFilter() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => '20110316',
'status_id' => 1,
'activity_name' => 'Test activity type',
'priority_id' => 1,
- );
+ ];
$result = $this->callAPISuccess('Activity', 'Create', $params);
- $this->callAPISuccess('Activity', 'Get', array('subject' => 'Make-it-Happen Meeting'));
+ $this->callAPISuccess('Activity', 'Get', ['subject' => 'Make-it-Happen Meeting']);
$this->assertEquals(1, $result['count']);
$this->assertEquals('Make-it-Happen Meeting', $result['values'][$result['id']]['subject']);
- $this->callAPISuccess('Activity', 'Delete', array('id' => $result['id']));
+ $this->callAPISuccess('Activity', 'Delete', ['id' => $result['id']]);
}
/**
*/
public function testActivityGetTargetFilter() {
$params = $this->_params;
- $contact1Params = array(
+ $contact1Params = [
'first_name' => 'John',
'middle_name' => 'J.',
'last_name' => 'Anderson',
'suffix_id' => 3,
'email' => 'john_anderson@civicrm.org',
'contact_type' => 'Individual',
- );
+ ];
$contact1 = $this->individualCreate($contact1Params);
- $contact2Params = array(
+ $contact2Params = [
'first_name' => 'Michal',
'middle_name' => 'J.',
'last_name' => 'Anderson',
'suffix_id' => 3,
'email' => 'michal_anderson@civicrm.org',
'contact_type' => 'Individual',
- );
+ ];
$contact2 = $this->individualCreate($contact2Params);
$this->callAPISuccess('OptionValue', 'get', ['name' => 'Activity Targets', 'api.OptionValue.create' => ['label' => 'oh so creative']]);
- $params['assignee_contact_id'] = array($contact1, $contact2);
- $params['target_contact_id'] = array($contact2 => $contact2);
+ $params['assignee_contact_id'] = [$contact1, $contact2];
+ $params['target_contact_id'] = [$contact2 => $contact2];
$activity = $this->callAPISuccess('Activity', 'Create', $params);
- $activityGet = $this->callAPISuccess('Activity', 'get', array(
+ $activityGet = $this->callAPISuccess('Activity', 'get', [
'id' => $activity['id'],
'target_contact_id' => $contact2,
'return.target_contact_id' => 1,
- ));
+ ]);
$this->assertEquals($activity['id'], $activityGet['id']);
$this->assertEquals($contact2, $activityGet['values'][$activityGet['id']]['target_contact_id'][0]);
- $activityGet = $this->callAPISuccess('activity', 'get', array(
+ $activityGet = $this->callAPISuccess('activity', 'get', [
'target_contact_id' => $this->_contactID,
'return.target_contact_id' => 1,
'id' => $activity['id'],
- ));
+ ]);
if ($activityGet['count'] > 0) {
$this->assertNotEquals($contact2, $activityGet['values'][$activityGet['id']]['target_contact_id'][0]);
}
$params = $this->_params;
$params['subject'] = $subject;
$this->callAPISuccess('Activity', 'Create', $params);
- $activityGet = $this->callAPISuccess('activity', 'getsingle', array(
+ $activityGet = $this->callAPISuccess('activity', 'getsingle', [
'subject' => $subject,
- ));
+ ]);
$this->assertEquals($activityGet['subject'], $subject);
}
$params = $this->_params;
$params['details'] = $details;
$activity = $this->callAPISuccess('Activity', 'Create', $params);
- $activityget = $this->callAPISuccess('activity', 'getsingle', array(
+ $activityget = $this->callAPISuccess('activity', 'getsingle', [
'details' => $details,
- ));
+ ]);
$this->assertEquals($activityget['details'], $details);
}
* Test that activity.get api works when filtering on tag.
*/
public function testActivityGetTagFilter() {
- $tag = $this->callAPISuccess('Tag', 'create', array('name' => mt_rand(), 'used_for' => 'Activities'));
+ $tag = $this->callAPISuccess('Tag', 'create', ['name' => mt_rand(), 'used_for' => 'Activities']);
$activity = $this->callAPISuccess('Activity', 'Create', $this->_params);
- $this->callAPISuccess('EntityTag', 'create', array('entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id']));
- $activityget = $this->callAPISuccess('activity', 'getsingle', array(
+ $this->callAPISuccess('EntityTag', 'create', ['entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id']]);
+ $activityget = $this->callAPISuccess('activity', 'getsingle', [
'tag_id' => $tag['id'],
- ));
+ ]);
$this->assertEquals($activityget['id'], $activity['id']);
}
$tagName = 'act_tag_nm_' . mt_rand();
$tagDescription = 'act_tag_ds_' . mt_rand();
$tagColor = '#' . substr(md5(mt_rand()), 0, 6);
- $tag = $this->callAPISuccess('Tag', 'create', array('name' => $tagName, 'color' => $tagColor, 'description' => $tagDescription, 'used_for' => 'Activities'));
+ $tag = $this->callAPISuccess('Tag', 'create', ['name' => $tagName, 'color' => $tagColor, 'description' => $tagDescription, 'used_for' => 'Activities']);
$activity = $this->callAPISuccess('Activity', 'Create', $this->_params);
- $this->callAPISuccess('EntityTag', 'create', array('entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id']));
- $activityget = $this->callAPISuccess('activity', 'getsingle', array(
+ $this->callAPISuccess('EntityTag', 'create', ['entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id']]);
+ $activityget = $this->callAPISuccess('activity', 'getsingle', [
'id' => $activity['id'],
- 'return' => array('tag_id.name', 'tag_id.description', 'tag_id.color'),
- ));
+ 'return' => ['tag_id.name', 'tag_id.description', 'tag_id.color'],
+ ]);
$this->assertEquals($tagName, $activityget['tag_id'][$tag['id']]['tag_id.name']);
$this->assertEquals($tagColor, $activityget['tag_id'][$tag['id']]['tag_id.color']);
$this->assertEquals($tagDescription, $activityget['tag_id'][$tag['id']]['tag_id.description']);
public function testActivityGetFile() {
$activity = $this->callAPISuccess('Activity', 'create', $this->_params);
$activity2 = $this->callAPISuccess('Activity', 'create', $this->_params2);
- $file = $this->callAPISuccess('Attachment', 'create', array(
+ $file = $this->callAPISuccess('Attachment', 'create', [
'name' => 'actAttachment.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'My test content',
'entity_table' => 'civicrm_activity',
'entity_id' => $activity2['id'],
- ));
- $activityget = $this->callAPISuccess('activity', 'getsingle', array(
+ ]);
+ $activityget = $this->callAPISuccess('activity', 'getsingle', [
'file_id' => $file['id'],
'return' => 'file_id',
- ));
+ ]);
$this->assertEquals($activityget['id'], $activity2['id']);
$this->assertEquals($file['id'], $activityget['file_id'][0]);
}
* test that get functioning does filtering.
*/
public function testGetStatusID() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => '20110316',
'status_id' => 1,
'activity_name' => 'Test activity type',
'priority_id' => 1,
- );
+ ];
$this->callAPISuccess('Activity', 'Create', $params);
- $result = $this->callAPISuccess('Activity', 'Get', array('activity_status_id' => '1'));
+ $result = $this->callAPISuccess('Activity', 'Get', ['activity_status_id' => '1']);
$this->assertEquals(1, $result['count'], 'one activity of status 1 should exist');
- $result = $this->callAPISuccess('Activity', 'Get', array('status_id' => '1'));
+ $result = $this->callAPISuccess('Activity', 'Get', ['status_id' => '1']);
$this->assertEquals(1, $result['count'], 'status_id should also work');
- $result = $this->callAPISuccess('Activity', 'Get', array('activity_status_id' => '2'));
+ $result = $this->callAPISuccess('Activity', 'Get', ['activity_status_id' => '2']);
$this->assertEquals(0, $result['count'], 'No activities of status 1 should exist');
- $result = $this->callAPISuccess('Activity', 'Get', array(
+ $result = $this->callAPISuccess('Activity', 'Get', [
'version' => $this->_apiversion,
'status_id' => '2',
- ));
+ ]);
$this->assertEquals(0, $result['count'], 'No activities of status 1 should exist');
}
* test that get functioning does filtering.
*/
public function testGetFilterMaxDate() {
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => '20110101',
'activity_name' => 'Test activity type',
'version' => $this->_apiversion,
'priority_id' => 1,
- );
+ ];
$activityOne = $this->callAPISuccess('Activity', 'Create', $params);
$params['activity_date_time'] = 20120216;
$activityTwo = $this->callAPISuccess('Activity', 'Create', $params);
- $result = $this->callAPISuccess('Activity', 'Get', array(
+ $result = $this->callAPISuccess('Activity', 'Get', [
'version' => 3,
- ));
+ ]);
$description = "Demonstrates _low filter (at time of writing doesn't work if contact_id is set.";
$subfile = "DateTimeLow";
$this->assertEquals(2, $result['count']);
- $params = array(
+ $params = [
'version' => 3,
'filter.activity_date_time_low' => '20120101000000',
'sequential' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(1, $result['count']);
$description = "Demonstrates _high filter (at time of writing doesn't work if contact_id is set.";
$subfile = "DateTimeHigh";
$this->assertEquals('2012-02-16 00:00:00', $result['values'][0]['activity_date_time']);
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'version' => 3,
'filter.activity_date_time_high' => '20120101000000',
'sequential' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(1, $result['count']);
$this->assertEquals('2011-01-01 00:00:00', $result['values'][0]['activity_date_time']);
- $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityOne['id']));
- $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityTwo['id']));
+ $this->callAPISuccess('Activity', 'Delete', ['version' => 3, 'id' => $activityOne['id']]);
+ $this->callAPISuccess('Activity', 'Delete', ['version' => 3, 'id' => $activityTwo['id']]);
}
/**
$this->callAPISuccess($this->_entity, 'create', $params);
// Retrieve the test value.
- $params = array(
+ $params = [
'activity_type_id' => $this->test_activity_type_value,
'sequential' => 1,
'return.custom_' . $ids['custom_field_id'] => 1,
- );
+ ];
$result = $this->callAPIAndDocument('activity', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']]);
$result = $this->callAPISuccess($this->_entity, 'create', $params);
// Retrieve the test value
- $params = array(
+ $params = [
'contact_id' => $this->_params['source_contact_id'],
'activity_type_id' => $this->test_activity_type_value,
'sequential' => 1,
'return.custom_' . $ids['custom_field_id'] => 1,
- );
+ ];
$result = $this->callAPIAndDocument('activity', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
* Test civicrm_activity_update() with non-numeric id
*/
public function testActivityUpdateWithNonNumericId() {
- $params = array(
+ $params = [
'id' => 'lets break it',
'activity_name' => 'Meeting',
'subject' => 'this case should fail',
'scheduled_date_time' => date('Ymd'),
- );
+ ];
$result = $this->callAPIFailure('activity', 'create', $params);
}
* Check with incorrect required fields.
*/
public function testActivityUpdateWithIncorrectContactActivityType() {
- $params = array(
+ $params = [
'id' => 1,
'activity_name' => 'Test Activity',
'subject' => 'this case should fail',
'scheduled_date_time' => date('Ymd'),
'source_contact_id' => $this->_contactID,
- );
+ ];
$result = $this->callAPIFailure('activity', 'create', $params,
'Invalid Activity Id');
$result = $this->callAPISuccess('activity', 'create', $this->_params);
$this->_contactID2 = $this->individualCreate();
- $params = array(
+ $params = [
'id' => $result['id'],
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => '20091011123456',
'source_contact_id' => $this->_contactID,
'assignee_contact_id' => $this->_contactID2,
'priority_id' => 1,
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
//hack on date comparison - really we should make getAndCheck smarter to handle dates
// we also unset source_contact_id since it is stored in an aux table
unset($params['source_contact_id']);
//Check if assignee created.
- $assignee = $this->callAPISuccess('ActivityContact', 'get', array(
+ $assignee = $this->callAPISuccess('ActivityContact', 'get', [
'activity_id' => $result['id'],
- 'return' => array("contact_id"),
+ 'return' => ["contact_id"],
'record_type_id' => "Activity Assignees",
- ));
+ ]);
$this->assertNotEmpty($assignee['values']);
//clear assignee contacts.
- $updateParams = array(
+ $updateParams = [
'id' => $result['id'],
- 'assignee_contact_id' => array(),
- );
+ 'assignee_contact_id' => [],
+ ];
$activity = $this->callAPISuccess('activity', 'create', $updateParams);
- $assignee = $this->callAPISuccess('ActivityContact', 'get', array(
+ $assignee = $this->callAPISuccess('ActivityContact', 'get', [
'activity_id' => $activity['id'],
- 'return' => array("contact_id"),
+ 'return' => ["contact_id"],
'record_type_id' => "Activity Assignees",
- ));
+ ]);
$this->assertEmpty($assignee['values']);
$this->getAndCheck($params, $result['id'], 'activity');
}
// Create an activity with custom data
//this has been updated from the previous 'old format' function - need to make it work
- $params = array(
+ $params = [
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => '2009-10-18',
'activity_name' => 'Test activity type',
'version' => $this->_apiversion,
'custom_' . $ids['custom_field_id'] => 'custom string',
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
$activityId = $result['id'];
- $result = $this->callAPISuccess($this->_entity, 'get', array(
+ $result = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
'version' => 3,
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]);
$this->assertEquals("2009-10-18 00:00:00", $result['values'][$result['id']]['activity_date_time']);
- $fields = $this->callAPISuccess('activity', 'getfields', array('version' => $this->_apiversion));
+ $fields = $this->callAPISuccess('activity', 'getfields', ['version' => $this->_apiversion]);
$this->assertTrue(is_array($fields['values']['custom_' . $ids['custom_field_id']]));
// Update the activity with custom data.
- $params = array(
+ $params = [
'id' => $activityId,
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
'custom_' . $ids['custom_field_id'] => 'Updated my test data',
'version' => $this->_apiversion,
- );
+ ];
$result = $this->callAPISuccess('Activity', 'Create', $params);
- $result = $this->callAPISuccess($this->_entity, 'get', array(
+ $result = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
'version' => 3,
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals("Updated my test data", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]);
}
*/
public function testActivityUpdateCheckCoreFields() {
$params = $this->_params;
- $contact1Params = array(
+ $contact1Params = [
'first_name' => 'John',
'middle_name' => 'J.',
'last_name' => 'Anderson',
'suffix_id' => 3,
'email' => 'john_anderson@civicrm.org',
'contact_type' => 'Individual',
- );
+ ];
$contact1 = $this->individualCreate($contact1Params);
- $contact2Params = array(
+ $contact2Params = [
'first_name' => 'Michal',
'middle_name' => 'J.',
'last_name' => 'Anderson',
'suffix_id' => 3,
'email' => 'michal_anderson@civicrm.org',
'contact_type' => 'Individual',
- );
+ ];
$contact2 = $this->individualCreate($contact2Params);
- $params['assignee_contact_id'] = array($contact1, $contact2);
- $params['target_contact_id'] = array($contact2 => $contact2);
+ $params['assignee_contact_id'] = [$contact1, $contact2];
+ $params['target_contact_id'] = [$contact2 => $contact2];
$result = $this->callAPISuccess('Activity', 'Create', $params);
$activityId = $result['id'];
- $getParams = array(
+ $getParams = [
'return.assignee_contact_id' => 1,
'return.target_contact_id' => 1,
'version' => $this->_apiversion,
'id' => $activityId,
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'get', $getParams);
$assignee = $result['values'][$result['id']]['assignee_contact_id'];
$target = $result['values'][$result['id']]['target_contact_id'];
$this->assertEquals(TRUE, in_array($contact1, $assignee), ' in line ' . __LINE__);
$this->assertEquals(TRUE, in_array($contact2, $target), ' in line ' . __LINE__);
- $contact3Params = array(
+ $contact3Params = [
'first_name' => 'Jijo',
'middle_name' => 'J.',
'last_name' => 'Anderson',
'suffix_id' => 3,
'email' => 'jijo_anderson@civicrm.org',
'contact_type' => 'Individual',
- );
+ ];
- $contact4Params = array(
+ $contact4Params = [
'first_name' => 'Grant',
'middle_name' => 'J.',
'last_name' => 'Anderson',
'suffix_id' => 3,
'email' => 'grant_anderson@civicrm.org',
'contact_type' => 'Individual',
- );
+ ];
$contact3 = $this->individualCreate($contact3Params);
$contact4 = $this->individualCreate($contact4Params);
- $params = array();
+ $params = [];
$params['id'] = $activityId;
- $params['assignee_contact_id'] = array($contact3 => $contact3);
- $params['target_contact_id'] = array($contact4 => $contact4);
+ $params['assignee_contact_id'] = [$contact3 => $contact3];
+ $params['target_contact_id'] = [$contact4 => $contact4];
$result = $this->callAPISuccess('activity', 'create', $params);
$result = $this->callAPISuccess(
$this->_entity,
'get',
- array(
+ [
'return.assignee_contact_id' => 1,
'return.target_contact_id' => 1,
'return.source_contact_id' => 1,
'id' => $result['id'],
- )
+ ]
);
$assignee = $result['values'][$result['id']]['assignee_contact_id'];
public function testActivityUpdateNotDate() {
$result = $this->callAPISuccess('activity', 'create', $this->_params);
- $params = array(
+ $params = [
'id' => $result['id'],
'subject' => 'Make-it-Happen Meeting',
'duration' => 120,
'status_id' => 1,
'source_contact_id' => $this->_contactID,
'priority_id' => 1,
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
//hack on date comparison - really we should make getAndCheck smarter to handle dates
*/
public function testActivityUpdateWithStatus() {
$activity = $this->callAPISuccess('activity', 'create', $this->_params);
- $params = array(
+ $params = [
'id' => $activity['id'],
'source_contact_id' => $this->_contactID,
'subject' => 'Hurry update works',
'status_id' => 1,
'activity_name' => 'Test activity type',
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
$this->assertEquals($result['id'], $activity['id']);
$activity = $this->callAPISuccess('activity', 'create', $this->_params);
// Updating the activity but not providing anything for the source contact
// (It was set as $this->_contactID earlier.)
- $params = array(
+ $params = [
'id' => $activity['id'],
'subject' => 'Updated Make-it-Happen Meeting',
'duration' => 120,
'status_id' => 1,
'activity_name' => 'Test activity type',
'priority_id' => 1,
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
- $findactivity = $this->callAPISuccess('Activity', 'Get', array('id' => $activity['id']));
+ $findactivity = $this->callAPISuccess('Activity', 'Get', ['id' => $activity['id']]);
}
/**
$activity = $this->callAPISuccess('activity', 'create', $this->_params);
$activity2 = $this->callAPISuccess('activity', 'create', $this->_params2);
// Get activities associated with contact $this->_contactID.
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
- );
+ ];
$result = $this->callAPISuccess('activity', 'get', $params);
$this->assertEquals(2, $result['count']);
*/
public function testChainedActivityGet() {
- $activity = $this->callAPISuccess('Contact', 'Create', array(
+ $activity = $this->callAPISuccess('Contact', 'Create', [
'display_name' => "bob brown",
'contact_type' => 'Individual',
- 'api.activity_type.create' => array(
+ 'api.activity_type.create' => [
'weight' => '2',
'label' => 'send out letters',
'filter' => 0,
'is_active' => 1,
'is_optgroup' => 1,
'is_default' => 0,
- ),
- 'api.activity.create' => array(
+ ],
+ 'api.activity.create' => [
'subject' => 'send letter',
'activity_type_id' => '$value.api.activity_type.create.values.0.value',
- ),
- ));
+ ],
+ ]);
- $result = $this->callAPISuccess('Activity', 'Get', array(
+ $result = $this->callAPISuccess('Activity', 'Get', [
'id' => $activity['id'],
'return.assignee_contact_id' => 1,
- 'api.contact.get' => array('api.pledge.get' => 1),
- ));
+ 'api.contact.get' => ['api.pledge.get' => 1],
+ ]);
}
/**
* Test civicrm_activity_contact_get() with invalid Contact ID.
*/
public function testActivitiesContactGetWithInvalidContactId() {
- $params = array('contact_id' => 'contact');
+ $params = ['contact_id' => 'contact'];
$this->callAPIFailure('activity', 'get', $params);
}
* Test civicrm_activity_contact_get() with contact having no Activity.
*/
public function testActivitiesContactGetHavingNoActivity() {
- $params = array(
+ $params = [
'first_name' => 'dan',
'last_name' => 'conberg',
'email' => 'dan.conberg@w.co.in',
'contact_type' => 'Individual',
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $params);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$result = $this->callAPISuccess('activity', 'get', $params);
$this->assertEquals($result['count'], 0);
}
* Test getfields function.
*/
public function testGetFields() {
- $params = array('action' => 'create');
+ $params = ['action' => 'create'];
$result = $this->callAPIAndDocument('activity', 'getfields', $params, __FUNCTION__, __FILE__, NULL, NULL);
$this->assertTrue(is_array($result['values']), 'get fields doesn\'t return values array');
foreach ($result['values'] as $key => $value) {
* Test or operator in api params
*/
public function testGetWithOr() {
- $acts = array(
+ $acts = [
'test or 1' => 'orOperator',
'test or 2' => 'orOperator',
'test or 3' => 'nothing',
- );
+ ];
foreach ($acts as $subject => $details) {
$params = $this->_params;
$params['subject'] = $subject;
$params['details'] = $details;
$this->callAPISuccess('Activity', 'create', $params);
}
- $result = $this->callAPISuccess('Activity', 'get', array(
+ $result = $this->callAPISuccess('Activity', 'get', [
'details' => 'orOperator',
- ));
+ ]);
$this->assertEquals(2, $result['count']);
- $result = $this->callAPISuccess('Activity', 'get', array(
+ $result = $this->callAPISuccess('Activity', 'get', [
'details' => 'orOperator',
'subject' => 'test or 3',
- ));
+ ]);
$this->assertEquals(0, $result['count']);
- $result = $this->callAPISuccess('Activity', 'get', array(
+ $result = $this->callAPISuccess('Activity', 'get', [
'details' => 'orOperator',
'subject' => 'test or 3',
- 'options' => array('or' => array(array('details', 'subject'))),
- ));
+ 'options' => ['or' => [['details', 'subject']]],
+ ]);
$this->assertEquals(3, $result['count']);
}
* Test handling of is_overdue calculated field
*/
public function testGetOverdue() {
- $overdueAct = $this->callAPISuccess('Activity', 'create', array(
+ $overdueAct = $this->callAPISuccess('Activity', 'create', [
'activity_date_time' => 'now - 1 week',
'status_id' => 'Scheduled',
- ) + $this->_params);
- $completedAct = $this->callAPISuccess('Activity', 'create', array(
+ ] + $this->_params);
+ $completedAct = $this->callAPISuccess('Activity', 'create', [
'activity_date_time' => 'now - 1 week',
'status_id' => 'Completed',
- ) + $this->_params);
- $ids = array($overdueAct['id'], $completedAct['id']);
+ ] + $this->_params);
+ $ids = [$overdueAct['id'], $completedAct['id']];
// Test sorting
- $completedFirst = $this->callAPISuccess('Activity', 'get', array(
- 'id' => array('IN' => $ids),
- 'options' => array('sort' => 'is_overdue ASC'),
- ));
+ $completedFirst = $this->callAPISuccess('Activity', 'get', [
+ 'id' => ['IN' => $ids],
+ 'options' => ['sort' => 'is_overdue ASC'],
+ ]);
$this->assertEquals(array_reverse($ids), array_keys($completedFirst['values']));
- $overdueFirst = $this->callAPISuccess('Activity', 'get', array(
- 'id' => array('IN' => $ids),
- 'options' => array('sort' => 'is_overdue DESC'),
+ $overdueFirst = $this->callAPISuccess('Activity', 'get', [
+ 'id' => ['IN' => $ids],
+ 'options' => ['sort' => 'is_overdue DESC'],
'return' => 'is_overdue',
- ));
+ ]);
$this->assertEquals($ids, array_keys($overdueFirst['values']));
// Test return value
$this->assertEquals(0, $overdueFirst['values'][$completedAct['id']]['is_overdue']);
// Test filtering
- $onlyOverdue = $this->callAPISuccess('Activity', 'get', array(
- 'id' => array('IN' => $ids),
+ $onlyOverdue = $this->callAPISuccess('Activity', 'get', [
+ 'id' => ['IN' => $ids],
'is_overdue' => 1,
- ));
- $this->assertEquals(array($overdueAct['id']), array_keys($onlyOverdue['values']));
+ ]);
+ $this->assertEquals([$overdueAct['id']], array_keys($onlyOverdue['values']));
}
}
* Test civicrm_activity_type_get().
*/
public function testActivityTypeGet() {
- $params = array();
+ $params = [];
$result = $this->callAPIAndDocument('activity_type', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values']['1'], 'Meeting');
}
* Test civicrm_activity_type_create().
*/
public function testActivityTypeCreate() {
- $params = array(
+ $params = [
'weight' => '2',
'label' => 'send out letters',
'filter' => 0,
'is_active' => 1,
'is_optgroup' => 1,
'is_default' => 0,
- );
+ ];
$result = $this->callAPIAndDocument('activity_type', 'create', $params, __FUNCTION__, __FILE__);
}
* Test civicrm_activity_type_create - check id
*/
public function testActivityTypecreatecheckId() {
- $params = array(
+ $params = [
'label' => 'type_create',
'weight' => '2',
- );
+ ];
$activitycreate = $this->callAPISuccess('activity_type', 'create', $params);
$this->assertArrayHasKey('id', $activitycreate);
$this->assertArrayHasKey('option_group_id', $activitycreate['values'][$activitycreate['id']]);
* Test civicrm_activity_type_delete()
*/
public function testActivityTypeDelete() {
- $params = array(
+ $params = [
'label' => 'type_create_delete',
'weight' => '2',
- );
+ ];
$activitycreate = $this->callAPISuccess('activity_type', 'create', $params);
- $params = array(
+ $params = [
'activity_type_id' => $activitycreate['id'],
- );
+ ];
$result = $this->callAPISuccess('activity_type', 'delete', $params, __FUNCTION__, __FILE__);
}
$this->_locationType = $this->locationTypeCreate();
CRM_Core_PseudoConstant::flush();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'street_name' => 'Ambachtstraat',
'country_id' => '1152',
'city' => 'Brummen',
'is_primary' => 1,
- );
+ ];
}
public function tearDown() {
$this->locationTypeDelete($this->_locationType->id);
$this->contactDelete($this->_contactID);
- $this->quickCleanup(array('civicrm_address', 'civicrm_relationship'));
+ $this->quickCleanup(['civicrm_address', 'civicrm_relationship']);
parent::tearDown();
}
*/
public function testCreateAddressParsing($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'street_parsing' => 1,
'street_address' => '54A Excelsior Ave. Apt 1C',
'location_type_id' => $this->_locationType->id,
'contact_id' => $this->_contactID,
- );
+ ];
$subfile = "AddressParse";
$description = "Demonstrates Use of address parsing param.";
$result = $this->callAPIAndDocument('address', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals('A', $result['values'][$result['id']]['street_number_suffix']);
$this->assertEquals('Excelsior Ave.', $result['values'][$result['id']]['street_name']);
$this->assertEquals('Apt 1C', $result['values'][$result['id']]['street_unit']);
- $this->callAPISuccess('address', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('address', 'delete', ['id' => $result['id']]);
}
public function testCreateAddressWithMasterRelationshipHousehold($version) {
$this->_apiversion = $version;
$householdID = $this->householdCreate();
- $address = $this->callAPISuccess('address', 'create', array_merge($this->_params, $this->_params, array('contact_id' => $householdID)));
+ $address = $this->callAPISuccess('address', 'create', array_merge($this->_params, $this->_params, ['contact_id' => $householdID]));
$individualID = $this->individualCreate();
- $individualParams = array(
+ $individualParams = [
'contact_id' => $individualID,
'master_id' => $address['id'],
- );
+ ];
$this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams));
- $this->callAPISuccess('relationship', 'getcount', array(
+ $this->callAPISuccess('relationship', 'getcount', [
'contact_id_a' => $individualID,
'contact_id_b' => $this->_contactID,
- ));
+ ]);
}
/**
$this->_apiversion = $version;
$address = $this->callAPISuccess('address', 'create', $this->_params);
$individualID = $this->individualCreate();
- $individualParams = array(
+ $individualParams = [
'contact_id' => $individualID,
'master_id' => $address['id'],
- );
+ ];
$this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams));
- $this->callAPISuccess('relationship', 'getcount', array(
+ $this->callAPISuccess('relationship', 'getcount', [
'contact_id_a' => $individualID,
'contact_id_b' => $this->_contactID,
- ), 1);
+ ], 1);
}
/**
$this->_apiversion = $version;
$address = $this->callAPISuccess('address', 'create', $this->_params);
$individualID = $this->individualCreate();
- $individualParams = array(
+ $individualParams = [
'contact_id' => $individualID,
'master_id' => $address['id'],
'update_current_employer' => 0,
- );
+ ];
$this->callAPISuccess('address', 'create', array_merge($this->_params, $individualParams));
- $this->callAPISuccess('relationship', 'getcount', array(
+ $this->callAPISuccess('relationship', 'getcount', [
'contact_id_a' => $individualID,
'contact_id_b' => $this->_contactID,
- ), 0);
+ ], 0);
}
/**
$this->_apiversion = $version;
$address = $this->callAPISuccess('address', 'create', $this->_params);
$organisation2ID = $this->organizationCreate();
- $address2 = $this->callAPISuccess('address', 'create', array_merge($this->_params, array('contact_id' => $organisation2ID)));
+ $address2 = $this->callAPISuccess('address', 'create', array_merge($this->_params, ['contact_id' => $organisation2ID]));
$individualID = $this->individualCreate();
- $individualParams = array_merge($this->_params, array(
+ $individualParams = array_merge($this->_params, [
'contact_id' => $individualID,
'master_id' => $address['id'],
- ));
+ ]);
$individualAddress = $this->callAPISuccess('address', 'create', $individualParams);
$individualParams['master_id'] = $address2['id'];
$individualParams['id'] = $individualAddress['id'];
$this->callAPISuccess('address', 'create', $individualParams);
- $this->callAPISuccessGetCount('relationship', array('contact_id_a' => $individualID), 2);
+ $this->callAPISuccessGetCount('relationship', ['contact_id_a' => $individualID], 2);
$this->markTestIncomplete('Remainder of test checks that employer relationship is disabled when new one is created but turns out to be not happening - by design?');
- $this->callAPISuccessGetCount('relationship', array('contact_id_a' => $individualID, 'is_active' => FALSE), 1);
- $this->callAPISuccessGetCount('relationship', array(
+ $this->callAPISuccessGetCount('relationship', ['contact_id_a' => $individualID, 'is_active' => FALSE], 1);
+ $this->callAPISuccessGetCount('relationship', [
'contact_id_a' => $individualID,
'is_active' => TRUE,
'contact_id_b' => $organisation2ID,
- ), 1);
+ ], 1);
}
unset($params['is_primary']);
$params['id'] = $result['id'];
$this->callAPISuccess('address', 'create', $params);
- $result = $this->callAPISuccess('address', 'get', array('contact_id' => $params['contact_id']));
+ $result = $this->callAPISuccess('address', 'get', ['contact_id' => $params['contact_id']]);
$this->assertEquals(1, $result['count']);
$this->assertEquals(1, $result['values'][$result['id']]['is_primary']);
$this->getAndCheck($params, $result['id'], 'address', __FUNCTION__);
public function testDeleteAddress($version) {
$this->_apiversion = $version;
//check there are no address to start with
- $get = $this->callAPISuccess('address', 'get', array(
+ $get = $this->callAPISuccess('address', 'get', [
'location_type_id' => $this->_locationType->id,
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'Contact already exists ');
//create one
$create = $this->callAPISuccess('address', 'create', $this->_params);
- $result = $this->callAPIAndDocument('address', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('address', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
- $get = $this->callAPISuccess('address', 'get', array(
+ $get = $this->callAPISuccess('address', 'get', [
'location_type_id' => $this->_locationType->id,
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__);
}
$this->_apiversion = $version;
$address = $this->callAPISuccess('address', 'create', $this->_params);
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'street_name' => $address['values'][$address['id']]['street_name'],
- );
+ ];
$result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__);
- $this->callAPISuccess('Address', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('Address', 'delete', ['id' => $result['id']]);
$this->assertEquals($address['values'][$address['id']]['location_type_id'], $result['values'][$address['id']]['location_type_id']);
$this->assertEquals($address['values'][$address['id']]['is_primary'], $result['values'][$address['id']]['is_primary']);
$this->assertEquals($address['values'][$address['id']]['street_address'], $result['values'][$address['id']]['street_address']);
public function testGetSingleAddress($version) {
$this->_apiversion = $version;
$this->callAPISuccess('address', 'create', $this->_params);
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
- );
+ ];
$address = $this->callAPISuccess('Address', 'getsingle', ($params));
$this->assertEquals($address['location_type_id'], $this->_params['location_type_id']);
- $this->callAPISuccess('address', 'delete', array('id' => $address['id']));
+ $this->callAPISuccess('address', 'delete', ['id' => $address['id']]);
}
/**
public function testGetAddressSort($version) {
$this->_apiversion = $version;
$create = $this->callAPISuccess('address', 'create', $this->_params);
- $this->callAPISuccess('address', 'create', array_merge($this->_params, array('street_address' => 'yzy')));
+ $this->callAPISuccess('address', 'create', array_merge($this->_params, ['street_address' => 'yzy']));
$subfile = "AddressSort";
$description = "Demonstrates Use of sort filter.";
- $params = array(
- 'options' => array(
+ $params = [
+ 'options' => [
'sort' => 'street_address DESC',
'limit' => 2,
- ),
+ ],
'sequential' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(2, $result['count']);
$this->assertEquals('Ambachtstraat 23', $result['values'][1]['street_address']);
- $this->callAPISuccess('address', 'delete', array('id' => $create['id']));
+ $this->callAPISuccess('address', 'delete', ['id' => $create['id']]);
}
/**
$this->callAPISuccess('address', 'create', $this->_params);
$subfile = "AddressLike";
$description = "Demonstrates Use of Like.";
- $params = array(
- 'street_address' => array('LIKE' => '%mb%'),
+ $params = [
+ 'street_address' => ['LIKE' => '%mb%'],
'sequential' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(1, $result['count']);
$this->assertEquals('Ambachtstraat 23', $result['values'][0]['street_address']);
- $this->callAPISuccess('address', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('address', 'delete', ['id' => $result['id']]);
}
/**
public function testGetAddressLikeFail($version) {
$this->_apiversion = $version;
$create = $this->callAPISuccess('address', 'create', $this->_params);
- $params = array(
- 'street_address' => array('LIKE' => "'%xy%'"),
+ $params = [
+ 'street_address' => ['LIKE' => "'%xy%'"],
'sequential' => 1,
- );
+ ];
$result = $this->callAPISuccess('Address', 'Get', ($params));
$this->assertEquals(0, $result['count']);
- $this->callAPISuccess('address', 'delete', array('id' => $create['id']));
+ $this->callAPISuccess('address', 'delete', ['id' => $create['id']]);
}
/**
$result = $this->callAPISuccess($this->_entity, 'create', $params);
- $getParams = array('id' => $result['id'], 'return' => array('custom'));
+ $getParams = ['id' => $result['id'], 'return' => ['custom']];
$check = $this->callAPISuccess($this->_entity, 'get', $getParams);
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
$this->customFieldDelete($ids['custom_field_id']);
$this->customGroupDelete($ids['custom_group_id']);
- $this->callAPISuccess('address', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('address', 'delete', ['id' => $result['id']]);
}
/**
$address1 = $this->callAPISuccess('address', 'create', $params);
$this->assertApiSuccess($address1);
//now we check & make sure it has been set to primary
- $check = $this->callAPISuccess('address', 'getcount', array(
+ $check = $this->callAPISuccess('address', 'getcount', [
'is_primary' => 1,
'id' => $address1['id'],
- ));
+ ]);
$this->assertEquals(1, $check);
- $this->callAPISuccess('address', 'delete', array('id' => $address1['id']));
+ $this->callAPISuccess('address', 'delete', ['id' => $address1['id']]);
}
/**
$this->_apiversion = $version;
$address1 = $this->callAPISuccess('address', 'create', $this->_params);
$this->callAPISuccess('address', 'create', $this->_params);
- $check = $this->callAPISuccess('address', 'getcount', array(
+ $check = $this->callAPISuccess('address', 'getcount', [
'is_primary' => 1,
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertEquals(1, $check);
- $this->callAPISuccess('address', 'delete', array('id' => $address1['id']));
+ $this->callAPISuccess('address', 'delete', ['id' => $address1['id']]);
}
/**
*/
public function testCreateDuplicateLocationTypes() {
$address1 = $this->callAPISuccess('address', 'create', $this->_params);
- $address2 = $this->callAPISuccess('address', 'create', array(
+ $address2 = $this->callAPISuccess('address', 'create', [
'location_type_id' => $this->_locationType->id,
'street_address' => '1600 Pensilvania Avenue',
'city' => 'Washington DC',
'is_primary' => 0,
'is_billing' => 0,
'contact_id' => $this->_contactID,
- ));
- $check = $this->callAPISuccess('address', 'getcount', array(
+ ]);
+ $check = $this->callAPISuccess('address', 'getcount', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
- ));
+ ]);
$this->assertEquals(2, $check);
- $this->callAPISuccess('address', 'delete', array('id' => $address1['id']));
- $this->callAPISuccess('address', 'delete', array('id' => $address2['id']));
+ $this->callAPISuccess('address', 'delete', ['id' => $address1['id']]);
+ $this->callAPISuccess('address', 'delete', ['id' => $address2['id']]);
}
public function testGetWithJoin() {
- $cid = $this->individualCreate(array(
- 'api.Address.create' => array(
+ $cid = $this->individualCreate([
+ 'api.Address.create' => [
'street_address' => __FUNCTION__,
'location_type_id' => $this->_locationType->id,
- ),
- ));
- $result = $this->callAPISuccess('address', 'getsingle', array(
+ ],
+ ]);
+ $result = $this->callAPISuccess('address', 'getsingle', [
'check_permissions' => TRUE,
'contact_id' => $cid,
'street_address' => __FUNCTION__,
'return' => 'contact_id.contact_type',
- ));
+ ]);
$this->assertEquals('Individual', $result['contact_id.contact_type']);
}
*/
public function okCreateProvider() {
// array($entityClass, $createParams, $expectedContent)
- $cases = array();
+ $cases = [];
- $cases[] = array(
+ $cases[] = [
'CRM_Activity_DAO_Activity',
- array(
+ [
'name' => self::getFilePrefix() . 'exampleFromContent.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'My test content',
- ),
+ ],
'My test content',
- );
+ ];
- $cases[] = array(
+ $cases[] = [
'CRM_Activity_DAO_Activity',
- array(
+ [
'name' => self::getFilePrefix() . 'exampleWithEmptyContent.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => '',
- ),
+ ],
'',
- );
+ ];
- $cases[] = array(
+ $cases[] = [
'CRM_Activity_DAO_Activity',
- array(
+ [
'name' => self::getFilePrefix() . 'exampleFromMove.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
- 'options' => array(
+ 'options' => [
'move-file' => $this->tmpFile('mytest.txt'),
- ),
- ),
+ ],
+ ],
'This comes from a file',
- );
+ ];
return $cases;
}
*/
public function badCreateProvider() {
// array($entityClass, $createParams, $expectedError)
- $cases = array();
+ $cases = [];
- $cases[] = array(
+ $cases[] = [
'CRM_Activity_DAO_Activity',
- array(
+ [
'id' => 12345,
'name' => self::getFilePrefix() . 'exampleFromContent.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'My test content',
- ),
+ ],
'/Invalid ID/',
- );
- $cases[] = array(
+ ];
+ $cases[] = [
'CRM_Activity_DAO_Activity',
- array(
+ [
'name' => self::getFilePrefix() . 'failedExample.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
- ),
+ ],
"/Mandatory key\\(s\\) missing from params array: 'id' or 'content' or 'options.move-file'/",
- );
- $cases[] = array(
+ ];
+ $cases[] = [
'CRM_Activity_DAO_Activity',
- array(
+ [
'name' => self::getFilePrefix() . 'failedExample.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'too much content',
- 'options' => array(
+ 'options' => [
'move-file' => $this->tmpFile('too-much.txt'),
- ),
- ),
+ ],
+ ],
"/'content' and 'options.move-file' are mutually exclusive/",
- );
- $cases[] = array(
+ ];
+ $cases[] = [
'CRM_Activity_DAO_Activity',
- array(
+ [
'name' => 'inv/alid.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'My test content',
- ),
+ ],
"/Malformed name/",
- );
- $cases[] = array(
+ ];
+ $cases[] = [
'CRM_Core_DAO_Domain',
- array(
+ [
'name' => self::getFilePrefix() . 'exampleFromContent.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'My test content',
'check_permissions' => 1,
- ),
+ ],
"/Unrecognized target entity/",
- );
+ ];
return $cases;
}
*/
public function badUpdateProvider() {
// array($entityClass, $createParams, $updateParams, $expectedError)
- $cases = array();
+ $cases = [];
- $readOnlyFields = array(
+ $readOnlyFields = [
'name' => 'newname.txt',
'entity_table' => 'civicrm_domain',
'entity_id' => 5,
'upload_date' => '2010-11-12 13:14:15',
- );
+ ];
foreach ($readOnlyFields as $readOnlyField => $newValue) {
- $cases[] = array(
+ $cases[] = [
'CRM_Activity_DAO_Activity',
- array(
+ [
'name' => self::getFilePrefix() . 'exampleFromContent.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'My test content',
- ),
- array(
+ ],
+ [
'check_permissions' => 1,
$readOnlyField => $newValue,
- ),
+ ],
"/Cannot modify $readOnlyField/",
- );
+ ];
}
return $cases;
*/
public function okGetProvider() {
// array($getParams, $expectedNames)
- $cases = array();
+ $cases = [];
// Each search runs in a DB which contains these attachments:
// Activity #123: example_123.txt (text/plain) and example_123.csv (text/csv)
// array(self::getFilePrefix() . 'example_123.txt', self::getFilePrefix() . 'example_456.txt'),
//);
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'entity_id' => '123'),
- array(self::getFilePrefix() . 'example_123.txt', self::getFilePrefix() . 'example_123.csv'),
- );
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'entity_id' => '456'),
- array(self::getFilePrefix() . 'example_456.txt', self::getFilePrefix() . 'example_456.csv'),
- );
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'entity_id' => '456', 'mime_type' => 'text/csv'),
- array(self::getFilePrefix() . 'example_456.csv'),
- );
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'entity_id' => '456', 'mime_type' => 'text/html'),
- array(),
- );
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'entity_id' => '999'),
- array(),
- );
+ $cases[] = [
+ ['entity_table' => 'civicrm_activity', 'entity_id' => '123'],
+ [self::getFilePrefix() . 'example_123.txt', self::getFilePrefix() . 'example_123.csv'],
+ ];
+ $cases[] = [
+ ['entity_table' => 'civicrm_activity', 'entity_id' => '456'],
+ [self::getFilePrefix() . 'example_456.txt', self::getFilePrefix() . 'example_456.csv'],
+ ];
+ $cases[] = [
+ ['entity_table' => 'civicrm_activity', 'entity_id' => '456', 'mime_type' => 'text/csv'],
+ [self::getFilePrefix() . 'example_456.csv'],
+ ];
+ $cases[] = [
+ ['entity_table' => 'civicrm_activity', 'entity_id' => '456', 'mime_type' => 'text/html'],
+ [],
+ ];
+ $cases[] = [
+ ['entity_table' => 'civicrm_activity', 'entity_id' => '999'],
+ [],
+ ];
return $cases;
}
*/
public function badGetProvider() {
// array($getParams, $expectedNames)
- $cases = array();
+ $cases = [];
// Each search runs in a DB which contains these attachments:
// Activity #123: example_123.txt (text/plain) and example_123.csv (text/csv)
// Activity #456: example_456.txt (text/plain) and example_456.csv (text/csv)
- $cases[] = array(
- array('check_permissions' => 1, 'mime_type' => 'text/plain'),
+ $cases[] = [
+ ['check_permissions' => 1, 'mime_type' => 'text/plain'],
"/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table'/",
- );
- $cases[] = array(
- array('check_permissions' => 1, 'entity_id' => '123'),
+ ];
+ $cases[] = [
+ ['check_permissions' => 1, 'entity_id' => '123'],
"/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table'/",
- );
- $cases[] = array(
- array('check_permissions' => 1),
+ ];
+ $cases[] = [
+ ['check_permissions' => 1],
"/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table'/",
- );
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'name' => 'example_456.csv'),
+ ];
+ $cases[] = [
+ ['entity_table' => 'civicrm_activity', 'entity_id' => '123', 'name' => 'example_456.csv'],
"/Get by name is not currently supported/",
- );
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'content' => 'test'),
+ ];
+ $cases[] = [
+ ['entity_table' => 'civicrm_activity', 'entity_id' => '123', 'content' => 'test'],
"/Get by content is not currently supported/",
- );
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'path' => '/home/foo'),
+ ];
+ $cases[] = [
+ ['entity_table' => 'civicrm_activity', 'entity_id' => '123', 'path' => '/home/foo'],
"/Get by path is not currently supported/",
- );
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'url' => '/index.php'),
+ ];
+ $cases[] = [
+ ['entity_table' => 'civicrm_activity', 'entity_id' => '123', 'url' => '/index.php'],
"/Get by url is not currently supported/",
- );
+ ];
return $cases;
}
$entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass);
$this->assertTrue(is_numeric($entity->id));
- $createResult = $this->callAPISuccess('Attachment', 'create', $createParams + array(
+ $createResult = $this->callAPISuccess('Attachment', 'create', $createParams + [
'entity_table' => $entity_table,
'entity_id' => $entity->id,
- ));
+ ]);
$fileId = $createResult['id'];
$this->assertTrue(is_numeric($fileId));
$this->assertEquals($entity_table, $createResult['values'][$fileId]['entity_table']);
$this->assertTrue(!empty($createResult['values'][$fileId]['url']));
$this->assertAttachmentExistence(TRUE, $createResult);
- $getResult = $this->callAPISuccess('Attachment', 'get', array(
+ $getResult = $this->callAPISuccess('Attachment', 'get', [
'entity_table' => $entity_table,
'entity_id' => $entity->id,
- ));
+ ]);
$this->assertEquals(1, $getResult['count']);
- foreach (array('id', 'entity_table', 'entity_id', 'url') as $field) {
+ foreach (['id', 'entity_table', 'entity_id', 'url'] as $field) {
$this->assertEquals($createResult['values'][$fileId][$field], $getResult['values'][$fileId][$field], "Expect field $field to match");
}
$this->assertTrue(!isset($getResult['values'][$fileId]['content']));
- $getResult2 = $this->callAPISuccess('Attachment', 'get', array(
+ $getResult2 = $this->callAPISuccess('Attachment', 'get', [
'entity_table' => $entity_table,
'entity_id' => $entity->id,
- 'return' => array('content'),
- ));
+ 'return' => ['content'],
+ ]);
$this->assertEquals($expectedContent, $getResult2['values'][$fileId]['content']);
- foreach (array('id', 'entity_table', 'entity_id', 'url') as $field) {
+ foreach (['id', 'entity_table', 'entity_id', 'url'] as $field) {
$this->assertEquals($createResult['values'][$fileId][$field], $getResult['values'][$fileId][$field], "Expect field $field to match");
}
}
$entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass);
$this->assertTrue(is_numeric($entity->id));
- $createResult = $this->callAPIFailure('Attachment', 'create', $createParams + array(
+ $createResult = $this->callAPIFailure('Attachment', 'create', $createParams + [
'entity_table' => $entity_table,
'entity_id' => $entity->id,
- ));
+ ]);
$this->assertRegExp($expectedError, $createResult['error_message']);
}
$entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass);
$this->assertTrue(is_numeric($entity->id));
- $createResult = $this->callAPISuccess('Attachment', 'create', $createParams + array(
+ $createResult = $this->callAPISuccess('Attachment', 'create', $createParams + [
'entity_table' => $entity_table,
'entity_id' => $entity->id,
- ));
+ ]);
$fileId = $createResult['id'];
$this->assertTrue(is_numeric($fileId));
- $updateResult = $this->callAPIFailure('Attachment', 'create', $updateParams + array(
+ $updateResult = $this->callAPIFailure('Attachment', 'create', $updateParams + [
'id' => $fileId,
- ));
+ ]);
$this->assertRegExp($expectedError, $updateResult['error_message']);
}
$entity = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity');
$this->assertTrue(is_numeric($entity->id));
- $createResult = $this->callAPISuccess('Attachment', 'create', array(
+ $createResult = $this->callAPISuccess('Attachment', 'create', [
'name' => self::getFilePrefix() . 'weird:na"me.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'My test content',
'entity_table' => 'civicrm_activity',
'entity_id' => $entity->id,
- ));
+ ]);
$fileId = $createResult['id'];
$this->assertTrue(is_numeric($fileId));
$this->assertEquals(self::getFilePrefix() . 'weird_na_me.txt', $createResult['values'][$fileId]['name']);
$entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass);
$this->assertTrue(is_numeric($entity->id));
- $createResult = $this->callAPISuccess('Attachment', 'create', array(
+ $createResult = $this->callAPISuccess('Attachment', 'create', [
'name' => self::getFilePrefix() . 'exampleFromContent.txt',
'mime_type' => 'text/plain',
'content' => 'My test content',
'entity_table' => $entity_table,
'entity_id' => $entity->id,
- ));
+ ]);
$fileId = $createResult['id'];
$this->assertEquals($loggedInUser, $createResult['values'][$fileId]['created_id']);
$entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass);
$this->assertTrue(is_numeric($entity->id));
- $createResult = $this->callAPISuccess('Attachment', 'create', array(
+ $createResult = $this->callAPISuccess('Attachment', 'create', [
'name' => self::getFilePrefix() . 'exampleFromContent.txt',
'mime_type' => 'text/plain',
'content' => 'My test content',
'entity_table' => $entity_table,
'entity_id' => $entity->id,
- ));
+ ]);
$fileId = $createResult['id'];
$this->assertEmpty($createResult['values'][$fileId]['created_id']);
$entity_table = CRM_Core_DAO_AllCoreTables::getTableForClass($testEntityClass);
$this->assertTrue(is_numeric($entity->id));
- $attachmentParams = array(
+ $attachmentParams = [
'name' => self::getFilePrefix() . 'exampleFromContent.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'My test content',
'entity_table' => $entity_table,
'entity_id' => $entity->id,
- );
+ ];
$createResult = $this->callAPISuccess('Attachment', 'create', $attachmentParams);
$this->callAPISuccess('Attachment', 'create', $attachmentParams);
- $updatedAttachment = $this->callAPISuccess('Attachment', 'get', array(
+ $updatedAttachment = $this->callAPISuccess('Attachment', 'get', [
'id' => $fileId,
'entity_id' => $attachmentParams['entity_id'],
'entity_table' => $attachmentParams['entity_table'],
- ));
+ ]);
$this->assertNotEmpty($loggedInUser);
$this->assertEmpty($updatedAttachment['values'][$fileId]['created_id']);
* @dataProvider okGetProvider
*/
public function testGet($getParams, $expectedNames) {
- foreach (array(123, 456) as $entity_id) {
- foreach (array('text/plain' => '.txt', 'text/csv' => '.csv') as $mime => $ext) {
- $this->callAPISuccess('Attachment', 'create', array(
+ foreach ([123, 456] as $entity_id) {
+ foreach (['text/plain' => '.txt', 'text/csv' => '.csv'] as $mime => $ext) {
+ $this->callAPISuccess('Attachment', 'create', [
'name' => self::getFilePrefix() . 'example_' . $entity_id . $ext,
'mime_type' => $mime,
'description' => 'My test description',
'content' => 'My test content',
'entity_table' => 'civicrm_activity',
'entity_id' => $entity_id,
- ));
+ ]);
}
}
* @dataProvider badGetProvider
*/
public function testGetError($getParams, $expectedError) {
- foreach (array(123, 456) as $entity_id) {
- foreach (array('text/plain' => '.txt', 'text/csv' => '.csv') as $mime => $ext) {
- $this->callAPISuccess('Attachment', 'create', array(
+ foreach ([123, 456] as $entity_id) {
+ foreach (['text/plain' => '.txt', 'text/csv' => '.csv'] as $mime => $ext) {
+ $this->callAPISuccess('Attachment', 'create', [
'name' => self::getFilePrefix() . 'example_' . $entity_id . $ext,
'mime_type' => $mime,
'description' => 'My test description',
'content' => 'My test content',
'entity_table' => 'civicrm_activity',
'entity_id' => $entity_id,
- ));
+ ]);
}
}
$entity = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity');
$this->assertTrue(is_numeric($entity->id));
- $createResult = $this->callAPISuccess('Attachment', 'create', array(
+ $createResult = $this->callAPISuccess('Attachment', 'create', [
'name' => self::getFilePrefix() . 'getThenUpdate.txt',
'mime_type' => 'text/plain',
'description' => 'My test description',
'content' => 'My test content',
'entity_table' => 'civicrm_activity',
'entity_id' => $entity->id,
- ));
+ ]);
$fileId = $createResult['id'];
$this->assertTrue(is_numeric($fileId));
$this->assertEquals(self::getFilePrefix() . 'getThenUpdate.txt', $createResult['values'][$fileId]['name']);
$this->assertAttachmentExistence(TRUE, $createResult);
- $getResult = $this->callAPISuccess('Attachment', 'get', array(
+ $getResult = $this->callAPISuccess('Attachment', 'get', [
'id' => $fileId,
- ));
+ ]);
$this->assertTrue(is_array($getResult['values'][$fileId]));
$updateParams = $getResult['values'][$fileId];
$entity = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity');
$this->assertTrue(is_numeric($entity->id));
- foreach (array('first', 'second') as $n) {
- $createResults[$n] = $this->callAPISuccess('Attachment', 'create', array(
+ foreach (['first', 'second'] as $n) {
+ $createResults[$n] = $this->callAPISuccess('Attachment', 'create', [
'name' => self::getFilePrefix() . 'testDeleteByID.txt',
'mime_type' => 'text/plain',
'content' => 'My test content',
'entity_table' => 'civicrm_activity',
'entity_id' => $entity->id,
- ));
+ ]);
$this->assertTrue(is_numeric($createResults[$n]['id']));
$this->assertEquals(self::getFilePrefix() . 'testDeleteByID.txt', $createResults[$n]['values'][$createResults[$n]['id']]['name']);
}
$this->assertAttachmentExistence(TRUE, $createResults['first']);
$this->assertAttachmentExistence(TRUE, $createResults['second']);
- $this->callAPISuccess('Attachment', 'delete', array(
+ $this->callAPISuccess('Attachment', 'delete', [
'id' => $createResults['first']['id'],
- ));
+ ]);
$this->assertAttachmentExistence(FALSE, $createResults['first']);
$this->assertAttachmentExistence(TRUE, $createResults['second']);
}
*/
public function testDeleteByEntity() {
// create 2 entities (keepme,delme) -- each with 2 attachments (first,second)
- foreach (array('keepme', 'delme') as $e) {
+ foreach (['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(
+ foreach (['first', 'second'] as $n) {
+ $createResults[$e][$n] = $this->callAPISuccess('Attachment', 'create', [
'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['delme']['first']);
$this->assertAttachmentExistence(TRUE, $createResults['delme']['second']);
- $this->callAPISuccess('Attachment', 'delete', array(
+ $this->callAPISuccess('Attachment', 'delete', [
'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']);
$entity = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity');
$this->assertTrue(is_numeric($entity->id));
- $createResult = $this->callAPISuccess('Attachment', 'create', array(
+ $createResult = $this->callAPISuccess('Attachment', 'create', [
'name' => self::getFilePrefix() . 'hasIcon.docx',
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'description' => 'My test description',
'content' => 'My test content',
'entity_table' => 'civicrm_activity',
'entity_id' => $entity->id,
- ));
+ ]);
$fileId = $createResult['id'];
$this->assertEquals('fa-file-word-o', $createResult['values'][$fileId]['icon']);
- $createResult = $this->callAPISuccess('Attachment', 'create', array(
+ $createResult = $this->callAPISuccess('Attachment', 'create', [
'name' => self::getFilePrefix() . 'hasIcon.jpg',
'mime_type' => 'image/jpg',
'description' => 'My test description',
'content' => 'My test content',
'entity_table' => 'civicrm_activity',
'entity_id' => $entity->id,
- ));
+ ]);
$fileId = $createResult['id'];
$this->assertEquals('fa-file-image-o', $createResult['values'][$fileId]['icon']);
}
protected function cleanupFiles() {
$config = CRM_Core_Config::singleton();
- $dirs = array(
+ $dirs = [
sys_get_temp_dir(),
$config->customFileUploadDir,
- );
+ ];
foreach ($dirs as $dir) {
$files = (array) glob($dir . "/" . self::getFilePrefix() . "*");
foreach ($files as $file) {
*/
class api_v3_BatchTest extends CiviUnitTestCase {
- protected $_params = array();
+ protected $_params = [];
protected $_entity = 'batch';
/**
* Test civicrm_batch_get - success expected.
*/
public function testGet() {
- $params = array(
+ $params = [
'id' => $this->batchCreate(),
- );
+ ];
$result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($params['id'], $result['id']);
}
* Test civicrm_batch_create - success expected.
*/
public function testCreate() {
- $params = array(
+ $params = [
'name' => 'New_Batch_03',
'title' => 'New Batch 03',
'description' => 'This is description for New Batch 03',
'total' => '300.33',
'item_count' => 3,
'status_id' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($result['id']);
* Test civicrm_batch_create with id.
*/
public function testUpdate() {
- $params = array(
+ $params = [
'name' => 'New_Batch_04',
'title' => 'New Batch 04',
'description' => 'This is description for New Batch 04',
'total' => '400.44',
'item_count' => 4,
'id' => $this->batchCreate(),
- );
+ ];
$result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($result['id']);
*/
public function testBatchDeleteOldSyntax() {
$batchID = $this->batchCreate();
- $params = array(
+ $params = [
'batch_id' => $batchID,
- );
+ ];
$result = $this->callAPISuccess('batch', 'delete', $params);
}
*/
public function testBatchDeleteCorrectSyntax() {
$batchID = $this->batchCreate();
- $params = array(
+ $params = [
'id' => $batchID,
- );
+ ];
$result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__);
}
$result = $this->callAPISuccess(
'contact',
'get',
- array(
+ [
'contact_type' => $contactType,
- )
+ ]
);
foreach ($result['values'] as $idx => $contact) {
public $DBResetRequired = FALSE;
public function setUp() {
- $this->params = array(
+ $this->params = [
'title' => "campaign title",
'description' => "Call people, ask for money",
'created_date' => 'first sat of July 2008',
- );
+ ];
parent::setUp();
$this->useTransaction(TRUE);
}
$result = $this->callAPIAndDocument('campaign', 'create', $this->params, __FUNCTION__, __FILE__, $description);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->getAndCheck(array_merge($this->params, array('created_date' => '2008-07-05 00:00:00')), $result['id'], 'campaign', TRUE);
+ $this->getAndCheck(array_merge($this->params, ['created_date' => '2008-07-05 00:00:00']), $result['id'], 'campaign', TRUE);
}
/**
$this->_apiversion = $version;
$this->callAPISuccess('campaign', 'create', $this->params);
$entity = $this->callAPISuccess('campaign', 'get', ($this->params));
- $delete = array('id' => $entity['id']);
+ $delete = ['id' => $entity['id']];
$result = $this->callAPIAndDocument('campaign', 'delete', $delete, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess('campaign', 'get', array());
+ $checkDeleted = $this->callAPISuccess('campaign', 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
parent::setUp();
$this->_cid = $this->individualCreate();
- $this->_cid2 = $this->individualCreate(array(), 1);
+ $this->_cid2 = $this->individualCreate([], 1);
- $this->_case = $this->callAPISuccess('case', 'create', array(
+ $this->_case = $this->callAPISuccess('case', 'create', [
'case_type_id' => $this->caseTypeId,
'subject' => __CLASS__,
'contact_id' => $this->_cid,
- ));
+ ]);
- $this->_params = array(
+ $this->_params = [
'case_id' => $this->_case['id'],
'contact_id' => $this->_cid2,
- );
+ ];
}
public function testCaseContactGet() {
- $result = $this->callAPIAndDocument('CaseContact', 'get', array(
+ $result = $this->callAPIAndDocument('CaseContact', 'get', [
'contact_id' => $this->_cid,
- ), __FUNCTION__, __FILE__);
+ ], __FUNCTION__, __FILE__);
$this->assertEquals($this->_case['id'], $result['id']);
}
$id = $result['id'];
// Check result
- $result = $this->callAPISuccess('CaseContact', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('CaseContact', 'get', ['id' => $id]);
$this->assertEquals($result['values'][$id]['case_id'], $params['case_id']);
$this->assertEquals($result['values'][$id]['contact_id'], $params['contact_id']);
}
parent::setUp();
- $activityTypes = $this->callAPISuccess('option_value', 'get', array(
+ $activityTypes = $this->callAPISuccess('option_value', 'get', [
'option_group_id' => 2,
'name' => 'Follow Up',
'label' => 'Follow Up',
'sequential' => 1,
- ));
+ ]);
$this->followup_activity_type_value = $activityTypes['values'][0]['value'];
- $this->_params = array(
+ $this->_params = [
'case_type_id' => $this->caseTypeId,
'subject' => 'Test case',
'contact_id' => 17,
- );
+ ];
$this->settingsStack = new \Civi\Core\SettingsStack();
}
* Check with empty array.
*/
public function testCaseCreateEmpty() {
- $this->callAPIFailure('case', 'create', array());
+ $this->callAPIFailure('case', 'create', []);
}
/**
* Check if required fields are not passed.
*/
public function testCaseCreateWithoutRequired() {
- $params = array(
+ $params = [
'subject' => 'this case should fail',
'case_type_id' => 1,
- );
+ ];
$this->callAPIFailure('case', 'create', $params);
}
$params['subject'] = 'Test Case 3';
$this->callAPISuccess('case', 'create', $params);
- $getParams = array(
- 'id' => array($case1['id']),
- 'extra' => array('contact_id'),
- 'params' => array(
+ $getParams = [
+ 'id' => [$case1['id']],
+ 'extra' => ['contact_id'],
+ 'params' => [
'version' => 3,
- 'case_id' => array('!=' => $case2['id']),
+ 'case_id' => ['!=' => $case2['id']],
'case_id.is_deleted' => 0,
- 'case_id.status_id' => array('!=' => "Closed"),
- 'case_id.end_date' => array('IS NULL' => 1),
- ),
- );
+ 'case_id.status_id' => ['!=' => "Closed"],
+ 'case_id.end_date' => ['IS NULL' => 1],
+ ],
+ ];
$result = $this->callAPISuccess('case', 'getlist', $getParams);
//Only 1 case should be returned.
$id = $result['id'];
// Check result
- $result = $this->callAPISuccess('case', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('case', 'get', ['id' => $id]);
$this->assertEquals($result['values'][$id]['id'], $id);
$this->assertEquals($result['values'][$id]['case_type_id'], $this->caseTypeId);
$this->assertEquals($result['values'][$id]['subject'], $params['subject']);
$id = $result['id'];
// Check result
- $result = $this->callAPISuccess('case', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('case', 'get', ['id' => $id]);
$this->assertEquals($result['values'][$id]['id'], $id);
$this->assertEquals($result['values'][$id]['case_type_id'], $this->caseTypeId);
$this->assertEquals($result['values'][$id]['subject'], $params['subject']);
$this->assertEquals($result['values'][$id]['end_date'], date('Y-m-d'));
//Check all relationship end dates are set to case end date.
- $relationships = $this->callAPISuccess('Relationship', 'get', array(
+ $relationships = $this->callAPISuccess('Relationship', 'get', [
'sequential' => 1,
'case_id' => $id,
- ));
+ ]);
foreach ($relationships['values'] as $key => $values) {
$this->assertEquals($values['end_date'], date('Y-m-d'));
}
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
- $result = $this->callAPISuccess($this->_entity, 'get', array(
+ $result = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]);
$this->customFieldDelete($ids['custom_field_id']);
$params['case_type'] = $this->caseType;
$result = $this->callAPISuccess('case', 'create', $params);
$id = $result['id'];
- $case = $this->callAPISuccess('case', 'getsingle', array('id' => $id));
+ $case = $this->callAPISuccess('case', 'getsingle', ['id' => $id]);
// Update Case.
- $params = array('id' => $id);
+ $params = ['id' => $id];
$params['subject'] = $case['subject'] = 'Something Else';
$this->callAPISuccess('case', 'create', $params);
// Verify that updated case is equal to the original with new subject.
- $result = $this->callAPISuccessGetSingle('Case', array('case_id' => $id));
+ $result = $this->callAPISuccessGetSingle('Case', ['case_id' => $id]);
// Modification dates are likely to differ by 0-2 sec. Check manually.
$this->assertGreaterThanOrEqual($case['modified_date'], $result['modified_date']);
unset($result['modified_date'], $case['modified_date']);
$params['case_type'] = $this->caseType;
$result = $this->callAPISuccess('case', 'create', $params);
$id = $result['id'];
- $case = $this->callAPISuccess('case', 'getsingle', array('id' => $id));
+ $case = $this->callAPISuccess('case', 'getsingle', ['id' => $id]);
// Update Case, we specify existing case ID and existing contact ID to verify that CaseContact.create is not called
$params = $this->_params;
$this->callAPISuccess('case', 'create', $params);
// Verify that updated case is equal to the original with new subject.
- $result = $this->callAPISuccessGetSingle('Case', array('case_id' => $id));
+ $result = $this->callAPISuccessGetSingle('Case', ['case_id' => $id]);
// Modification dates are likely to differ by 0-2 sec. Check manually.
$this->assertGreaterThanOrEqual($case['modified_date'], $result['modified_date']);
unset($result['modified_date'], $case['modified_date']);
$result = $this->callAPISuccess($this->_entity, 'create', $params);
$caseId = $result['id'];
- $result = $this->callAPISuccess($this->_entity, 'get', array(
+ $result = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
'version' => 3,
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]);
- $fields = $this->callAPISuccess($this->_entity, 'getfields', array('version' => $this->_apiversion));
+ $fields = $this->callAPISuccess($this->_entity, 'getfields', ['version' => $this->_apiversion]);
$this->assertTrue(is_array($fields['values']['custom_' . $ids['custom_field_id']]));
// Update the activity with custom data.
- $params = array(
+ $params = [
'id' => $caseId,
'custom_' . $ids['custom_field_id'] => 'Updated my test data',
'version' => $this->_apiversion,
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'create', $params);
- $result = $this->callAPISuccess($this->_entity, 'get', array(
+ $result = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
'version' => 3,
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals("Updated my test data", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]);
}
// Move Case to Trash
$id = $result['id'];
- $this->callAPISuccess('case', 'delete', array('id' => $id, 'move_to_trash' => 1));
+ $this->callAPISuccess('case', 'delete', ['id' => $id, 'move_to_trash' => 1]);
// Check result - also check that 'case_id' works as well as 'id'
- $result = $this->callAPISuccess('case', 'get', array('case_id' => $id));
+ $result = $this->callAPISuccess('case', 'get', ['case_id' => $id]);
$this->assertEquals(1, $result['values'][$id]['is_deleted']);
// Restore Case from Trash
- $this->callAPISuccess('case', 'restore', array('id' => $id));
+ $this->callAPISuccess('case', 'restore', ['id' => $id]);
// Check result
- $result = $this->callAPISuccess('case', 'get', array('case_id' => $id));
+ $result = $this->callAPISuccess('case', 'get', ['case_id' => $id]);
$this->assertEquals(0, $result['values'][$id]['is_deleted']);
// Delete Case Permanently
- $this->callAPISuccess('case', 'delete', array('case_id' => $id));
+ $this->callAPISuccess('case', 'delete', ['case_id' => $id]);
// Check result - case should no longer exist
- $result = $this->callAPISuccess('case', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('case', 'get', ['id' => $id]);
$this->assertEquals(0, $result['count']);
}
public function testCaseRoleRelationships() {
// Create Case
$case = $this->callAPISuccess('case', 'create', $this->_params);
- $relType = $this->relationshipTypeCreate(array('name_a_b' => 'Test AB', 'name_b_a' => 'Test BA', 'contact_type_b' => 'Individual'));
- $relContact = $this->individualCreate(array('first_name' => 'First', 'last_name' => 'Last'));
+ $relType = $this->relationshipTypeCreate(['name_a_b' => 'Test AB', 'name_b_a' => 'Test BA', 'contact_type_b' => 'Individual']);
+ $relContact = $this->individualCreate(['first_name' => 'First', 'last_name' => 'Last']);
- $_REQUEST = array(
+ $_REQUEST = [
'rel_type' => "{$relType}_b_a",
'rel_contact' => $relContact,
'case_id' => $case['id'],
'is_unit_test' => TRUE,
- );
+ ];
$ret = CRM_Contact_Page_AJAX::relationship();
$this->assertEquals(0, $ret['is_error']);
//Check if relationship exist for the case.
- $relationship = $this->callAPISuccess('Relationship', 'get', array(
+ $relationship = $this->callAPISuccess('Relationship', 'get', [
'sequential' => 1,
'relationship_type_id' => $relType,
'case_id' => $case['id'],
- ));
+ ]);
$this->assertEquals($relContact, $relationship['values'][0]['contact_id_a']);
$this->assertEquals($this->_params['contact_id'], $relationship['values'][0]['contact_id_b']);
//Check if activity is assigned to correct contact.
- $activity = $this->callAPISuccess('Activity', 'get', array(
+ $activity = $this->callAPISuccess('Activity', 'get', [
'subject' => 'Test BA : Mr. First Last II',
- ));
- $this->callAPISuccess('ActivityContact', 'get', array(
+ ]);
+ $this->callAPISuccess('ActivityContact', 'get', [
'contact_id' => $relContact,
'activity_id' => $activity['id'],
- ));
+ ]);
}
/**
$id = $result['id'];
// Check result - we should get a list of activity ids
- $result = $this->callAPISuccess('case', 'get', array('id' => $id, 'return' => 'activities'));
+ $result = $this->callAPISuccess('case', 'get', ['id' => $id, 'return' => 'activities']);
$case = $result['values'][$id];
$activity = $case['activities'][0];
// Fetch case based on an activity id
- $result = $this->callAPISuccess('case', 'get', array(
+ $result = $this->callAPISuccess('case', 'get', [
'activity_id' => $activity,
'return' => 'activities',
- ));
+ ]);
$this->assertEquals(FALSE, empty($result['values'][$id]));
$this->assertEquals($result['values'][$id], $case);
}
$id = $result['id'];
// Store result for later
- $case = $this->callAPISuccessGetSingle('case', array('id' => $id, 'return' => array('activities', 'contacts')));
+ $case = $this->callAPISuccessGetSingle('case', ['id' => $id, 'return' => ['activities', 'contacts']]);
// Fetch case based on client contact id
- $result = $this->callAPISuccess('case', 'get', array(
+ $result = $this->callAPISuccess('case', 'get', [
'client_id' => $this->_params['contact_id'],
- 'return' => array('activities', 'contacts'),
- ));
+ 'return' => ['activities', 'contacts'],
+ ]);
$this->assertAPIArrayComparison($result['values'][$id], $case);
}
$id = $result['id'];
// Store result for later
- $case = $this->callAPISuccessGetSingle('Case', array('id' => $id, 'return' => 'subject'));
+ $case = $this->callAPISuccessGetSingle('Case', ['id' => $id, 'return' => 'subject']);
// Fetch case based on client contact id
- $result = $this->callAPISuccess('case', 'get', array(
+ $result = $this->callAPISuccess('case', 'get', [
'subject' => $this->_params['subject'],
- 'return' => array('subject'),
- ));
+ 'return' => ['subject'],
+ ]);
$this->assertAPIArrayComparison($result['values'][$id], $case);
}
$this->callAPISuccess('case', 'create', $this->_params);
// Append 'wrong' to subject so that it is no longer the same.
- $result = $this->callAPISuccess('case', 'get', array(
+ $result = $this->callAPISuccess('case', 'get', [
'subject' => $this->_params['subject'] . 'wrong',
- 'return' => array('activities', 'contacts'),
- ));
+ 'return' => ['activities', 'contacts'],
+ ]);
$this->assertEquals(0, $result['count']);
}
$id = $result['id'];
// Store result for later
- $case = $this->callAPISuccessGetSingle('Case', array('id' => $id, 'return' => 'contact_id'));
+ $case = $this->callAPISuccessGetSingle('Case', ['id' => $id, 'return' => 'contact_id']);
- $result = $this->callAPISuccess('case', 'get', array('limit' => 0, 'return' => array('contact_id')));
+ $result = $this->callAPISuccess('case', 'get', ['limit' => 0, 'return' => ['contact_id']]);
$this->assertAPIArrayComparison($result['values'][$id], $case);
}
public function testCaseActivityCreate() {
$params = $this->_params;
$case = $this->callAPISuccess('case', 'create', $params);
- $params = array(
+ $params = [
'case_id' => $case['id'],
// follow up
'activity_type_id' => $this->followup_activity_type_value,
'subject' => 'Test followup 123',
'source_contact_id' => $this->_loggedInUser,
'target_contact_id' => $this->_params['contact_id'],
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
$this->assertEquals($result['values'][$result['id']]['activity_type_id'], $params['activity_type_id']);
$this->assertEquals($dao->find(), 1, 'activity_contact table not populated correctly');
// Check that fetching an activity by case id works, as well as returning case_id
- $result = $this->callAPISuccessGetSingle('Activity', array(
+ $result = $this->callAPISuccessGetSingle('Activity', [
'case_id' => $case['id'],
'activity_type_id' => $this->followup_activity_type_value,
'subject' => 'Test followup 123',
- 'return' => array('case_id'),
- ));
+ 'return' => ['case_id'],
+ ]);
$this->assertContains($case['id'], $result['case_id']);
}
// Need to create the case and activity before we can update it
$this->testCaseActivityCreate();
- $params = array(
+ $params = [
'activity_id' => $this->_caseActivityId,
'case_id' => 1,
'activity_type_id' => 14,
'source_contact_id' => $this->_loggedInUser,
'subject' => 'New subject',
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
$this->assertEquals($result['values'][$result['id']]['subject'], $params['subject']);
$this->assertEquals($result['values'][$result['id']]['original_id'], $this->_caseActivityId);
// Check revision is as expected
- $revParams = array(
+ $revParams = [
'activity_id' => $this->_caseActivityId,
- );
+ ];
$revActivity = $this->callAPISuccess('activity', 'get', $revParams);
$this->assertEquals($revActivity['values'][$this->_caseActivityId]['is_current_revision'],
0);
->orderBy('id')
->execute()->fetchAll();
- $params = array(
+ $params = [
'activity_id' => $this->_caseActivityId,
'case_id' => 1,
'activity_type_id' => 14,
'source_contact_id' => $this->_loggedInUser,
'subject' => 'New subject',
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
$this->assertEquals($result['values'][$result['id']]['subject'], $params['subject']);
$custom_ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ActivityTest.php');
// create activity
- $params = array(
+ $params = [
'case_id' => $result['id'],
// follow up
'activity_type_id' => 14,
'source_contact_id' => $this->_loggedInUser,
'target_contact_id' => $this->_params['contact_id'],
'custom_' . $custom_ids['custom_field_id'] => "custom string",
- );
+ ];
$result = $this->callAPISuccess('activity', 'create', $params);
$aid = $result['values'][$result['id']]['id'];
// Update activity
- $params = array(
+ $params = [
'activity_id' => $aid,
'case_id' => 1,
'activity_type_id' => 14,
'source_contact_id' => $this->_loggedInUser,
'subject' => 'New subject',
- );
+ ];
$this->callAPISuccess('activity', 'create', $params);
// Retrieve revision and check custom fields got copied.
- $revParams = array(
+ $revParams = [
'activity_id' => $aid + 1,
'return.custom_' . $custom_ids['custom_field_id'] => 1,
- );
+ ];
$revAct = $this->callAPISuccess('activity', 'get', $revParams);
$this->assertEquals($revAct['values'][$aid + 1]['custom_' . $custom_ids['custom_field_id']], "custom string",
public function testCaseGetByStatus() {
// Create 2 cases with different status ids.
- $case1 = $this->callAPISuccess('Case', 'create', array(
+ $case1 = $this->callAPISuccess('Case', 'create', [
'contact_id' => 17,
'subject' => "Test case 1",
'case_type_id' => $this->caseTypeId,
'status_id' => "Open",
'sequential' => 1,
- ));
- $this->callAPISuccess('Case', 'create', array(
+ ]);
+ $this->callAPISuccess('Case', 'create', [
'contact_id' => 17,
'subject' => "Test case 2",
'case_type_id' => $this->caseTypeId,
'status_id' => "Urgent",
'sequential' => 1,
- ));
- $result = $this->callAPISuccessGetSingle('Case', array(
+ ]);
+ $result = $this->callAPISuccessGetSingle('Case', [
'sequential' => 1,
'contact_id' => 17,
'status_id' => "Open",
- ));
+ ]);
$this->assertEquals($case1['id'], $result['id']);
}
public function testCaseGetWithRoles() {
- $case1 = $this->callAPISuccess('Case', 'create', array(
+ $case1 = $this->callAPISuccess('Case', 'create', [
'contact_id' => 17,
'subject' => "Test case with roles",
'case_type_id' => $this->caseTypeId,
'status_id' => "Open",
- ));
- $result = $this->callAPISuccessGetSingle('Case', array(
+ ]);
+ $result = $this->callAPISuccessGetSingle('Case', [
'id' => $case1['id'],
'status_id' => "Open",
- 'return' => array('contacts'),
- ));
+ 'return' => ['contacts'],
+ ]);
foreach ($result['contacts'] as $contact) {
if ($contact['role'] == 'Client') {
$this->assertEquals(17, $contact['contact_id']);
}
public function testCaseGetWithDefinition() {
- $case1 = $this->callAPISuccess('Case', 'create', array(
+ $case1 = $this->callAPISuccess('Case', 'create', [
'contact_id' => 17,
'subject' => "Test case with definition",
'case_type_id' => $this->caseTypeId,
'status_id' => "Open",
- ));
- $result1 = $this->callAPISuccessGetSingle('Case', array(
+ ]);
+ $result1 = $this->callAPISuccessGetSingle('Case', [
'id' => $case1['id'],
'status_id' => "Open",
- 'return' => array('case_type_id.definition'),
- ));
- $result2 = $this->callAPISuccessGetSingle('Case', array(
+ 'return' => ['case_type_id.definition'],
+ ]);
+ $result2 = $this->callAPISuccessGetSingle('Case', [
'id' => $case1['id'],
'status_id' => "Open",
- 'return' => array('case_type_id', 'case_type_id.definition'),
- ));
+ 'return' => ['case_type_id', 'case_type_id.definition'],
+ ]);
$this->assertEquals($result1['case_type_id.definition'], $result2['case_type_id.definition']);
$def = $result1['case_type_id.definition'];
- $this->assertEquals(array('name' => 'Open Case', 'max_instances' => 1), $def['activityTypes'][0]);
+ $this->assertEquals(['name' => 'Open Case', 'max_instances' => 1], $def['activityTypes'][0]);
$this->assertNotEmpty($def['activitySets'][0]['activityTypes']);
$this->assertNotEmpty($def['caseRoles'][0]['manager']);
$this->assertNotEmpty($def['caseRoles'][0]['creator']);
}
public function testCaseGetTags() {
- $case1 = $this->callAPISuccess('Case', 'create', array(
+ $case1 = $this->callAPISuccess('Case', 'create', [
'contact_id' => 17,
'subject' => "Test case with tags",
'case_type_id' => $this->caseTypeId,
'status_id' => "Open",
- ));
- $tag1 = $this->tagCreate(array(
+ ]);
+ $tag1 = $this->tagCreate([
'name' => 'CaseTag1',
'used_for' => 'civicrm_case',
- ));
- $tag2 = $this->tagCreate(array(
+ ]);
+ $tag2 = $this->tagCreate([
'name' => 'CaseTag2',
'used_for' => 'civicrm_case',
- ));
- $this->callAPISuccess('EntityTag', 'create', array(
+ ]);
+ $this->callAPISuccess('EntityTag', 'create', [
'entity_table' => 'civicrm_case',
'entity_id' => $case1['id'],
'tag_id' => $tag1['id'],
- ));
- $this->callAPIFailure('Case', 'getsingle', array(
+ ]);
+ $this->callAPIFailure('Case', 'getsingle', [
'tag_id' => $tag2['id'],
- ));
- $result = $this->callAPISuccessGetSingle('Case', array(
+ ]);
+ $result = $this->callAPISuccessGetSingle('Case', [
'tag_id' => $tag1['id'],
'return' => 'tag_id.name',
- ));
+ ]);
$this->assertEquals('CaseTag1', $result['tag_id'][$tag1['id']]['tag_id.name']);
}
* @throws \Exception
*/
public function testCaseGetChainedOp() {
- $contact1 = $this->individualCreate(array(), 1);
- $contact2 = $this->individualCreate(array(), 2);
- $case1 = $this->callAPISuccess('Case', 'create', array(
+ $contact1 = $this->individualCreate([], 1);
+ $contact2 = $this->individualCreate([], 2);
+ $case1 = $this->callAPISuccess('Case', 'create', [
'contact_id' => $contact1,
'subject' => "Test case 1",
'case_type_id' => $this->caseTypeId,
- ));
- $case2 = $this->callAPISuccess('Case', 'create', array(
+ ]);
+ $case2 = $this->callAPISuccess('Case', 'create', [
'contact_id' => $contact2,
'subject' => "Test case 2",
'case_type_id' => $this->caseTypeId,
- ));
- $case3 = $this->callAPISuccess('Case', 'create', array(
- 'contact_id' => array($contact1, $contact2),
+ ]);
+ $case3 = $this->callAPISuccess('Case', 'create', [
+ 'contact_id' => [$contact1, $contact2],
'subject' => "Test case 3",
'case_type_id' => $this->caseTypeId,
- ));
+ ]);
// Fetch case 1 and all cases with the same client. Chained get should return case 3.
- $result = $this->callAPISuccessGetSingle('Case', array(
+ $result = $this->callAPISuccessGetSingle('Case', [
'id' => $case1['id'],
'return' => 'contact_id',
- 'api.Case.get' => array(
- 'contact_id' => array('IN' => "\$value.contact_id"),
- 'id' => array('!=' => "\$value.id"),
- ),
- ));
+ 'api.Case.get' => [
+ 'contact_id' => ['IN' => "\$value.contact_id"],
+ 'id' => ['!=' => "\$value.id"],
+ ],
+ ]);
$this->assertEquals($case3['id'], $result['api.Case.get']['id']);
// Fetch case 3 and all cases with the same clients. Chained get should return case 1&2.
- $result = $this->callAPISuccessGetSingle('Case', array(
+ $result = $this->callAPISuccessGetSingle('Case', [
'id' => $case3['id'],
- 'return' => array('contact_id'),
- 'api.Case.get' => array(
+ 'return' => ['contact_id'],
+ 'api.Case.get' => [
'return' => 'id',
- 'contact_id' => array('IN' => "\$value.contact_id"),
- 'id' => array('!=' => "\$value.id"),
- ),
- ));
- $this->assertEquals(array($case1['id'], $case2['id']), array_keys(CRM_Utils_Array::rekey($result['api.Case.get']['values'], 'id')));
+ 'contact_id' => ['IN' => "\$value.contact_id"],
+ 'id' => ['!=' => "\$value.id"],
+ ],
+ ]);
+ $this->assertEquals([$case1['id'], $case2['id']], array_keys(CRM_Utils_Array::rekey($result['api.Case.get']['values'], 'id')));
}
/**
* For multi-client cases, should order by the first client.
*/
public function testCaseGetOrderByClient() {
- $contact1 = $this->individualCreate(array('first_name' => 'Aa', 'last_name' => 'Zz'));
- $contact2 = $this->individualCreate(array('first_name' => 'Bb', 'last_name' => 'Zz'));
- $contact3 = $this->individualCreate(array('first_name' => 'Cc', 'last_name' => 'Xx'));
+ $contact1 = $this->individualCreate(['first_name' => 'Aa', 'last_name' => 'Zz']);
+ $contact2 = $this->individualCreate(['first_name' => 'Bb', 'last_name' => 'Zz']);
+ $contact3 = $this->individualCreate(['first_name' => 'Cc', 'last_name' => 'Xx']);
- $case1 = $this->callAPISuccess('Case', 'create', array(
+ $case1 = $this->callAPISuccess('Case', 'create', [
'contact_id' => $contact1,
'subject' => "Test case 1",
'case_type_id' => $this->caseTypeId,
- ));
- $case2 = $this->callAPISuccess('Case', 'create', array(
+ ]);
+ $case2 = $this->callAPISuccess('Case', 'create', [
'contact_id' => $contact2,
'subject' => "Test case 2",
'case_type_id' => $this->caseTypeId,
- ));
- $case3 = $this->callAPISuccess('Case', 'create', array(
- 'contact_id' => array($contact3, $contact1),
+ ]);
+ $case3 = $this->callAPISuccess('Case', 'create', [
+ 'contact_id' => [$contact3, $contact1],
'subject' => "Test case 3",
'case_type_id' => $this->caseTypeId,
- ));
+ ]);
- $result = $this->callAPISuccess('Case', 'get', array(
- 'contact_id' => array('IN' => array($contact1, $contact2, $contact3)),
+ $result = $this->callAPISuccess('Case', 'get', [
+ 'contact_id' => ['IN' => [$contact1, $contact2, $contact3]],
'sequential' => 1,
'return' => 'id',
- 'options' => array('sort' => 'contact_id.first_name'),
- ));
+ 'options' => ['sort' => 'contact_id.first_name'],
+ ]);
$this->assertEquals($case3['id'], $result['values'][2]['id']);
$this->assertEquals($case2['id'], $result['values'][1]['id']);
$this->assertEquals($case1['id'], $result['values'][0]['id']);
- $result = $this->callAPISuccess('Case', 'get', array(
- 'contact_id' => array('IN' => array($contact1, $contact2, $contact3)),
+ $result = $this->callAPISuccess('Case', 'get', [
+ 'contact_id' => ['IN' => [$contact1, $contact2, $contact3]],
'sequential' => 1,
'return' => 'id',
- 'options' => array('sort' => 'contact_id.last_name ASC, contact_id.first_name DESC'),
- ));
+ 'options' => ['sort' => 'contact_id.last_name ASC, contact_id.first_name DESC'],
+ ]);
$this->assertEquals($case1['id'], $result['values'][2]['id']);
$this->assertEquals($case2['id'], $result['values'][1]['id']);
$this->assertEquals($case3['id'], $result['values'][0]['id']);
- $result = $this->callAPISuccess('Case', 'get', array(
- 'contact_id' => array('IN' => array($contact1, $contact2, $contact3)),
+ $result = $this->callAPISuccess('Case', 'get', [
+ 'contact_id' => ['IN' => [$contact1, $contact2, $contact3]],
'sequential' => 1,
'return' => 'id',
- 'options' => array('sort' => 'contact_id.first_name DESC'),
- ));
+ 'options' => ['sort' => 'contact_id.first_name DESC'],
+ ]);
$this->assertEquals($case1['id'], $result['values'][2]['id']);
$this->assertEquals($case2['id'], $result['values'][1]['id']);
$this->assertEquals($case3['id'], $result['values'][0]['id']);
- $result = $this->callAPISuccess('Case', 'get', array(
- 'contact_id' => array('IN' => array($contact1, $contact2, $contact3)),
+ $result = $this->callAPISuccess('Case', 'get', [
+ 'contact_id' => ['IN' => [$contact1, $contact2, $contact3]],
'sequential' => 1,
'return' => 'id',
- 'options' => array('sort' => 'case_type_id, contact_id DESC, status_id'),
- ));
+ 'options' => ['sort' => 'case_type_id, contact_id DESC, status_id'],
+ ]);
$this->assertEquals($case1['id'], $result['values'][2]['id']);
$this->assertEquals($case2['id'], $result['values'][1]['id']);
$this->assertEquals($case3['id'], $result['values'][0]['id']);
public function testCaseAddtimeline($enableRevisions) {
$this->settingsStack->push('civicaseActivityRevisions', $enableRevisions);
- $caseSpec = array(
+ $caseSpec = [
'title' => 'Application with Definition',
'name' => 'Application_with_Definition',
'is_active' => 1,
'weight' => 4,
- 'definition' => array(
- 'activityTypes' => array(
- array('name' => 'Follow up'),
- ),
- 'activitySets' => array(
- array(
+ 'definition' => [
+ 'activityTypes' => [
+ ['name' => 'Follow up'],
+ ],
+ 'activitySets' => [
+ [
'name' => 'set1',
'label' => 'Label 1',
'timeline' => 1,
- 'activityTypes' => array(
- array('name' => 'Open Case', 'status' => 'Completed'),
- ),
- ),
- array(
+ 'activityTypes' => [
+ ['name' => 'Open Case', 'status' => 'Completed'],
+ ],
+ ],
+ [
'name' => 'set2',
'label' => 'Label 2',
'timeline' => 1,
- 'activityTypes' => array(
- array('name' => 'Follow up'),
- ),
- ),
- ),
- 'caseRoles' => array(
- array('name' => 'Homeless Services Coordinator', 'creator' => 1, 'manager' => 1),
- ),
- ),
- );
+ 'activityTypes' => [
+ ['name' => 'Follow up'],
+ ],
+ ],
+ ],
+ 'caseRoles' => [
+ ['name' => 'Homeless Services Coordinator', 'creator' => 1, 'manager' => 1],
+ ],
+ ],
+ ];
$cid = $this->individualCreate();
$caseType = $this->callAPISuccess('CaseType', 'create', $caseSpec);
- $case = $this->callAPISuccess('Case', 'create', array(
+ $case = $this->callAPISuccess('Case', 'create', [
'case_type_id' => $caseType['id'],
'contact_id' => $cid,
'subject' => 'Test case with timeline',
- ));
+ ]);
// Created case should only have 1 activity per the spec
- $result = $this->callAPISuccessGetSingle('Activity', array('case_id' => $case['id'], 'return' => 'activity_type_id.name'));
+ $result = $this->callAPISuccessGetSingle('Activity', ['case_id' => $case['id'], 'return' => 'activity_type_id.name']);
$this->assertEquals('Open Case', $result['activity_type_id.name']);
// Add timeline.
- $this->callAPISuccess('Case', 'addtimeline', array(
+ $this->callAPISuccess('Case', 'addtimeline', [
'case_id' => $case['id'],
'timeline' => 'set2',
- ));
- $result = $this->callAPISuccess('Activity', 'get', array(
+ ]);
+ $result = $this->callAPISuccess('Activity', 'get', [
'case_id' => $case['id'],
'return' => 'activity_type_id.name',
'sequential' => 1,
- 'options' => array('sort' => 'id'),
- ));
+ 'options' => ['sort' => 'id'],
+ ]);
$this->assertEquals(2, $result['count']);
$this->assertEquals('Follow up', $result['values'][1]['activity_type_id.name']);
}
* @throws \Exception
*/
public function testCaseMerge() {
- $contact1 = $this->individualCreate(array(), 1);
- $case1 = $this->callAPISuccess('Case', 'create', array(
+ $contact1 = $this->individualCreate([], 1);
+ $case1 = $this->callAPISuccess('Case', 'create', [
'contact_id' => $contact1,
'subject' => "Test case 1",
'case_type_id' => $this->caseTypeId,
- ));
- $case2 = $this->callAPISuccess('Case', 'create', array(
+ ]);
+ $case2 = $this->callAPISuccess('Case', 'create', [
'contact_id' => $contact1,
'subject' => "Test case 2",
'case_type_id' => $this->caseTypeId,
- ));
- $result = $this->callAPISuccess('Case', 'getcount', array('contact_id' => $contact1));
+ ]);
+ $result = $this->callAPISuccess('Case', 'getcount', ['contact_id' => $contact1]);
$this->assertEquals(2, $result);
- $this->callAPISuccess('Case', 'merge', array('case_id_1' => $case1['id'], 'case_id_2' => $case2['id']));
+ $this->callAPISuccess('Case', 'merge', ['case_id_1' => $case1['id'], 'case_id_2' => $case2['id']]);
- $result = $this->callAPISuccess('Case', 'getsingle', array('id' => $case2['id']));
+ $result = $this->callAPISuccess('Case', 'getsingle', ['id' => $case2['id']]);
$this->assertEquals(1, $result['is_deleted']);
}
* @return array
*/
public function caseActivityRevisionExamples() {
- $examples = array();
- $examples[] = array(FALSE);
- $examples[] = array(TRUE);
+ $examples = [];
+ $examples[] = [FALSE];
+ $examples[] = [TRUE];
return $examples;
}
$params = $this->_params;
$case_created = $this->callAPISuccess('case', 'create', $params);
- $case_1 = $this->callAPISuccess('Case', 'getsingle', array(
+ $case_1 = $this->callAPISuccess('Case', 'getsingle', [
'id' => $case_created['id'],
- ));
+ ]);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_1['created_date']);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_1['modified_date']);
$this->assertApproxEquals(strtotime($case_1['created_date']), strtotime($case_1['modified_date']), 2);
- $activity_1 = $this->callAPISuccess('activity', 'getsingle', array(
+ $activity_1 = $this->callAPISuccess('activity', 'getsingle', [
'case_id' => $case_created['id'],
- 'options' => array(
+ 'options' => [
'limit' => 1,
- ),
- ));
+ ],
+ ]);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_1['created_date']);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_1['modified_date']);
$this->assertApproxEquals(strtotime($activity_1['created_date']), strtotime($activity_1['modified_date']), 2);
usleep(1.5 * 1000000);
- $this->callAPISuccess('activity', 'create', array(
+ $this->callAPISuccess('activity', 'create', [
'id' => $activity_1['id'],
'subject' => 'Make cheese',
- ));
+ ]);
- $activity_2 = $this->callAPISuccess('activity', 'getsingle', array(
+ $activity_2 = $this->callAPISuccess('activity', 'getsingle', [
'id' => $activity_1['id'],
- ));
+ ]);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_2['created_date']);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $activity_2['modified_date']);
$this->assertNotEquals($activity_2['created_date'], $activity_2['modified_date']);
$this->assertLessThan($activity_2['modified_date'], $activity_1['modified_date'],
sprintf("Original modification time (%s) should predate later modification time (%s)", $activity_1['modified_date'], $activity_2['modified_date']));
- $case_2 = $this->callAPISuccess('Case', 'getsingle', array(
+ $case_2 = $this->callAPISuccess('Case', 'getsingle', [
'id' => $case_created['id'],
- ));
+ ]);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_2['created_date']);
$this->assertRegExp(';^\d\d\d\d-\d\d-\d\d \d\d:\d\d;', $case_2['modified_date']);
$this->assertEquals($case_1['created_date'], $case_2['created_date']);
class api_v3_CaseTypeTest extends CiviCaseTestCase {
public function setUp() {
- $this->quickCleanup(array('civicrm_case_type'));
+ $this->quickCleanup(['civicrm_case_type']);
parent::setUp();
- $this->fixtures['Application_with_Definition'] = array(
+ $this->fixtures['Application_with_Definition'] = [
'title' => 'Application with Definition',
'name' => 'Application_with_Definition',
'is_active' => 1,
'weight' => 4,
- 'definition' => array(
- 'activityTypes' => array(
- array('name' => 'First act'),
- ),
- 'activitySets' => array(
- array(
+ 'definition' => [
+ 'activityTypes' => [
+ ['name' => 'First act'],
+ ],
+ 'activitySets' => [
+ [
'name' => 'set1',
'label' => 'Label 1',
'timeline' => 1,
- 'activityTypes' => array(
- array('name' => 'Open Case', 'status' => 'Completed'),
- ),
- ),
- ),
- 'timelineActivityTypes' => array(
- array('name' => 'Open Case', 'status' => 'Completed'),
- ),
- 'caseRoles' => array(
- array('name' => 'First role', 'creator' => 1, 'manager' => 1),
- ),
- ),
- );
+ 'activityTypes' => [
+ ['name' => 'Open Case', 'status' => 'Completed'],
+ ],
+ ],
+ ],
+ 'timelineActivityTypes' => [
+ ['name' => 'Open Case', 'status' => 'Completed'],
+ ],
+ 'caseRoles' => [
+ ['name' => 'First role', 'creator' => 1, 'manager' => 1],
+ ],
+ ],
+ ];
}
/**
*/
public function tearDown() {
parent::tearDown();
- $this->quickCleanup(array('civicrm_case_type', 'civicrm_uf_match'));
+ $this->quickCleanup(['civicrm_case_type', 'civicrm_uf_match']);
}
/**
* Check with empty array.
*/
public function testCaseTypeCreateEmpty() {
- $this->callAPIFailure('CaseType', 'create', array());
+ $this->callAPIFailure('CaseType', 'create', []);
}
/**
* Check if required fields are not passed.
*/
public function testCaseTypeCreateWithoutRequired() {
- $params = array(
+ $params = [
'name' => 'this case should fail',
- );
+ ];
$this->callAPIFailure('CaseType', 'create', $params);
- $params = array(
+ $params = [
'name' => 'this case should fail',
'weight' => 4,
- );
+ ];
$this->callAPIFailure('CaseType', 'create', $params);
}
*/
public function testCaseTypeCreate() {
// Create Case Type.
- $params = array(
+ $params = [
'title' => 'Application',
'name' => 'Application',
'is_active' => 1,
'weight' => 4,
- );
+ ];
$result = $this->callAPISuccess('CaseType', 'create', $params);
$id = $result['id'];
// Check result.
- $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]);
$this->assertEquals($result['values'][$id]['id'], $id);
$this->assertEquals($result['values'][$id]['title'], $params['title']);
}
*/
public function testCaseTypeCreate_invalidName() {
// Create Case Type
- $params = array(
+ $params = [
'title' => 'Application',
// spaces are not allowed
'name' => 'Appl ication',
'is_active' => 1,
'weight' => 4,
- );
+ ];
$this->callAPIFailure('CaseType', 'create', $params);
}
*/
public function testCaseTypeUpdate() {
// Create Case Type
- $params = array(
+ $params = [
'title' => 'Application',
'name' => 'Application',
'is_active' => 1,
'weight' => 4,
- );
+ ];
$result = $this->callAPISuccess('CaseType', 'create', $params);
$id = $result['id'];
- $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]);
$caseType = $result['values'][$id];
// Update Case Type.
- $params = array('id' => $id);
+ $params = ['id' => $id];
$params['title'] = $caseType['title'] = 'Something Else';
$this->callAPISuccess('CaseType', 'create', $params);
// Verify that updated case Type is exactly equal to the original with new title.
- $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]);
$this->assertEquals($result['values'][$id], $caseType);
}
*/
public function testCaseTypeDelete_New() {
// Create Case Type.
- $params = array(
+ $params = [
'title' => 'Application',
'name' => 'Application',
'is_active' => 1,
'weight' => 4,
- );
+ ];
$result = $this->callAPISuccess('CaseType', 'create', $params);
$id = $result['id'];
- $this->callAPISuccess('CaseType', 'delete', array('id' => $id));
+ $this->callAPISuccess('CaseType', 'delete', ['id' => $id]);
// Check result - case type should no longer exist
- $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]);
$this->assertEquals(0, $result['count']);
}
$id = $result['id'];
// Check result
- $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('CaseType', 'get', ['id' => $id]);
$this->assertEquals($result['values'][$id]['id'], $id);
$this->assertEquals($result['values'][$id]['title'], $params['title']);
$this->assertEquals($result['values'][$id]['definition'], $params['definition']);
$params = $this->fixtures['Application_with_Definition'];
$createCaseType = $this->callAPISuccess('CaseType', 'create', $params);
- $createCase = $this->callAPISuccess('Case', 'create', array(
+ $createCase = $this->callAPISuccess('Case', 'create', [
'case_type_id' => $createCaseType['id'],
'contact_id' => $this->_loggedInUser,
'subject' => 'Example',
- ));
+ ]);
// Deletion fails while case-type is in-use
- $deleteCaseType = $this->callAPIFailure('CaseType', 'delete', array('id' => $createCaseType['id']));
+ $deleteCaseType = $this->callAPIFailure('CaseType', 'delete', ['id' => $createCaseType['id']]);
$this->assertEquals("You can not delete this case type -- it is assigned to 1 existing case record(s). If you do not want this case type to be used going forward, consider disabling it instead.", $deleteCaseType['error_message']);
- $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
+ $getCaseType = $this->callAPISuccess('CaseType', 'get', ['id' => $createCaseType['id']]);
$this->assertEquals(1, $getCaseType['count']);
// Deletion succeeds when it's not in-use.
- $this->callAPISuccess('Case', 'delete', array('id' => $createCase['id']));
+ $this->callAPISuccess('Case', 'delete', ['id' => $createCase['id']]);
// Check result - case type should no longer exist.
- $this->callAPISuccess('CaseType', 'delete', array('id' => $createCaseType['id']));
- $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
+ $this->callAPISuccess('CaseType', 'delete', ['id' => $createCaseType['id']]);
+ $getCaseType = $this->callAPISuccess('CaseType', 'get', ['id' => $createCaseType['id']]);
$this->assertEquals(0, $getCaseType['count']);
}
public function testCaseStatusByCaseType() {
$this->markTestIncomplete('Cannot figure out why this passes locally but fails on Jenkins.');
$statusName = md5(mt_rand());
- $template = $this->callAPISuccess('CaseType', 'getsingle', array('id' => $this->caseTypeId));
+ $template = $this->callAPISuccess('CaseType', 'getsingle', ['id' => $this->caseTypeId]);
unset($template['id']);
$template['name'] = $template['title'] = 'test_case_type';
- $template['definition']['statuses'] = array('Closed', $statusName);
+ $template['definition']['statuses'] = ['Closed', $statusName];
$this->callAPISuccess('CaseType', 'create', $template);
- $this->callAPISuccess('OptionValue', 'create', array(
+ $this->callAPISuccess('OptionValue', 'create', [
'option_group_id' => 'case_status',
'name' => $statusName,
'label' => $statusName,
'weight' => 99,
- ));
- $result = $this->callAPISuccess('Case', 'getoptions', array('field' => 'status_id', 'case_type_id' => 'test_case_type', 'context' => 'validate'));
+ ]);
+ $result = $this->callAPISuccess('Case', 'getoptions', ['field' => 'status_id', 'case_type_id' => 'test_case_type', 'context' => 'validate']);
$this->assertEquals($template['definition']['statuses'], array_values($result['values']));
}
* Test civicrm_constant_get( ) for unknown constant
*/
public function testUnknownConstant() {
- $result = $this->callAPIFailure('constant', 'get', array(
+ $result = $this->callAPIFailure('constant', 'get', [
'name' => 'thisTypeDoesNotExist',
- ));
+ ]);
}
/**
*/
public function testActivityStatus() {
- $result = $this->callAPISuccess('constant', 'get', array(
+ $result = $this->callAPISuccess('constant', 'get', [
'name' => 'activityStatus',
- ));
+ ]);
$this->assertTrue($result['count'] > 5, "In line " . __LINE__);
$this->assertContains('Scheduled', $result['values'], "In line " . __LINE__);
* Test civicrm_constant_get( 'activityType' )
*/
public function testActivityType() {
- $result = $this->callAPIAndDocument('constant', 'get', array(
+ $result = $this->callAPIAndDocument('constant', 'get', [
'name' => 'activityType',
- ), __FUNCTION__, __FILE__, NULL, NULL, 'get');
+ ], __FUNCTION__, __FILE__, NULL, NULL, 'get');
$this->assertTrue($result['count'] > 2, "In line " . __LINE__);
$this->assertContains('Meeting', $result['values'], "In line " . __LINE__);
}
// needed to get rid of cached values from previous tests
CRM_Core_PseudoConstant::flush();
- $params = array(
+ $params = [
'field' => 'location_type_id',
- );
+ ];
$result = $this->callAPIAndDocument('address', 'getoptions', $params, __FUNCTION__, __FILE__);
$this->assertTrue($result['count'] > 3, "In line " . __LINE__);
$this->assertContains('Home', $result['values'], "In line " . __LINE__);
*/
public function testPhoneType($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'field' => 'phone_type_id',
- );
+ ];
$result = $this->callAPIAndDocument('phone', 'getoptions', $params, __FUNCTION__, __FILE__);
$this->assertEquals(5, $result['count'], "In line " . __LINE__);
*/
public function testmailProtocol($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'field' => 'protocol',
- );
+ ];
$result = $this->callAPIAndDocument('mail_settings', 'getoptions', $params, __FUNCTION__, __FILE__);
$this->assertEquals(4, $result['count'], "In line " . __LINE__);
public function setUp() {
parent::setUp();
$this->useTransaction(TRUE);
- $params = array(
+ $params = [
'label' => 'sub_individual',
'name' => 'sub_individual',
// Individual
'parent_id' => 1,
'is_active' => 1,
- );
+ ];
$result = CRM_Contact_BAO_ContactType::add($params);
$this->subTypeIndividual = $params['name'];
- $params = array(
+ $params = [
'label' => 'sub_organization',
'name' => 'sub_organization',
// Organization
'parent_id' => 3,
'is_active' => 1,
- );
+ ];
$result = CRM_Contact_BAO_ContactType::add($params);
$this->subTypeOrganization = $params['name'];
- $params = array(
+ $params = [
'label' => 'sub_household',
'name' => 'sub_household',
// Household
'parent_id' => 2,
'is_active' => 1,
- );
+ ];
$result = CRM_Contact_BAO_ContactType::add($params);
$this->subTypeHousehold = $params['name'];
}
$this->_apiversion = $version;
// check for Type:Individual Subtype:sub_individual
- $contactParams = array(
+ $contactParams = [
'first_name' => 'Anne',
'last_name' => 'Grant',
'contact_type' => 'Individual',
'contact_sub_type' => $this->subTypeIndividual,
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$result = $this->callAPISuccess('contact', 'get', $params);
$this->assertEquals($result['values'][$contact['id']]['first_name'], $contactParams['first_name'], "In line " . __LINE__);
$this->assertEquals($result['values'][$contact['id']]['last_name'], $contactParams['last_name'], "In line " . __LINE__);
$this->callAPISuccess('contact', 'delete', $params);
// check for Type:Organization Subtype:sub_organization
- $contactParams = array(
+ $contactParams = [
'organization_name' => 'Compumentor',
'contact_type' => 'Organization',
'contact_sub_type' => $this->subTypeOrganization,
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$getContacts = $this->callAPISuccess('contact', 'get', $params);
$result = $getContacts['values'][$contact['id']];
$this->assertEquals($result['organization_name'], $contactParams['organization_name'], "In line " . __LINE__);
$this->_apiversion = $version;
// check for Type:Individual Subtype:sub_household
- $contactParams = array(
+ $contactParams = [
'first_name' => 'Anne',
'last_name' => 'Grant',
'contact_type' => 'Individual',
'contact_sub_type' => $this->subTypeHousehold,
- );
+ ];
$contact = $this->callAPIFailure('contact', 'create', $contactParams);
// check for Type:Organization Subtype:sub_individual
- $contactParams = array(
+ $contactParams = [
'organization_name' => 'Compumentor',
'contact_type' => 'Organization',
'contact_sub_type' => $this->subTypeIndividual,
- );
+ ];
$contact = $this->callAPIFailure('contact', 'create', $contactParams);
}
$this->_apiversion = $version;
// check for Type:Individual
- $contactParams = array(
+ $contactParams = [
'first_name' => 'Anne',
'last_name' => 'Grant',
'contact_type' => 'Individual',
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
// subype:sub_individual
- $updateParams = array(
+ $updateParams = [
'first_name' => 'John',
'last_name' => 'Grant',
'contact_id' => $contact['id'],
'contact_type' => 'Individual',
'contact_sub_type' => $this->subTypeIndividual,
- );
+ ];
$updateContact = $this->callAPISuccess('contact', 'create', $updateParams);
$this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$getContacts = $this->callAPISuccess('contact', 'get', $params);
$result = $getContacts['values'][$contact['id']];
$this->callAPISuccess('contact', 'delete', $params);
// check for Type:Organization
- $contactParams = array(
+ $contactParams = [
'organization_name' => 'Compumentor',
'contact_type' => 'Organization',
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
// subype:sub_organization
- $updateParams = array(
+ $updateParams = [
'organization_name' => 'Intel Arts',
'contact_id' => $contact['id'],
'contact_type' => 'Organization',
'contact_sub_type' => $this->subTypeOrganization,
- );
+ ];
$updateContact = $this->callAPISuccess('contact', 'create', $updateParams);
$this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$getContacts = $this->callAPISuccess('contact', 'get', $params);
$result = $getContacts['values'][$contact['id']];
$this->_apiversion = $version;
// check for Type:Individual
- $contactParams = array(
+ $contactParams = [
'first_name' => 'Anne',
'last_name' => 'Grant',
'contact_type' => 'Individual',
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
// subype:sub_household
- $updateParams = array(
+ $updateParams = [
'first_name' => 'John',
'last_name' => 'Grant',
'contact_id' => $contact['id'],
'contact_type' => 'Individual',
'contact_sub_type' => $this->subTypeHousehold,
- );
+ ];
$updateContact = $this->callAPIFailure('contact', 'create', $updateParams);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$this->callAPISuccess('contact', 'delete', $params);
// check for Type:Organization
- $contactParams = array(
+ $contactParams = [
'organization_name' => 'Compumentor',
'contact_type' => 'Organization',
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
- $updateParams = array(
+ $updateParams = [
'organization_name' => 'Intel Arts',
'contact_id' => $contact['id'],
'contact_type' => 'Organization',
'contact_sub_type' => $this->subTypeIndividual,
- );
+ ];
$updateContact = $this->callAPIFailure('contact', 'create', $updateParams);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$this->callAPISuccess('contact', 'delete', $params);
}
public function testContactUpdateSubtypeValid($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'label' => 'sub2_individual',
'name' => 'sub2_individual',
// Individual
'parent_id' => 1,
'is_active' => 1,
- );
+ ];
$getSubtype = CRM_Contact_BAO_ContactType::add($params);
$subtype = $params['name'];
// check for Type:Individual subype:sub_individual
- $contactParams = array(
+ $contactParams = [
'first_name' => 'Anne',
'last_name' => 'Grant',
'contact_type' => 'Individual',
'contact_sub_type' => $this->subTypeIndividual,
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
// subype:sub2_individual
- $updateParams = array(
+ $updateParams = [
'id' => $contact['id'],
'first_name' => 'John',
'last_name' => 'Grant',
'contact_id' => $contact['id'],
'contact_type' => 'Individual',
'contact_sub_type' => $subtype,
- );
+ ];
$updateContact = $this->callAPISuccess('contact', 'create', $updateParams);
$this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$getContacts = $this->callAPISuccess('contact', 'get', $params);
$result = $getContacts['values'][$contact['id']];
$this->assertEquals(end($result['contact_sub_type']), $updateParams['contact_sub_type'], "In line " . __LINE__);
$this->callAPISuccess('contact', 'delete', $params);
- $params = array(
+ $params = [
'label' => 'sub2_organization',
'name' => 'sub2_organization',
// Organization
'parent_id' => 3,
'is_active' => 1,
- );
+ ];
$getSubtype = CRM_Contact_BAO_ContactType::add($params);
$subtype = $params['name'];
// check for Type:Organization subype:sub_organization
- $contactParams = array(
+ $contactParams = [
'organization_name' => 'Compumentor',
'contact_type' => 'Organization',
'contact_sub_type' => $this->subTypeOrganization,
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
// subype:sub2_organization
- $updateParams = array(
+ $updateParams = [
'organization_name' => 'Intel Arts',
'contact_id' => $contact['id'],
'contact_type' => 'Organization',
'contact_sub_type' => $subtype,
- );
+ ];
$updateContact = $this->callAPISuccess('contact', 'create', $updateParams);
$this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$getContacts = $this->callAPISuccess('contact', 'get', $params);
$result = $getContacts['values'][$contact['id']];
$this->_apiversion = $version;
// check for Type:Individual subtype:sub_individual
- $contactParams = array(
+ $contactParams = [
'first_name' => 'Anne',
'last_name' => 'Grant',
'contact_type' => 'Individual',
'contact_sub_type' => $this->subTypeIndividual,
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
// subype:sub_household
- $updateParams = array(
+ $updateParams = [
'first_name' => 'John',
'last_name' => 'Grant',
'contact_id' => $contact['id'],
'contact_type' => 'Individual',
'contact_sub_type' => $this->subTypeHousehold,
- );
+ ];
$updateContact = $this->callAPIFailure('contact', 'create', $updateParams);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$this->callAPISuccess('contact', 'delete', $params);
// check for Type:Organization subtype:
- $contactParams = array(
+ $contactParams = [
'organization_name' => 'Compumentor',
'contact_type' => 'Organization',
'contact_sub_type' => $this->subTypeOrganization,
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $contactParams);
- $updateParams = array(
+ $updateParams = [
'organization_name' => 'Intel Arts',
'contact_id' => $contact['id'],
'contact_sub_type' => $this->subTypeIndividual,
- );
+ ];
$updateContact = $this->callAPIFailure('contact', 'create', $updateParams);
- $params = array(
+ $params = [
'contact_id' => $contact['id'],
- );
+ ];
$this->callAPISuccess('contact', 'delete', $params);
}
protected $testAmount = 34567;
protected $params;
protected $id = 0;
- protected $contactIds = array();
+ protected $contactIds = [];
protected $_entity = 'contribution_page';
protected $contribution_result = NULL;
- protected $_priceSetParams = array();
+ protected $_priceSetParams = [];
protected $_membershipBlockAmount = 2;
/**
* Payment processor details.
* @var array
*/
- protected $_paymentProcessor = array();
+ protected $_paymentProcessor = [];
/**
* @var array
* - price_field
* - price_field_value
*/
- protected $_ids = array();
+ protected $_ids = [];
public $DBResetRequired = TRUE;
public function setUp() {
parent::setUp();
$this->contactIds[] = $this->individualCreate();
- $this->params = array(
+ $this->params = [
'title' => "Test Contribution Page",
'financial_type_id' => 1,
'currency' => 'NZD',
'is_email_receipt' => TRUE,
'receipt_from_email' => 'yourconscience@donate.com',
'receipt_from_name' => 'Ego Freud',
- );
+ ];
- $this->_priceSetParams = array(
+ $this->_priceSetParams = [
'is_quick_config' => 1,
'extends' => 'CiviContribute',
'financial_type_id' => 'Donation',
'title' => 'my Page',
- );
+ ];
}
public function tearDown() {
foreach ($this->contactIds as $id) {
- $this->callAPISuccess('contact', 'delete', array('id' => $id));
+ $this->callAPISuccess('contact', 'delete', ['id' => $id]);
}
$this->quickCleanUpFinancialEntities();
parent::tearDown();
$this->_apiversion = $version;
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
$this->id = $createResult['id'];
- $getParams = array(
+ $getParams = [
'currency' => 'NZD',
'financial_type_id' => 1,
- );
+ ];
$getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
$this->assertEquals(1, $getResult['count']);
}
public function testGetContributionPageByAmount() {
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
$this->id = $createResult['id'];
- $getParams = array(
+ $getParams = [
// 3456
'amount' => '' . $this->testAmount,
'currency' => 'NZD',
'financial_type_id' => 1,
- );
+ ];
$getResult = $this->callAPISuccess($this->_entity, 'get', $getParams);
$this->assertEquals(1, $getResult['count']);
}
public function testDeleteContributionPage($version) {
$this->_apiversion = $version;
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => $createResult['id']);
+ $deleteParams = ['id' => $createResult['id']];
$this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testGetFieldsContributionPage() {
- $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
+ $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
$this->assertEquals(12, $result['values']['start_date']['type']);
}
$submitParams = $this->getBasicSubmitParams();
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
//assert non-deductible amount
$this->assertEquals(5.00, $contribution['non_deductible_amount']);
}
];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
$this->assertEquals($this->formatMoneyInput(0), $contribution['non_deductible_amount']);
$this->assertEquals($this->formatMoneyInput(0), $contribution['total_amount']);
*/
public function testSubmitNewBillingNameData() {
$this->setUpContributionPage();
- $contact = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => 'wonderwoman@amazon.com'));
+ $contact = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'email' => 'wonderwoman@amazon.com']);
$priceFieldID = reset($this->_ids['price_field']);
$priceFieldValueID = reset($this->_ids['price_field_value']);
- $submitParams = array(
+ $submitParams = [
'price_' . $priceFieldID => $priceFieldValueID,
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'billing_last_name' => 'Woman',
'contactID' => $contact['id'],
'email' => 'wonderwoman@amazon.com',
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contact = $this->callAPISuccess('Contact', 'get', array(
+ $contact = $this->callAPISuccess('Contact', 'get', [
'id' => $contact['id'],
- 'return' => array(
+ 'return' => [
'first_name',
'last_name',
'sort_name',
'display_name',
- ),
- ));
- $this->assertEquals(array(
+ ],
+ ]);
+ $this->assertEquals([
'first_name' => 'Wonder',
'last_name' => 'Woman',
'display_name' => 'Wonder Woman',
'sort_name' => 'Woman, Wonder',
'id' => $contact['id'],
'contact_id' => $contact['id'],
- ), $contact['values'][$contact['id']]);
+ ], $contact['values'][$contact['id']]);
}
*/
public function testSubmitNewBillingNameDoNotOverwrite() {
$this->setUpContributionPage();
- $contact = $this->callAPISuccess('Contact', 'create', array(
+ $contact = $this->callAPISuccess('Contact', 'create', [
'contact_type' => 'Individual',
'email' => 'wonderwoman@amazon.com',
'first_name' => 'Super',
'last_name' => 'Boy',
- ));
+ ]);
$priceFieldID = reset($this->_ids['price_field']);
$priceFieldValueID = reset($this->_ids['price_field_value']);
- $submitParams = array(
+ $submitParams = [
'price_' . $priceFieldID => $priceFieldValueID,
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'billing_last_name' => 'Woman',
'contactID' => $contact['id'],
'email' => 'wonderwoman@amazon.com',
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contact = $this->callAPISuccess('Contact', 'get', array(
+ $contact = $this->callAPISuccess('Contact', 'get', [
'id' => $contact['id'],
- 'return' => array(
+ 'return' => [
'first_name',
'last_name',
'sort_name',
'display_name',
- ),
- ));
- $this->assertEquals(array(
+ ],
+ ]);
+ $this->assertEquals([
'first_name' => 'Super',
'last_name' => 'Boy',
'display_name' => 'Super Boy',
'sort_name' => 'Boy, Super',
'id' => $contact['id'],
'contact_id' => $contact['id'],
- ), $contact['values'][$contact['id']]);
+ ], $contact['values'][$contact['id']]);
}
public function testSubmitRecurMultiProcessorInstantPayment() {
$this->setUpContributionPage();
$this->setupPaymentProcessor();
- $paymentProcessor2ID = $this->paymentProcessorCreate(array(
+ $paymentProcessor2ID = $this->paymentProcessorCreate([
'payment_processor_type_id' => 'Dummy',
'name' => 'processor 2',
'class_name' => 'Payment_Dummy',
'billing_mode' => 1,
- ));
+ ]);
$dummyPP = Civi\Payment\System::singleton()->getById($paymentProcessor2ID);
- $dummyPP->setDoDirectPaymentResult(array(
+ $dummyPP->setDoDirectPaymentResult([
'payment_status_id' => 1,
'trxn_id' => 'create_first_success',
'fee_amount' => .85,
- ));
+ ]);
$processor = $dummyPP->getPaymentProcessor();
- $this->callAPISuccess('ContributionPage', 'create', array(
+ $this->callAPISuccess('ContributionPage', 'create', [
'id' => $this->_ids['contribution_page'],
- 'payment_processor' => array($paymentProcessor2ID, $this->_ids['payment_processor']),
- ));
+ 'payment_processor' => [$paymentProcessor2ID, $this->_ids['payment_processor']],
+ ]);
$priceFieldID = reset($this->_ids['price_field']);
$priceFieldValueID = reset($this->_ids['price_field_value']);
- $submitParams = array(
+ $submitParams = [
'price_' . $priceFieldID => $priceFieldValueID,
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'frequency_interval' => 1,
'frequency_unit' => 'month',
'payment_processor_id' => $paymentProcessor2ID,
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
+ ]);
$this->assertEquals('create_first_success', $contribution['trxn_id']);
$this->assertEquals(10, $contribution['total_amount']);
$this->assertEquals(.85, $contribution['fee_amount']);
$this->assertEquals(9.15, $contribution['net_amount']);
- $this->_checkFinancialRecords(array(
+ $this->_checkFinancialRecords([
'id' => $contribution['id'],
'total_amount' => $contribution['total_amount'],
'payment_instrument_id' => $processor['payment_instrument_id'],
- ), 'online');
+ ], 'online');
}
/**
*/
public function testSubmitMembershipBlockNotSeparatePayment() {
$this->setUpMembershipContributionPage();
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'billing_last_name' => 'Gruff',
'selectMembership' => $this->_ids['membership_type'],
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
- $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
+ $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']]);
}
/**
public function testSubmitMembershipBlockNotSeparatePaymentProcessorInstantRenew() {
$this->setUpMembershipContributionPage();
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1));
- $submitParams = array(
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1]);
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
- $this->callAPISuccessGetCount('LineItem', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
+ $this->callAPISuccessGetCount('LineItem', [
'entity_table' => 'civicrm_membership',
'entity_id' => $membershipPayment['id'],
- ), 1);
+ ], 1);
$submitParams['contact_id'] = $contribution['contact_id'];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $this->callAPISuccessGetCount('LineItem', array(
+ $this->callAPISuccessGetCount('LineItem', [
'entity_table' => 'civicrm_membership',
'entity_id' => $membershipPayment['id'],
- ), 2);
- $membership = $this->callAPISuccessGetSingle('Membership', array(
+ ], 2);
+ $membership = $this->callAPISuccessGetSingle('Membership', [
'id' => $membershipPayment['membership_id'],
- 'return' => array('end_date', 'join_date', 'start_date'),
- ));
+ 'return' => ['end_date', 'join_date', 'start_date'],
+ ]);
$this->assertEquals(date('Y-m-d'), $membership['start_date']);
$this->assertEquals(date('Y-m-d'), $membership['join_date']);
$this->assertEquals(date('Y-m-d', strtotime('+ 2 year - 1 day')), $membership['end_date']);
$this->setUpMembershipContributionPage();
$this->addProfile('supporter_profile', $this->_ids['contribution_page']);
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'payment_processor_id' => $this->_paymentProcessor['id'],
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
- $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
- $mut->checkMailLog(array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
+ $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
+ $mut->checkMailLog([
'Membership Type: General',
- ));
+ ]);
$mut->stop();
$mut->clearMessages();
}
*/
public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail() {
$mut = new CiviMailUtils($this, TRUE);
- $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 0)));
+ $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 0])];
$this->setUpMembershipContributionPage();
$this->addProfile('supporter_profile', $this->_ids['contribution_page']);
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 0,
'selectMembership' => $this->_ids['membership_type'],
'email-Primary' => 'billy-goat@the-new-bridge.net',
'payment_processor_id' => $this->params['payment_processor_id'],
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
- $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
+ $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
//Assert only one mail is being sent.
$msgs = $mut->getAllMessages();
$this->assertCount(1, $msgs);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Membership Type: General',
'Gruffier',
- ), array(
+ ], [
'Amount',
- ));
+ ]);
$mut->stop();
$mut->clearMessages();
}
public function testSubmitMembershipBlockIsSeparatePaymentPayLaterWithEmail() {
$mut = new CiviMailUtils($this, TRUE);
$this->setUpMembershipContributionPage();
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'is_pay_later' => 1,
'selectMembership' => $this->_ids['membership_type'],
'email-Primary' => 'billy-goat@the-bridge.net',
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
- $this->callAPISuccess('membership_payment', 'getsingle', array('contribution_id' => $contribution['id']));
- $mut->checkMailLog(array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
+ $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
+ $mut->checkMailLog([
'Membership Amount -... $ 2.00',
- ));
+ ]);
$mut->stop();
$mut->clearMessages();
}
*/
public function testSubmitMembershipBlockIsSeparatePayment() {
$this->setUpMembershipContributionPage(TRUE);
- $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2)));
- $submitParams = array(
+ $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 2])];
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'selectMembership' => $this->_ids['membership_type'],
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
+ $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]);
$this->assertCount(2, $contributions['values']);
- $lines = $this->callAPISuccess('LineItem', 'get', array('sequential' => 1));
+ $lines = $this->callAPISuccess('LineItem', 'get', ['sequential' => 1]);
$this->assertEquals(10, $lines['values'][0]['line_total']);
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
}
*/
public function testSubmitMembershipBlockIsSeparatePaymentWithPayLater() {
$this->setUpMembershipContributionPage(TRUE);
- $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 2)));
+ $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 2])];
//Pay later
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 0,
'billing_last_name' => 'Gruff',
'is_pay_later' => 1,
'selectMembership' => $this->_ids['membership_type'],
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
+ $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]);
$this->assertCount(2, $contributions['values']);
foreach ($contributions['values'] as $val) {
$this->assertEquals('Pending', $val['contribution_status']);
}
//Membership should be in Pending state.
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
- $pendingStatus = $this->callAPISuccessGetSingle('MembershipStatus', array(
- 'return' => array("id"),
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
+ $pendingStatus = $this->callAPISuccessGetSingle('MembershipStatus', [
+ 'return' => ["id"],
'name' => "Pending",
- ));
+ ]);
$this->assertEquals($membership['status_id'], $pendingStatus['id']);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
}
$this->setUpMembershipContributionPage(TRUE);
$this->addProfile('supporter_profile', $this->_ids['contribution_page']);
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'payment_processor_id' => $this->_paymentProcessor['id'],
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
+ $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]);
$this->assertCount(2, $contributions['values']);
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
// We should have two separate email messages, each with their own amount
// line and no total line.
$mut->checkAllMailLog(
- array(
+ [
'Amount: $ 2.00',
'Amount: $ 10.00',
'Membership Fee',
- ),
- array(
+ ],
+ [
'Total: $',
- )
+ ]
);
$mut->stop();
$mut->clearMessages();
*/
public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWithEmail() {
$mut = new CiviMailUtils($this, TRUE);
- $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 0)));
+ $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 0])];
$this->setUpMembershipContributionPage(TRUE);
$this->addProfile('supporter_profile', $this->_ids['contribution_page']);
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 0,
'selectMembership' => $this->_ids['membership_type'],
'payment_processor_id' => 0,
'email-Primary' => 'gruffalo@the-bridge.net',
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
+ $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]);
$this->assertCount(2, $contributions['values']);
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Gruffalo',
'General Membership: $ 0.00',
'Membership Fee',
- ));
+ ]);
$mut->stop();
$mut->clearMessages();
}
* Test submit with a membership block in place.
*/
public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() {
- $this->_ids['membership_type'] = array($this->membershipTypeCreate(array('minimum_fee' => 6)));
- $this->_ids['membership_type'][] = $this->membershipTypeCreate(array('name' => 'Student', 'minimum_fee' => 50));
+ $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 6])];
+ $this->_ids['membership_type'][] = $this->membershipTypeCreate(['name' => 'Student', 'minimum_fee' => 50]);
$this->setUpMembershipContributionPage(TRUE);
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value'][1],
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'selectMembership' => $this->_ids['membership_type'][1],
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contributions = $this->callAPISuccess('contribution', 'get', array('contribution_page_id' => $this->_ids['contribution_page']));
+ $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]);
$this->assertCount(2, $contributions['values']);
$ids = array_keys($contributions['values']);
$this->assertEquals('10.00', $contributions['values'][$ids[0]]['total_amount']);
$this->assertEquals('50.00', $contributions['values'][$ids[1]]['total_amount']);
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertArrayHasKey($membershipPayment['contribution_id'], $contributions['values']);
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
}
$mut = new CiviMailUtils($this, TRUE);
$this->setUpMembershipContributionPage(TRUE);
$processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessor['id']);
- $processor->setDoDirectPaymentResult(array('fee_amount' => .72));
- $submitParams = array(
+ $processor->setDoDirectPaymentResult(['fee_amount' => .72]);
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'payment_processor_id' => $this->_paymentProcessor['id'],
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contributions = $this->callAPISuccess('contribution', 'get', array(
+ $contributions = $this->callAPISuccess('contribution', 'get', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
+ ]);
$this->assertCount(2, $contributions['values']);
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
- $lineItem = $this->callAPISuccessGetSingle('LineItem', array('entity_table' => 'civicrm_membership'));
+ $lineItem = $this->callAPISuccessGetSingle('LineItem', ['entity_table' => 'civicrm_membership']);
$this->assertEquals($lineItem['entity_id'], $membership['id']);
$this->assertEquals($lineItem['contribution_id'], $membershipPayment['contribution_id']);
$this->assertEquals($lineItem['qty'], 1);
}
// The total string is currently absent & it seems worse with - although at some point
// it may have been intended
- $mut->checkAllMailLog(array('$ 2.00', 'Contribution Amount', '$ 10.00'), array('Total:'));
+ $mut->checkAllMailLog(['$ 2.00', 'Contribution Amount', '$ 10.00'], ['Total:']);
$mut->stop();
$mut->clearMessages();
}
$this->setCurrencySeparators($thousandSeparator);
$this->setUpMembershipContributionPage(TRUE);
$processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessor['id']);
- $processor->setDoDirectPaymentResult(array('fee_amount' => .72));
+ $processor->setDoDirectPaymentResult(['fee_amount' => .72]);
$test_uniq = uniqid();
$contributionPageAmount = 10;
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => $contributionPageAmount,
'payment_processor_id' => $this->_paymentProcessor['id'],
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
'TEST_UNIQ' => $test_uniq,
- );
+ ];
// set custom hook
- $this->hookClass->setHook('civicrm_alterPaymentProcessorParams', array($this, 'hook_civicrm_alterPaymentProcessorParams'));
+ $this->hookClass->setHook('civicrm_alterPaymentProcessorParams', [$this, 'hook_civicrm_alterPaymentProcessorParams']);
$this->callAPISuccess('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contributions = $this->callAPISuccess('contribution', 'get', array(
+ $contributions = $this->callAPISuccess('contribution', 'get', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
+ ]);
- $result = civicrm_api3('SystemLog', 'get', array(
+ $result = civicrm_api3('SystemLog', 'get', [
'sequential' => 1,
- 'message' => array('LIKE' => "%{$test_uniq}%"),
- ));
+ 'message' => ['LIKE' => "%{$test_uniq}%"],
+ ]);
$this->assertCount(2, $result['values'], "Expected exactly 2 log entries matching {$test_uniq}.");
// Examine logged entries to ensure correct values.
- $contribution_ids = array();
+ $contribution_ids = [];
$found_membership_amount = $found_contribution_amount = FALSE;
foreach ($result['values'] as $value) {
list($junk, $json) = explode("$test_uniq:", $value['message']);
$this->createLoggedInUser();
$priceFieldID = reset($this->_ids['price_field']);
$priceFieldValueID = reset($this->_ids['price_field_value']);
- $submitParams = array(
+ $submitParams = [
'price_' . $priceFieldID => $priceFieldValueID,
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2008),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2008],
'cvv2' => 123,
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccessGetSingle('contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('contribution', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 'Failed',
- ));
+ ]);
- $this->callAPISuccessGetSingle('activity', array(
+ $this->callAPISuccessGetSingle('activity', [
'source_record_id' => $contribution['id'],
'activity_type_id' => 'Failed Payment',
- ));
+ ]);
}
* - create another - end date should be extended
*/
public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPaymentYear() {
- $this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(array('duration_unit' => 'year', 'recur_frequency_unit' => 'year'));
+ $this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(['duration_unit' => 'year', 'recur_frequency_unit' => 'year']);
}
/**
* - create another - end date should be extended
*/
public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPaymentMonth() {
- $this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(array('duration_unit' => 'month', 'recur_frequency_unit' => 'month'));
+ $this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(['duration_unit' => 'month', 'recur_frequency_unit' => 'month']);
}
/**
* @throws \CRM_Core_Exception
* @throws \Exception
*/
- public function doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment($params = array()) {
+ public function doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment($params = []) {
$this->params['is_recur'] = 1;
$this->params['recur_frequency_unit'] = $params['recur_frequency_unit'];
$membershipTypeParams['duration_unit'] = $params['duration_unit'];
}
$this->setUpMembershipContributionPage(FALSE, FALSE, $membershipTypeParams);
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']);
$processor = $dummyPP->getPaymentProcessor();
if ($params['recur_frequency_unit'] === $params['duration_unit']) {
$expectedMembershipStatus = 5;
}
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
'is_recur' => 1,
'frequency_interval' => 1,
'frequency_unit' => $this->params['recur_frequency_unit'],
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
+ ]);
$this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']);
$this->assertEquals('create_first_success', $contribution['trxn_id']);
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals($membership['contact_id'], $contribution['contact_id']);
$this->assertEquals($expectedMembershipStatus, $membership['status_id']);
- $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
+ $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]);
- $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id'], 'entity_id' => $membership['id']));
+ $this->callAPISuccess('line_item', 'getsingle', ['contribution_id' => $contribution['id'], 'entity_id' => $membership['id']]);
//renew it with processor setting completed - should extend membership
$submitParams['contact_id'] = $contribution['contact_id'];
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_second_success']);
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $this->callAPISuccess('contribution', 'getsingle', array(
- 'id' => array('NOT IN' => array($contribution['id'])),
+ $this->callAPISuccess('contribution', 'getsingle', [
+ 'id' => ['NOT IN' => [$contribution['id']]],
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
- $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ ]);
+ $renewedMembership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
if ($durationUnit) {
// We only have an end_date if frequency units match, otherwise membership won't be autorenewed and dates won't be calculated.
$renewedMembershipEndDate = $this->membershipRenewalDate($durationUnit, $membership['end_date']);
$this->assertEquals($renewedMembershipEndDate, $renewedMembership['end_date']);
}
- $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
+ $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]);
$this->assertEquals($processor['payment_instrument_id'], $recurringContribution['payment_instrument_id']);
$this->assertEquals(5, $recurringContribution['contribution_status_id']);
}
$this->params['is_recur'] = 1;
$this->params['recur_frequency_unit'] = $membershipTypeParams['duration_unit'] = 'year';
// Add a membership so membership & contribution are not both 1.
- $preExistingMembershipID = $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0]));
+ $preExistingMembershipID = $this->contactMembershipCreate(['contact_id' => $this->contactIds[0]]);
$this->setUpMembershipContributionPage(FALSE, FALSE, $membershipTypeParams);
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']);
$processor = $dummyPP->getPaymentProcessor();
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'price_' . $this->_ids['price_field']['cont'] => 88,
'id' => (int) $this->_ids['contribution_page'],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
'is_recur' => 1,
'frequency_interval' => 1,
'frequency_unit' => $this->params['recur_frequency_unit'],
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
+ ]);
$this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']);
$this->assertEquals('create_first_success', $contribution['trxn_id']);
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals($membership['contact_id'], $contribution['contact_id']);
$this->assertEquals(1, $membership['status_id']);
- $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
+ $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]);
- $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $contribution['id']));
+ $lines = $this->callAPISuccess('line_item', 'get', ['sequential' => 1, 'contribution_id' => $contribution['id']]);
$this->assertEquals(2, $lines['count']);
$this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']);
$this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']);
$this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']);
$this->assertEquals($contribution['id'], $lines['values'][1]['entity_id']);
- $this->callAPISuccessGetSingle('MembershipPayment', array('contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1));
+ $this->callAPISuccessGetSingle('MembershipPayment', ['contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1]);
//renew it with processor setting completed - should extend membership
$submitParams['contact_id'] = $contribution['contact_id'];
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_second_success']);
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $renewContribution = $this->callAPISuccess('contribution', 'getsingle', array(
- 'id' => array('NOT IN' => array($contribution['id'])),
+ $renewContribution = $this->callAPISuccess('contribution', 'getsingle', [
+ 'id' => ['NOT IN' => [$contribution['id']]],
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
- $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $renewContribution['id']));
+ ]);
+ $lines = $this->callAPISuccess('line_item', 'get', ['sequential' => 1, 'contribution_id' => $renewContribution['id']]);
$this->assertEquals(2, $lines['count']);
$this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']);
$this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']);
$this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']);
$this->assertEquals($renewContribution['id'], $lines['values'][1]['entity_id']);
- $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $renewedMembership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals(date('Y-m-d', strtotime('+ 1 ' . $this->params['recur_frequency_unit'], strtotime($membership['end_date']))), $renewedMembership['end_date']);
- $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
+ $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]);
$this->assertEquals($processor['payment_instrument_id'], $recurringContribution['payment_instrument_id']);
$this->assertEquals(5, $recurringContribution['contribution_status_id']);
}
$this->params['is_recur'] = 1;
$this->params['recur_frequency_unit'] = $membershipTypeParams['duration_unit'] = 'year';
// Add a membership so membership & contribution are not both 1.
- $preExistingMembershipID = $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0]));
+ $preExistingMembershipID = $this->contactMembershipCreate(['contact_id' => $this->contactIds[0]]);
$this->createPriceSetWithPage();
$this->addSecondOrganizationMembershipToPriceSet();
$this->setupPaymentProcessor();
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']);
$processor = $dummyPP->getPaymentProcessor();
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value']['cont'],
'price_' . $this->_ids['price_field']['org1'] => $this->_ids['price_field_value']['org1'],
'price_' . $this->_ids['price_field']['org2'] => $this->_ids['price_field_value']['org2'],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
'frequency_interval' => 1,
'frequency_unit' => $this->params['recur_frequency_unit'],
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
+ ]);
$this->assertEquals($processor['payment_instrument_id'], $contribution['payment_instrument_id']);
$this->assertEquals('create_first_success', $contribution['trxn_id']);
- $membershipPayments = $this->callAPISuccess('membership_payment', 'get', array(
+ $membershipPayments = $this->callAPISuccess('membership_payment', 'get', [
'sequential' => 1,
'contribution_id' => $contribution['id'],
- ));
+ ]);
$this->assertEquals(2, $membershipPayments['count']);
- $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $contribution['id']));
+ $lines = $this->callAPISuccess('line_item', 'get', ['sequential' => 1, 'contribution_id' => $contribution['id']]);
$this->assertEquals(3, $lines['count']);
$this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']);
$this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']);
$this->assertEquals('civicrm_membership', $lines['values'][2]['entity_table']);
$this->assertEquals($preExistingMembershipID + 2, $lines['values'][2]['entity_id']);
- $this->callAPISuccessGetSingle('MembershipPayment', array('contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1));
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $preExistingMembershipID + 1));
+ $this->callAPISuccessGetSingle('MembershipPayment', ['contribution_id' => $contribution['id'], 'membership_id' => $preExistingMembershipID + 1]);
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $preExistingMembershipID + 1]);
//renew it with processor setting completed - should extend membership
$submitParams['contact_id'] = $contribution['contact_id'];
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_second_success'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_second_success']);
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $renewContribution = $this->callAPISuccess('contribution', 'getsingle', array(
- 'id' => array('NOT IN' => array($contribution['id'])),
+ $renewContribution = $this->callAPISuccess('contribution', 'getsingle', [
+ 'id' => ['NOT IN' => [$contribution['id']]],
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
- $lines = $this->callAPISuccess('line_item', 'get', array('sequential' => 1, 'contribution_id' => $renewContribution['id']));
+ ]);
+ $lines = $this->callAPISuccess('line_item', 'get', ['sequential' => 1, 'contribution_id' => $renewContribution['id']]);
$this->assertEquals(3, $lines['count']);
$this->assertEquals('civicrm_membership', $lines['values'][0]['entity_table']);
$this->assertEquals($preExistingMembershipID + 1, $lines['values'][0]['entity_id']);
$this->assertEquals('civicrm_contribution', $lines['values'][1]['entity_table']);
$this->assertEquals($renewContribution['id'], $lines['values'][1]['entity_id']);
- $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $preExistingMembershipID + 1));
+ $renewedMembership = $this->callAPISuccessGetSingle('membership', ['id' => $preExistingMembershipID + 1]);
$this->assertEquals(date('Y-m-d', strtotime('+ 1 ' . $this->params['recur_frequency_unit'], strtotime($membership['end_date']))), $renewedMembership['end_date']);
}
*/
public function addSecondOrganizationMembershipToPriceSet() {
$organization2ID = $this->organizationCreate();
- $membershipTypes = $this->callAPISuccess('MembershipType', 'get', array());
+ $membershipTypes = $this->callAPISuccess('MembershipType', 'get', []);
$this->_ids['membership_type'] = array_keys($membershipTypes['values']);
- $this->_ids['membership_type']['org2'] = $this->membershipTypeCreate(array('contact_id' => $organization2ID, 'name' => 'Org 2'));
- $priceField = $this->callAPISuccess('PriceField', 'create', array(
+ $this->_ids['membership_type']['org2'] = $this->membershipTypeCreate(['contact_id' => $organization2ID, 'name' => 'Org 2']);
+ $priceField = $this->callAPISuccess('PriceField', 'create', [
'price_set_id' => $this->_ids['price_set'],
'html_type' => 'Radio',
'name' => 'Org1 Price',
'label' => 'Org1Price',
- ));
+ ]);
$this->_ids['price_field']['org1'] = $priceField['id'];
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'name' => 'org1 amount',
'label' => 'org 1 Amount',
'amount' => 2,
'format.only_id' => TRUE,
'membership_type_id' => reset($this->_ids['membership_type']),
'price_field_id' => $priceField['id'],
- ));
+ ]);
$this->_ids['price_field_value']['org1'] = $priceFieldValue;
- $priceField = $this->callAPISuccess('PriceField', 'create', array(
+ $priceField = $this->callAPISuccess('PriceField', 'create', [
'price_set_id' => $this->_ids['price_set'],
'html_type' => 'Radio',
'name' => 'Org2 Price',
'label' => 'Org2Price',
- ));
+ ]);
$this->_ids['price_field']['org2'] = $priceField['id'];
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'name' => 'org2 amount',
'label' => 'org 2 Amount',
'amount' => 200,
'format.only_id' => TRUE,
'membership_type_id' => $this->_ids['membership_type']['org2'],
'price_field_id' => $priceField['id'],
- ));
+ ]);
$this->_ids['price_field_value']['org2'] = $priceFieldValue;
}
$this->setUpMembershipContributionPage(TRUE);
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']);
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
'is_recur' => 1,
'auto_renew' => TRUE,
'frequency_interval' => 1,
'frequency_unit' => 'month',
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
- ));
+ ]);
$this->assertEquals(2, $contribution['count']);
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
- $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
+ $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertNotEmpty($contribution['values'][$membershipPayment['contribution_id']]['contribution_recur_id']);
- $this->callAPISuccess('contribution_recur', 'getsingle', array());
+ $this->callAPISuccess('contribution_recur', 'getsingle', []);
}
/**
$this->params['recur_frequency_unit'] = $membershipTypeParams['duration_unit'] = 'year';
$this->setUpMembershipContributionPage();
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2));
- $this->membershipTypeCreate(array('name' => 'Student'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 2]);
+ $this->membershipTypeCreate(['name' => 'Student']);
// Add a contribution & a couple of memberships so the id will not be 1 & will differ from membership id.
// This saves us from 'accidental success'.
- $this->contributionCreate(array('contact_id' => $this->contactIds[0]));
- $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0]));
- $this->contactMembershipCreate(array('contact_id' => $this->contactIds[0], 'membership_type_id' => 'Student'));
+ $this->contributionCreate(['contact_id' => $this->contactIds[0]]);
+ $this->contactMembershipCreate(['contact_id' => $this->contactIds[0]]);
+ $this->contactMembershipCreate(['contact_id' => $this->contactIds[0], 'membership_type_id' => 'Student']);
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
'is_recur' => 1,
'frequency_interval' => 1,
'frequency_unit' => $this->params['recur_frequency_unit'],
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 2,
- ));
+ ]);
- $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', array());
+ $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertEquals($membershipPayment['contribution_id'], $contribution['id']);
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
$this->assertEquals($membership['contact_id'], $contribution['contact_id']);
$this->assertEquals(5, $membership['status_id']);
- $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id']));
+ $line = $this->callAPISuccess('line_item', 'getsingle', ['contribution_id' => $contribution['id']]);
$this->assertEquals('civicrm_membership', $line['entity_table']);
$this->assertEquals($membership['id'], $line['entity_id']);
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
'trxn_id' => 'ipn_called',
'payment_processor_id' => $this->_paymentProcessor['id'],
- ));
- $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $contribution['id']));
+ ]);
+ $line = $this->callAPISuccess('line_item', 'getsingle', ['contribution_id' => $contribution['id']]);
$this->assertEquals('civicrm_membership', $line['entity_table']);
$this->assertEquals($membership['id'], $line['entity_id']);
- $membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
//renew it with processor setting completed - should extend membership
- $submitParams = array_merge($submitParams, array(
+ $submitParams = array_merge($submitParams, [
'contact_id' => $contribution['contact_id'],
'is_recur' => 1,
'frequency_interval' => 1,
'frequency_unit' => $this->params['recur_frequency_unit'],
- ));
+ ]);
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 2));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 2]);
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $newContribution = $this->callAPISuccess('contribution', 'getsingle', array(
- 'id' => array(
- 'NOT IN' => array($contribution['id']),
- ),
+ $newContribution = $this->callAPISuccess('contribution', 'getsingle', [
+ 'id' => [
+ 'NOT IN' => [$contribution['id']],
+ ],
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 2,
- ));
- $line = $this->callAPISuccess('line_item', 'getsingle', array('contribution_id' => $newContribution['id']));
+ ]);
+ $line = $this->callAPISuccess('line_item', 'getsingle', ['contribution_id' => $newContribution['id']]);
$this->assertEquals('civicrm_membership', $line['entity_table']);
$this->assertEquals($membership['id'], $line['entity_id']);
- $renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
+ $renewedMembership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
//no renewal as the date hasn't changed
$this->assertEquals($membership['end_date'], $renewedMembership['end_date']);
- $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $newContribution['contribution_recur_id']));
+ $recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $newContribution['contribution_recur_id']]);
$this->assertEquals(2, $recurringContribution['contribution_status_id']);
}
//Create recur contribution page.
$this->setUpMembershipContributionPage(TRUE, TRUE);
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']);
//Sumbit payment with recur disabled.
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
- );
+ ];
//Assert if recur contribution is created.
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $recur = $this->callAPISuccess('contribution_recur', 'get', array());
+ $recur = $this->callAPISuccess('contribution_recur', 'get', []);
$this->assertEmpty($recur['count']);
}
* @param bool $isRecur
* @param array $membershipTypeParams Parameters to pass to membershiptype.create API
*/
- public function setUpMembershipContributionPage($isSeparatePayment = FALSE, $isRecur = FALSE, $membershipTypeParams = array()) {
+ public function setUpMembershipContributionPage($isSeparatePayment = FALSE, $isRecur = FALSE, $membershipTypeParams = []) {
$this->setUpMembershipBlockPriceSet($membershipTypeParams);
$this->setupPaymentProcessor();
$this->setUpContributionPage($isRecur);
- $this->callAPISuccess('membership_block', 'create', array(
+ $this->callAPISuccess('membership_block', 'create', [
'entity_id' => $this->_ids['contribution_page'],
'entity_table' => 'civicrm_contribution_page',
'is_required' => TRUE,
'is_active' => TRUE,
'is_separate_payment' => $isSeparatePayment,
'membership_type_default' => $this->_ids['membership_type'],
- ));
+ ]);
}
/**
* Set up pledge block.
*/
public function setUpPledgeBlock() {
- $params = array(
+ $params = [
'entity_table' => 'civicrm_contribution_page',
'entity_id' => $this->_ids['contribution_page'],
'pledge_frequency_unit' => 'week',
'is_pledge_interval' => 0,
- 'pledge_start_date' => json_encode(array('calendar_date' => date('Ymd', strtotime("+1 month")))),
- );
+ 'pledge_start_date' => json_encode(['calendar_date' => date('Ymd', strtotime("+1 month"))]),
+ ];
$pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params);
$this->_ids['pledge_block_id'] = $pledgeBlock->id;
}
*
* This function ensures it exists & populates $this->_ids with it's data
*/
- public function setUpMembershipBlockPriceSet($membershipTypeParams = array()) {
- $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', array(
+ public function setUpMembershipBlockPriceSet($membershipTypeParams = []) {
+ $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', [
'name' => 'default_membership_type_amount',
'return' => 'id',
- ));
+ ]);
if (empty($this->_ids['membership_type'])) {
- $membershipTypeParams = array_merge(array(
+ $membershipTypeParams = array_merge([
'minimum_fee' => 2,
- ), $membershipTypeParams);
- $this->_ids['membership_type'] = array($this->membershipTypeCreate($membershipTypeParams));
+ ], $membershipTypeParams);
+ $this->_ids['membership_type'] = [$this->membershipTypeCreate($membershipTypeParams)];
}
- $priceField = $this->callAPISuccess('price_field', 'create', array(
+ $priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => reset($this->_ids['price_set']),
'name' => 'membership_amount',
'label' => 'Membership Amount',
'html_type' => 'Radio',
'sequential' => 1,
- ));
+ ]);
$this->_ids['price_field'][] = $priceField['id'];
foreach ($this->_ids['membership_type'] as $membershipTypeID) {
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'name' => 'membership_amount',
'label' => 'Membership Amount',
'amount' => $this->_membershipBlockAmount,
'format.only_id' => TRUE,
'membership_type_id' => $membershipTypeID,
'price_field_id' => $priceField['id'],
- ));
+ ]);
$this->_ids['price_field_value'][] = $priceFieldValue;
}
if (!empty($this->_ids['membership_type']['org2'])) {
- $priceField = $this->callAPISuccess('price_field', 'create', array(
+ $priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => reset($this->_ids['price_set']),
'name' => 'membership_org2',
'label' => 'Membership Org2',
'html_type' => 'Checkbox',
'sequential' => 1,
- ));
+ ]);
$this->_ids['price_field']['org2'] = $priceField['id'];
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'name' => 'membership_org2',
'label' => 'Membership org 2',
'amount' => 55,
'format.only_id' => TRUE,
'membership_type_id' => $this->_ids['membership_type']['org2'],
'price_field_id' => $priceField['id'],
- ));
+ ]);
$this->_ids['price_field_value']['org2'] = $priceFieldValue;
}
- $priceField = $this->callAPISuccess('price_field', 'create', array(
+ $priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => reset($this->_ids['price_set']),
'name' => 'Contribution',
'label' => 'Contribution',
'html_type' => 'Text',
'sequential' => 1,
'is_enter_qty' => 1,
- ));
+ ]);
$this->_ids['price_field']['cont'] = $priceField['id'];
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'name' => 'contribution',
'label' => 'Give me money',
'amount' => 88,
'financial_type_id' => 'Donation',
'format.only_id' => TRUE,
'price_field_id' => $priceField['id'],
- ));
+ ]);
$this->_ids['price_field_value'][] = $priceFieldValue;
}
* Add text field other amount to the price set.
*/
public function addOtherAmountFieldToMembershipPriceSet() {
- $this->_ids['price_field']['other_amount'] = $this->callAPISuccess('price_field', 'create', array(
+ $this->_ids['price_field']['other_amount'] = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => reset($this->_ids['price_set']),
'name' => 'other_amount',
'label' => 'Other Amount',
'html_type' => 'Text',
'format.only_id' => TRUE,
'sequential' => 1,
- ));
- $this->_ids['price_field_value']['other_amount'] = $this->callAPISuccess('price_field_value', 'create', array(
+ ]);
+ $this->_ids['price_field_value']['other_amount'] = $this->callAPISuccess('price_field_value', 'create', [
'financial_type_id' => 'Donation',
'format.only_id' => TRUE,
'label' => 'Other Amount',
'amount' => 1,
'price_field_id' => $this->_ids['price_field']['other_amount'],
- ));
+ ]);
}
/**
CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
if (empty($this->_ids['price_field'])) {
- $priceField = $this->callAPISuccess('price_field', 'create', array(
+ $priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => $priceSetID,
'label' => 'Goat Breed',
'html_type' => 'Radio',
- ));
- $this->_ids['price_field'] = array($priceField['id']);
+ ]);
+ $this->_ids['price_field'] = [$priceField['id']];
}
if (empty($this->_ids['price_field_value'])) {
- $this->callAPISuccess('price_field_value', 'create', array(
+ $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Long Haired Goat',
'financial_type_id' => 'Donation',
'amount' => 20,
'non_deductible_amount' => 15,
- ));
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ ]);
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Shoe-eating Goat',
'financial_type_id' => 'Donation',
'amount' => 10,
'non_deductible_amount' => 5,
- ));
- $this->_ids['price_field_value'] = array($priceFieldValue['id']);
+ ]);
+ $this->_ids['price_field_value'] = [$priceFieldValue['id']];
- $this->_ids['price_field_value']['cheapskate'] = $this->callAPISuccess('price_field_value', 'create', array(
+ $this->_ids['price_field_value']['cheapskate'] = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Stingy Goat',
'financial_type_id' => 'Donation',
'amount' => 0,
'non_deductible_amount' => 0,
- ))['id'];
+ ])['id'];
}
$this->_ids['contribution_page'] = $contributionPageResult['id'];
}
$contributionPage = $this->callAPISuccess($this->_entity, 'create', $this->params);
$this->_ids['contribution_page'] = $contributionPage['id'];
- $this->_ids['membership_type'] = $this->membershipTypeCreate(array(
+ $this->_ids['membership_type'] = $this->membershipTypeCreate([
// force auto-renew
'auto_renew' => 2,
'duration_unit' => 'month',
- ));
+ ]);
- $priceSet = civicrm_api3('PriceSet', 'create', array(
+ $priceSet = civicrm_api3('PriceSet', 'create', [
'is_quick_config' => 0,
'extends' => 'CiviMember',
'financial_type_id' => 'Member Dues',
'title' => 'CRM-21177',
- ));
+ ]);
$this->_ids['price_set'] = $priceSet['id'];
- $priceField = $this->callAPISuccess('price_field', 'create', array(
+ $priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => $this->_ids['price_set'],
'name' => 'membership_type',
'label' => 'Membership Type',
'html_type' => 'Radio',
- ));
+ ]);
$this->_ids['price_field'] = $priceField['id'];
- $priceFieldValueMonthly = $this->callAPISuccess('price_field_value', 'create', array(
+ $priceFieldValueMonthly = $this->callAPISuccess('price_field_value', 'create', [
'name' => 'CRM-21177_Monthly',
'label' => 'CRM-21177 - Monthly',
'amount' => 20,
'membership_type_id' => $this->_ids['membership_type'],
'price_field_id' => $this->_ids['price_field'],
'financial_type_id' => 'Member Dues',
- ));
+ ]);
$this->_ids['price_field_value_monthly'] = $priceFieldValueMonthly['id'];
- $priceFieldValueYearly = $this->callAPISuccess('price_field_value', 'create', array(
+ $priceFieldValueYearly = $this->callAPISuccess('price_field_value', 'create', [
'name' => 'CRM-21177_Yearly',
'label' => 'CRM-21177 - Yearly',
'amount' => 200,
'membership_type_id' => $this->_ids['membership_type'],
'price_field_id' => $this->_ids['price_field'],
'financial_type_id' => 'Member Dues',
- ));
+ ]);
$this->_ids['price_field_value_yearly'] = $priceFieldValueYearly['id'];
CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_ids['contribution_page'], $this->_ids['price_set']);
- $this->callAPISuccess('membership_block', 'create', array(
+ $this->callAPISuccess('membership_block', 'create', [
'entity_id' => $this->_ids['contribution_page'],
'entity_table' => 'civicrm_contribution_page',
'is_required' => TRUE,
'is_separate_payment' => FALSE,
'is_active' => TRUE,
'membership_type_default' => $this->_ids['membership_type'],
- ));
+ ]);
}
/**
*/
public function testSubmitMultiIntervalMembershipContributionPage() {
$this->setUpMultiIntervalMembershipContributionPage();
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'] => $this->_ids['price_field_value_monthly'],
'id' => (int) $this->_ids['contribution_page'],
'amount' => 20,
'payment_processor_id' => $this->_ids['payment_processor'],
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
'auto_renew' => 1,
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
$submitParams['price_' . $this->_ids['price_field']] = $this->_ids['price_field_value_yearly'];
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccess('Contribution', 'get', array(
+ $contribution = $this->callAPISuccess('Contribution', 'get', [
'contribution_page_id' => $this->_ids['contribution_page'],
'sequential' => 1,
- 'api.ContributionRecur.getsingle' => array(),
- ));
+ 'api.ContributionRecur.getsingle' => [],
+ ]);
$this->assertEquals(1, $contribution['values'][0]['api.ContributionRecur.getsingle']['frequency_interval']);
//$this->assertEquals(12, $contribution['values'][1]['api.ContributionRecur.getsingle']['frequency_interval']);
}
* @throws \Exception
*/
public static function tearDownAfterClass() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contact',
'civicrm_financial_type',
'civicrm_contribution',
'civicrm_contribution_page',
- );
+ ];
$unitTest = new CiviUnitTestCase();
$unitTest->quickCleanup($tablesToTruncate);
}
* Create a payment processor instance.
*/
protected function setupPaymentProcessor() {
- $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate(array(
+ $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate([
'payment_processor_type_id' => 'Dummy',
'class_name' => 'Payment_Dummy',
'billing_mode' => 1,
- ));
- $this->_paymentProcessor = $this->callAPISuccess('payment_processor', 'getsingle', array('id' => $this->params['payment_processor_id']));
+ ]);
+ $this->_paymentProcessor = $this->callAPISuccess('payment_processor', 'getsingle', ['id' => $this->params['payment_processor_id']]);
}
/**
$this->setUpPledgeBlock();
$this->setupPaymentProcessor();
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
- $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
+ $dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']);
- $submitParams = array(
+ $submitParams = [
'id' => (int) $this->_ids['contribution_page'],
'amount' => 100,
'billing_first_name' => 'Billy',
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
'pledge_frequency_interval' => 1,
'pledge_frequency_unit' => 'week',
'pledge_installments' => 3,
'is_pledge' => TRUE,
'pledge_block_id' => (int) $this->_ids['pledge_block_id'],
- );
+ ];
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
// Check if contribution created.
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'contribution_page_id' => $this->_ids['contribution_page'],
// Will be pending when actual payment processor is used (dummy processor does not support future payments).
'contribution_status_id' => 'Completed',
- ));
+ ]);
$this->assertEquals('create_first_success', $contribution['trxn_id']);
// Check if pledge created.
- $pledge = $this->callAPISuccess('pledge', 'getsingle', array());
+ $pledge = $this->callAPISuccess('pledge', 'getsingle', []);
$this->assertEquals(date('Ymd', strtotime($pledge['pledge_start_date'])), date('Ymd', strtotime("+1 month")));
$this->assertEquals($pledge['pledge_amount'], 300.00);
// Check if pledge payments created.
- $params = array(
+ $params = [
'pledge_id' => $pledge['id'],
- );
+ ];
$pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
$this->assertEquals($pledgePayment['count'], 3);
$this->assertEquals(date('Ymd', strtotime($pledgePayment['values'][1]['scheduled_date'])), date('Ymd', strtotime("+1 month")));
$this->assertEquals($pledgePayment['values'][1]['status_id'], 1);
// Check contribution recur record.
- $recur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
+ $recur = $this->callAPISuccess('contribution_recur', 'getsingle', ['id' => $contribution['contribution_recur_id']]);
$this->assertEquals(date('Ymd', strtotime($recur['start_date'])), date('Ymd', strtotime("+1 month")));
$this->assertEquals($recur['amount'], 100.00);
// In progress status.
*/
public function testSubmitPledgePayment() {
$this->testSubmitPledgePaymentPaymentProcessorRecurFuturePayment();
- $pledge = $this->callAPISuccess('pledge', 'getsingle', array());
- $params = array(
+ $pledge = $this->callAPISuccess('pledge', 'getsingle', []);
+ $params = [
'pledge_id' => $pledge['id'],
- );
- $submitParams = array(
+ ];
+ $submitParams = [
'id' => (int) $pledge['pledge_contribution_page_id'],
- 'pledge_amount' => array(2 => 1),
+ 'pledge_amount' => [2 => 1],
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
- 'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
+ 'credit_card_exp_date' => ['M' => 9, 'Y' => 2040],
'cvv2' => 123,
'pledge_id' => $pledge['id'],
'cid' => $pledge['contact_id'],
'amount' => 100.00,
'is_pledge' => TRUE,
'pledge_block_id' => $this->_ids['pledge_block_id'],
- );
+ ];
$pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
$this->assertEquals($pledgePayment['values'][2]['status_id'], 2);
$this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
// Check if contribution created.
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'contribution_page_id' => $pledge['pledge_contribution_page_id'],
'contribution_status_id' => 'Completed',
'contact_id' => $pledge['contact_id'],
- 'contribution_recur_id' => array('IS NULL' => 1),
- ));
+ 'contribution_recur_id' => ['IS NULL' => 1],
+ ]);
$this->assertEquals(100.00, $contribution['total_amount']);
$pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
$this->setCurrencySeparators($thousandSeparator);
$this->_priceSetParams['is_quick_config'] = 0;
$this->setUpContributionPage();
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'amount' => 80,
'last_name' => 'Gruff',
'email' => 'billy@goat.gruff',
'is_pay_later' => TRUE,
- );
+ ];
$this->addPriceFields($submitParams);
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccessGetSingle('contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('contribution', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 'Pending',
- ));
+ ]);
$this->assertEquals(80, $contribution['total_amount']);
- $lineItems = $this->callAPISuccess('LineItem', 'get', array(
+ $lineItems = $this->callAPISuccess('LineItem', 'get', [
'contribution_id' => $contribution['id'],
- ));
+ ]);
$this->assertEquals(3, $lineItems['count']);
$totalLineAmount = 0;
foreach ($lineItems['values'] as $lineItem) {
*/
public function addPriceFields(&$params) {
$priceSetID = reset($this->_ids['price_set']);
- $priceField = $this->callAPISuccess('price_field', 'create', array(
+ $priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => $priceSetID,
'label' => 'Chicken Breed',
'html_type' => 'CheckBox',
- ));
- $priceFieldValue1 = $this->callAPISuccess('price_field_value', 'create', array(
+ ]);
+ $priceFieldValue1 = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Shoe-eating chicken -1',
'financial_type_id' => 'Donation',
'amount' => 30,
- ));
- $priceFieldValue2 = $this->callAPISuccess('price_field_value', 'create', array(
+ ]);
+ $priceFieldValue2 = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Shoe-eating chicken -2',
'financial_type_id' => 'Donation',
'amount' => 40,
- ));
- $params['price_' . $priceField['id']] = array(
+ ]);
+ $params['price_' . $priceField['id']] = [
$priceFieldValue1['id'] => 1,
$priceFieldValue2['id'] => 1,
- );
+ ];
}
/**
$this->relationForFinancialTypeWithFinancialAccount($financialType['id'], 5);
$this->setUpContributionPage();
- $submitParams = array(
+ $submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
'first_name' => 'J',
'email' => 'JT@ohcanada.ca',
'is_pay_later' => TRUE,
'receive_date' => date('Y-m-d H:i:s'),
- );
+ ];
// Create PriceSet/PriceField
$priceSetID = reset($this->_ids['price_set']);
- $priceField = $this->callAPISuccess('price_field', 'create', array(
+ $priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => $priceSetID,
'label' => 'Printing Rights',
'html_type' => 'Text',
- ));
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ ]);
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Printing Rights',
'financial_type_id' => $financialTypeId,
'amount' => '16.95',
- ));
+ ]);
$priceFieldId = $priceField['id'];
// Set quantity for our test
$submitParams['tax_amount'] = $this->formatMoneyInput(180 * 16.95 * 0.10);
$this->callAPISuccess('contribution_page', 'submit', $submitParams);
- $contribution = $this->callAPISuccessGetSingle('contribution', array(
+ $contribution = $this->callAPISuccessGetSingle('contribution', [
'contribution_page_id' => $this->_ids['contribution_page'],
- ));
+ ]);
// Retrieve the lineItem that belongs to the Printing Rights and check the tax_amount CiviCRM Core calculated for it
- $lineItem = $this->callAPISuccessGetSingle('LineItem', array(
+ $lineItem = $this->callAPISuccessGetSingle('LineItem', [
'contribution_id' => $contribution['id'],
'label' => 'Printing Rights',
- ));
+ ]);
$lineItem_TaxAmount = round($lineItem['tax_amount'], 2);
// Log parameters for later debugging and testing.
$message = __FUNCTION__ . ": {$rawParams['TEST_UNIQ']}:";
- $log_params = array_intersect_key($rawParams, array(
+ $log_params = array_intersect_key($rawParams, [
'amount' => 1,
'total_amount' => 1,
'contributionID' => 1,
- ));
+ ]);
$message .= json_encode($log_params);
$log = new CRM_Utils_SystemLogger();
$log->debug($message, $_REQUEST);
class api_v3_ContributionRecurTest extends CiviUnitTestCase {
protected $_apiversion = 3;
protected $params;
- protected $ids = array();
+ protected $ids = [];
protected $_entity = 'contribution_recur';
public $DBResetRequired = FALSE;
parent::setUp();
$this->useTransaction(TRUE);
$this->ids['contact'][0] = $this->individualCreate();
- $this->params = array(
+ $this->params = [
'contact_id' => $this->ids['contact'][0],
'installments' => '12',
'frequency_interval' => '1',
'start_date' => '2012-01-01 00:00:00',
'currency' => 'USD',
'frequency_unit' => 'day',
- );
+ ];
}
public function testCreateContributionRecur() {
public function testGetContributionRecur() {
$this->callAPISuccess($this->_entity, 'create', $this->params);
- $getParams = array(
+ $getParams = [
'amount' => '500',
- );
+ ];
$result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
}
public function testCreateContributionRecurWithToken() {
// create token
$this->createLoggedInUser();
- $token = $this->callAPISuccess('PaymentToken', 'create', array(
+ $token = $this->callAPISuccess('PaymentToken', 'create', [
'payment_processor_id' => $this->processorCreate(),
'token' => 'hhh',
'contact_id' => $this->individualCreate(),
- ));
+ ]);
$params['payment_token_id'] = $token['id'];
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
$this->assertEquals(1, $result['count']);
public function testDeleteContributionRecur() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => $result['id']);
+ $deleteParams = ['id' => $result['id']];
$this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testGetFieldsContributionRecur() {
- $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
+ $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
$this->assertEquals(12, $result['values']['start_date']['type']);
}
$this->_individualId = $this->individualCreate();
$this->_softIndividual1Id = $this->individualCreate();
$this->_softIndividual2Id = $this->individualCreate();
- $this->_contributionId = $this->contributionCreate(array('contact_id' => $this->_individualId));
+ $this->_contributionId = $this->contributionCreate(['contact_id' => $this->_individualId]);
$this->processorCreate();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'net_amount' => 95.00,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
- $this->_processorParams = array(
+ ];
+ $this->_processorParams = [
'domain_id' => 1,
'name' => 'Dummy',
'payment_processor_type_id' => 10,
'url_site' => 'http://dummy.com',
'url_recur' => 'http://dummy.com',
'billing_mode' => 1,
- );
+ ];
}
/**
*/
public function testGetContributionSoft() {
//We don't test for PCP fields because there's no PCP API, so we can't create campaigns.
- $p = array(
+ $p = [
'contribution_id' => $this->_contributionId,
'contact_id' => $this->_softIndividual1Id,
'amount' => 10.00,
'currency' => 'USD',
'soft_credit_type_id' => 4,
- );
+ ];
$this->_softcontribution = $this->callAPISuccess('contribution_soft', 'create', $p);
- $params = array(
+ $params = [
'id' => $this->_softcontribution['id'],
- );
+ ];
$softcontribution = $this->callAPIAndDocument('contribution_soft', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $softcontribution['count']);
$this->assertEquals($softcontribution['values'][$this->_softcontribution['id']]['contribution_id'], $this->_contributionId);
$this->_softcontribution2 = $this->callAPISuccess('contribution_soft', 'create', $p);
// now we have 2 - test getcount
- $softcontribution = $this->callAPISuccess('contribution_soft', 'getcount', array());
+ $softcontribution = $this->callAPISuccess('contribution_soft', 'getcount', []);
$this->assertEquals(2, $softcontribution);
//check first contribution
- $result = $this->callAPISuccess('contribution_soft', 'get', array(
+ $result = $this->callAPISuccess('contribution_soft', 'get', [
'id' => $this->_softcontribution['id'],
- ));
+ ]);
$this->assertEquals(1, $result['count']);
$this->assertEquals($this->_softcontribution['id'], $result['id']);
$this->assertEquals($this->_softcontribution['id'], $result['id'], print_r($softcontribution, TRUE));
//test id only format - second soft credit
- $resultID2 = $this->callAPISuccess('contribution_soft', 'get', array(
+ $resultID2 = $this->callAPISuccess('contribution_soft', 'get', [
'id' => $this->_softcontribution2['id'],
'format.only_id' => 1,
- ));
+ ]);
$this->assertEquals($this->_softcontribution2['id'], $resultID2);
//test get by contact id works
- $result = $this->callAPISuccess('contribution_soft', 'get', array(
+ $result = $this->callAPISuccess('contribution_soft', 'get', [
'contact_id' => $this->_softIndividual2Id,
- ));
+ ]);
$this->assertEquals(1, $result['count']);
- $this->callAPISuccess('contribution_soft', 'Delete', array(
+ $this->callAPISuccess('contribution_soft', 'Delete', [
'id' => $this->_softcontribution['id'],
- ));
+ ]);
// check one soft credit remains
$expectedCount = 1;
- $this->callAPISuccess('contribution_soft', 'getcount', array(), $expectedCount);
+ $this->callAPISuccess('contribution_soft', 'getcount', [], $expectedCount);
//check id is same as 2
- $this->assertEquals($this->_softcontribution2['id'], $this->callAPISuccess('contribution_soft', 'getvalue', array('return' => 'id')));
+ $this->assertEquals($this->_softcontribution2['id'], $this->callAPISuccess('contribution_soft', 'getvalue', ['return' => 'id']));
- $this->callAPISuccess('ContributionSoft', 'Delete', array(
+ $this->callAPISuccess('ContributionSoft', 'Delete', [
'id' => $this->_softcontribution2['id'],
- ));
+ ]);
}
/**
* civicrm_contribution_soft.
*/
public function testCreateEmptyParamsContributionSoft() {
- $softcontribution = $this->callAPIFailure('contribution_soft', 'create', array(),
+ $softcontribution = $this->callAPIFailure('contribution_soft', 'create', [],
'Mandatory key(s) missing from params array: contribution_id, amount, contact_id'
);
}
public function testCreateParamsWithoutRequiredKeysContributionSoft() {
- $softcontribution = $this->callAPIFailure('contribution_soft', 'create', array(),
+ $softcontribution = $this->callAPIFailure('contribution_soft', 'create', [],
'Mandatory key(s) missing from params array: contribution_id, amount, contact_id'
);
}
public function testCreateContributionSoftInvalidContact() {
- $params = array(
+ $params = [
'contact_id' => 999,
'contribution_id' => $this->_contributionId,
'amount' => 10.00,
'currency' => 'USD',
- );
+ ];
$softcontribution = $this->callAPIFailure('contribution_soft', 'create', $params,
'contact_id is not valid : 999'
}
public function testCreateContributionSoftInvalidContributionId() {
- $params = array(
+ $params = [
'contribution_id' => 999999,
'contact_id' => $this->_softIndividual1Id,
'amount' => 10.00,
'currency' => 'USD',
- );
+ ];
$softcontribution = $this->callAPIFailure('contribution_soft', 'create', $params,
'contribution_id is not valid : 999999'
* Function tests that additional financial records are created when fee amount is recorded.
*/
public function testCreateContributionSoft() {
- $params = array(
+ $params = [
'contribution_id' => $this->_contributionId,
'contact_id' => $this->_softIndividual1Id,
'amount' => 10.00,
'currency' => 'USD',
'soft_credit_type_id' => 5,
- );
+ ];
$softcontribution = $this->callAPIAndDocument('contribution_soft', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($softcontribution['values'][$softcontribution['id']]['contribution_id'], $this->_contributionId);
*/
public function testCreateUpdateContributionSoft() {
//create a soft credit
- $params = array(
+ $params = [
'contribution_id' => $this->_contributionId,
'contact_id' => $this->_softIndividual1Id,
'amount' => 10.00,
'currency' => 'USD',
'soft_credit_type_id' => 6,
- );
+ ];
$softcontribution = $this->callAPISuccess('contribution_soft', 'create', $params);
$softcontributionID = $softcontribution['id'];
- $old_params = array(
+ $old_params = [
'contribution_soft_id' => $softcontributionID,
- );
+ ];
$original = $this->callAPISuccess('contribution_soft', 'get', $old_params);
//Make sure it came back
$this->assertEquals($original['id'], $softcontributionID);
$this->assertEquals($old_amount, 10.00);
$this->assertEquals($old_currency, 'USD');
$this->assertEquals($old_soft_credit_type_id, 6);
- $params = array(
+ $params = [
'id' => $softcontributionID,
'contribution_id' => $this->_contributionId,
'contact_id' => $this->_softIndividual1Id,
'amount' => 7.00,
'currency' => 'CAD',
'soft_credit_type_id' => 7,
- );
+ ];
$softcontribution = $this->callAPISuccess('contribution_soft', 'create', $params);
- $new_params = array(
+ $new_params = [
'id' => $softcontribution['id'],
- );
+ ];
$softcontribution = $this->callAPISuccess('contribution_soft', 'get', $new_params);
//check against original values
$this->assertEquals($softcontribution['values'][$softcontributionID]['contribution_id'], $this->_contributionId);
$this->assertEquals($softcontribution['values'][$softcontributionID]['currency'], 'CAD');
$this->assertEquals($softcontribution['values'][$softcontributionID]['soft_credit_type_id'], 7);
- $params = array(
+ $params = [
'id' => $softcontributionID,
- );
+ ];
$this->callAPISuccess('contribution_soft', 'delete', $params);
}
*
*/
public function testDeleteEmptyParamsContributionSoft() {
- $params = array();
+ $params = [];
$softcontribution = $this->callAPIFailure('contribution_soft', 'delete', $params);
}
public function testDeleteWrongParamContributionSoft() {
- $params = array(
+ $params = [
'contribution_source' => 'SSF',
- );
+ ];
$this->callAPIFailure('contribution_soft', 'delete', $params);
}
public function testDeleteContributionSoft() {
//create a soft credit
- $params = array(
+ $params = [
'contribution_id' => $this->_contributionId,
'contact_id' => $this->_softIndividual1Id,
'amount' => 10.00,
'currency' => 'USD',
- );
+ ];
$softcontribution = $this->callAPISuccess('contribution_soft', 'create', $params);
$softcontributionID = $softcontribution['id'];
- $params = array(
+ $params = [
'id' => $softcontributionID,
- );
+ ];
$this->callAPIAndDocument('contribution_soft', 'delete', $params, __FUNCTION__, __FILE__);
}
* All available contributions expected.
*/
public function testSearchEmptyParams() {
- $p = array(
+ $p = [
'contribution_id' => $this->_contributionId,
'contact_id' => $this->_softIndividual1Id,
'amount' => 10.00,
'currency' => 'USD',
- );
+ ];
$softcontribution = $this->callAPISuccess('contribution_soft', 'create', $p);
- $result = $this->callAPISuccess('contribution_soft', 'get', array());
+ $result = $this->callAPISuccess('contribution_soft', 'get', []);
// We're taking the first element.
$res = $result['values'][$softcontribution['id']];
* Test civicrm_contribution_soft_search. Success expected.
*/
public function testSearch() {
- $p1 = array(
+ $p1 = [
'contribution_id' => $this->_contributionId,
'contact_id' => $this->_softIndividual1Id,
'amount' => 10.00,
'currency' => 'USD',
- );
+ ];
$softcontribution1 = $this->callAPISuccess('contribution_soft', 'create', $p1);
- $p2 = array(
+ $p2 = [
'contribution_id' => $this->_contributionId,
'contact_id' => $this->_softIndividual2Id,
'amount' => 25.00,
'currency' => 'CAD',
- );
+ ];
$softcontribution2 = $this->callAPISuccess('contribution_soft', 'create', $p2);
- $params = array(
+ $params = [
'id' => $softcontribution2['id'],
- );
+ ];
$result = $this->callAPISuccess('contribution_soft', 'get', $params);
$res = $result['values'][$softcontribution2['id']];
protected $_entity = 'Contribution';
public $debug = 0;
protected $_params;
- protected $_ids = array();
- protected $_pageParams = array();
+ protected $_ids = [];
+ protected $_pageParams = [];
/**
* Payment processor ID (dummy processor).
*
*
* @var array
*/
- protected $_processorParams = array();
+ protected $_processorParams = [];
/**
* ID of created event.
$this->_apiversion = 3;
$this->_individualId = $this->individualCreate();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'net_amount' => 95.00,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
- $this->_processorParams = array(
+ ];
+ $this->_processorParams = [
'domain_id' => 1,
'name' => 'Dummy',
'payment_processor_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', 'Dummy'),
'url_site' => 'http://dummy.com',
'url_recur' => 'http://dummy.com',
'billing_mode' => 1,
- );
+ ];
$this->paymentProcessorID = $this->processorCreate();
- $this->_pageParams = array(
+ $this->_pageParams = [
'title' => 'Test Contribution Page',
'financial_type_id' => 1,
'currency' => 'USD',
'is_allow_other_amount' => 1,
'min_amount' => 10,
'max_amount' => 1000,
- );
+ ];
}
/**
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
- $this->quickCleanup(array('civicrm_uf_match'));
- $financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', array());
+ $this->quickCleanup(['civicrm_uf_match']);
+ $financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', []);
foreach ($financialAccounts['values'] as $financialAccount) {
if ($financialAccount['name'] == 'Test Tax financial account ' || $financialAccount['name'] == 'Test taxable financial Type') {
- $entityFinancialTypes = $this->callAPISuccess('EntityFinancialAccount', 'get', array(
+ $entityFinancialTypes = $this->callAPISuccess('EntityFinancialAccount', 'get', [
'financial_account_id' => $financialAccount['id'],
- ));
+ ]);
foreach ($entityFinancialTypes['values'] as $entityFinancialType) {
- $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialType['id']));
+ $this->callAPISuccess('EntityFinancialAccount', 'delete', ['id' => $entityFinancialType['id']]);
}
- $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id']));
+ $this->callAPISuccess('FinancialAccount', 'delete', ['id' => $financialAccount['id']]);
}
}
}
public function testGetContribution() {
$contributionSettings = $this->enableTaxAndInvoicing();
$invoice_prefix = CRM_Contribute_BAO_Contribution::checkContributeSettings('invoice_prefix', TRUE);
- $p = array(
+ $p = [
'contact_id' => $this->_individualId,
'receive_date' => '2010-01-20',
'total_amount' => 100.00,
'invoice_id' => 78910,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$this->_contribution = $this->callAPISuccess('contribution', 'create', $p);
- $params = array(
+ $params = [
'contribution_id' => $this->_contribution['id'],
- );
+ ];
$contributions = $this->callAPIAndDocument('contribution', 'get', $params, __FUNCTION__, __FILE__);
$financialParams['id'] = $this->_financialTypeId;
$contribution2 = $this->callAPISuccess('contribution', 'create', $p);
// Now we have 2 - test getcount.
- $contribution = $this->callAPISuccess('contribution', 'getcount', array());
+ $contribution = $this->callAPISuccess('contribution', 'getcount', []);
$this->assertEquals(2, $contribution);
// Test id only format.
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'id' => $this->_contribution['id'],
'format.only_id' => 1,
- ));
+ ]);
$this->assertEquals($this->_contribution['id'], $contribution, print_r($contribution, TRUE));
// Test id only format.
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'id' => $contribution2['id'],
'format.only_id' => 1,
- ));
+ ]);
$this->assertEquals($contribution2['id'], $contribution);
// Test id as field.
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'id' => $this->_contribution['id'],
- ));
+ ]);
$this->assertEquals(1, $contribution['count']);
// Test get by contact id works.
- $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId));
+ $contribution = $this->callAPISuccess('contribution', 'get', ['contact_id' => $this->_individualId]);
$this->assertEquals(2, $contribution['count']);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $this->_contribution['id'],
- ));
- $this->callAPISuccess('Contribution', 'Delete', array(
+ ]);
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution2['id'],
- ));
+ ]);
}
/**
* Test that test contributions can be retrieved.
*/
public function testGetTestContribution() {
- $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('is_test' => 1)));
- $this->callAPISuccessGetSingle('Contribution', array('is_test' => 1));
+ $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['is_test' => 1]));
+ $this->callAPISuccessGetSingle('Contribution', ['is_test' => 1]);
}
/**
$params['cancel_reason'] = 'You lose sucker';
$params['creditnote_id'] = 'sudo rm -rf';
$params['tax_amount'] = '1';
- $address = $this->callAPISuccess('Address', 'create', array(
+ $address = $this->callAPISuccess('Address', 'create', [
'street_address' => 'Knockturn Alley',
'contact_id' => $this->_individualId,
'location_type_id' => 'Home',
- ));
+ ]);
$params['address_id'] = $address['id'];
$contributionPage = $this->contributionPageCreate();
$params['contribution_page_id'] = $contributionPage['id'];
- $contributionRecur = $this->callAPISuccess('ContributionRecur', 'create', array(
+ $contributionRecur = $this->callAPISuccess('ContributionRecur', 'create', [
'contact_id' => $this->_individualId,
'frequency_interval' => 1,
'amount' => 5,
- ));
+ ]);
$params['contribution_recur_id'] = $contributionRecur['id'];
$params['campaign_id'] = $this->campaignCreate();
$contributionID = $this->contributionCreate($params);
// update contribution with invoice number
- $params = array_merge($params, array(
+ $params = array_merge($params, [
'id' => $contributionID,
'invoice_number' => CRM_Utils_Array::value('invoice_prefix', Civi::settings()->get('contribution_invoice_settings')) . "" . $contributionID,
'trxn_id' => 12345,
'invoice_id' => 6789,
- ));
+ ]);
$contributionID = $this->contributionCreate($params);
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contributionID));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contributionID]);
$this->assertEquals('bouncer', $contribution['check_number']);
$this->assertEquals('bouncer', $contribution['contribution_check_number']);
$fields['address_id'] = $fields['contribution_address_id'];
$fields['check_number'] = $fields['contribution_check_number'];
- $fieldsLockedIn = array(
+ $fieldsLockedIn = [
'contribution_id', 'contribution_contact_id', 'financial_type_id', 'contribution_page_id',
'payment_instrument_id', 'receive_date', 'non_deductible_amount', 'total_amount',
'fee_amount', 'net_amount', 'trxn_id', 'invoice_id', 'currency', 'contribution_cancel_date', 'cancel_reason',
'receipt_date', 'thankyou_date', 'contribution_source', 'amount_level', 'contribution_recur_id',
'is_test', 'is_pay_later', 'contribution_status_id', 'address_id', 'check_number', 'contribution_campaign_id',
'creditnote_id', 'tax_amount', 'revenue_recognition_date', 'decoy',
- );
+ ];
$missingFields = array_diff($fieldsLockedIn, array_keys($fields));
// If any of the locked in fields disappear from the $fields array we need to make sure it is still
// covered as the test contract now guarantees them in the return array.
- $this->assertEquals($missingFields, array(29 => 'decoy'), 'A field which was covered by the test contract has changed.');
+ $this->assertEquals($missingFields, [29 => 'decoy'], 'A field which was covered by the test contract has changed.');
foreach ($fields as $fieldName => $fieldSpec) {
- $contribution = $this->callAPISuccessGetSingle('Contribution', array('id' => $contributionID, 'return' => $fieldName));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contributionID, 'return' => $fieldName]);
$returnField = $fieldName;
if ($returnField == 'contribution_contact_id') {
$returnField = 'contact_id';
* We need to ensure previous tested behaviour still works as part of the api contract.
*/
public function testGetContributionLegacyBehaviour() {
- $p = array(
+ $p = [
'contact_id' => $this->_individualId,
'receive_date' => '2010-01-20',
'total_amount' => 100.00,
'invoice_id' => 78910,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$this->_contribution = $this->callAPISuccess('Contribution', 'create', $p);
- $params = array(
+ $params = [
'contribution_id' => $this->_contribution['id'],
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'get', $params);
$financialParams['id'] = $this->_financialTypeId;
$default = NULL;
$contribution2 = $this->callAPISuccess('contribution', 'create', $p);
// now we have 2 - test getcount
- $contribution = $this->callAPISuccess('contribution', 'getcount', array());
+ $contribution = $this->callAPISuccess('contribution', 'getcount', []);
$this->assertEquals(2, $contribution);
//test id only format
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'id' => $this->_contribution['id'],
'format.only_id' => 1,
- ));
+ ]);
$this->assertEquals($this->_contribution['id'], $contribution, print_r($contribution, TRUE));
//test id only format
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'id' => $contribution2['id'],
'format.only_id' => 1,
- ));
+ ]);
$this->assertEquals($contribution2['id'], $contribution);
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'id' => $this->_contribution['id'],
- ));
+ ]);
//test id as field
$this->assertEquals(1, $contribution['count']);
// $this->assertEquals($this->_contribution['id'], $contribution['id'] ) ;
//test get by contact id works
- $contribution = $this->callAPISuccess('contribution', 'get', array('contact_id' => $this->_individualId));
+ $contribution = $this->callAPISuccess('contribution', 'get', ['contact_id' => $this->_individualId]);
$this->assertEquals(2, $contribution['count']);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $this->_contribution['id'],
- ));
- $this->callAPISuccess('Contribution', 'Delete', array(
+ ]);
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution2['id'],
- ));
+ ]);
}
/**
* Create an contribution_id=FALSE and financial_type_id=Donation.
*/
public function testCreateEmptyContributionIDUseDonation() {
- $params = array(
+ $params = [
'contribution_id' => FALSE,
'contact_id' => 1,
'total_amount' => 1,
'check_permissions' => FALSE,
'financial_type_id' => 'Donation',
- );
+ ];
$this->callAPISuccess('contribution', 'create', $params);
}
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
- $check = $this->callAPISuccess($this->_entity, 'get', array(
+ $check = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
'id' => $result['id'],
- ));
+ ]);
$this->customFieldDelete($ids['custom_field_id']);
$this->customGroupDelete($ids['custom_group_id']);
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]);
public function testCreateGetFieldsWithCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$idsContact = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTest.php');
- $result = $this->callAPISuccess('Contribution', 'getfields', array());
+ $result = $this->callAPISuccess('Contribution', 'getfields', []);
$this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $result['values']);
$this->assertArrayNotHasKey('custom_' . $idsContact['custom_field_id'], $result['values']);
$this->customFieldDelete($ids['custom_field_id']);
public function testCreateContributionNoLineItems() {
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 1,
'skipLineItem' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $lineItems = $this->callAPISuccess('line_item', 'get', array(
+ $lineItems = $this->callAPISuccess('line_item', 'get', [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(0, $lineItems['count']);
}
* Test checks that passing in line items suppresses the create mechanism.
*/
public function testCreateContributionChainedLineItems() {
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 1,
'skipLineItem' => 1,
- 'api.line_item.create' => array(
- array(
+ 'api.line_item.create' => [
+ [
'price_field_id' => 1,
'qty' => 2,
'line_total' => '20',
'unit_price' => '10',
- ),
- array(
+ ],
+ [
'price_field_id' => 1,
'qty' => 1,
'line_total' => '80',
'unit_price' => '80',
- ),
- ),
- );
+ ],
+ ],
+ ];
$description = "Create Contribution with Nested Line Items.";
$subfile = "CreateWithNestedLineItems";
$contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $lineItems = $this->callAPISuccess('line_item', 'get', array(
+ $lineItems = $this->callAPISuccess('line_item', 'get', [
'entity_id' => $contribution['id'],
'contribution_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(2, $lineItems['count']);
}
public function testCreateContributionOffline() {
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
$this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
$this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
$this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
- $lineItems = $this->callAPISuccess('line_item', 'get', array(
+ $lineItems = $this->callAPISuccess('line_item', 'get', [
'entity_id' => $contribution['id'],
'contribution_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(1, $lineItems['count']);
$this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']);
$this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']);
* Test create with valid payment instrument.
*/
public function testCreateContributionWithPaymentInstrument() {
- $params = $this->_params + array('payment_instrument' => 'EFT');
+ $params = $this->_params + ['payment_instrument' => 'EFT'];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'sequential' => 1,
'id' => $contribution['id'],
- ));
+ ]);
$this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
$this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
- $this->callAPISuccess('contribution', 'create', array(
+ $this->callAPISuccess('contribution', 'create', [
'id' => $contribution['id'],
'payment_instrument' => 'Credit Card',
- ));
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ ]);
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'sequential' => 1,
'id' => $contribution['id'],
- ));
+ ]);
$this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
$this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']);
}
public function testGetContributionByPaymentInstrument() {
- $params = $this->_params + array('payment_instrument' => 'EFT');
- $params2 = $this->_params + array('payment_instrument' => 'Cash');
+ $params = $this->_params + ['payment_instrument' => 'EFT'];
+ $params2 = $this->_params + ['payment_instrument' => 'Cash'];
$this->callAPISuccess('contribution', 'create', $params);
$this->callAPISuccess('contribution', 'create', $params2);
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'sequential' => 1,
'contribution_payment_instrument' => 'Cash',
- ));
+ ]);
$this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
$this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']);
$this->assertEquals(1, $contribution['count']);
- $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'payment_instrument' => 'Cash'));
+ $contribution = $this->callAPISuccess('contribution', 'get', ['sequential' => 1, 'payment_instrument' => 'Cash']);
$this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
$this->assertEquals('Cash', $contribution['values'][0]['payment_instrument']);
$this->assertEquals(1, $contribution['count']);
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'sequential' => 1,
'payment_instrument_id' => 5,
- ));
+ ]);
$this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
$this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
$this->assertEquals(1, $contribution['count']);
- $contribution = $this->callAPISuccess('contribution', 'get', array(
+ $contribution = $this->callAPISuccess('contribution', 'get', [
'sequential' => 1,
'payment_instrument' => 'EFT',
- ));
+ ]);
$this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
$this->assertEquals('EFT', $contribution['values'][0]['payment_instrument']);
$this->assertEquals(1, $contribution['count']);
- $contribution = $this->callAPISuccess('contribution', 'create', array(
+ $contribution = $this->callAPISuccess('contribution', 'create', [
'id' => $contribution['id'],
'payment_instrument' => 'Credit Card',
- ));
- $contribution = $this->callAPISuccess('contribution', 'get', array('sequential' => 1, 'id' => $contribution['id']));
+ ]);
+ $contribution = $this->callAPISuccess('contribution', 'get', ['sequential' => 1, 'id' => $contribution['id']]);
$this->assertArrayHasKey('payment_instrument', $contribution['values'][0]);
$this->assertEquals('Credit Card', $contribution['values'][0]['payment_instrument']);
$this->assertEquals(1, $contribution['count']);
* CRM-16227 introduces invoice_id as a parameter.
*/
public function testGetContributionByInvoice() {
- $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('invoice_id' => 'curly')));
- $this->callAPISuccess('Contribution', 'create', array_merge($this->_params), array('invoice_id' => 'churlish'));
- $this->callAPISuccessGetCount('Contribution', array(), 2);
- $this->callAPISuccessGetSingle('Contribution', array('invoice_id' => 'curly'));
+ $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['invoice_id' => 'curly']));
+ $this->callAPISuccess('Contribution', 'create', array_merge($this->_params), ['invoice_id' => 'churlish']);
+ $this->callAPISuccessGetCount('Contribution', [], 2);
+ $this->callAPISuccessGetSingle('Contribution', ['invoice_id' => 'curly']);
// The following don't work. They are the format we are trying to introduce but although the form uses this format
// CRM_Contact_BAO_Query::convertFormValues puts them into the other format & the where only supports that.
// ideally the where clause would support this format (as it does on contact_BAO_Query) and those lines would
* Check the credit note retrieval is case insensitive.
*/
public function testGetCreditNoteCaseInsensitive() {
- $this->contributionCreate(array('contact_id' => $this->_individualId));
- $this->contributionCreate(array('creditnote_id' => 'cN1234', 'contact_id' => $this->_individualId, 'invoice_id' => rand(), 'trxn_id' => rand()));
- $contribution = $this->callAPISuccess('Contribution', 'getsingle', array('creditnote_id' => 'CN1234'));
+ $this->contributionCreate(['contact_id' => $this->_individualId]);
+ $this->contributionCreate(['creditnote_id' => 'cN1234', 'contact_id' => $this->_individualId, 'invoice_id' => rand(), 'trxn_id' => rand()]);
+ $contribution = $this->callAPISuccess('Contribution', 'getsingle', ['creditnote_id' => 'CN1234']);
$this->assertEquals($contribution['creditnote_id'], 'cN1234');
}
* @throws Exception
*/
public function testGetContributionByTotalAmount() {
- $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '5')));
- $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '10')));
- $this->callAPISuccessGetCount('Contribution', array('total_amount' => 10), 1);
- $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 6)), 1);
- $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 0)), 2);
- $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => -5)), 2);
- $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('<' => 0)), 0);
- $this->callAPISuccessGetCount('Contribution', array(), 2);
+ $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['total_amount' => '5']));
+ $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['total_amount' => '10']));
+ $this->callAPISuccessGetCount('Contribution', ['total_amount' => 10], 1);
+ $this->callAPISuccessGetCount('Contribution', ['total_amount' => ['>' => 6]], 1);
+ $this->callAPISuccessGetCount('Contribution', ['total_amount' => ['>' => 0]], 2);
+ $this->callAPISuccessGetCount('Contribution', ['total_amount' => ['>' => -5]], 2);
+ $this->callAPISuccessGetCount('Contribution', ['total_amount' => ['<' => 0]], 0);
+ $this->callAPISuccessGetCount('Contribution', [], 2);
}
/**
*/
public function testCreateContributionSource() {
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => date('Ymd'),
'total_amount' => 100.00,
'invoice_id' => 67890,
'contribution_source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
$params['skipCleanMoney'] = FALSE;
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id']));
+ $contribution = $this->callAPISuccessGetSingle('contribution', ['id' => $contribution['id']]);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receive_date'])));
$this->assertEquals(5000.77, $contribution['total_amount'], 'failed to handle ' . $this->formatMoneyInput(5000.77));
$this->assertEquals(.77, $contribution['fee_amount']);
$params['thankyou_date'] = 'yesterday';
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id']));
+ $contribution = $this->callAPISuccessGetSingle('contribution', ['id' => $contribution['id']]);
$this->assertEquals(date('Y-m-d', strtotime('yesterday')), date('Y-m-d', strtotime($contribution['thankyou_date'])));
$params['thankyou_date'] = 'null';
*/
public function testCreateContributionSourceInvalidContact() {
- $params = array(
+ $params = [
'contact_id' => 999,
'receive_date' => date('Ymd'),
'total_amount' => 100.00,
'invoice_id' => 67890,
'contribution_source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999');
}
public function testCreateContributionSourceInvalidContContact() {
- $params = array(
+ $params = [
'contribution_contact_id' => 999,
'receive_date' => date('Ymd'),
'total_amount' => 100.00,
'invoice_id' => 67890,
'contribution_source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$this->callAPIFailure('contribution', 'create', $params);
}
public function testCreateContributionWithNote() {
$description = "Demonstrates creating contribution with Note Entity.";
$subfile = "ContributionCreateWithNote";
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 1,
'note' => 'my contribution note',
- );
+ ];
$contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $result = $this->callAPISuccess('note', 'get', array(
+ $result = $this->callAPISuccess('note', 'get', [
'entity_table' => 'civicrm_contribution',
'entity_id' => $contribution['id'],
'sequential' => 1,
- ));
+ ]);
$this->assertEquals('my contribution note', $result['values'][0]['note']);
- $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
+ $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]);
}
public function testCreateContributionWithNoteUniqueNameAliases() {
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 1,
'contribution_note' => 'my contribution note',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $result = $this->callAPISuccess('note', 'get', array(
+ $result = $this->callAPISuccess('note', 'get', [
'entity_table' => 'civicrm_contribution',
'entity_id' => $contribution['id'],
'sequential' => 1,
- ));
+ ]);
$this->assertEquals('my contribution note', $result['values'][0]['note']);
- $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
+ $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]);
}
/**
public function testCreateContributionWithSoftCredit() {
$description = "Demonstrates creating contribution with SoftCredit.";
$subfile = "ContributionCreateWithSoftCredit";
- $contact2 = $this->callAPISuccess('Contact', 'create', array(
+ $contact2 = $this->callAPISuccess('Contact', 'create', [
'display_name' => 'superman',
'contact_type' => 'Individual',
- ));
- $softParams = array(
+ ]);
+ $softParams = [
'contact_id' => $contact2['id'],
'amount' => 50,
'soft_credit_type_id' => 3,
- );
+ ];
- $params = $this->_params + array('soft_credit' => array(1 => $softParams));
+ $params = $this->_params + ['soft_credit' => [1 => $softParams]];
$contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
+ $result = $this->callAPISuccess('contribution', 'get', ['return' => 'soft_credit', 'sequential' => 1]);
$this->assertEquals($softParams['contact_id'], $result['values'][0]['soft_credit'][1]['contact_id']);
$this->assertEquals($softParams['amount'], $result['values'][0]['soft_credit'][1]['amount']);
$this->assertEquals($softParams['soft_credit_type_id'], $result['values'][0]['soft_credit'][1]['soft_credit_type']);
- $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
- $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
+ $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]);
+ $this->callAPISuccess('contact', 'delete', ['id' => $contact2['id']]);
}
public function testCreateContributionWithSoftCreditDefaults() {
$description = "Demonstrates creating contribution with Soft Credit defaults for amount and type.";
$subfile = "ContributionCreateWithSoftCreditDefaults";
- $contact2 = $this->callAPISuccess('Contact', 'create', array(
+ $contact2 = $this->callAPISuccess('Contact', 'create', [
'display_name' => 'superman',
'contact_type' => 'Individual',
- ));
- $params = $this->_params + array(
+ ]);
+ $params = $this->_params + [
'soft_credit_to' => $contact2['id'],
- );
+ ];
$contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
+ $result = $this->callAPISuccess('contribution', 'get', ['return' => 'soft_credit', 'sequential' => 1]);
$this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']);
// Default soft credit amount = contribution.total_amount
$this->assertEquals($this->_params['total_amount'], $result['values'][0]['soft_credit'][1]['amount']);
$this->assertEquals(CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), $result['values'][0]['soft_credit'][1]['soft_credit_type']);
- $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
- $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
+ $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]);
+ $this->callAPISuccess('contact', 'delete', ['id' => $contact2['id']]);
}
/**
public function testCreateContributionWithHonoreeContact() {
$description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id.";
$subfile = "ContributionCreateWithHonoreeContact";
- $contact2 = $this->callAPISuccess('Contact', 'create', array(
+ $contact2 = $this->callAPISuccess('Contact', 'create', [
'display_name' => 'superman',
'contact_type' => 'Individual',
- ));
- $params = $this->_params + array(
+ ]);
+ $params = $this->_params + [
'honor_contact_id' => $contact2['id'],
- );
+ ];
$contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $result = $this->callAPISuccess('contribution', 'get', array('return' => 'soft_credit', 'sequential' => 1));
+ $result = $this->callAPISuccess('contribution', 'get', ['return' => 'soft_credit', 'sequential' => 1]);
$this->assertEquals($contact2['id'], $result['values'][0]['soft_credit'][1]['contact_id']);
// Default soft credit amount = contribution.total_amount
$softCreditValueTypeID = $result['values'][0]['soft_credit'][1]['soft_credit_type'];
$this->assertEquals('in_honor_of', CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', $softCreditValueTypeID));
- $this->callAPISuccess('contribution', 'delete', array('id' => $contribution['id']));
- $this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
+ $this->callAPISuccess('contribution', 'delete', ['id' => $contribution['id']]);
+ $this->callAPISuccess('contact', 'delete', ['id' => $contact2['id']]);
}
/**
* Function tests that additional financial records are created when fee amount is recorded.
*/
public function testCreateContributionWithFee() {
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
$this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
$this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
- $lineItems = $this->callAPISuccess('line_item', 'get', array(
+ $lineItems = $this->callAPISuccess('line_item', 'get', [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(1, $lineItems['count']);
$this->assertEquals($contribution['id'], $lineItems['values'][0]['entity_id']);
$this->assertEquals($contribution['id'], $lineItems['values'][0]['contribution_id']);
- $lineItems = $this->callAPISuccess('line_item', 'get', array(
+ $lineItems = $this->callAPISuccess('line_item', 'get', [
'entity_id' => $contribution['id'],
'contribution_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(1, $lineItems['count']);
$this->_checkFinancialRecords($contribution, 'feeAmount');
}
CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams);
$contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams);
$this->assertAPISuccess($contributionPage);
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
$this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 67890);
$this->assertEquals($contribution['values'][$contribution['id']]['source'], 'SSF');
$this->assertEquals($contribution['values'][$contribution['id']]['contribution_status_id'], 1);
- $contribution['payment_instrument_id'] = $this->callAPISuccessGetValue('PaymentProcessor', array(
+ $contribution['payment_instrument_id'] = $this->callAPISuccessGetValue('PaymentProcessor', [
'id' => $this->paymentProcessorID,
'return' => 'payment_instrument_id',
- ));
+ ]);
$this->_checkFinancialRecords($contribution, 'online');
}
$this->_pageParams['is_pay_later'] = 1;
$contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams);
$this->assertAPISuccess($contributionPage);
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 2,
- );
+ ];
$contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams);
$contributionPage = $this->callAPISuccess('contribution_page', 'create', $this->_pageParams);
$this->assertAPISuccess($contributionPage);
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 2,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
public function testCreateBAODefaults() {
unset($this->_params['contribution_source_id'], $this->_params['payment_instrument_id']);
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'id' => $contribution['id'],
'api.contribution.delete' => 1,
- ));
+ ]);
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('Check', $contribution['payment_instrument']);
$this->callAPISuccessGetCount('Contribution', ['id' => $contribution['id']], 0);
*/
public function testDeleteChainedGetSingle() {
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'id' => $contribution['id'],
'api.contribution.delete' => 1,
- ));
+ ]);
$this->callAPISuccessGetCount('Contribution', ['id' => $contribution['id']], 0);
}
*/
public function testCreateUpdateContributionChangeTotal() {
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
- $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
+ $lineItems = $this->callAPISuccess('line_item', 'getvalue', [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
'return' => 'line_total',
- ));
+ ]);
$this->assertEquals('100.00', $lineItems);
$trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
// Financial trxn SUM = 100 + 5 (fee)
$this->assertEquals('105.00', $trxnAmount);
- $newParams = array(
+ $newParams = [
'id' => $contribution['id'],
'total_amount' => '125',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
- $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
+ $lineItems = $this->callAPISuccess('line_item', 'getvalue', [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
'return' => 'line_total',
- ));
+ ]);
$this->assertEquals('125.00', $lineItems);
$trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
* Function tests that line items, financial records are updated when pay later contribution is received.
*/
public function testCreateUpdateContributionPayLater() {
- $contribParams = array(
+ $contribParams = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'contribution_status_id' => 2,
'is_pay_later' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
- $newParams = array_merge($contribParams, array(
+ $newParams = array_merge($contribParams, [
'id' => $contribution['id'],
'contribution_status_id' => 1,
- ));
+ ]);
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
$contribution = $contribution['values'][$contribution['id']];
$this->assertEquals($contribution['contribution_status_id'], '1');
*/
public function testCreateUpdateContributionPaymentInstrument() {
$instrumentId = $this->_addPaymentInstrument();
- $contribParams = array(
+ $contribParams = [
'contact_id' => $this->_individualId,
'total_amount' => 100.00,
'financial_type_id' => $this->_financialTypeId,
'payment_instrument_id' => 4,
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
- $newParams = array_merge($contribParams, array(
+ $newParams = array_merge($contribParams, [
'id' => $contribution['id'],
'payment_instrument_id' => $instrumentId,
- ));
+ ]);
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
$this->assertAPISuccess($contribution);
$this->checkFinancialTrxnPaymentInstrumentChange($contribution['id'], 4, $instrumentId);
*/
public function testCreateUpdateNegativeContributionPaymentInstrument() {
$instrumentId = $this->_addPaymentInstrument();
- $contribParams = array(
+ $contribParams = [
'contact_id' => $this->_individualId,
'total_amount' => -100.00,
'financial_type_id' => $this->_financialTypeId,
'payment_instrument_id' => 4,
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
- $newParams = array_merge($contribParams, array(
+ $newParams = array_merge($contribParams, [
'id' => $contribution['id'],
'payment_instrument_id' => $instrumentId,
- ));
+ ]);
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
$this->assertAPISuccess($contribution);
$this->checkFinancialTrxnPaymentInstrumentChange($contribution['id'], 4, $instrumentId, -100);
* Function tests that financial records are added when Contribution is Refunded.
*/
public function testCreateUpdateContributionRefund() {
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'payment_instrument_id' => 4,
'contribution_status_id' => 1,
'trxn_id' => 'original_payment',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
- $newParams = array_merge($contributionParams, array(
+ $newParams = array_merge($contributionParams, [
'id' => $contribution['id'],
'contribution_status_id' => 'Refunded',
'cancel_date' => '2015-01-01 09:00',
'refund_trxn_id' => 'the refund',
- ));
+ ]);
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
$this->_checkFinancialTrxn($contribution, 'refund');
$this->_checkFinancialItem($contribution['id'], 'refund');
- $this->assertEquals('original_payment', $this->callAPISuccessGetValue('Contribution', array(
+ $this->assertEquals('original_payment', $this->callAPISuccessGetValue('Contribution', [
'id' => $contribution['id'],
'return' => 'trxn_id',
- )));
+ ]));
}
/**
*/
public function testCreateUpdateChargebackContributionDefaultAccount() {
$contribution = $this->callAPISuccess('Contribution', 'create', $this->_params);
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'id' => $contribution['id'],
'contribution_status_id' => 'Chargeback',
- ));
- $this->callAPISuccessGetSingle('Contribution', array('contribution_status_id' => 'Chargeback'));
+ ]);
+ $this->callAPISuccessGetSingle('Contribution', ['contribution_status_id' => 'Chargeback']);
- $lineItems = $this->callAPISuccessGetSingle('LineItem', array(
+ $lineItems = $this->callAPISuccessGetSingle('LineItem', [
'contribution_id' => $contribution['id'],
- 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)),
- ));
+ 'api.FinancialItem.getsingle' => ['amount' => ['<' => 0]],
+ ]);
$this->assertEquals(1, $lineItems['api.FinancialItem.getsingle']['financial_account_id']);
- $this->callAPISuccessGetSingle('FinancialTrxn', array(
+ $this->callAPISuccessGetSingle('FinancialTrxn', [
'total_amount' => -100,
'status_id' => 'Chargeback',
'to_financial_account_id' => 6,
- ));
+ ]);
}
/**
* in the financial_trxn & financial_item table if it is.
*/
public function testCreateUpdateChargebackContributionCustomAccount() {
- $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array(
+ $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', [
'name' => 'Chargeback Account',
'is_active' => TRUE,
- ));
+ ]);
- $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', array(
+ $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', [
'entity_id' => $this->_financialTypeId,
'entity_table' => 'civicrm_financial_type',
'account_relationship' => 'Chargeback Account is',
'financial_account_id' => 'Chargeback Account',
- ));
+ ]);
$contribution = $this->callAPISuccess('Contribution', 'create', $this->_params);
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'id' => $contribution['id'],
'contribution_status_id' => 'Chargeback',
- ));
- $this->callAPISuccessGetSingle('Contribution', array('contribution_status_id' => 'Chargeback'));
+ ]);
+ $this->callAPISuccessGetSingle('Contribution', ['contribution_status_id' => 'Chargeback']);
- $lineItems = $this->callAPISuccessGetSingle('LineItem', array(
+ $lineItems = $this->callAPISuccessGetSingle('LineItem', [
'contribution_id' => $contribution['id'],
- 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)),
- ));
+ 'api.FinancialItem.getsingle' => ['amount' => ['<' => 0]],
+ ]);
$this->assertEquals($financialAccount['id'], $lineItems['api.FinancialItem.getsingle']['financial_account_id']);
- $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id']));
- $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialAccount['id']));
- $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id']));
+ $this->callAPISuccess('Contribution', 'delete', ['id' => $contribution['id']]);
+ $this->callAPISuccess('EntityFinancialAccount', 'delete', ['id' => $entityFinancialAccount['id']]);
+ $this->callAPISuccess('FinancialAccount', 'delete', ['id' => $financialAccount['id']]);
}
/**
* in the financial_trxn & financial_item table if it is.
*/
public function testCreateUpdateRefundContributionConfiguredContraAccount() {
- $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', array(
+ $financialAccount = $this->callAPISuccess('FinancialAccount', 'create', [
'name' => 'Refund Account',
'is_active' => TRUE,
- ));
+ ]);
- $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', array(
+ $entityFinancialAccount = $this->callAPISuccess('EntityFinancialAccount', 'create', [
'entity_id' => $this->_financialTypeId,
'entity_table' => 'civicrm_financial_type',
'account_relationship' => 'Credit/Contra Revenue Account is',
'financial_account_id' => 'Refund Account',
- ));
+ ]);
$contribution = $this->callAPISuccess('Contribution', 'create', $this->_params);
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'id' => $contribution['id'],
'contribution_status_id' => 'Refunded',
- ));
+ ]);
- $lineItems = $this->callAPISuccessGetSingle('LineItem', array(
+ $lineItems = $this->callAPISuccessGetSingle('LineItem', [
'contribution_id' => $contribution['id'],
- 'api.FinancialItem.getsingle' => array('amount' => array('<' => 0)),
- ));
+ 'api.FinancialItem.getsingle' => ['amount' => ['<' => 0]],
+ ]);
$this->assertEquals($financialAccount['id'], $lineItems['api.FinancialItem.getsingle']['financial_account_id']);
- $this->callAPISuccess('Contribution', 'delete', array('id' => $contribution['id']));
- $this->callAPISuccess('EntityFinancialAccount', 'delete', array('id' => $entityFinancialAccount['id']));
- $this->callAPISuccess('FinancialAccount', 'delete', array('id' => $financialAccount['id']));
+ $this->callAPISuccess('Contribution', 'delete', ['id' => $contribution['id']]);
+ $this->callAPISuccess('EntityFinancialAccount', 'delete', ['id' => $entityFinancialAccount['id']]);
+ $this->callAPISuccess('FinancialAccount', 'delete', ['id' => $financialAccount['id']]);
}
/**
* when trxn_id is passed in.
*/
public function testCreateUpdateContributionRefundTrxnIDPassedIn() {
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'payment_instrument_id' => 4,
'contribution_status_id' => 1,
'trxn_id' => 'original_payment',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
- $newParams = array_merge($contributionParams, array(
+ $newParams = array_merge($contributionParams, [
'id' => $contribution['id'],
'contribution_status_id' => 'Refunded',
'cancel_date' => '2015-01-01 09:00',
'trxn_id' => 'the refund',
- ));
+ ]);
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
$this->_checkFinancialTrxn($contribution, 'refund');
$this->_checkFinancialItem($contribution['id'], 'refund');
- $this->assertEquals('the refund', $this->callAPISuccessGetValue('Contribution', array(
+ $this->assertEquals('the refund', $this->callAPISuccessGetValue('Contribution', [
'id' => $contribution['id'],
'return' => 'trxn_id',
- )));
+ ]));
}
/**
* is kept for the refund transaction.
*/
public function testCreateUpdateContributionRefundRefundAndTrxnIDPassedIn() {
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'payment_instrument_id' => 4,
'contribution_status_id' => 1,
'trxn_id' => 'original_payment',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
- $newParams = array_merge($contributionParams, array(
+ $newParams = array_merge($contributionParams, [
'id' => $contribution['id'],
'contribution_status_id' => 'Refunded',
'cancel_date' => '2015-01-01 09:00',
'trxn_id' => 'cont id',
'refund_trxn_id' => 'the refund',
- ));
+ ]);
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
$this->_checkFinancialTrxn($contribution, 'refund');
$this->_checkFinancialItem($contribution['id'], 'refund');
- $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array(
+ $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', [
'id' => $contribution['id'],
'return' => 'trxn_id',
- )));
+ ]));
}
/**
* is kept for the refund transaction.
*/
public function testCreateUpdateContributionRefundRefundNullTrxnIDPassedIn() {
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'payment_instrument_id' => 4,
'contribution_status_id' => 1,
'trxn_id' => 'original_payment',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
- $newParams = array_merge($contributionParams, array(
+ $newParams = array_merge($contributionParams, [
'id' => $contribution['id'],
'contribution_status_id' => 'Refunded',
'cancel_date' => '2015-01-01 09:00',
'trxn_id' => 'cont id',
'refund_trxn_id' => '',
- ));
+ ]);
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
- $this->_checkFinancialTrxn($contribution, 'refund', NULL, array('trxn_id' => NULL));
+ $this->_checkFinancialTrxn($contribution, 'refund', NULL, ['trxn_id' => NULL]);
$this->_checkFinancialItem($contribution['id'], 'refund');
- $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', array(
+ $this->assertEquals('cont id', $this->callAPISuccessGetValue('Contribution', [
'id' => $contribution['id'],
'return' => 'trxn_id',
- )));
+ ]));
}
/**
* Function tests invalid contribution status change.
*/
public function testCreateUpdateContributionInValidStatusChange() {
- $contribParams = array(
+ $contribParams = [
'contact_id' => 1,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'financial_type_id' => 1,
'payment_instrument_id' => 1,
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
- $newParams = array_merge($contribParams, array(
+ $newParams = array_merge($contribParams, [
'id' => $contribution['id'],
'contribution_status_id' => 2,
- ));
+ ]);
$this->callAPIFailure('contribution', 'create', $newParams, ts('Cannot change contribution status from Completed to Pending.'));
}
* Function tests that financial records are added when Pending Contribution is Canceled.
*/
public function testCreateUpdateContributionCancelPending() {
- $contribParams = array(
+ $contribParams = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'contribution_status_id' => 2,
'is_pay_later' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
- $newParams = array_merge($contribParams, array(
+ $newParams = array_merge($contribParams, [
'id' => $contribution['id'],
'contribution_status_id' => 3,
'cancel_date' => '2012-02-02 09:00',
- ));
+ ]);
//Check if trxn_date is same as cancel_date.
- $checkTrxnDate = array(
+ $checkTrxnDate = [
'trxn_date' => '2012-02-02 09:00:00',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
$this->_checkFinancialTrxn($contribution, 'cancelPending', NULL, $checkTrxnDate);
$this->_checkFinancialItem($contribution['id'], 'cancelPending');
* Function tests that financial records are added when Financial Type is Changed.
*/
public function testCreateUpdateContributionChangeFinancialType() {
- $contribParams = array(
+ $contribParams = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
'total_amount' => 100.00,
'payment_instrument_id' => 1,
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
- $newParams = array_merge($contribParams, array(
+ $newParams = array_merge($contribParams, [
'id' => $contribution['id'],
'financial_type_id' => 3,
- ));
+ ]);
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
$this->_checkFinancialTrxn($contribution, 'changeFinancial');
$this->_checkFinancialItem($contribution['id'], 'changeFinancial');
* Test that update does not change status id CRM-15105.
*/
public function testCreateUpdateWithoutChangingPendingStatus() {
- $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array('contribution_status_id' => 2)));
- $this->callAPISuccess('contribution', 'create', array('id' => $contribution['id'], 'source' => 'new source'));
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array(
+ $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, ['contribution_status_id' => 2]));
+ $this->callAPISuccess('contribution', 'create', ['id' => $contribution['id'], 'source' => 'new source']);
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', [
'id' => $contribution['id'],
'api.contribution.delete' => 1,
- ));
+ ]);
$this->assertEquals(2, $contribution['contribution_status_id']);
}
* CHANGE: we require the API to do an incremental update
*/
public function testCreateUpdateContribution() {
- $contributionID = $this->contributionCreate(array(
+ $contributionID = $this->contributionCreate([
'contact_id' => $this->_individualId,
'trxn_id' => 212355,
'financial_type_id' => $this->_financialTypeId,
'invoice_id' => 'old_invoice',
- ));
- $old_params = array(
+ ]);
+ $old_params = [
'contribution_id' => $contributionID,
- );
+ ];
$original = $this->callAPISuccess('contribution', 'get', $old_params);
$this->assertEquals($original['id'], $contributionID);
//set up list of old params, verify
$this->assertEquals($old_source, 'SSF');
$this->assertEquals($old_trxn_id, 212355);
$this->assertEquals($old_invoice_id, 'old_invoice');
- $params = array(
+ $params = [
'id' => $contributionID,
'contact_id' => $this->_individualId,
'total_amount' => 105.00,
'non_deductible_amount' => 22.00,
'contribution_status_id' => 1,
'note' => 'Donating for Noble Cause',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $new_params = array(
+ $new_params = [
'contribution_id' => $contribution['id'],
- );
+ ];
$contribution = $this->callAPISuccessGetSingle('contribution', $new_params);
$this->assertEquals($contribution['contact_id'], $this->_individualId);
$this->assertEquals($contribution['net_amount'], $contribution['total_amount'] - $contribution['fee_amount']);
- $params = array(
+ $params = [
'contribution_id' => $contributionID,
- );
+ ];
$result = $this->callAPISuccess('contribution', 'delete', $params);
$this->assertAPISuccess($result);
}
* Attempt (but fail) to delete a contribution without parameters.
*/
public function testDeleteEmptyParamsContribution() {
- $params = array();
+ $params = [];
$this->callAPIFailure('contribution', 'delete', $params);
}
}
public function testDeleteWrongParamContribution() {
- $params = array(
+ $params = [
'contribution_source' => 'SSF',
- );
+ ];
$this->callAPIFailure('contribution', 'delete', $params);
}
public function testDeleteContribution() {
- $contributionID = $this->contributionCreate(array(
+ $contributionID = $this->contributionCreate([
'contact_id' => $this->_individualId,
'financial_type_id' => $this->_financialTypeId,
- ));
- $params = array(
+ ]);
+ $params = [
'id' => $contributionID,
- );
+ ];
$this->callAPIAndDocument('contribution', 'delete', $params, __FUNCTION__, __FILE__);
}
* All available contributions expected.
*/
public function testSearchEmptyParams() {
- $params = array();
+ $params = [];
- $p = array(
+ $p = [
'contact_id' => $this->_individualId,
'receive_date' => date('Ymd'),
'total_amount' => 100.00,
'invoice_id' => 78910,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $p);
$result = $this->callAPISuccess('contribution', 'get', $params);
* Test civicrm_contribution_search. Success expected.
*/
public function testSearch() {
- $p1 = array(
+ $p1 = [
'contact_id' => $this->_individualId,
'receive_date' => date('Ymd'),
'total_amount' => 100.00,
'financial_type_id' => $this->_financialTypeId,
'non_deductible_amount' => 10.00,
'contribution_status_id' => 1,
- );
+ ];
$contribution1 = $this->callAPISuccess('contribution', 'create', $p1);
- $p2 = array(
+ $p2 = [
'contact_id' => $this->_individualId,
'receive_date' => date('Ymd'),
'total_amount' => 200.00,
'fee_amount' => 50.00,
'net_amount' => 60.00,
'contribution_status_id' => 2,
- );
+ ];
$contribution2 = $this->callAPISuccess('contribution', 'create', $p2);
- $params = array(
+ $params = [
'contribution_id' => $contribution2['id'],
- );
+ ];
$result = $this->callAPISuccess('contribution', 'get', $params);
$res = $result['values'][$contribution2['id']];
$mut = new CiviMailUtils($this, TRUE);
$this->swapMessageTemplateForTestTemplate();
$this->createLoggedInUser();
- $params = array_merge($this->_params, array('contribution_status_id' => 2));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2]);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
- ));
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
+ ]);
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $contribution['id']]);
$this->assertEquals('SSF', $contribution['contribution_source']);
$this->assertEquals('Completed', $contribution['contribution_status']);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receipt_date'])));
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'email:::anthony_anderson@civicrm.org',
'is_monetary:::1',
'amount:::100.00',
'title:::Contribution',
'displayName:::Mr. Anthony Anderson II',
'contributionStatus:::Completed',
- ));
+ ]);
$mut->stop();
$this->revertTemplateToReservedTemplate();
}
$mut = new CiviMailUtils($this, TRUE);
$this->swapMessageTemplateForTestTemplate();
$this->createLoggedInUser();
- $params = array_merge($this->_params, array('contribution_status_id' => 2, 'currency' => 'EUR'));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2, 'currency' => 'EUR']);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
- ));
+ ]);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $contribution['id']]);
$this->assertEquals('SSF', $contribution['contribution_source']);
$this->assertEquals('Completed', $contribution['contribution_status']);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receipt_date'])));
$entityFinancialTransactions = $this->getFinancialTransactionsForContribution($contribution['id']);
$entityFinancialTransaction = reset($entityFinancialTransactions);
- $financialTrxn = $this->callAPISuccessGetSingle('FinancialTrxn', array('id' => $entityFinancialTransaction['financial_trxn_id']));
+ $financialTrxn = $this->callAPISuccessGetSingle('FinancialTrxn', ['id' => $entityFinancialTransaction['financial_trxn_id']]);
$this->assertEquals('EUR', $financialTrxn['currency']);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'email:::anthony_anderson@civicrm.org',
'is_monetary:::1',
'amount:::100.00',
'title:::Contribution',
'displayName:::Mr. Anthony Anderson II',
'contributionStatus:::Completed',
- ));
+ ]);
$mut->stop();
$this->revertTemplateToReservedTemplate();
}
$this->createLoggedInUser();
// create contribution page first
- $contributionPageParams = array(
+ $contributionPageParams = [
'title' => 'Help Support CiviCRM!',
'financial_type_id' => 1,
'is_monetary' => TRUE,
'amount_block_is_active' => 1,
'currency' => 'USD',
'is_billing_required' => 0,
- );
+ ];
$contributionPageResult = $this->callAPISuccess('contribution_page', 'create', $contributionPageParams);
// submit form values
- $priceSet = $this->callAPISuccess('price_set', 'getsingle', array('name' => 'default_contribution_amount'));
- $params = array(
+ $priceSet = $this->callAPISuccess('price_set', 'getsingle', ['name' => 'default_contribution_amount']);
+ $params = [
'id' => $contributionPageResult['id'],
'contact_id' => $this->_individualId,
'email-5' => 'anthony_anderson@civicrm.org',
'is_quick_config' => 1,
'description' => 'Online Contribution: Help Support CiviCRM!',
'price_set_id' => $priceSet['id'],
- );
+ ];
$this->callAPISuccess('contribution_page', 'submit', $params);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'is_pay_later:::1',
'email:::anthony_anderson@civicrm.org',
'pay_later_receipt:::' . $contributionPageParams['pay_later_receipt'],
'contributionPageId:::' . $contributionPageResult['id'],
'title:::' . $contributionPageParams['title'],
'amount:::' . $params['amount'],
- ));
+ ]);
$mut->stop();
$this->revertTemplateToReservedTemplate();
}
$this->createLoggedInUser();
//Scenario 1: When Contact don't have any address
- $params = array_merge($this->_params, array('contribution_status_id' => 2));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2]);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
- ));
- $mut->checkMailLog(array(
+ ]);
+ $mut->checkMailLog([
'address:::',
- ));
+ ]);
// Scenario 2: Contribution using address
- $address = $this->callAPISuccess('address', 'create', array(
+ $address = $this->callAPISuccess('address', 'create', [
'street_address' => 'contribution billing st',
'location_type_id' => 2,
'contact_id' => $this->_params['contact_id'],
- ));
- $params = array_merge($this->_params, array(
+ ]);
+ $params = array_merge($this->_params, [
'contribution_status_id' => 2,
'address_id' => $address['id'],
- )
+ ]
);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
- ));
- $mut->checkMailLog(array(
+ ]);
+ $mut->checkMailLog([
'address:::contribution billing st',
- ));
+ ]);
// Scenario 3: Contribution wtth no address but contact has a billing address
- $this->callAPISuccess('address', 'create', array(
+ $this->callAPISuccess('address', 'create', [
'id' => $address['id'],
'street_address' => 'is billing st',
'contact_id' => $this->_params['contact_id'],
- ));
- $params = array_merge($this->_params, array('contribution_status_id' => 2));
+ ]);
+ $params = array_merge($this->_params, ['contribution_status_id' => 2]);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
- ));
- $mut->checkMailLog(array(
+ ]);
+ $mut->checkMailLog([
'address:::is billing st',
- ));
+ ]);
$mut->stop();
$this->revertTemplateToReservedTemplate();
*/
public function testCompleteTransactionFeeAmount() {
$this->createLoggedInUser();
- $params = array_merge($this->_params, array('contribution_status_id' => 2));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2]);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
'fee_amount' => '.56',
'trxn_id' => '7778888',
- ));
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id'], 'sequential' => 1));
+ ]);
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $contribution['id'], 'sequential' => 1]);
$this->assertEquals('Completed', $contribution['contribution_status']);
$this->assertEquals('7778888', $contribution['trxn_id']);
$this->assertEquals('.56', $contribution['fee_amount']);
public function testCheckTaxAmount($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$contact = $this->createLoggedInUser();
- $financialType = $this->callAPISuccess('financial_type', 'create', array(
+ $financialType = $this->callAPISuccess('financial_type', 'create', [
'name' => 'Test taxable financial Type',
'is_reserved' => 0,
'is_active' => 1,
- ));
- $financialAccount = $this->callAPISuccess('financial_account', 'create', array(
+ ]);
+ $financialAccount = $this->callAPISuccess('financial_account', 'create', [
'name' => 'Test Tax financial account ',
'contact_id' => $contact,
'financial_account_type_id' => 2,
'is_reserved' => 0,
'is_active' => 1,
'is_default' => 0,
- ));
+ ]);
$financialTypeId = $financialType['id'];
$financialAccountId = $financialAccount['id'];
- $financialAccountParams = array(
+ $financialAccountParams = [
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialTypeId,
'account_relationship' => 10,
'financial_account_id' => $financialAccountId,
- );
+ ];
CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams);
- $params = array_merge($this->_params, array('contribution_status_id' => 2, 'financial_type_id' => $financialTypeId));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2, 'financial_type_id' => $financialTypeId]);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $contribution1 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => 'tax_amount', 'sequential' => 1));
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $contribution1 = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id'], 'return' => 'tax_amount', 'sequential' => 1]);
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
'trxn_id' => '777788888',
'fee_amount' => '6.00',
- ));
- $contribution2 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => array('tax_amount', 'fee_amount', 'net_amount'), 'sequential' => 1));
+ ]);
+ $contribution2 = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id'], 'return' => ['tax_amount', 'fee_amount', 'net_amount'], 'sequential' => 1]);
$this->assertEquals($contribution1['values'][0]['tax_amount'], $contribution2['values'][0]['tax_amount']);
$this->assertEquals('6.00', $contribution2['values'][0]['fee_amount']);
$this->assertEquals('99.00', $contribution2['values'][0]['net_amount']);
* Test repeat contribution successfully creates line item.
*/
public function testRepeatTransaction() {
- $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'single');
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $originalContribution = $this->setUpRepeatTransaction($recurParams = [], 'single');
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
- $lineItemParams = array(
+ ]);
+ $lineItemParams = [
'entity_id' => $originalContribution['id'],
'sequential' => 1,
- 'return' => array(
+ 'return' => [
'entity_table',
'qty',
'unit_price',
'deductible_amount',
'price_field_value_id',
'price_field_id',
- ),
- );
- $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ ],
+ ];
+ $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'],
- )));
- $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ ]));
+ $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'] + 1,
- )));
+ ]));
unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']);
unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
$this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]);
- $this->_checkFinancialRecords(array(
+ $this->_checkFinancialRecords([
'id' => $originalContribution['id'] + 1,
- 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array(
+ 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [
'id' => $originalContribution['payment_processor_id'],
'return' => 'payment_instrument_id',
- )),
- ), 'online');
+ ]),
+ ], 'online');
$this->quickCleanUpFinancialEntities();
}
*/
public function testRepeatTransactionLineItems() {
// CRM-19309
- $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'multiple');
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $originalContribution = $this->setUpRepeatTransaction($recurParams = [], 'multiple');
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
+ ]);
- $lineItemParams = array(
+ $lineItemParams = [
'entity_id' => $originalContribution['id'],
'sequential' => 1,
- 'return' => array(
+ 'return' => [
'entity_table',
'qty',
'unit_price',
'deductible_amount',
'price_field_value_id',
'price_field_id',
- ),
- );
- $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ ],
+ ];
+ $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'],
- )));
- $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ ]));
+ $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'] + 1,
- )));
+ ]));
// unset id and entity_id for all of them to be able to compare the lineItems:
unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']);
// CRM-19309 so in future we also want to:
// check that financial_line_items have been created for entity_id 3 and 4;
- $this->callAPISuccessGetCount('FinancialItem', array('description' => 'Sales Tax', 'amount' => 0), 0);
+ $this->callAPISuccessGetCount('FinancialItem', ['description' => 'Sales Tax', 'amount' => 0], 0);
$this->quickCleanUpFinancialEntities();
}
*/
public function testRepeatTransactionIsTest() {
$this->_params['is_test'] = 1;
- $originalContribution = $this->setUpRepeatTransaction(array('is_test' => 1), 'single');
+ $originalContribution = $this->setUpRepeatTransaction(['is_test' => 1], 'single');
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
- $this->callAPISuccessGetCount('Contribution', array('contribution_test' => 1), 2);
+ ]);
+ $this->callAPISuccessGetCount('Contribution', ['contribution_test' => 1], 2);
}
/**
* Test repeat contribution passed in status.
*/
public function testRepeatTransactionPassedInStatus() {
- $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'single');
+ $originalContribution = $this->setUpRepeatTransaction($recurParams = [], 'single');
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Pending',
'trxn_id' => uniqid(),
- ));
- $this->callAPISuccessGetCount('Contribution', array('contribution_status_id' => 2), 1);
+ ]);
+ $this->callAPISuccessGetCount('Contribution', ['contribution_status_id' => 2], 1);
}
/**
* Test repeat contribution accepts recur_id instead of original_contribution_id.
*/
public function testRepeatTransactionAcceptRecurID() {
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [
'contact_id' => $this->_individualId,
'installments' => '12',
'frequency_interval' => '1',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $this->paymentProcessorID,
- ));
+ ]);
$this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array('contribution_recur_id' => $contributionRecur['id']))
+ ['contribution_recur_id' => $contributionRecur['id']])
);
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_recur_id' => $contributionRecur['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
+ ]);
$this->quickCleanUpFinancialEntities();
}
* CRM-19873 Test repattransaction if contribution_recur_id is a test.
*/
public function testRepeatTransactionTestRecurId() {
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [
'contact_id' => $this->_individualId,
'frequency_interval' => '1',
'amount' => '1.00',
'frequency_unit' => 'month',
'payment_processor_id' => $this->paymentProcessorID,
'is_test' => 1,
- ));
+ ]);
$this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array(
+ [
'contribution_recur_id' => $contributionRecur['id'],
'is_test' => 1,
- ))
+ ])
);
- $repeatedContribution = $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $repeatedContribution = $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_recur_id' => $contributionRecur['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
+ ]);
$this->assertEquals($contributionRecur['values'][1]['is_test'], $repeatedContribution['values'][2]['is_test']);
$this->quickCleanUpFinancialEntities();
public function testRepeatTransactionMembershipRenewCompletedContribution() {
list($originalContribution, $membership) = $this->setUpAutoRenewMembership();
- $this->callAPISuccess('contribution', 'create', array(
+ $this->callAPISuccess('contribution', 'create', [
'contact_id' => $originalContribution['values'][1]['contact_id'],
'financial_type_id' => $originalContribution['values'][1]['financial_type_id'],
'total_amount' => $originalContribution['values'][1]['total_amount'],
'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'],
'contribution_status_id' => "Failed",
- ));
+ ]);
- $this->callAPISuccess('membership', 'create', array(
+ $this->callAPISuccess('membership', 'create', [
'id' => $membership['id'],
'end_date' => 'yesterday',
'status_id' => 'Expired',
- ));
+ ]);
- $contribution = $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $contribution = $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'],
'contribution_status_id' => 'Completed',
'trxn_id' => 'bobsled',
- ));
+ ]);
- $membershipStatusId = $this->callAPISuccess('membership', 'getvalue', array(
+ $membershipStatusId = $this->callAPISuccess('membership', 'getvalue', [
'id' => $membership['id'],
'return' => 'status_id',
- ));
+ ]);
- $membership = $this->callAPISuccess('membership', 'get', array(
+ $membership = $this->callAPISuccess('membership', 'get', [
'id' => $membership['id'],
- ));
+ ]);
$this->assertEquals('New', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membershipStatusId));
- $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id']));
+ $lineItem = $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id']]);
$this->assertEquals('civicrm_membership', $lineItem['entity_table']);
- $this->callAPISuccessGetCount('MembershipPayment', array('membership_id' => $membership['id']));
+ $this->callAPISuccessGetCount('MembershipPayment', ['membership_id' => $membership['id']]);
$this->quickCleanUpFinancialEntities();
$this->contactDelete($originalContribution['values'][1]['contact_id']);
}
}
list($originalContribution, $membership) = $this->setUpAutoRenewMembership();
- $this->callAPISuccess('contribution', 'create', array(
+ $this->callAPISuccess('contribution', 'create', [
'contact_id' => $originalContribution['values'][1]['contact_id'],
'financial_type_id' => $originalContribution['values'][1]['financial_type_id'],
'total_amount' => $originalContribution['values'][1]['total_amount'],
'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'],
'contribution_status_id' => "Completed",
- ));
+ ]);
- $this->callAPISuccess('membership', 'create', array(
+ $this->callAPISuccess('membership', 'create', [
'id' => $membership['id'],
'end_date' => 'yesterday',
'status_id' => 'Expired',
- ));
+ ]);
- $contribution = $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $contribution = $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'],
'contribution_status_id' => $contributionStatus['name'],
'trxn_id' => 'bobsled',
- ));
+ ]);
- $updatedMembership = $this->callAPISuccess('membership', 'getsingle', array(
+ $updatedMembership = $this->callAPISuccess('membership', 'getsingle', [
'id' => $membership['id'],
- ));
+ ]);
$dateTime = new DateTime('yesterday');
$this->assertEquals($dateTime->format('Y-m-d'), $updatedMembership['end_date']);
$this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Expired'), $updatedMembership['status_id']);
- $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id']));
+ $lineItem = $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id']]);
$this->assertEquals('civicrm_membership', $lineItem['entity_table']);
- $this->callAPISuccessGetCount('MembershipPayment', array('membership_id' => $membership['id']));
+ $this->callAPISuccessGetCount('MembershipPayment', ['membership_id' => $membership['id']]);
$this->quickCleanUpFinancialEntities();
$this->contactDelete($originalContribution['values'][1]['contact_id']);
}
*/
public function testRepeatTransactionAlteredAmount() {
$paymentProcessorID = $this->paymentProcessorCreate();
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [
'contact_id' => $this->_individualId,
'installments' => '12',
'frequency_interval' => '1',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $paymentProcessorID,
- ));
+ ]);
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array(
+ [
'contribution_recur_id' => $contributionRecur['id'],
- ))
+ ])
);
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
'total_amount' => '400',
'fee_amount' => 50,
- ));
+ ]);
- $lineItemParams = array(
+ $lineItemParams = [
'entity_id' => $originalContribution['id'],
'sequential' => 1,
- 'return' => array(
+ 'return' => [
'entity_table',
'qty',
'unit_price',
'deductible_amount',
'price_field_value_id',
'price_field_id',
- ),
- );
- $this->callAPISuccessGetSingle('contribution', array(
+ ],
+ ];
+ $this->callAPISuccessGetSingle('contribution', [
'total_amount' => 400,
'fee_amount' => 50,
'net_amount' => 350,
- ));
- $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ ]);
+ $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'],
- )));
+ ]));
$expectedLineItem = array_merge(
- $lineItem1['values'][0], array(
+ $lineItem1['values'][0], [
'line_total' => '400.00',
'unit_price' => '400.00',
- )
+ ]
);
- $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'] + 1,
- )));
+ ]));
unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
public function testRepeatTransactionPassedInFinancialType() {
$originalContribution = $this->setUpRecurringContribution();
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
'financial_type_id' => 2,
- ));
- $lineItemParams = array(
+ ]);
+ $lineItemParams = [
'entity_id' => $originalContribution['id'],
'sequential' => 1,
- 'return' => array(
+ 'return' => [
'entity_table',
'qty',
'unit_price',
'deductible_amount',
'price_field_value_id',
'price_field_id',
- ),
- );
+ ],
+ ];
- $this->callAPISuccessGetSingle('contribution', array(
+ $this->callAPISuccessGetSingle('contribution', [
'total_amount' => 100,
'financial_type_id' => 2,
- ));
- $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ ]);
+ $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'],
- )));
+ ]));
$expectedLineItem = array_merge(
- $lineItem1['values'][0], array(
+ $lineItem1['values'][0], [
'line_total' => '100.00',
'unit_price' => '100.00',
'financial_type_id' => 2,
'contribution_type_id' => 2,
- )
+ ]
);
- $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'] + 1,
- )));
+ ]));
unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
$this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
* CRM-17718 test appropriate action if financial type has changed for single line items.
*/
public function testRepeatTransactionUpdatedFinancialType() {
- $originalContribution = $this->setUpRecurringContribution(array(), array('financial_type_id' => 2));
+ $originalContribution = $this->setUpRecurringContribution([], ['financial_type_id' => 2]);
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_recur_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
- $lineItemParams = array(
+ ]);
+ $lineItemParams = [
'entity_id' => $originalContribution['id'],
'sequential' => 1,
- 'return' => array(
+ 'return' => [
'entity_table',
'qty',
'unit_price',
'deductible_amount',
'price_field_value_id',
'price_field_id',
- ),
- );
+ ],
+ ];
- $this->callAPISuccessGetSingle('contribution', array(
+ $this->callAPISuccessGetSingle('contribution', [
'total_amount' => 100,
'financial_type_id' => 2,
- ));
- $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ ]);
+ $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'],
- )));
+ ]));
$expectedLineItem = array_merge(
- $lineItem1['values'][0], array(
+ $lineItem1['values'][0], [
'line_total' => '100.00',
'unit_price' => '100.00',
'financial_type_id' => 2,
'contribution_type_id' => 2,
- )
+ ]
);
- $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'] + 1,
- )));
+ ]));
unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
$this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
$paymentProcessorID = $this->paymentProcessorCreate();
$campaignID = $this->campaignCreate();
$campaignID2 = $this->campaignCreate();
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [
'contact_id' => $this->_individualId,
'installments' => '12',
'frequency_interval' => '1',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $paymentProcessorID,
- ));
+ ]);
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array(
+ [
'contribution_recur_id' => $contributionRecur['id'],
'campaign_id' => $campaignID,
- ))
+ ])
);
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
'campaign_id' => $campaignID2,
- ));
+ ]);
- $this->callAPISuccessGetSingle('contribution', array(
+ $this->callAPISuccessGetSingle('contribution', [
'total_amount' => 100,
'campaign_id' => $campaignID2,
- ));
+ ]);
}
/**
$paymentProcessorID = $this->paymentProcessorCreate();
$campaignID = $this->campaignCreate();
$campaignID2 = $this->campaignCreate();
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [
'contact_id' => $this->_individualId,
'installments' => '12',
'frequency_interval' => '1',
'frequency_unit' => 'month',
'payment_processor_id' => $paymentProcessorID,
'campaign_id' => $campaignID,
- ));
+ ]);
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array(
+ [
'contribution_recur_id' => $contributionRecur['id'],
'campaign_id' => $campaignID2,
- ))
+ ])
);
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
+ ]);
- $this->callAPISuccessGetSingle('contribution', array(
+ $this->callAPISuccessGetSingle('contribution', [
'total_amount' => 100,
'campaign_id' => $campaignID,
- ));
+ ]);
}
/**
* This case happens when the line item & contribution do not have the same type in his initiating transaction.
*/
public function testRepeatTransactionUpdatedFinancialTypeAndNotEquals() {
- $originalContribution = $this->setUpRecurringContribution(array(), array('financial_type_id' => 2));
+ $originalContribution = $this->setUpRecurringContribution([], ['financial_type_id' => 2]);
// This will made the trick to get the not equals behaviour.
- $this->callAPISuccess('line_item', 'create', array('id' => 1, 'financial_type_id' => 4));
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('line_item', 'create', ['id' => 1, 'financial_type_id' => 4]);
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_recur_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
- $lineItemParams = array(
+ ]);
+ $lineItemParams = [
'entity_id' => $originalContribution['id'],
'sequential' => 1,
- 'return' => array(
+ 'return' => [
'entity_table',
'qty',
'unit_price',
'deductible_amount',
'price_field_value_id',
'price_field_id',
- ),
- );
- $this->callAPISuccessGetSingle('contribution', array(
+ ],
+ ];
+ $this->callAPISuccessGetSingle('contribution', [
'total_amount' => 100,
'financial_type_id' => 2,
- ));
- $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ ]);
+ $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'],
- )));
+ ]));
$expectedLineItem = array_merge(
- $lineItem1['values'][0], array(
+ $lineItem1['values'][0], [
'line_total' => '100.00',
'unit_price' => '100.00',
'financial_type_id' => 4,
'contribution_type_id' => 4,
- )
+ ]
);
- $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, [
'entity_id' => $originalContribution['id'] + 1,
- )));
- $this->callAPISuccess('line_item', 'create', array('id' => 1, 'financial_type_id' => 1));
+ ]));
+ $this->callAPISuccess('line_item', 'create', ['id' => 1, 'financial_type_id' => 1]);
unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
$this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
*/
public function testCompleteTransactionNetAmountOK() {
$this->createLoggedInUser();
- $params = array_merge($this->_params, array('contribution_status_id' => 2));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2]);
unset($params['net_amount']);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
- ));
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
+ ]);
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', ['id' => $contribution['id']]);
$this->assertEquals('Completed', $contribution['contribution_status']);
$this->assertTrue(($contribution['total_amount'] - $contribution['net_amount']) == $contribution['fee_amount']);
}
$this->swapMessageTemplateForTestTemplate();
$mut = new CiviMailUtils($this, TRUE);
$this->createLoggedInUser();
- $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2, 'receipt_date' => 'now']);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id'], 'trxn_date' => date('Y-m-d')));
- $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1));
+ $this->callAPISuccess('contribution', 'completetransaction', ['id' => $contribution['id'], 'trxn_date' => date('Y-m-d')]);
+ $contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id'], 'sequential' => 1]);
$this->assertEquals('Completed', $contribution['values'][0]['contribution_status']);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][0]['receive_date'])));
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Receipt - Contribution',
'receipt_date:::' . date('Ymd'),
- ));
+ ]);
$mut->stop();
$this->revertTemplateToReservedTemplate();
}
$contributionPage = $this->createReceiptableContributionPage();
$this->_params['contribution_page_id'] = $contributionPage['id'];
- $params = array_merge($this->_params, array('contribution_status_id' => 2));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2]);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
// Complete the transaction overriding is_email_receipt to = FALSE
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
'trxn_date' => date('2011-04-09'),
'trxn_id' => 'kazam',
'is_email_receipt' => 0,
- ));
+ ]);
// Check if a receipt was issued
- $receipt_date = $this->callAPISuccess('Contribution', 'getvalue', array('id' => $contribution['id'], 'return' => 'receipt_date'));
+ $receipt_date = $this->callAPISuccess('Contribution', 'getvalue', ['id' => $contribution['id'], 'return' => 'receipt_date']);
$this->assertEquals('', $receipt_date);
}
$this->swapMessageTemplateForTestTemplate();
$recurring = $this->setUpRecurringContribution();
- $contributionPage = $this->createReceiptableContributionPage(array('is_recur' => TRUE, 'recur_frequency_unit' => 'month', 'recur_interval' => 1));
+ $contributionPage = $this->createReceiptableContributionPage(['is_recur' => TRUE, 'recur_frequency_unit' => 'month', 'recur_interval' => 1]);
$this->_params['contribution_page_id'] = $contributionPage['id'];
$this->_params['contribution_recur_id'] = $recurring['id'];
$contribution = $this->setUpForCompleteTransaction();
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
'trxn_date' => date('2011-04-09'),
'trxn_id' => 'kazam',
'is_email_receipt' => 1,
- ));
+ ]);
- $this->mut->checkMailLog(array(
+ $this->mut->checkMailLog([
'is_recur:::1',
'cancelSubscriptionUrl:::' . CIVICRM_UF_BASEURL,
- ));
+ ]);
$this->mut->stop();
$this->revertTemplateToReservedTemplate();
}
$mut = new CiviMailUtils($this, TRUE);
$this->createLoggedInUser();
// Create a Contribution Page with is_email_receipt = FALSE
- $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array(
+ $contributionPage = $this->callAPISuccess('ContributionPage', 'create', [
'receipt_from_name' => 'Mickey Mouse',
'receipt_from_email' => 'mickey@mouse.com',
'title' => "Test Contribution Page",
'currency' => 'CAD',
'is_monetary' => TRUE,
'is_email_receipt' => 0,
- ));
+ ]);
$this->_params['contribution_page_id'] = $contributionPage['id'];
- $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2, 'receipt_date' => 'now']);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
// Complete the transaction overriding is_email_receipt to = TRUE
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
'is_email_receipt' => 1,
- ));
- $mut->checkMailLog(array(
+ ]);
+ $mut->checkMailLog([
'Please print this receipt for your records.',
- ));
+ ]);
$mut->stop();
}
public function testCompleteTransactionWithTestTemplate() {
$this->swapMessageTemplateForTestTemplate();
$contribution = $this->setUpForCompleteTransaction();
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contribution['id'],
'trxn_date' => date('2011-04-09'),
'trxn_id' => 'kazam',
- ));
- $receive_date = $this->callAPISuccess('Contribution', 'getvalue', array('id' => $contribution['id'], 'return' => 'receive_date'));
- $this->mut->checkMailLog(array(
+ ]);
+ $receive_date = $this->callAPISuccess('Contribution', 'getvalue', ['id' => $contribution['id'], 'return' => 'receive_date']);
+ $this->mut->checkMailLog([
'email:::anthony_anderson@civicrm.org',
'is_monetary:::1',
'amount:::100.00',
'contributionID:::' . $contribution['id'],
'financialTypeId:::1',
'financialTypeName:::Donation',
- ));
+ ]);
$this->mut->stop();
$this->revertTemplateToReservedTemplate();
}
* Complete the transaction using the template with all the possible.
*/
public function testCompleteTransactionContributionPageFromAddress() {
- $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array(
+ $contributionPage = $this->callAPISuccess('ContributionPage', 'create', [
'receipt_from_name' => 'Mickey Mouse',
'receipt_from_email' => 'mickey@mouse.com',
'title' => "Test Contribution Page",
'is_pay_later' => 1,
'is_monetary' => TRUE,
'is_email_receipt' => TRUE,
- ));
+ ]);
$this->_params['contribution_page_id'] = $contributionPage['id'];
$contribution = $this->setUpForCompleteTransaction();
- $this->callAPISuccess('contribution', 'completetransaction', array('id' => $contribution['id']));
- $this->mut->checkMailLog(array(
+ $this->callAPISuccess('contribution', 'completetransaction', ['id' => $contribution['id']]);
+ $this->mut->checkMailLog([
'mickey@mouse.com',
'Mickey Mouse <',
- ));
+ ]);
$this->mut->stop();
}
*/
public function testCompleteTransactionSetStatusToInProgress($dataSet) {
$paymentProcessorID = $this->paymentProcessorCreate();
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([
'contact_id' => $this->_individualId,
'installments' => '2',
'frequency_interval' => '1',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $paymentProcessorID,
- ), $dataSet['data']));
+ ], $dataSet['data']));
$contribution = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array(
+ [
'contribution_recur_id' => $contributionRecur['id'],
'contribution_status_id' => 'Pending',
'receive_date' => $dataSet['receive_date'],
- ))
+ ])
);
- $this->callAPISuccess('Contribution', 'completetransaction', array(
+ $this->callAPISuccess('Contribution', 'completetransaction', [
'id' => $contribution,
'receive_date' => $dataSet['receive_date'],
- ));
- $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array(
+ ]);
+ $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', [
'id' => $contributionRecur['id'],
- 'return' => array('next_sched_contribution_date', 'contribution_status_id'),
- ));
+ 'return' => ['next_sched_contribution_date', 'contribution_status_id'],
+ ]);
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
$this->assertEquals($dataSet['expected'], $contributionRecur['next_sched_contribution_date']);
$this->callAPISuccess('Contribution', 'create', array_merge(
$this->_params,
- array(
+ [
'contribution_recur_id' => $contributionRecur['id'],
'contribution_status_id' => 'Completed',
- )
+ ]
));
- $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array(
+ $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', [
'id' => $contributionRecur['id'],
- 'return' => array('contribution_status_id'),
- ));
+ 'return' => ['contribution_status_id'],
+ ]);
$this->assertEquals(1, $contributionRecur['contribution_status_id']);
}
* @return array
*/
public function getScheduledDateData() {
- $result = array();
- $result[]['2016-08-31-1-month'] = array(
- 'data' => array(
+ $result = [];
+ $result[]['2016-08-31-1-month'] = [
+ 'data' => [
'start_date' => '2016-08-31',
'frequency_interval' => 1,
'frequency_unit' => 'month',
- ),
+ ],
'receive_date' => '2016-08-31',
'expected' => '2016-10-01 00:00:00',
- );
- $result[]['2012-01-01-1-month'] = array(
- 'data' => array(
+ ];
+ $result[]['2012-01-01-1-month'] = [
+ 'data' => [
'start_date' => '2012-01-01',
'frequency_interval' => 1,
'frequency_unit' => 'month',
- ),
+ ],
'receive_date' => '2012-01-01',
'expected' => '2012-02-01 00:00:00',
- );
- $result[]['2012-01-01-1-month'] = array(
- 'data' => array(
+ ];
+ $result[]['2012-01-01-1-month'] = [
+ 'data' => [
'start_date' => '2012-01-01',
'frequency_interval' => 1,
'frequency_unit' => 'month',
- ),
+ ],
'receive_date' => '2012-02-29',
'expected' => '2012-03-29 00:00:00',
- );
- $result['receive_date_includes_time']['2012-01-01-1-month'] = array(
- 'data' => array(
+ ];
+ $result['receive_date_includes_time']['2012-01-01-1-month'] = [
+ 'data' => [
'start_date' => '2012-01-01',
'frequency_interval' => 1,
'frequency_unit' => 'month',
'next_sched_contribution_date' => '2012-02-29',
- ),
+ ],
'receive_date' => '2012-02-29 16:00:00',
'expected' => '2012-03-29 00:00:00',
- );
+ ];
return $result;
}
$mut->clearMessages();
$this->createLoggedInUser();
$contributionID = $this->createPendingPledgeContribution();
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contributionID,
'trxn_date' => '1 Feb 2013',
- ));
- $pledge = $this->callAPISuccessGetSingle('Pledge', array(
+ ]);
+ $pledge = $this->callAPISuccessGetSingle('Pledge', [
'id' => $this->_ids['pledge'],
- ));
+ ]);
$this->assertEquals('Completed', $pledge['pledge_status']);
- $status = $this->callAPISuccessGetValue('PledgePayment', array(
+ $status = $this->callAPISuccessGetValue('PledgePayment', [
'pledge_id' => $this->_ids['pledge'],
'return' => 'status_id',
- ));
+ ]);
$this->assertEquals(1, $status);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'amount:::500.00',
'receive_date:::20130201000000',
"receipt_date:::\n",
- ));
+ ]);
$mut->stop();
$this->revertTemplateToReservedTemplate();
}
$mut->clearMessages();
$this->_individualId = $this->createLoggedInUser();
$contributionID = $this->createPendingParticipantContribution();
- $this->callAPISuccess('contribution', 'completetransaction', array(
+ $this->callAPISuccess('contribution', 'completetransaction', [
'id' => $contributionID,
- )
+ ]
);
- $participantStatus = $this->callAPISuccessGetValue('participant', array(
+ $participantStatus = $this->callAPISuccessGetValue('participant', [
'id' => $this->_ids['participant'],
'return' => 'participant_status_id',
- ));
+ ]);
$this->assertEquals(1, $participantStatus);
//Assert only three activities are created.
// update the original 'Contribution' activity created after completing payment
$this->assertEquals(1, $activityNames['Contribution']);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Annual CiviCRM meet',
'Event',
'This letter is a confirmation that your registration has been received and your status has been updated to Registered.',
- ));
+ ]);
$mut->stop();
}
*/
public function testCompleteTransactionMembershipPriceSet() {
$this->createPriceSetWithPage('membership');
- $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', array(
+ $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', [
'name' => 'Grace',
'return' => 'id',
- ));
+ ]);
$this->setUpPendingContribution($this->_ids['price_field_value'][0]);
- $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
- $logs = $this->callAPISuccess('MembershipLog', 'get', array(
+ $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]);
+ $logs = $this->callAPISuccess('MembershipLog', 'get', [
'membership_id' => $this->_ids['membership'],
- ));
+ ]);
$this->assertEquals(1, $logs['count']);
$this->assertEquals($stateOfGrace, $membership['status_id']);
- $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids['contribution']));
- $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
+ $this->callAPISuccess('contribution', 'completetransaction', ['id' => $this->_ids['contribution']]);
+ $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]);
$this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 year')), $membership['end_date']);
- $this->callAPISuccessGetSingle('LineItem', array(
+ $this->callAPISuccessGetSingle('LineItem', [
'entity_id' => $this->_ids['membership'],
'entity_table' => 'civicrm_membership',
- ));
- $logs = $this->callAPISuccess('MembershipLog', 'get', array(
+ ]);
+ $logs = $this->callAPISuccess('MembershipLog', 'get', [
'membership_id' => $this->_ids['membership'],
- ));
+ ]);
$this->assertEquals(2, $logs['count']);
$this->assertNotEquals($stateOfGrace, $logs['values'][2]['status_id']);
//Assert only three activities are created.
public function testPendingToCompleteContribution() {
$this->createPriceSetWithPage('membership');
$this->setUpPendingContribution($this->_ids['price_field_value'][0]);
- $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
+ $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]);
// Case 1: Assert that Membership Signup Activity is created on Pending to Completed Contribution via backoffice
- $activity = $this->callAPISuccess('Activity', 'get', array(
+ $activity = $this->callAPISuccess('Activity', 'get', [
'activity_type_id' => 'Membership Signup',
'source_record_id' => $this->_ids['membership'],
'status_id' => 'Scheduled',
- ));
+ ]);
$this->assertEquals(1, $activity['count']);
// change pending contribution to completed
$form = new CRM_Contribute_Form_Contribution();
- $form->_params = array(
+ $form->_params = [
'id' => $this->_ids['contribution'],
'total_amount' => 20,
'net_amount' => 20,
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_mode' => 'membership',
'source' => 'Membership Signup and Renewal',
- );
+ ];
$form->testSubmit($form->_params, CRM_Core_Action::UPDATE);
// Case 2: After successful payment for Pending backoffice there are three activities created
// 2.a Update status of existing Scheduled Membership Signup (created in step 1) to Completed
- $activity = $this->callAPISuccess('Activity', 'get', array(
+ $activity = $this->callAPISuccess('Activity', 'get', [
'activity_type_id' => 'Membership Signup',
'source_record_id' => $this->_ids['membership'],
'status_id' => 'Completed',
- ));
+ ]);
$this->assertEquals(1, $activity['count']);
// 2.b Contribution activity created to record successful payment
- $activity = $this->callAPISuccess('Activity', 'get', array(
+ $activity = $this->callAPISuccess('Activity', 'get', [
'activity_type_id' => 'Contribution',
'source_record_id' => $this->_ids['contribution'],
'status_id' => 'Completed',
- ));
+ ]);
$this->assertEquals(1, $activity['count']);
// 2.c 'Change membership type' activity created to record Membership status change from Grace to Current
- $activity = $this->callAPISuccess('Activity', 'get', array(
+ $activity = $this->callAPISuccess('Activity', 'get', [
'activity_type_id' => 'Change Membership Status',
'source_record_id' => $this->_ids['membership'],
'status_id' => 'Completed',
- ));
+ ]);
$this->assertEquals(1, $activity['count']);
$this->assertEquals('Status changed from Grace to Current', $activity['values'][$activity['id']]['subject']);
//Create another pending contribution for renewal
- $contribution = $this->callAPISuccess('contribution', 'create', array(
+ $contribution = $this->callAPISuccess('contribution', 'create', [
'domain_id' => 1,
'contact_id' => $this->_ids['contact'],
'receive_date' => date('Ymd'),
'contribution_page_id' => $this->_ids['contribution_page'],
// We can't rely on contribution api to link line items correctly to membership
'skipLineItem' => TRUE,
- 'api.membership_payment.create' => array('membership_id' => $this->_ids['membership']),
- ));
+ 'api.membership_payment.create' => ['membership_id' => $this->_ids['membership']],
+ ]);
- $this->callAPISuccess('line_item', 'create', array(
+ $this->callAPISuccess('line_item', 'create', [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'contribution_id' => $contribution['id'],
'line_total' => 20,
'financial_type_id' => 1,
'price_field_value_id' => $this->_ids['price_field_value']['cont'],
- ));
- $this->callAPISuccess('line_item', 'create', array(
+ ]);
+ $this->callAPISuccess('line_item', 'create', [
'entity_id' => $this->_ids['membership'],
'entity_table' => 'civicrm_membership',
'contribution_id' => $contribution['id'],
'financial_type_id' => 1,
'price_field_value_id' => $this->_ids['price_field_value'][0],
'membership_type_id' => $this->_ids['membership_type'],
- ));
+ ]);
//Update it to Failed.
$form->_params['id'] = $contribution['id'];
$form->testSubmit($form->_params, CRM_Core_Action::UPDATE);
//Existing membership should not get updated to expired.
- $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
+ $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]);
$this->assertNotEquals($membership['status_id'], 4);
}
public function testCompleteTransactionMembershipPriceSetTwoTerms() {
$this->createPriceSetWithPage('membership');
$this->setUpPendingContribution($this->_ids['price_field_value'][1]);
- $this->callAPISuccess('contribution', 'completetransaction', array('id' => $this->_ids['contribution']));
- $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
+ $this->callAPISuccess('contribution', 'completetransaction', ['id' => $this->_ids['contribution']]);
+ $membership = $this->callAPISuccess('membership', 'getsingle', ['id' => $this->_ids['membership']]);
$this->assertEquals(date('Y-m-d', strtotime('yesterday + 2 years')), $membership['end_date']);
$this->cleanUpAfterPriceSets();
}
* @param int $priceFieldValueID
* @param array $contriParams
*/
- public function setUpPendingContribution($priceFieldValueID, $contriParams = array()) {
+ public function setUpPendingContribution($priceFieldValueID, $contriParams = []) {
$contactID = $this->individualCreate();
- $membership = $this->callAPISuccess('membership', 'create', array(
+ $membership = $this->callAPISuccess('membership', 'create', [
'contact_id' => $contactID,
'membership_type_id' => $this->_ids['membership_type'],
'start_date' => 'yesterday - 1 year',
'end_date' => 'yesterday',
'join_date' => 'yesterday - 1 year',
- ));
- $contribution = $this->callAPISuccess('contribution', 'create', array_merge(array(
+ ]);
+ $contribution = $this->callAPISuccess('contribution', 'create', array_merge([
'domain_id' => 1,
'contact_id' => $contactID,
'receive_date' => date('Ymd'),
'source' => 'SSF',
'contribution_status_id' => 2,
'contribution_page_id' => $this->_ids['contribution_page'],
- 'api.membership_payment.create' => array('membership_id' => $membership['id']),
- ), $contriParams));
+ 'api.membership_payment.create' => ['membership_id' => $membership['id']],
+ ], $contriParams));
- $this->callAPISuccess('line_item', 'create', array(
+ $this->callAPISuccess('line_item', 'create', [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'contribution_id' => $contribution['id'],
'line_total' => 20,
'financial_type_id' => 1,
'price_field_value_id' => $priceFieldValueID,
- ));
+ ]);
$this->_ids['contact'] = $contactID;
$this->_ids['contribution'] = $contribution['id'];
$this->_ids['membership'] = $membership['id'];
public function testSendMail() {
$mut = new CiviMailUtils($this, TRUE);
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
- $this->callAPISuccess('contribution', 'sendconfirmation', array(
+ $this->callAPISuccess('contribution', 'sendconfirmation', [
'id' => $contribution['id'],
'receipt_from_email' => 'api@civicrm.org',
- ));
- $mut->checkMailLog(array(
+ ]);
+ $mut->checkMailLog([
'$ 100.00',
'Contribution Information',
'Please print this confirmation for your records',
- ), array(
+ ], [
'Event',
- ));
+ ]);
$this->checkCreditCardDetails($mut, $contribution['id']);
$mut->stop();
$mut = new CiviMailUtils($this, TRUE);
// Create contribution page
- $pageParams = array(
+ $pageParams = [
'title' => 'Webform Contributions',
'financial_type_id' => 1,
'contribution_type_id' => 1,
'is_pay_later' => 1,
'pay_later_text' => 'I will send payment by cheque',
'pay_later_receipt' => 'Send your cheque payable to "CiviCRM LLC" to the office',
- );
+ ];
$contributionPage = $this->callAPISuccess('contribution_page', 'create', $pageParams);
// Create pay later contribution
- $contribParams = array(
+ $contribParams = [
'contact_id' => $this->_individualId,
'financial_type_id' => 1,
'is_pay_later' => 1,
'contribution_status_id' => 2,
'contribution_page_id' => $contributionPage['id'],
'total_amount' => '10.00',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
// Create line item
- $lineItemParams = array(
+ $lineItemParams = [
'contribution_id' => $contribution['id'],
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'qty' => 1,
'unit_price' => "10.00",
'line_total' => "10.00",
- );
+ ];
$lineItem = $this->callAPISuccess('lineItem', 'create', $lineItemParams);
// Create email
try {
- civicrm_api3('contribution', 'sendconfirmation', array(
+ civicrm_api3('contribution', 'sendconfirmation', [
'id' => $contribution['id'],
'receipt_from_email' => 'api@civicrm.org',
- ));
+ ]);
}
catch (Exception $e) {
// Need to figure out how to stop this some other day
// Retrieve mail & check it has the pay_later_receipt info
$mut->getMostRecentEmail('raw');
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
(string) $contribParams['total_amount'],
$pageParams['pay_later_receipt'],
- ), array(
+ ], [
'Event',
- ));
+ ]);
$mut->stop();
}
*/
public function checkCreditCardDetails($mut, $contributionID) {
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
- $this->callAPISuccess('contribution', 'sendconfirmation', array(
+ $this->callAPISuccess('contribution', 'sendconfirmation', [
'id' => $contributionID,
'receipt_from_email' => 'api@civicrm.org',
'payment_processor_id' => $this->paymentProcessorID,
- ));
- $mut->checkMailLog(array(
+ ]);
+ $mut->checkMailLog([
// credit card header
'Credit Card Information',
// billing header
'Billing Name and Address',
// billing name
'anthony_anderson@civicrm.org',
- ), array(
+ ], [
'Event',
- ));
+ ]);
}
/**
public function testSendMailEvent() {
$mut = new CiviMailUtils($this, TRUE);
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
- $event = $this->eventCreate(array(
+ $event = $this->eventCreate([
'is_email_confirm' => 1,
'confirm_from_email' => 'test@civicrm.org',
- ));
+ ]);
$this->_eventID = $event['id'];
- $participantParams = array(
+ $participantParams = [
'contact_id' => $this->_individualId,
'event_id' => $this->_eventID,
'status_id' => 1,
'register_date' => '2007-07-21 00:00:00',
'source' => 'Online Event Registration: API Testing',
- );
+ ];
$participant = $this->callAPISuccess('participant', 'create', $participantParams);
- $this->callAPISuccess('participant_payment', 'create', array(
+ $this->callAPISuccess('participant_payment', 'create', [
'participant_id' => $participant['id'],
'contribution_id' => $contribution['id'],
- ));
- $this->callAPISuccess('contribution', 'sendconfirmation', array(
+ ]);
+ $this->callAPISuccess('contribution', 'sendconfirmation', [
'id' => $contribution['id'],
'receipt_from_email' => 'api@civicrm.org',
- ));
+ ]);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'Annual CiviCRM meet',
'Event',
'To: "Mr. Anthony Anderson II" <anthony_anderson@civicrm.org>',
- ), array());
+ ], []);
$mut->stop();
}
*/
public function contributionGetnCheck($params, $id, $delete = TRUE) {
- $contribution = $this->callAPISuccess('Contribution', 'Get', array(
+ $contribution = $this->callAPISuccess('Contribution', 'Get', [
'id' => $id,
- ));
+ ]);
if ($delete) {
- $this->callAPISuccess('contribution', 'delete', array('id' => $id));
+ $this->callAPISuccess('contribution', 'delete', ['id' => $id]);
}
$this->assertAPISuccess($contribution, 0);
$values = $contribution['values'][$contribution['id']];
*/
public function createPendingPledgeContribution() {
- $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId, 'installments' => 1, 'amount' => 500));
+ $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId, 'installments' => 1, 'amount' => 500]);
$this->_ids['pledge'] = $pledgeID;
- $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array(
+ $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, [
'contribution_status_id' => 'Pending',
'total_amount' => 500,
- )));
- $paymentID = $this->callAPISuccessGetValue('PledgePayment', array(
- 'options' => array('limit' => 1),
+ ]));
+ $paymentID = $this->callAPISuccessGetValue('PledgePayment', [
+ 'options' => ['limit' => 1],
'return' => 'id',
- ));
- $this->callAPISuccess('PledgePayment', 'create', array(
+ ]);
+ $this->callAPISuccess('PledgePayment', 'create', [
'id' => $paymentID,
'contribution_id' =>
$contribution['id'],
'status_id' => 'Pending',
'scheduled_amount' => 500,
- ));
+ ]);
return $contribution['id'];
}
* Create a pending contribution & linked pending participant record (along with an event).
*/
public function createPendingParticipantContribution() {
- $event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org'));
- $participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6, 'contact_id' => $this->_individualId));
+ $event = $this->eventCreate(['is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org']);
+ $participantID = $this->participantCreate(['event_id' => $event['id'], 'status_id' => 6, 'contact_id' => $this->_individualId]);
$this->_ids['participant'] = $participantID;
- $params = array_merge($this->_params, array('contact_id' => $this->_individualId, 'contribution_status_id' => 2, 'financial_type_id' => 'Event Fee'));
+ $params = array_merge($this->_params, ['contact_id' => $this->_individualId, 'contribution_status_id' => 2, 'financial_type_id' => 'Event Fee']);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $this->callAPISuccess('participant_payment', 'create', array(
+ $this->callAPISuccess('participant_payment', 'create', [
'contribution_id' => $contribution['id'],
'participant_id' => $participantID,
- ));
- $this->callAPISuccess('line_item', 'get', array(
+ ]);
+ $this->callAPISuccess('line_item', 'get', [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
- 'api.line_item.create' => array(
+ 'api.line_item.create' => [
'entity_id' => $participantID,
'entity_table' => 'civicrm_participant',
- ),
- ));
+ ],
+ ]);
return $contribution['id'];
}
*/
public function _checkFinancialItem($contId, $context) {
if ($context != 'paylater') {
- $params = array(
+ $params = [
'entity_id' => $contId,
'entity_table' => 'civicrm_contribution',
- );
+ ];
$trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($params, TRUE));
- $entityParams = array(
+ $entityParams = [
'financial_trxn_id' => $trxn['financial_trxn_id'],
'entity_table' => 'civicrm_financial_item',
- );
+ ];
$entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
- $params = array(
+ $params = [
'id' => $entityTrxn['entity_id'],
- );
+ ];
}
if ($context == 'paylater') {
$lineItems = CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution');
foreach ($lineItems as $key => $item) {
- $params = array(
+ $params = [
'entity_id' => $key,
'entity_table' => 'civicrm_line_item',
- );
- $compareParams = array('status_id' => 1);
+ ];
+ $compareParams = ['status_id' => 1];
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
}
}
elseif ($context == 'refund') {
- $compareParams = array(
+ $compareParams = [
'status_id' => 1,
'financial_account_id' => 1,
'amount' => -100,
- );
+ ];
}
elseif ($context == 'cancelPending') {
- $compareParams = array(
+ $compareParams = [
'status_id' => 3,
'financial_account_id' => 1,
'amount' => -100,
- );
+ ];
}
elseif ($context == 'changeFinancial') {
$lineKey = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'));
- $params = array(
+ $params = [
'entity_id' => $lineKey,
'amount' => -100,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'financial_account_id' => 1,
- );
+ ];
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
- $params = array(
+ $params = [
'financial_account_id' => 3,
'entity_id' => $lineKey,
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'amount' => 100,
- );
+ ];
}
if ($context != 'paylater') {
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $params, $compareParams);
$entityFinancialTrxns = $this->getFinancialTransactionsForContribution($contributionID);
- $originalTrxnParams = array(
+ $originalTrxnParams = [
'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($originalInstrumentID),
'payment_instrument_id' => $originalInstrumentID,
'amount' => $amount,
'status_id' => 1,
- );
+ ];
- $reversalTrxnParams = array(
+ $reversalTrxnParams = [
'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($originalInstrumentID),
'payment_instrument_id' => $originalInstrumentID,
'amount' => -$amount,
'status_id' => 1,
- );
+ ];
- $newTrxnParams = array(
+ $newTrxnParams = [
'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($newInstrumentID),
'payment_instrument_id' => $newInstrumentID,
'amount' => $amount,
'status_id' => 1,
- );
+ ];
- foreach (array($originalTrxnParams, $reversalTrxnParams, $newTrxnParams) as $index => $transaction) {
+ foreach ([$originalTrxnParams, $reversalTrxnParams, $newTrxnParams] as $index => $transaction) {
$entityFinancialTrxn = $entityFinancialTrxns[$index];
$this->assertEquals($entityFinancialTrxn['amount'], $transaction['amount']);
- $financialTrxn = $this->callAPISuccessGetSingle('FinancialTrxn', array(
+ $financialTrxn = $this->callAPISuccessGetSingle('FinancialTrxn', [
'id' => $entityFinancialTrxn['financial_trxn_id'],
- ));
+ ]);
$this->assertEquals($transaction['status_id'], $financialTrxn['status_id']);
$this->assertEquals($transaction['amount'], $financialTrxn['total_amount']);
$this->assertEquals($transaction['amount'], $financialTrxn['net_amount']);
* @param int $instrumentId
* @param array $extraParams
*/
- public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = array()) {
+ public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = []) {
$financialTrxns = $this->getFinancialTransactionsForContribution($contribution['id']);
$trxn = array_pop($financialTrxns);
- $params = array(
+ $params = [
'id' => $trxn['financial_trxn_id'],
- );
+ ];
if ($context == 'payLater') {
- $compareParams = array(
+ $compareParams = [
'status_id' => 1,
'from_financial_account_id' => CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($contribution['financial_type_id'], 'Accounts Receivable Account is'),
- );
+ ];
}
elseif ($context == 'refund') {
- $compareParams = array(
+ $compareParams = [
'to_financial_account_id' => 6,
'total_amount' => -100,
'status_id' => 7,
'trxn_date' => '2015-01-01 09:00:00',
'trxn_id' => 'the refund',
- );
+ ];
}
elseif ($context == 'cancelPending') {
- $compareParams = array(
+ $compareParams = [
'to_financial_account_id' => 7,
'total_amount' => -100,
'status_id' => 3,
- );
+ ];
}
elseif ($context == 'changeFinancial' || $context == 'paymentInstrument') {
// @todo checkFinancialTrxnPaymentInstrumentChange instead for paymentInstrument.
// It does the same thing with greater readability.
// @todo remove handling for
- $entityParams = array(
+ $entityParams = [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'amount' => -100,
- );
+ ];
$trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
- $trxnParams1 = array(
+ $trxnParams1 = [
'id' => $trxn['financial_trxn_id'],
- );
+ ];
if (empty($extraParams)) {
- $compareParams = array(
+ $compareParams = [
'total_amount' => -100,
'status_id' => 1,
- );
+ ];
}
else {
- $compareParams = array(
+ $compareParams = [
'total_amount' => 100,
'status_id' => 1,
- );
+ ];
}
if ($context == 'paymentInstrument') {
$compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($instrumentId);
*/
public function _addPaymentInstrument() {
$gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'payment_instrument', 'id', 'name');
- $optionParams = array(
+ $optionParams = [
'option_group_id' => $gId,
'label' => 'Test Card',
'name' => 'Test Card',
'value' => '6',
'weight' => '6',
'is_active' => 1,
- );
+ ];
$optionValue = $this->callAPISuccess('option_value', 'create', $optionParams);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
- $financialParams = array(
+ $financialParams = [
'entity_table' => 'civicrm_option_value',
'entity_id' => $optionValue['id'],
'account_relationship' => $relationTypeId,
'financial_account_id' => 7,
- );
+ ];
CRM_Financial_BAO_FinancialTypeAccount::add($financialParams);
$this->assertNotEmpty($optionValue['values'][$optionValue['id']]['value']);
return $optionValue['values'][$optionValue['id']]['value'];
}
public function _deletedAddedPaymentInstrument() {
- $result = $this->callAPISuccess('OptionValue', 'get', array(
+ $result = $this->callAPISuccess('OptionValue', 'get', [
'option_group_id' => 'payment_instrument',
'name' => 'Test Card',
'value' => '6',
'is_active' => 1,
- ));
+ ]);
if ($id = CRM_Utils_Array::value('id', $result)) {
- $this->callAPISuccess('OptionValue', 'delete', array('id' => $id));
+ $this->callAPISuccess('OptionValue', 'delete', ['id' => $id]);
}
}
*
* @return array|int
*/
- protected function setUpRecurringContribution($generalParams = array(), $recurParams = array()) {
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
+ protected function setUpRecurringContribution($generalParams = [], $recurParams = []) {
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([
'contact_id' => $this->_individualId,
'installments' => '12',
'frequency_interval' => '1',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $this->paymentProcessorID,
- ), $generalParams, $recurParams));
+ ], $generalParams, $recurParams));
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array(
+ [
'contribution_recur_id' => $contributionRecur['id'],
- ), $generalParams)
+ ], $generalParams)
);
return $originalContribution;
}
*
* @return array|int
*/
- protected function setUpAutoRenewMembership($generalParams = array(), $recurParams = array()) {
- $newContact = $this->callAPISuccess('Contact', 'create', array(
+ protected function setUpAutoRenewMembership($generalParams = [], $recurParams = []) {
+ $newContact = $this->callAPISuccess('Contact', 'create', [
'contact_type' => 'Individual',
'sort_name' => 'McTesterson, Testy',
'display_name' => 'Testy McTesterson',
'email_id' => '4',
'email' => 'tmctesterson@example.com',
'on_hold' => '0',
- ));
- $membershipType = $this->callAPISuccess('MembershipType', 'create', array(
+ ]);
+ $membershipType = $this->callAPISuccess('MembershipType', 'create', [
'domain_id' => "Default Domain Name",
'member_of_contact_id' => 1,
'financial_type_id' => "Member Dues",
'period_type' => 'rolling',
'name' => "Standard Member",
'minimum_fee' => 100,
- ));
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
+ ]);
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([
'contact_id' => $newContact['id'],
'installments' => '12',
'frequency_interval' => '1',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $this->paymentProcessorID,
- ), $generalParams, $recurParams));
+ ], $generalParams, $recurParams));
- $membership = $this->callAPISuccess('membership', 'create', array(
+ $membership = $this->callAPISuccess('membership', 'create', [
'contact_id' => $newContact['id'],
'contribution_recur_id' => $contributionRecur['id'],
'financial_type_id' => "Member Dues",
'membership_type_id' => $membershipType['id'],
'num_terms' => 1,
'skipLineItem' => TRUE,
- ));
+ ]);
CRM_Price_BAO_LineItem::getLineItemArray($this->_params, NULL, 'membership', $membershipType['id']);
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array(
+ [
'contact_id' => $newContact['id'],
'contribution_recur_id' => $contributionRecur['id'],
'financial_type_id' => "Member Dues",
'contribution_status_id' => 1,
'invoice_id' => uniqid(),
- ), $generalParams)
+ ], $generalParams)
);
- $lineItem = $this->callAPISuccess('LineItem', 'getsingle', array());
+ $lineItem = $this->callAPISuccess('LineItem', 'getsingle', []);
$this->assertEquals('civicrm_membership', $lineItem['entity_table']);
- $membership = $this->callAPISuccess('Membership', 'getsingle', array('id' => $lineItem['entity_id']));
- $this->callAPISuccess('LineItem', 'getsingle', array());
- $this->callAPISuccessGetCount('MembershipPayment', array('membership_id' => $membership['id']), 1);
+ $membership = $this->callAPISuccess('Membership', 'getsingle', ['id' => $lineItem['entity_id']]);
+ $this->callAPISuccess('LineItem', 'getsingle', []);
+ $this->callAPISuccessGetCount('MembershipPayment', ['membership_id' => $membership['id']], 1);
- return array($originalContribution, $membership);
+ return [$originalContribution, $membership];
}
/**
* @param array $contributionParams
* @return array
*/
- protected function setUpRepeatTransaction($recurParams = array(), $flag, $contributionParams = array()) {
+ protected function setUpRepeatTransaction($recurParams = [], $flag, $contributionParams = []) {
$paymentProcessorID = $this->paymentProcessorCreate();
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge([
'contact_id' => $this->_individualId,
'installments' => '12',
'frequency_interval' => '1',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $paymentProcessorID,
- ), $recurParams));
+ ], $recurParams));
$originalContribution = '';
if ($flag == 'multiple') {
$params = array_merge($this->_params, $contributionParams);
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$params,
- array(
+ [
'contribution_recur_id' => $contributionRecur['id'],
'skipLineItem' => 1,
- 'api.line_item.create' => array(
- array(
+ 'api.line_item.create' => [
+ [
'price_field_id' => 1,
'qty' => 2,
'line_total' => '20',
'unit_price' => '10',
'financial_type_id' => 1,
- ),
- array(
+ ],
+ [
'price_field_id' => 1,
'qty' => 1,
'line_total' => '80',
'unit_price' => '80',
'financial_type_id' => 2,
- ),
- ),
- )
+ ],
+ ],
+ ]
)
);
}
elseif ($flag == 'single') {
- $params = array_merge($this->_params, array('contribution_recur_id' => $contributionRecur['id']));
+ $params = array_merge($this->_params, ['contribution_recur_id' => $contributionRecur['id']]);
$params = array_merge($params, $contributionParams);
$originalContribution = $this->callAPISuccess('contribution', 'create', $params);
}
protected function setUpForCompleteTransaction() {
$this->mut = new CiviMailUtils($this, TRUE);
$this->createLoggedInUser();
- $params = array_merge($this->_params, array('contribution_status_id' => 2, 'receipt_date' => 'now'));
+ $params = array_merge($this->_params, ['contribution_status_id' => 2, 'receipt_date' => 'now']);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
return $contribution;
}
* Test repeat contribution uses the Payment Processor' payment_instrument setting.
*/
public function testRepeatTransactionWithNonCreditCardDefault() {
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [
'contact_id' => $this->_individualId,
'installments' => '12',
'frequency_interval' => '1',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $this->paymentProcessorID,
- ));
+ ]);
$contribution1 = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array('contribution_recur_id' => $contributionRecur['id'], 'payment_instrument_id' => 2))
+ ['contribution_recur_id' => $contributionRecur['id'], 'payment_instrument_id' => 2])
);
$paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name');
- $contribution2 = $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $contribution2 = $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
'original_contribution_id' => $contribution1,
- ));
+ ]);
$this->assertEquals(array_search('Debit Card', $paymentInstruments), $contribution2['values'][$contribution2['id']]['payment_instrument_id']);
$this->quickCleanUpFinancialEntities();
}
*/
public function testRepeatTransactionMembershipCreatePendingContribution() {
list($originalContribution, $membership) = $this->setUpAutoRenewMembership();
- $this->callAPISuccess('membership', 'create', array(
+ $this->callAPISuccess('membership', 'create', [
'id' => $membership['id'],
'end_date' => 'yesterday',
'status_id' => 'Expired',
- ));
- $repeatedContribution = $this->callAPISuccess('contribution', 'repeattransaction', array(
+ ]);
+ $repeatedContribution = $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'],
'contribution_status_id' => 'Pending',
'trxn_id' => uniqid(),
- ));
- $membershipStatusId = $this->callAPISuccess('membership', 'getvalue', array(
+ ]);
+ $membershipStatusId = $this->callAPISuccess('membership', 'getvalue', [
'id' => $membership['id'],
'return' => 'status_id',
- ));
+ ]);
// Let's see if the membership payments got created while we're at it.
- $membershipPayments = $this->callAPISuccess('MembershipPayment', 'get', array(
+ $membershipPayments = $this->callAPISuccess('MembershipPayment', 'get', [
'membership_id' => $membership['id'],
- ));
+ ]);
$this->assertEquals(2, $membershipPayments['count']);
$this->assertEquals('Expired', CRM_Core_PseudoConstant::getLabel('CRM_Member_BAO_Membership', 'status_id', $membershipStatusId));
- $this->callAPISuccess('Contribution', 'completetransaction', array('id' => $repeatedContribution['id']));
- $membership = $this->callAPISuccessGetSingle('membership', array(
+ $this->callAPISuccess('Contribution', 'completetransaction', ['id' => $repeatedContribution['id']]);
+ $membership = $this->callAPISuccessGetSingle('membership', [
'id' => $membership['id'],
'return' => 'status_id, end_date',
- ));
+ ]);
$this->assertEquals('New', CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membership['status_id']));
$this->assertEquals(date('Y-m-d', strtotime('yesterday + 1 month')), $membership['end_date']);
public function testSendMailWithAPISetFromDetails() {
$mut = new CiviMailUtils($this, TRUE);
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
- $this->callAPISuccess('contribution', 'sendconfirmation', array(
+ $this->callAPISuccess('contribution', 'sendconfirmation', [
'id' => $contribution['id'],
'receipt_from_email' => 'api@civicrm.org',
'receipt_from_name' => 'CiviCRM LLC',
- ));
- $mut->checkMailLog(array(
+ ]);
+ $mut->checkMailLog([
'From: CiviCRM LLC <api@civicrm.org>',
'Contribution Information',
'Please print this confirmation for your records',
- ), array(
+ ], [
'Event',
- ));
+ ]);
$mut->stop();
}
$this->createLoggedInUser();
$mut = new CiviMailUtils($this, TRUE);
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
- $this->callAPISuccess('contribution', 'sendconfirmation', array(
+ $this->callAPISuccess('contribution', 'sendconfirmation', [
'id' => $contribution['id'],
- ));
- $domain = $this->callAPISuccess('domain', 'getsingle', array('id' => 1));
- $mut->checkMailLog(array(
+ ]);
+ $domain = $this->callAPISuccess('domain', 'getsingle', ['id' => 1]);
+ $mut->checkMailLog([
'From: ' . $domain['from_name'] . ' <' . $domain['from_email'] . '>',
'Contribution Information',
'Please print this confirmation for your records',
- ), array(
+ ], [
'Event',
- ));
+ ]);
$mut->stop();
}
public function testSendMailWithRepeatTransactionAPIFalltoDomain() {
$this->createLoggedInUser();
$mut = new CiviMailUtils($this, TRUE);
- $contribution = $this->setUpRepeatTransaction(array(), 'single');
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $contribution = $this->setUpRepeatTransaction([], 'single');
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
'original_contribution_id' => $contribution,
- ));
- $domain = $this->callAPISuccess('domain', 'getsingle', array('id' => 1));
- $mut->checkMailLog(array(
+ ]);
+ $domain = $this->callAPISuccess('domain', 'getsingle', ['id' => 1]);
+ $mut->checkMailLog([
'From: ' . $domain['from_name'] . ' <' . $domain['from_email'] . '>',
'Contribution Information',
'Please print this confirmation for your records',
- ), array(
+ ], [
'Event',
- )
+ ]
);
$mut->stop();
}
*/
public function testSendMailWithRepeatTransactionAPIFalltoContributionPage() {
$mut = new CiviMailUtils($this, TRUE);
- $contributionPage = $this->contributionPageCreate(array('receipt_from_name' => 'CiviCRM LLC', 'receipt_from_email' => 'contributionpage@civicrm.org', 'is_email_receipt' => 1));
+ $contributionPage = $this->contributionPageCreate(['receipt_from_name' => 'CiviCRM LLC', 'receipt_from_email' => 'contributionpage@civicrm.org', 'is_email_receipt' => 1]);
$paymentProcessorID = $this->paymentProcessorCreate();
- $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
+ $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [
'contact_id' => $this->_individualId,
'installments' => '12',
'frequency_interval' => '1',
'currency' => 'USD',
'frequency_unit' => 'month',
'payment_processor_id' => $paymentProcessorID,
- ));
+ ]);
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
- array(
+ [
'contribution_recur_id' => $contributionRecur['id'],
'contribution_page_id' => $contributionPage['id'],
- ))
+ ])
);
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
'original_contribution_id' => $originalContribution,
- )
+ ]
);
- $mut->checkMailLog(array(
+ $mut->checkMailLog([
'From: CiviCRM LLC <contributionpage@civicrm.org>',
'Contribution Information',
'Please print this confirmation for your records',
- ), array(
+ ], [
'Event',
- ));
+ ]);
$mut->stop();
}
*/
public function testSendMailWithRepeatTransactionAPIFalltoSystemFromNoDefaultFrom() {
$mut = new CiviMailUtils($this, TRUE);
- $originalContribution = $contribution = $this->setUpRepeatTransaction(array(), 'single');
- $fromEmail = $this->CallAPISuccess('optionValue', 'get', array('is_default' => 1, 'option_group_id' => 'from_email_address', 'sequential' => 1));
+ $originalContribution = $contribution = $this->setUpRepeatTransaction([], 'single');
+ $fromEmail = $this->CallAPISuccess('optionValue', 'get', ['is_default' => 1, 'option_group_id' => 'from_email_address', 'sequential' => 1]);
foreach ($fromEmail['values'] as $from) {
- $this->callAPISuccess('optionValue', 'create', array('is_default' => 0, 'id' => $from['id']));
+ $this->callAPISuccess('optionValue', 'create', ['is_default' => 0, 'id' => $from['id']]);
}
- $domain = $this->callAPISuccess('domain', 'getsingle', array('id' => CRM_Core_Config::domainID()));
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $domain = $this->callAPISuccess('domain', 'getsingle', ['id' => CRM_Core_Config::domainID()]);
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
'original_contribution_id' => $originalContribution,
- ));
- $mut->checkMailLog(array(
+ ]);
+ $mut->checkMailLog([
'From: ' . $domain['name'] . ' <' . $domain['domain_email'] . '>',
'Contribution Information',
'Please print this confirmation for your records',
- ), array(
+ ], [
'Event',
- ));
+ ]);
$mut->stop();
}
*
* @return array|int
*/
- protected function createReceiptableContributionPage($params = array()) {
- $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array_merge(array(
+ protected function createReceiptableContributionPage($params = []) {
+ $contributionPage = $this->callAPISuccess('ContributionPage', 'create', array_merge([
'receipt_from_name' => 'Mickey Mouse',
'receipt_from_email' => 'mickey@mouse.com',
'title' => "Test Contribution Page",
'currency' => 'CAD',
'is_monetary' => TRUE,
'is_email_receipt' => TRUE,
- ), $params));
+ ], $params));
return $contributionPage;
}
public function testCardTypeAndPanTruncation() {
$creditCardTypeIDs = array_flip(CRM_Financial_DAO_FinancialTrxn::buildOptions('card_type_id'));
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'receive_date' => '2016-01-20',
'total_amount' => 100,
'payment_instrument' => 'Credit Card',
'card_type_id' => $creditCardTypeIDs['Visa'],
'pan_truncation' => 4567,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('card_type_id', 'pan_truncation'),
- )
+ 'return' => ['card_type_id', 'pan_truncation'],
+ ]
);
$this->assertEquals(CRM_Utils_Array::value('card_type_id', $financialTrxn), $creditCardTypeIDs['Visa']);
$this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 4567);
- $params = array(
+ $params = [
'id' => $contribution['id'],
'pan_truncation' => 2345,
'card_type_id' => $creditCardTypeIDs['Amex'],
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
- array(
+ [
'id' => $lastFinancialTrxnId['financialTrxnId'],
- 'return' => array('card_type_id', 'pan_truncation'),
- )
+ 'return' => ['card_type_id', 'pan_truncation'],
+ ]
);
$this->assertEquals(CRM_Utils_Array::value('card_type_id', $financialTrxn), $creditCardTypeIDs['Amex']);
$this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 2345);
* @see https://issues.civicrm.org/jira/projects/CRM/issues/CRM-20678
*/
public function testRepeatTransactionWithDifferenceCurrency() {
- $originalContribution = $this->setUpRepeatTransaction(array('currency' => 'AUD'), 'single', array('currency' => 'AUD'));
- $contribution = $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $originalContribution = $this->setUpRepeatTransaction(['currency' => 'AUD'], 'single', ['currency' => 'AUD']);
+ $contribution = $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
+ ]);
$this->assertEquals('AUD', $contribution['values'][$contribution['id']]['currency']);
}
* Array of associated financial items.
*/
protected function getFinancialTransactionsForContribution($contributionID) {
- $trxnParams = array(
+ $trxnParams = [
'entity_id' => $contributionID,
'entity_table' => 'civicrm_contribution',
- );
+ ];
// @todo the following function has naming errors & has a weird signature & appears to
// only be called from test classes. Move into test suite & maybe just use api
// from this function.
- return array_merge(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, FALSE, array()));
+ return array_merge(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, FALSE, []));
}
/**
* Test getunique api call for Contribution entity
*/
public function testContributionGetUnique() {
- $result = $this->callAPIAndDocument($this->_entity, 'getunique', array(), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument($this->_entity, 'getunique', [], __FUNCTION__, __FILE__);
$this->assertEquals(2, $result['count']);
- $this->assertEquals(array('trxn_id'), $result['values']['UI_contrib_trxn_id']);
- $this->assertEquals(array('invoice_id'), $result['values']['UI_contrib_invoice_id']);
+ $this->assertEquals(['trxn_id'], $result['values']['UI_contrib_trxn_id']);
+ $this->assertEquals(['invoice_id'], $result['values']['UI_contrib_invoice_id']);
}
/**
'financial_type_id' => $financialType['id'],
]
);
- $this->callAPISuccess('contribution', 'repeattransaction', array(
+ $this->callAPISuccess('contribution', 'repeattransaction', [
'original_contribution_id' => $contribution['id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
- ));
+ ]);
$this->callAPISuccessGetCount('Contribution', [], 2);
}
$this->_apiversion = 3;
parent::setUp();
$this->useTransaction(TRUE);
- $this->_params = array(
+ $this->_params = [
'name' => 'Made Up Land',
'iso_code' => 'ZZ',
'region_id' => 1,
- );
+ ];
}
public function testCreateCountry() {
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->callAPISuccess('country', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('country', 'delete', ['id' => $result['id']]);
}
public function testDeleteCountry() {
//create one
$create = $this->callAPISuccess('country', 'create', $this->_params);
- $result = $this->callAPIAndDocument('country', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('country', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
- $get = $this->callAPISuccess('country', 'get', array(
+ $get = $this->callAPISuccess('country', 'get', [
'id' => $create['id'],
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'Country not successfully deleted');
}
* Test civicrm_phone_get with empty params.
*/
public function testGetEmptyParams() {
- $result = $this->callAPISuccess('Country', 'Get', array());
+ $result = $this->callAPISuccess('Country', 'Get', []);
}
/**
* Test civicrm_phone_get with wrong params.
*/
public function testGetWrongParams() {
- $this->callAPIFailure('Country', 'Get', array('id' => 'abc'));
+ $this->callAPIFailure('Country', 'Get', ['id' => 'abc']);
}
/**
*/
public function testGet() {
$country = $this->callAPISuccess('Country', 'create', $this->_params);
- $params = array(
+ $params = [
'iso_code' => $this->_params['iso_code'],
- );
+ ];
$result = $this->callAPIAndDocument('Country', 'Get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($country['values'][$country['id']]['name'], $result['values'][$country['id']]['name']);
$this->assertEquals($country['values'][$country['id']]['iso_code'], $result['values'][$country['id']]['iso_code']);
unset($params['id']);
$this->callAPISuccess('country', 'create', $params);
$this->callAPIFailure('country', 'create', $params);
- $check = $this->callAPISuccess('country', 'getcount', array(
+ $check = $this->callAPISuccess('country', 'getcount', [
'iso_code' => $params['iso_code'],
- ));
+ ]);
$this->assertEquals(1, $check);
}
*/
public function testCustomApi() {
$this->installApi();
- $this->callAPISuccess('MailingProviderData', 'create', array(
+ $this->callAPISuccess('MailingProviderData', 'create', [
'contact_identifier' => 'xyz',
'mailing_identifier' => 'abx',
- ));
- $this->callAPISuccess('Mailing', 'create', array('name' => 'CiviMail', 'hash' => 'abx'));
- $result = $this->callAPISuccess('MailingProviderData', 'get', array('return' => array('mailing_identifier.name', 'contact_identifier', 'mailing_identifier')));
+ ]);
+ $this->callAPISuccess('Mailing', 'create', ['name' => 'CiviMail', 'hash' => 'abx']);
+ $result = $this->callAPISuccess('MailingProviderData', 'get', ['return' => ['mailing_identifier.name', 'contact_identifier', 'mailing_identifier']]);
$this->assertEquals(1, $result['count']);
$this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']);
$this->assertEquals('xyzabx2017-01-01 00:00:00', $result['id']);
- $this->assertEquals(array(
+ $this->assertEquals([
'contact_identifier' => 'xyz',
'mailing_identifier' => 'abx',
'mailing_identifier.name' => 'CiviMail',
- ), reset($result['values']));
+ ], reset($result['values']));
}
/**
* @param array $entityTypes
*/
public function hookEntityTypes(&$entityTypes) {
- $entityTypes['CRM_Omnimail_DAO_MailingProviderData'] = array(
+ $entityTypes['CRM_Omnimail_DAO_MailingProviderData'] = [
'name' => 'MailingProviderData',
'class' => 'CRM_Omnimail_DAO_MailingProviderData',
'table' => 'civicrm_maiing_provider_data',
- );
+ ];
}
/**
*/
public function installApi() {
require_once __DIR__ . '/custom_api/MailingProviderData.php';
- $this->hookClass->setHook('civicrm_entityTypes', array($this, 'hookEntityTypes'));
+ $this->hookClass->setHook('civicrm_entityTypes', [$this, 'hookEntityTypes']);
CRM_Core_DAO_AllCoreTables::init(TRUE);
CRM_Core_DAO::executeQuery(
"CREATE TABLE IF NOT EXISTS `civicrm_mailing_provider_data` (
public function setUp() {
$this->_entity = 'CustomGroup';
- $this->_params = array(
+ $this->_params = [
'title' => 'Test_Group_1',
'name' => 'test_group_1',
'extends' => 'Individual',
'help_pre' => 'This is Pre Help For Test Group 1',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
- );
+ ];
parent::setUp();
}
public function tearDown() {
- $tablesToTruncate = array('civicrm_custom_group', 'civicrm_custom_field');
+ $tablesToTruncate = ['civicrm_custom_group', 'civicrm_custom_field'];
// true tells quickCleanup to drop any tables that might have been created in the test
$this->quickCleanup($tablesToTruncate, TRUE);
}
* & delete (& it would be easy to add if not there)
*/
public function testCustomGroupCreateNoParam() {
- $customGroup = $this->callAPIFailure('custom_group', 'create', array(),
+ $customGroup = $this->callAPIFailure('custom_group', 'create', [],
'Mandatory key(s) missing from params array: title, extends'
);
}
* Check with empty array.
*/
public function testCustomGroupCreateNoExtends() {
- $params = array(
+ $params = [
'domain_id' => 1,
'title' => 'Test_Group_1',
'name' => 'test_group_1',
'help_pre' => 'This is Pre Help For Test Group 1',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
- );
+ ];
$customGroup = $this->callAPIFailure('custom_group', 'create', $params);
$this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends');
* Check with empty array.
*/
public function testCustomGroupCreateInvalidExtends() {
- $params = array(
+ $params = [
'domain_id' => 1,
'title' => 'Test_Group_1',
'name' => 'test_group_1',
'help_pre' => 'This is Pre Help For Test Group 1',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
- 'extends' => array(),
- );
+ 'extends' => [],
+ ];
$customGroup = $this->callAPIFailure('custom_group', 'create', $params);
$this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends');
* Check with a string instead of array for extends.
*/
public function testCustomGroupCreateExtendsString() {
- $params = array(
+ $params = [
'domain_id' => 1,
'title' => 'Test_Group_1',
'name' => 'test_group_1',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
'extends' => 'Individual',
- );
+ ];
$customGroup = $this->callAPISuccess('custom_group', 'create', $params);
}
* Check with valid array.
*/
public function testCustomGroupCreate() {
- $params = array(
+ $params = [
'title' => 'Test_Group_1',
'name' => 'test_group_1',
- 'extends' => array('Individual'),
+ 'extends' => ['Individual'],
'weight' => 4,
'collapse_display' => 1,
'style' => 'Inline',
'help_pre' => 'This is Pre Help For Test Group 1',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('custom_group', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($result['id']);
* Check with valid array.
*/
public function testCustomGroupGetFields() {
- $params = array(
- 'options' => array('get_options' => 'style'),
- );
+ $params = [
+ 'options' => ['get_options' => 'style'],
+ ];
$result = $this->callAPISuccess('custom_group', 'getfields', $params);
- $expected = array(
+ $expected = [
'Tab' => 'Tab',
'Inline' => 'Inline',
'Tab with table' => 'Tab with table',
- );
+ ];
$this->assertEquals($expected, $result['values']['style']['options']);
}
* Check with extends array length greater than 1
*/
public function testCustomGroupExtendsMultipleCreate() {
- $params = array(
+ $params = [
'title' => 'Test_Group_1',
'name' => 'test_group_1',
- 'extends' => array('Individual', 'Household'),
+ 'extends' => ['Individual', 'Household'],
'weight' => 4,
'collapse_display' => 1,
'style' => 'Inline',
'help_pre' => 'This is Pre Help For Test Group 1',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
- );
+ ];
$result = $this->callAPIFailure('custom_group', 'create', $params,
'implode(): Invalid arguments passed');
* Check with style missing from params array.
*/
public function testCustomGroupCreateNoStyle() {
- $params = array(
+ $params = [
'title' => 'Test_Group_1',
'name' => 'test_group_1',
- 'extends' => array('Individual'),
+ 'extends' => ['Individual'],
'weight' => 4,
'collapse_display' => 1,
'help_pre' => 'This is Pre Help For Test Group 1',
'help_post' => 'This is Post Help For Test Group 1',
'is_active' => 1,
- );
+ ];
$customGroup = $this->callAPISuccess('custom_group', 'create', $params);
$this->assertNotNull($customGroup['id']);
* Check without title.
*/
public function testCustomGroupCreateNoTitle() {
- $params = array(
- 'extends' => array('Contact'),
+ $params = [
+ 'extends' => ['Contact'],
'weight' => 5,
'collapse_display' => 1,
'style' => 'Tab',
'help_pre' => 'This is Pre Help For Test Group 2',
'help_post' => 'This is Post Help For Test Group 2',
- );
+ ];
$customGroup = $this->callAPIFailure('custom_group', 'create', $params,
'Mandatory key(s) missing from params array: title');
* Check for household without weight.
*/
public function testCustomGroupCreateHouseholdNoWeight() {
- $params = array(
+ $params = [
'title' => 'Test_Group_3',
'name' => 'test_group_3',
- 'extends' => array('Household'),
+ 'extends' => ['Household'],
'collapse_display' => 1,
'style' => 'Tab',
'help_pre' => 'This is Pre Help For Test Group 3',
'help_post' => 'This is Post Help For Test Group 3',
'is_active' => 1,
- );
+ ];
$customGroup = $this->callAPISuccess('custom_group', 'create', $params);
$this->assertNotNull($customGroup['id']);
* Check for Contribution Donation.
*/
public function testCustomGroupCreateContributionDonation() {
- $params = array(
+ $params = [
'title' => 'Test_Group_6',
'name' => 'test_group_6',
- 'extends' => array('Contribution', array(1)),
+ 'extends' => ['Contribution', [1]],
'weight' => 6,
'collapse_display' => 1,
'style' => 'Inline',
'help_pre' => 'This is Pre Help For Test Group 6',
'help_post' => 'This is Post Help For Test Group 6',
'is_active' => 1,
- );
+ ];
$customGroup = $this->callAPISuccess('custom_group', 'create', $params);
$this->assertNotNull($customGroup['id']);
* Check with valid array.
*/
public function testCustomGroupCreateGroup() {
- $params = array(
+ $params = [
'domain_id' => 1,
'title' => 'Test_Group_8',
'name' => 'test_group_8',
- 'extends' => array('Group'),
+ 'extends' => ['Group'],
'weight' => 7,
'collapse_display' => 1,
'is_active' => 1,
'style' => 'Inline',
'help_pre' => 'This is Pre Help For Test Group 8',
'help_post' => 'This is Post Help For Test Group 8',
- );
+ ];
$customGroup = $this->callAPISuccess('CustomGroup', 'create', $params);
$this->assertNotNull($customGroup['id']);
* Check with Activity - Meeting Type
*/
public function testCustomGroupCreateActivityMeeting() {
- $params = array(
+ $params = [
'title' => 'Test_Group_10',
'name' => 'test_group_10',
- 'extends' => array('Activity', array(1)),
+ 'extends' => ['Activity', [1]],
'weight' => 8,
'collapse_display' => 1,
'style' => 'Inline',
'help_pre' => 'This is Pre Help For Test Group 10',
'help_post' => 'This is Post Help For Test Group 10',
- );
+ ];
$customGroup = $this->callAPISuccess('custom_group', 'create', $params);
$this->assertNotNull($customGroup['id']);
* Check without GroupID.
*/
public function testCustomGroupDeleteWithoutGroupID() {
- $customGroup = $this->callAPIFailure('custom_group', 'delete', array());
+ $customGroup = $this->callAPIFailure('custom_group', 'delete', []);
$this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id');
}
* Check with valid custom group id.
*/
public function testCustomGroupDelete() {
- $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
- $params = array(
+ $customGroup = $this->customGroupCreate(['extends' => 'Individual', 'title' => 'test_group']);
+ $params = [
'id' => $customGroup['id'],
- );
+ ];
$result = $this->callAPIAndDocument('custom_group', 'delete', $params, __FUNCTION__, __FILE__);
$this->assertAPISuccess($result);
}
public function testGetCustomGroupSuccess() {
$this->callAPISuccess($this->_entity, 'create', $this->_params);
- $params = array();
+ $params = [];
$result = $this->callAPIAndDocument($this->_entity, 'get', $params, __FUNCTION__, __FILE__);
$values = $result['values'][$result['id']];
foreach ($this->_params as $key => $value) {
}
public function testCustomSearch() {
- $result = $this->callAPISuccess('CustomSearch', 'create', array(
+ $result = $this->callAPISuccess('CustomSearch', 'create', [
'label' => 'Invalid, overwritten',
'description' => 'Longish description of the example search form',
'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
- ));
+ ]);
$this->assertAPISuccess($result);
$this->assertEquals(1, $result['count']);
$entityId = $result['id'];
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
// deactivate
- $result = $this->callAPISuccess('CustomSearch', 'create', array(
+ $result = $this->callAPISuccess('CustomSearch', 'create', [
'id' => $entityId,
'is_active' => 0,
- ));
+ ]);
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
// activate
- $result = $this->callAPISuccess('CustomSearch', 'create', array(
+ $result = $this->callAPISuccess('CustomSearch', 'create', [
'id' => $entityId,
'is_active' => 1,
- ));
+ ]);
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
$this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
- $check = $this->callAPISuccess('CustomSearch', 'get', array('id' => $entityId));
+ $check = $this->callAPISuccess('CustomSearch', 'get', ['id' => $entityId]);
if (!empty($check['count'])) {
- $result = $this->callAPISuccess('CustomSearch', 'delete', array(
+ $result = $this->callAPISuccess('CustomSearch', 'delete', [
'id' => $entityId,
- ));
+ ]);
}
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
public function setUp() {
parent::setUp();
// Create Group For Individual Contact Type
- $groupIndividual = array(
+ $groupIndividual = [
'title' => 'TestGroup For Indivi' . substr(sha1(rand()), 0, 5),
- 'extends' => array('Individual'),
+ 'extends' => ['Individual'],
'style' => 'Inline',
'is_active' => 1,
- );
+ ];
$this->CustomGroupIndividual = $this->customGroupCreate($groupIndividual);
- $this->IndividualField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndividual['id']));
+ $this->IndividualField = $this->customFieldCreate(['custom_group_id' => $this->CustomGroupIndividual['id']]);
// Create Group For Individual-Student Contact Sub Type
- $groupIndiStudent = array(
+ $groupIndiStudent = [
'title' => 'Student Test' . substr(sha1(rand()), 0, 5),
- 'extends' => array('Individual', array('Student')),
+ 'extends' => ['Individual', ['Student']],
'style' => 'Inline',
'is_active' => 1,
- );
+ ];
$this->CustomGroupIndiStudent = $this->customGroupCreate($groupIndiStudent);
- $this->IndiStudentField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndiStudent['id']));
+ $this->IndiStudentField = $this->customFieldCreate(['custom_group_id' => $this->CustomGroupIndiStudent['id']]);
- $params = array(
+ $params = [
'first_name' => 'Mathev',
'last_name' => 'Adison',
'contact_type' => 'Individual',
- );
+ ];
$this->individual = $this->individualCreate($params);
- $params = array(
+ $params = [
'first_name' => 'Steve',
'last_name' => 'Tosun',
'contact_type' => 'Individual',
'contact_sub_type' => 'Student',
- );
+ ];
$this->individualStudent = $this->individualCreate($params);
- $params = array(
+ $params = [
'first_name' => 'Mark',
'last_name' => 'Dawson',
'contact_type' => 'Individual',
'contact_sub_type' => 'Parent',
- );
+ ];
$this->individualParent = $this->individualCreate($params);
- $params = array(
+ $params = [
'organization_name' => 'Wellspring',
'contact_type' => 'Organization',
- );
+ ];
$this->organization = $this->organizationCreate($params);
- $params = array(
+ $params = [
'organization_name' => 'SubUrban',
'contact_type' => 'Organization',
'contact_sub_type' => 'Sponsor',
- );
+ ];
$this->organizationSponsor = $this->organizationCreate($params);
//refresh php cached variables
CRM_Core_PseudoConstant::flush();
}
public function tearDown() {
- $tablesToTruncate = array('civicrm_contact', 'civicrm_cache');
+ $tablesToTruncate = ['civicrm_contact', 'civicrm_cache'];
$this->quickCleanup($tablesToTruncate, TRUE);
}
* Test that custom fields is returned for correct contact type only.
*/
public function testGetFields() {
- $result = $this->callAPISuccess('Contact', 'getfields', array());
+ $result = $this->callAPISuccess('Contact', 'getfields', []);
$this->assertArrayHasKey("custom_{$this->IndividualField['id']}", $result['values'], 'If This fails there is probably a caching issue - failure in line' . __LINE__ . print_r(array_keys($result['values']), TRUE));
- $result = $this->callAPISuccess('Contact', 'getfields', array(
+ $result = $this->callAPISuccess('Contact', 'getfields', [
'action' => 'create',
'contact_type' => 'Individual',
- ), 'in line' . __LINE__);
+ ], 'in line' . __LINE__);
$this->assertArrayHasKey("custom_{$this->IndividualField['id']}", $result['values']);
- $result = $this->callAPISuccess('Contact', 'getfields', array(
+ $result = $this->callAPISuccess('Contact', 'getfields', [
'action' => 'create',
'contact_type' => 'Organization',
- ));
+ ]);
$this->assertArrayNotHasKey("custom_{$this->IndividualField['id']}", $result['values'], 'in line' . __LINE__ . print_r(array_keys($result['values']), TRUE));
- $result = $this->callAPISuccess('Relationship', 'getfields', array('action' => 'create'), 'in line' . __LINE__);
+ $result = $this->callAPISuccess('Relationship', 'getfields', ['action' => 'create'], 'in line' . __LINE__);
$this->assertArrayNotHasKey("custom_{$this->IndividualField['id']}", $result['values']);
}
*/
public function testAddIndividualCustomDataToOrganization() {
- $params = array(
+ $params = [
'id' => $this->organization,
'contact_type' => 'Organization',
"custom_{$this->IndividualField['id']}" => 'Test String',
// so that undefined_fields is returned
'debug' => 1,
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $params);
$this->assertTrue(is_array($contact['undefined_fields']), __LINE__);
* note - don't copy & paste this - is of marginal value
*/
public function testAddCustomDataEmptyToIndividual() {
- $contact = $this->callAPIFailure('contact', 'create', array(),
+ $contact = $this->callAPIFailure('contact', 'create', [],
'Mandatory key(s) missing from params array: contact_type'
);
}
*/
public function testAddValidCustomDataToIndividual() {
- $params = array(
+ $params = [
'contact_id' => $this->individual,
'contact_type' => 'Individual',
"custom_{$this->IndividualField['id']}" => 'Test String',
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $params);
$this->assertNotNull($contact['id']);
*/
public function testAddIndividualStudentCustomDataToOrganizationSponsor() {
- $params = array(
+ $params = [
'contact_id' => $this->organizationSponsor,
'contact_type' => 'Organization',
"custom_{$this->IndiStudentField['id']}" => 'Test String',
// so that undefined_fields is returned
'debug' => 1,
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $params);
$this->assertTrue(is_array($contact['undefined_fields']), __LINE__);
*/
public function testCreateValidCustomDataToIndividualStudent() {
- $params = array(
+ $params = [
'contact_id' => $this->individualStudent,
'contact_type' => 'Individual',
"custom_{$this->IndiStudentField['id']}" => 'Test String',
- );
+ ];
$result = $this->callAPISuccess('contact', 'create', $params);
*/
public function testAddIndividualStudentCustomDataToIndividualParent() {
- $params = array(
+ $params = [
'contact_id' => $this->individualParent,
'contact_type' => 'Individual',
"custom_{$this->IndiStudentField['id']}" => 'Test String',
// so that undefined_fields is returned
'debug' => 1,
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $params);
$this->assertTrue(is_array($contact['undefined_fields']), __LINE__);
$this->assertTrue(in_array("custom_{$this->IndiStudentField['id']}", $contact['undefined_fields']), __LINE__);
*/
public function testRetrieveValidCustomDataToIndividual() {
- $params = array(
+ $params = [
'contact_id' => $this->individual,
'contact_type' => 'Individual',
"custom_" . $this->IndividualField['id'] => 'Test String',
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $params);
$this->assertAPISuccess($contact);
- $params = array(
+ $params = [
'contact_id' => $this->individual,
'contact_type' => 'Individual',
"return.custom_{$this->IndividualField['id']}" => 1,
- );
+ ];
$getContact = $this->callAPISuccess('contact', 'get', $params);
*/
public function testRetrieveValidCustomDataToIndividualStudent() {
- $params = array(
+ $params = [
'contact_id' => $this->individualStudent,
'contact_type' => 'Individual',
'contact_sub_type' => 'Student',
"custom_{$this->IndiStudentField['id']}" => 'Test String',
- );
+ ];
$contact = $this->callAPISuccess('contact', 'create', $params);
$this->assertAPISuccess($contact);
- $params = array(
+ $params = [
'contact_id' => $this->individualStudent,
'contact_type' => 'Individual',
'contact_sub_type' => 'Student',
"return.custom_{$this->IndiStudentField['id']}" => 1,
- );
+ ];
$getContact = $this->callAPISuccess('contact', 'get', $params);
}
public function _populateOptionAndCustomGroup($type = NULL) {
- $dataValues = array(
- 'integer' => array(1, 2, 3),
- 'number' => array(10.11, 20.22, 30.33),
- 'string' => array(substr(sha1(rand()), 0, 4) . '(', substr(sha1(rand()), 0, 3) . '|', substr(sha1(rand()), 0, 2) . ','),
+ $dataValues = [
+ 'integer' => [1, 2, 3],
+ 'number' => [10.11, 20.22, 30.33],
+ 'string' => [substr(sha1(rand()), 0, 4) . '(', substr(sha1(rand()), 0, 3) . '|', substr(sha1(rand()), 0, 2) . ','],
// 'country' => array_rand(CRM_Core_PseudoConstant::country(FALSE, FALSE), 3),
// This does not work in the test at the moment due to caching issues.
//'state_province' => array_rand(CRM_Core_PseudoConstant::stateProvince(FALSE, FALSE), 3),
'date' => NULL,
'contact' => NULL,
'boolean' => NULL,
- );
+ ];
- $dataValues = !empty($type) ? array($type => $dataValues[$type]) : $dataValues;
+ $dataValues = !empty($type) ? [$type => $dataValues[$type]] : $dataValues;
foreach ($dataValues as $dataType => $values) {
- $this->optionGroup[$dataType] = array('values' => $values);
+ $this->optionGroup[$dataType] = ['values' => $values];
if (!empty($values)) {
$result = $this->callAPISuccess('OptionGroup', 'create',
- array(
+ [
'name' => "{$dataType}_group",
- 'api.option_value.create' => array('label' => "$dataType 1", 'value' => $values[0]),
- 'api.option_value.create.1' => array('label' => "$dataType 2", 'value' => $values[1]),
- 'api.option_value.create.2' => array('label' => "$dataType 3", 'value' => $values[2]),
- )
+ 'api.option_value.create' => ['label' => "$dataType 1", 'value' => $values[0]],
+ 'api.option_value.create.1' => ['label' => "$dataType 2", 'value' => $values[1]],
+ 'api.option_value.create.2' => ['label' => "$dataType 3", 'value' => $values[2]],
+ ]
);
$this->optionGroup[$dataType]['id'] = $result['id'];
}
elseif ($dataType == 'contact') {
for ($i = 0; $i < 3; $i++) {
- $result = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . '@yahoo.com'));
+ $result = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . '@yahoo.com']);
$this->optionGroup[$dataType]['values'][$i] = $result['id'];
}
}
}
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_email',
'civicrm_custom_field',
'civicrm_custom_group',
'civicrm_contact',
- );
+ ];
// true tells quickCleanup to drop any tables that might have been created in the test
$this->quickCleanup($tablesToTruncate, TRUE);
if (!empty($this->optionGroup)) {
foreach ($this->optionGroup as $type => $value) {
if (!empty($value['id'])) {
- $count = $this->callAPISuccess('OptionGroup', 'get', array('id' => $value['id']));
+ $count = $this->callAPISuccess('OptionGroup', 'get', ['id' => $value['id']]);
if ((bool) $count['count']) {
- $this->callAPISuccess('OptionGroup', 'delete', array('id' => $value['id']));
+ $this->callAPISuccess('OptionGroup', 'delete', ['id' => $value['id']]);
}
}
}
public function testCreateCustomValue() {
$this->_populateOptionAndCustomGroup();
- $this->_customField = $this->customFieldCreate(array('custom_group_id' => $this->ids['string']['custom_group_id']));
+ $this->_customField = $this->customFieldCreate(['custom_group_id' => $this->ids['string']['custom_group_id']]);
$this->_customFieldID = $this->_customField['id'];
$customFieldDataType = CRM_Core_BAO_CustomField::dataType();
$dataToHtmlTypes = CRM_Core_BAO_CustomField::dataToHtml();
$count = 0;
- $optionSupportingHTMLTypes = array('Select', 'Radio', 'CheckBox', 'Autocomplete-Select', 'Multi-Select');
+ $optionSupportingHTMLTypes = ['Select', 'Radio', 'CheckBox', 'Autocomplete-Select', 'Multi-Select'];
foreach ($customFieldDataType as $dataType => $label) {
switch ($dataType) {
case 'Boolean':
//Based on the custom field data-type choose desired SQL operators(to test with) and basic $type
- if (in_array($dataType, array('String', 'Link'))) {
- $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL');
+ if (in_array($dataType, ['String', 'Link'])) {
+ $validSQLOperators = ['=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL'];
$type = 'string';
}
elseif ($dataType == 'Boolean') {
- $validSQLOperators = array('=', '!=', 'IS NOT NULL', 'IS NULL');
+ $validSQLOperators = ['=', '!=', 'IS NOT NULL', 'IS NULL'];
$type = 'boolean';
}
else {
else {
$type = $dataType == 'Int' ? 'integer' : 'number';
}
- $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL');
+ $validSQLOperators = ['=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL'];
}
//Create custom field of $dataType and html-type $html
// the LIKE operator could potentially bypass ACLs (as could IS NOT NULL) and some thought needs to be given
// to it.
if (in_array($html, $optionSupportingHTMLTypes)) {
- $validSQLOperators = array_diff($validSQLOperators, array('LIKE', 'NOT LIKE'));
+ $validSQLOperators = array_diff($validSQLOperators, ['LIKE', 'NOT LIKE']);
}
- $params = array(
+ $params = [
'custom_group_id' => $this->ids[$type]['custom_group_id'],
'label' => "$dataType - $html",
'data_type' => $dataType,
'html_type' => $html,
'default_value' => NULL,
- );
- if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference', 'Boolean'))) {
- $params += array('option_group_id' => $this->optionGroup[$type]['id']);
+ ];
+ if (!in_array($html, ['Text', 'TextArea']) && !in_array($dataType, ['Link', 'Date', 'ContactReference', 'Boolean'])) {
+ $params += ['option_group_id' => $this->optionGroup[$type]['id']];
}
$customField = $this->customFieldCreate($params);
//Now test with $validSQLOperator SQL operators against its custom value(s)
public function _testCustomValue($customField, $sqlOps, $type) {
$isSerialized = CRM_Core_BAO_CustomField::isSerialized($customField);
$customId = $customField['id'];
- $params = array(
+ $params = [
'contact_type' => 'Individual',
'email' => substr(sha1(rand()), 0, 7) . 'man1@yahoo.com',
- );
+ ];
$result = $this->callAPISuccess('Contact', 'create', $params);
$contactId = $result['id'];
$qillOp = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op);
switch ($op) {
case '=':
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => (is_array($selectedValue) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $selectedValue) : $selectedValue)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => (is_array($selectedValue) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $selectedValue) : $selectedValue)]);
$this->assertEquals($contactId, $result['id']);
break;
case '!=':
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $notselectedValue)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $notselectedValue]]);
$this->assertEquals(TRUE, array_key_exists($contactId, $result['values']));
break;
}
// To be precise in for these operator we can't just rely on one contact,
// hence creating multiple contact with custom value less/more then $selectedValue respectively
- $result = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man2@yahoo.com'));
+ $result = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man2@yahoo.com']);
$contactId2 = $result['id'];
- $this->callAPISuccess('CustomValue', 'create', array('entity_id' => $contactId2, 'custom_' . $customId => $lesserSelectedValue));
+ $this->callAPISuccess('CustomValue', 'create', ['entity_id' => $contactId2, 'custom_' . $customId => $lesserSelectedValue]);
if ($op == '>') {
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $lesserSelectedValue)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $lesserSelectedValue]]);
$this->assertEquals($contactId, $result['id']);
}
elseif ($op == '<') {
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $selectedValue)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $selectedValue]]);
$this->assertEquals($contactId2, $result['id']);
}
else {
- $result = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man3@yahoo.com'));
+ $result = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'email' => substr(sha1(rand()), 0, 7) . 'man3@yahoo.com']);
$contactId3 = $result['id'];
- $this->callAPISuccess('CustomValue', 'create', array('entity_id' => $contactId3, 'custom_' . $customId => $greaterSelectedValue));
+ $this->callAPISuccess('CustomValue', 'create', ['entity_id' => $contactId3, 'custom_' . $customId => $greaterSelectedValue]);
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $selectedValue)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $selectedValue]]);
$this->assertEquals($contactId, $result['values'][$contactId]['id']);
if ($op == '>=') {
else {
$this->assertEquals($contactId2, $result['values'][$contactId2]['id']);
}
- $this->callAPISuccess('contact', 'delete', array('id' => $contactId3));
+ $this->callAPISuccess('contact', 'delete', ['id' => $contactId3]);
}
- $this->callAPISuccess('contact', 'delete', array('id' => $contactId2));
+ $this->callAPISuccess('contact', 'delete', ['id' => $contactId2]);
break;
case 'IN':
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => (array) $selectedValue)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => (array) $selectedValue]]);
$this->assertEquals($contactId, $result['id']);
break;
case 'NOT IN':
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => (array) $notselectedValue)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => (array) $notselectedValue]]);
$this->assertEquals($contactId, $result['id']);
break;
case 'LIKE':
$selectedValue = is_array($selectedValue) ? $selectedValue[0] : $selectedValue;
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => "%$selectedValue%")));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => "%$selectedValue%"]]);
$this->assertEquals($contactId, $result['id']);
break;
case 'NOT LIKE':
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => $notselectedValue)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => $notselectedValue]]);
$this->assertEquals($contactId, $result['id']);
break;
case 'IS NULL':
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => 1)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => 1]]);
$this->assertEquals(FALSE, array_key_exists($contactId, $result['values']));
break;
case 'IS NOT NULL':
- $result = $this->callAPISuccess('Contact', 'Get', array('custom_' . $customId => array($op => 1)));
+ $result = $this->callAPISuccess('Contact', 'Get', ['custom_' . $customId => [$op => 1]]);
$this->assertEquals($contactId, $result['id']);
break;
}
}
- $this->callAPISuccess('Contact', 'delete', array('id' => $contactId));
+ $this->callAPISuccess('Contact', 'delete', ['id' => $contactId]);
}
/**
public function testAlterOptionValue() {
$this->_populateOptionAndCustomGroup('string');
- $selectField = $this->customFieldCreate(array(
+ $selectField = $this->customFieldCreate([
'custom_group_id' => $this->ids['string']['custom_group_id'],
'label' => 'Custom Select',
'html_type' => 'Select',
'option_group_id' => $this->optionGroup['string']['id'],
- ));
- $selectField = civicrm_api3('customField', 'getsingle', array('id' => $selectField['id']));
- $radioField = $this->customFieldCreate(array(
+ ]);
+ $selectField = civicrm_api3('customField', 'getsingle', ['id' => $selectField['id']]);
+ $radioField = $this->customFieldCreate([
'custom_group_id' => $this->ids['string']['custom_group_id'],
'label' => 'Custom Radio',
'html_type' => 'Radio',
'option_group_id' => $selectField['option_group_id'],
- ));
- $multiSelectField = $this->customFieldCreate(array(
+ ]);
+ $multiSelectField = $this->customFieldCreate([
'custom_group_id' => $this->ids['string']['custom_group_id'],
'label' => 'Custom Multi-Select',
'html_type' => 'Multi-Select',
'option_group_id' => $selectField['option_group_id'],
- ));
+ ]);
$selectName = 'custom_' . $selectField['id'];
$radioName = 'custom_' . $radioField['id'];
$multiSelectName = 'custom_' . $multiSelectField['id'];
$controlFieldName = 'custom_' . $this->ids['string']['custom_field_id'];
- $params = array(
+ $params = [
'first_name' => 'abc4',
'last_name' => 'xyz4',
'contact_type' => 'Individual',
$radioName => $this->optionGroup['string']['values'][1],
// The control group in a science experiment should be unaffected
$controlFieldName => $this->optionGroup['string']['values'][2],
- );
+ ];
$contact = $this->callAPISuccess('Contact', 'create', $params);
- $result = $this->callAPISuccess('Contact', 'getsingle', array(
+ $result = $this->callAPISuccess('Contact', 'getsingle', [
'id' => $contact['id'],
- 'return' => array($selectName, $multiSelectName),
- ));
+ 'return' => [$selectName, $multiSelectName],
+ ]);
$this->assertEquals($params[$selectName], $result[$selectName]);
$this->assertEquals($params[$multiSelectName], $result[$multiSelectName]);
- $this->callAPISuccess('OptionValue', 'create', array(
+ $this->callAPISuccess('OptionValue', 'create', [
'value' => 'one-modified',
'option_group_id' => $selectField['option_group_id'],
'name' => 'string 1',
- 'options' => array(
- 'match-mandatory' => array('option_group_id', 'name'),
- ),
- ));
+ 'options' => [
+ 'match-mandatory' => ['option_group_id', 'name'],
+ ],
+ ]);
- $result = $this->callAPISuccess('Contact', 'getsingle', array(
+ $result = $this->callAPISuccess('Contact', 'getsingle', [
'id' => $contact['id'],
- 'return' => array($selectName, $multiSelectName, $controlFieldName, $radioName),
- ));
+ 'return' => [$selectName, $multiSelectName, $controlFieldName, $radioName],
+ ]);
// Ensure the relevant fields have been updated
$this->assertEquals('one-modified', $result[$selectName]);
- $this->assertEquals(array('one-modified', $params[$radioName], $params[$controlFieldName]), $result[$multiSelectName]);
+ $this->assertEquals(['one-modified', $params[$radioName], $params[$controlFieldName]], $result[$multiSelectName]);
// This field should not have changed because we didn't alter this option
$this->assertEquals($params[$radioName], $result[$radioName]);
// This should not have changed because this field doesn't use the affected option group
$this->assertEquals($params[$controlFieldName], $result[$controlFieldName]);
// Add test of proof that multivalue fields.
- $this->callAPISuccess('CustomValue', 'create', array(
+ $this->callAPISuccess('CustomValue', 'create', [
'entity_id' => $contact['id'],
- $multiSelectName => array($params[$radioName], $params[$controlFieldName]),
- ));
- $result = $this->callAPISuccess('Contact', 'getsingle', array(
+ $multiSelectName => [$params[$radioName], $params[$controlFieldName]],
+ ]);
+ $result = $this->callAPISuccess('Contact', 'getsingle', [
'id' => $contact['id'],
- 'return' => array($selectName, $multiSelectName, $controlFieldName, $radioName),
- ));
+ 'return' => [$selectName, $multiSelectName, $controlFieldName, $radioName],
+ ]);
- $this->assertEquals(array($params[$radioName], $params[$controlFieldName]), $result[$multiSelectName]);
+ $this->assertEquals([$params[$radioName], $params[$controlFieldName]], $result[$multiSelectName]);
}
public function testGettree() {
- $cg = $this->callAPISuccess('CustomGroup', 'create', array(
+ $cg = $this->callAPISuccess('CustomGroup', 'create', [
'title' => 'TestGettree',
'extends' => 'Individual',
- ));
- $cf = $this->callAPISuccess('CustomField', 'create', array(
+ ]);
+ $cf = $this->callAPISuccess('CustomField', 'create', [
'custom_group_id' => $cg['id'],
'label' => 'Got Options',
'name' => 'got_options',
"data_type" => "String",
"html_type" => "Multi-Select",
- 'option_values' => array('1' => 'One', '2' => 'Two', '3' => 'Three'),
- ));
+ 'option_values' => ['1' => 'One', '2' => 'Two', '3' => 'Three'],
+ ]);
$fieldName = 'custom_' . $cf['id'];
- $contact = $this->individualCreate(array($fieldName => array('2', '3')));
+ $contact = $this->individualCreate([$fieldName => ['2', '3']]);
// Verify values are formatted correctly
- $tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $contact));
- $this->assertEquals(array('2', '3'), $tree['values']['TestGettree']['fields']['got_options']['value']['data']);
+ $tree = $this->callAPISuccess('CustomValue', 'gettree', ['entity_type' => 'Contact', 'entity_id' => $contact]);
+ $this->assertEquals(['2', '3'], $tree['values']['TestGettree']['fields']['got_options']['value']['data']);
$this->assertEquals('Two, Three', $tree['values']['TestGettree']['fields']['got_options']['value']['display']);
// Try limiting the return params
- $tree = $this->callAPISuccess('CustomValue', 'gettree', array(
+ $tree = $this->callAPISuccess('CustomValue', 'gettree', [
'entity_type' => 'Contact',
'entity_id' => $contact,
- 'return' => array(
+ 'return' => [
'custom_group.id',
'custom_field.id',
- ),
- ));
- $this->assertEquals(array('2', '3'), $tree['values']['TestGettree']['fields']['got_options']['value']['data']);
+ ],
+ ]);
+ $this->assertEquals(['2', '3'], $tree['values']['TestGettree']['fields']['got_options']['value']['data']);
$this->assertEquals('Two, Three', $tree['values']['TestGettree']['fields']['got_options']['value']['display']);
- $this->assertEquals(array('id', 'fields'), array_keys($tree['values']['TestGettree']));
+ $this->assertEquals(['id', 'fields'], array_keys($tree['values']['TestGettree']));
// Ensure display values are returned even if data is not
- $tree = $this->callAPISuccess('CustomValue', 'gettree', array(
+ $tree = $this->callAPISuccess('CustomValue', 'gettree', [
'entity_type' => 'Contact',
'entity_id' => $contact,
- 'return' => array(
+ 'return' => [
'custom_value.display',
- ),
- ));
+ ],
+ ]);
$this->assertEquals('Two, Three', $tree['values']['TestGettree']['fields']['got_options']['value']['display']);
$this->assertFalse(isset($tree['values']['TestGettree']['fields']['got_options']['value']['data']));
// Verify that custom set appears for individuals even who don't have any custom data
$contact2 = $this->individualCreate();
- $tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $contact2));
+ $tree = $this->callAPISuccess('CustomValue', 'gettree', ['entity_type' => 'Contact', 'entity_id' => $contact2]);
$this->assertArrayHasKey('TestGettree', $tree['values']);
// Verify that custom set doesn't appear for other contact types
$org = $this->organizationCreate();
- $tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $org));
+ $tree = $this->callAPISuccess('CustomValue', 'gettree', ['entity_type' => 'Contact', 'entity_id' => $org]);
$this->assertArrayNotHasKey('TestGettree', $tree['values']);
}
public function testGettree_getfields() {
- $fields = $this->callAPISuccess('CustomValue', 'getfields', array('api_action' => 'gettree'));
+ $fields = $this->callAPISuccess('CustomValue', 'getfields', ['api_action' => 'gettree']);
$fields = $fields['values'];
$this->assertTrue((bool) $fields['entity_id']['api.required']);
$this->assertTrue((bool) $fields['entity_type']['api.required']);
*/
public function testUpdateCustomGreetings() {
// Create a custom group with one field.
- $customGroupResult = $this->callAPISuccess('CustomGroup', 'create', array(
+ $customGroupResult = $this->callAPISuccess('CustomGroup', 'create', [
'sequential' => 1,
'title' => "test custom group",
'extends' => "Individual",
- ));
- $customFieldResult = $this->callAPISuccess('CustomField', 'create', array(
+ ]);
+ $customFieldResult = $this->callAPISuccess('CustomField', 'create', [
'custom_group_id' => $customGroupResult['id'],
'label' => "greeting test",
'data_type' => "String",
'html_type' => "Text",
- ));
+ ]);
$customFieldId = $customFieldResult['id'];
// Create a contact with an email greeting format that includes the new custom field.
- $contactResult = $this->callAPISuccess('Contact', 'create', array(
+ $contactResult = $this->callAPISuccess('Contact', 'create', [
'contact_type' => 'Individual',
'email' => substr(sha1(rand()), 0, 7) . '@yahoo.com',
'email_greeting_id' => "Customized",
'email_greeting_custom' => "Dear {contact.custom_{$customFieldId}}",
- ));
+ ]);
$cid = $contactResult['id'];
// Define testing values.
$testGreetingValue = "Dear $uniq";
// Update contact's custom field with CustomValue.create
- $customValueResult = $this->callAPISuccess('CustomValue', 'create', array(
+ $customValueResult = $this->callAPISuccess('CustomValue', 'create', [
'entity_id' => $cid,
"custom_{$customFieldId}" => $uniq,
'entity_table' => "civicrm_contact",
- ));
+ ]);
- $contact = $this->callAPISuccessGetSingle('Contact', array('id' => $cid, 'return' => 'email_greeting'));
+ $contact = $this->callAPISuccessGetSingle('Contact', ['id' => $cid, 'return' => 'email_greeting']);
$this->assertEquals($testGreetingValue, $contact['email_greeting_display']);
}
}
public function testDashboardContactCreate() {
- $dashParams = array(
+ $dashParams = [
'version' => 3,
'label' => 'New Dashlet element',
'name' => 'New Dashlet element',
'url' => 'civicrm/report/list&compid=99&reset=1',
'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&context=dashletFullscreen',
- );
+ ];
$dashresult = $this->callAPISuccess('dashboard', 'create', $dashParams);
- $contact = $this->callAPISuccess('contact', 'create', array(
+ $contact = $this->callAPISuccess('contact', 'create', [
'first_name' => 'abc1',
'contact_type' => 'Individual',
'last_name' => 'xyz1',
'email' => 'abc@abc.com',
- ));
+ ]);
$oldCount = CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_dashboard_contact where contact_id = {$contact['id']} AND is_active = 1 AND dashboard_id = {$dashresult['id']}");
- $params = array(
+ $params = [
'version' => 3,
'contact_id' => $contact['id'],
'dashboard_id' => $dashresult['id'],
'is_active' => 1,
- );
+ ];
$dashboradContact = $this->callAPISuccess('dashboard_contact', 'create', $params);
$newCount = CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_dashboard_contact where contact_id = {$contact['id']} AND is_active = 1 AND dashboard_id = {$dashresult['id']}");
$this->assertEquals($oldCount + 1, $newCount);
public function testDashboardCreate() {
$oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_dashboard');
- $params = array(
+ $params = [
'label' => 'New Dashlet element',
'name' => 'New Dashlet element',
'url' => 'civicrm/report/list&reset=1&compid=99',
'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&context=dashletFullscreen',
- );
+ ];
$dashboard = $this->callAPISuccess('dashboard', 'create', $params);
$this->assertTrue(is_numeric($dashboard['id']), "In line " . __LINE__);
$this->assertTrue($dashboard['id'] > 0, "In line " . __LINE__);
*/
public function testDashboardCreateByNonAdmins() {
$loggedInContactID = $this->createLoggedInUser();
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array();
- $params = array(
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = [];
+ $params = [
'label' => 'New Dashlet element',
'name' => 'New Dashlet element',
'url' => 'civicrm/report/list&reset=1&compid=99',
'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&context=dashletFullscreen',
- );
+ ];
$dashboard = $this->callAPISuccess('dashboard', 'create', $params);
$this->assertTrue(is_numeric($dashboard['id']), "In line " . __LINE__);
$this->assertTrue($dashboard['id'] > 0, "In line " . __LINE__);
* Ensure that where is_active is specifically set to 0 is_active returns 0.
*/
public function testDashboardCreateNotActive() {
- $params = array(
+ $params = [
'label' => 'New Dashlet element',
'name' => 'New Dashlet element',
'url' => 'civicrm/report/list&reset=1&compid=99&snippet=5',
'fullscreen_url' => 'civicrm/report/list&compid=99&reset=1&snippet=5&context=dashletFullscreen',
'is_active' => 0,
- );
+ ];
$dashboard = $this->callAPISuccess('dashboard', 'create', $params);
$this->assertEquals($dashboard['values'][$dashboard['id']]['is_active'], 0);
}
* @param $oldCount
*/
public function DashboardDelete($id, $oldCount) {
- $params = array(
+ $params = [
'id' => $id,
- );
+ ];
$dashboardget = $this->callAPISuccess('dashboard', 'get', $params);
$this->assertEquals($id, $dashboardget['id']);
$dashboard = $this->callAPISuccess('dashboard', 'delete', $params);
$params['entity_id'] = 1;
$params['entity_table'] = CRM_Core_BAO_Domain::getTableName();
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
- $domContact = $this->callAPISuccess('contact', 'create', array(
+ $domContact = $this->callAPISuccess('contact', 'create', [
'contact_type' => 'Organization',
'organization_name' => 'new org',
- 'api.phone.create' => array(
+ 'api.phone.create' => [
'location_type_id' => $defaultLocationType->id,
'phone_type_id' => 1,
'phone' => '456-456',
- ),
- 'api.address.create' => array(
+ ],
+ 'api.address.create' => [
'location_type_id' => $defaultLocationType->id,
'street_address' => '45 Penny Lane',
- ),
- 'api.email.create' => array(
+ ],
+ 'api.email.create' => [
'location_type_id' => $defaultLocationType->id,
'email' => 'my@email.com',
- ),
- ));
+ ],
+ ]);
- $this->callAPISuccess('domain', 'create', array(
+ $this->callAPISuccess('domain', 'create', [
'id' => 1,
'contact_id' => $domContact['id'],
- ));
- $this->params = array(
+ ]);
+ $this->params = [
'name' => 'A-team domain',
'description' => 'domain of chaos',
'domain_version' => '4.2',
'contact_id' => $domContact['id'],
- );
+ ];
}
/**
*/
public function testGet() {
- $params = array('sequential' => 1);
+ $params = ['sequential' => 1];
$result = $this->callAPIAndDocument('domain', 'get', $params, __FUNCTION__, __FILE__);
$this->assertType('array', $result);
$this->assertArrayHasKey('id', $domain);
$this->assertArrayHasKey('name', $domain);
$this->assertArrayHasKey('domain_email', $domain);
- $this->assertEquals(array(
+ $this->assertEquals([
'phone_type' => 'Phone',
'phone' => '456-456',
- ), $domain['domain_phone']);
+ ], $domain['domain_phone']);
$this->assertArrayHasKey('domain_address', $domain);
}
* Test get function with current domain.
*/
public function testGetCurrentDomain() {
- $params = array('current_domain' => 1);
+ $params = ['current_domain' => 1];
$result = $this->callAPISuccess('domain', 'get', $params);
$this->assertType('array', $result);
*/
public function testGetCurrentDomainTwice($version) {
$this->_apiversion = $version;
- $domain = $this->callAPISuccess('domain', 'getvalue', array(
+ $domain = $this->callAPISuccess('domain', 'getvalue', [
'current_domain' => 1,
'return' => 'name',
- ));
+ ]);
$this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE));
- $domain = $this->callAPISuccess('domain', 'getvalue', array(
+ $domain = $this->callAPISuccess('domain', 'getvalue', [
'current_domain' => 1,
'return' => 'name',
- ));
+ ]);
$this->assertEquals('Default Domain Name', $domain, print_r($domain, TRUE));
}
$this->_apiversion = $version;
// First create a domain.
$domain_result = $this->callAPISuccess('domain', 'create', $this->params);
- $domain_before = $this->callAPISuccess('Domain', 'getsingle', array('id' => $domain_result['id']));
+ $domain_before = $this->callAPISuccess('Domain', 'getsingle', ['id' => $domain_result['id']]);
// Change domain name.
- $this->callAPISuccess('Domain', 'create', array(
+ $this->callAPISuccess('Domain', 'create', [
'id' => $domain_result['id'],
'name' => 'B-Team domain',
- ));
+ ]);
// Get domain again.
- $domain_after = $this->callAPISuccess('Domain', 'getsingle', array('id' => $domain_result['id']));
+ $domain_after = $this->callAPISuccess('Domain', 'getsingle', ['id' => $domain_result['id']]);
// Version should still be the same.
$this->assertEquals($domain_before['version'], $domain_after['version']);
*/
public function testCreateWithEmptyParams($version) {
$this->_apiversion = $version;
- $this->callAPIFailure('domain', 'create', array());
+ $this->callAPIFailure('domain', 'create', []);
}
}
$this->_contactID = $this->organizationCreate(NULL);
$this->_locationType = $this->locationTypeCreate(NULL);
- $this->_locationType2 = $this->locationTypeCreate(array(
+ $this->_locationType2 = $this->locationTypeCreate([
'name' => 'New Location Type 2',
'vcard_name' => 'New Location Type 2',
'description' => 'Another Location Type',
'is_active' => 1,
- ));
- $this->_params = array(
+ ]);
+ $this->_params = [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'email' => 'api@a-team.com',
'is_primary' => 1,
//TODO email_type_id
- );
+ ];
}
/**
$this->_apiversion = $version;
$params = $this->_params;
//check there are no emails to start with
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'location_type_id' => $this->_locationType->id,
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__);
$result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['id']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
+ $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]);
}
/**
unset($params['location_type_id']);
$result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']);
- $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
+ $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]);
}
/**
$email1 = $this->callAPISuccess('email', 'create', $params);
//now we check & make sure it has been set to primary
$expected = 1;
- $check = $this->callAPISuccess('email', 'getcount', array(
+ $check = $this->callAPISuccess('email', 'getcount', [
'is_primary' => 1,
'id' => $email1['id'],
- ),
+ ],
$expected
);
}
$this->_apiversion = $version;
$email1 = $this->callAPISuccess('email', 'create', $this->_params);
$email2 = $this->callAPISuccess('email', 'create', $this->_params);
- $check = $this->callAPISuccess('email', 'getcount', array(
+ $check = $this->callAPISuccess('email', 'getcount', [
'is_primary' => 1,
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertEquals(1, $check);
}
*/
public function testCreateEmailWithoutEmail($version) {
$this->_apiversion = $version;
- $result = $this->callAPIFailure('Email', 'Create', array('contact_id' => 4));
+ $result = $this->callAPIFailure('Email', 'Create', ['contact_id' => 4]);
$this->assertContains('missing', $result['error_message']);
$this->assertContains('email', $result['error_message']);
}
$result = $this->callAPISuccess('email', 'create', $this->_params);
$get = $this->callAPISuccess('email', 'create', $this->_params);
$this->assertEquals($get['count'], 1);
- $get = $this->callAPISuccess('email', 'create', $this->_params + array('debug' => 1));
+ $get = $this->callAPISuccess('email', 'create', $this->_params + ['debug' => 1]);
$this->assertEquals($get['count'], 1);
- $get = $this->callAPISuccess('email', 'create', $this->_params + array('debug' => 1, 'action' => 'get'));
+ $get = $this->callAPISuccess('email', 'create', $this->_params + ['debug' => 1, 'action' => 'get']);
$this->assertEquals($get['count'], 1);
- $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
+ $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]);
}
/**
*/
public function testDeleteEmail($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'email' => 'api@a-team.com',
'is_primary' => 1,
//TODO email_type_id
- );
+ ];
//check there are no emails to start with
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'location_type_id' => $this->_locationType->id,
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
//create one
$create = $this->callAPISuccess('email', 'create', $params);
- $result = $this->callAPIAndDocument('email', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('email', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'location_type_id' => $this->_locationType->id,
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__);
}
public function testReplaceEmail($version) {
$this->_apiversion = $version;
// check there are no emails to start with
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
// initialize email list with three emails at loc #1 and two emails at loc #2
- $replace1Params = array(
+ $replace1Params = [
'contact_id' => $this->_contactID,
- 'values' => array(
- array(
+ 'values' => [
+ [
'location_type_id' => $this->_locationType->id,
'email' => '1-1@example.com',
'is_primary' => 1,
- ),
- array(
+ ],
+ [
'location_type_id' => $this->_locationType->id,
'email' => '1-2@example.com',
'is_primary' => 0,
- ),
- array(
+ ],
+ [
'location_type_id' => $this->_locationType->id,
'email' => '1-3@example.com',
'is_primary' => 0,
- ),
- array(
+ ],
+ [
'location_type_id' => $this->_locationType2->id,
'email' => '2-1@example.com',
'is_primary' => 0,
- ),
- array(
+ ],
+ [
'location_type_id' => $this->_locationType2->id,
'email' => '2-2@example.com',
'is_primary' => 0,
- ),
- ),
- );
+ ],
+ ],
+ ];
$replace1 = $this->callAPIAndDocument('email', 'replace', $replace1Params, __FUNCTION__, __FILE__);
$this->assertEquals(5, $replace1['count']);
// check emails at location #1 or #2
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__);
// replace the subset of emails in location #1, but preserve location #2
- $replace2Params = array(
+ $replace2Params = [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
- 'values' => array(
- array(
+ 'values' => [
+ [
'email' => '1-4@example.com',
'is_primary' => 1,
- ),
- ),
- );
+ ],
+ ],
+ ];
$replace2 = $this->callAPISuccess('email', 'replace', $replace2Params);
$this->assertEquals(1, $replace2['count']);
// check emails at location #1 -- all three replaced by one
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
- ));
+ ]);
$this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__);
// check emails at location #2 -- preserve the original two
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType2->id,
- ));
+ ]);
$this->assertEquals(2, $get['count'], 'Incorrect email count at ' . __LINE__);
// replace the set of emails with an empty set
- $replace3Params = array(
+ $replace3Params = [
'contact_id' => $this->_contactID,
- 'values' => array(),
- );
+ 'values' => [],
+ ];
$replace3 = $this->callAPISuccess('email', 'replace', $replace3Params);
$this->assertEquals(0, $replace3['count']);
// check emails
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertAPISuccess($get);
$this->assertEquals(0, $get['count'], 'Incorrect email count at ' . __LINE__);
}
public function testReplaceEmailsInChain($version) {
$this->_apiversion = $version;
// check there are no emails to start with
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertAPISuccess($get);
$this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
$description = "Demonstrates use of Replace in a nested API call.";
$subfile = "NestedReplaceEmail";
// initialize email list with three emails at loc #1 and two emails at loc #2
- $getReplace1Params = array(
+ $getReplace1Params = [
'id' => $this->_contactID,
- 'api.email.replace' => array(
- 'values' => array(
- array(
+ 'api.email.replace' => [
+ 'values' => [
+ [
'location_type_id' => $this->_locationType->id,
'email' => '1-1@example.com',
'is_primary' => 1,
- ),
- array(
+ ],
+ [
'location_type_id' => $this->_locationType->id,
'email' => '1-2@example.com',
'is_primary' => 0,
- ),
- array(
+ ],
+ [
'location_type_id' => $this->_locationType->id,
'email' => '1-3@example.com',
'is_primary' => 0,
- ),
- array(
+ ],
+ [
'location_type_id' => $this->_locationType2->id,
'email' => '2-1@example.com',
'is_primary' => 0,
- ),
- array(
+ ],
+ [
'location_type_id' => $this->_locationType2->id,
'email' => '2-2@example.com',
'is_primary' => 0,
- ),
- ),
- ),
- );
+ ],
+ ],
+ ],
+ ];
$getReplace1 = $this->callAPIAndDocument('contact', 'get', $getReplace1Params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(5, $getReplace1['values'][$this->_contactID]['api.email.replace']['count']);
// check emails at location #1 or #2
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__);
// replace the subset of emails in location #1, but preserve location #2
- $getReplace2Params = array(
+ $getReplace2Params = [
'id' => $this->_contactID,
- 'api.email.replace' => array(
+ 'api.email.replace' => [
'location_type_id' => $this->_locationType->id,
- 'values' => array(
- array(
+ 'values' => [
+ [
'email' => '1-4@example.com',
'is_primary' => 1,
- ),
- ),
- ),
- );
+ ],
+ ],
+ ],
+ ];
$getReplace2 = $this->callAPISuccess('contact', 'get', $getReplace2Params);
$this->assertEquals(0, $getReplace2['values'][$this->_contactID]['api.email.replace']['is_error']);
$this->assertEquals(1, $getReplace2['values'][$this->_contactID]['api.email.replace']['count']);
// check emails at location #1 -- all three replaced by one
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
- ));
+ ]);
$this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__);
// check emails at location #2 -- preserve the original two
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType2->id,
- ));
+ ]);
$this->assertEquals(2, $get['count'], 'Incorrect email count at ' . __LINE__);
}
public function testReplaceEmailWithId($version) {
$this->_apiversion = $version;
// check there are no emails to start with
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
// initialize email address
- $replace1Params = array(
+ $replace1Params = [
'contact_id' => $this->_contactID,
- 'values' => array(
- array(
+ 'values' => [
+ [
'location_type_id' => $this->_locationType->id,
'email' => '1-1@example.com',
'is_primary' => 1,
'on_hold' => 1,
- ),
- ),
- );
+ ],
+ ],
+ ];
$replace1 = $this->callAPISuccess('email', 'replace', $replace1Params);
$this->assertEquals(1, $replace1['count']);
$emailID = array_shift($keys);
// update the email address, but preserve any other fields
- $replace2Params = array(
+ $replace2Params = [
'contact_id' => $this->_contactID,
- 'values' => array(
- array(
+ 'values' => [
+ [
'id' => $emailID,
'email' => '1-2@example.com',
- ),
- ),
- );
+ ],
+ ],
+ ];
$replace2 = $this->callAPISuccess('email', 'replace', $replace2Params);
$this->assertEquals(1, $replace2['count']);
// ensure the 'email' was updated while other fields were preserved
- $get = $this->callAPISuccess('email', 'get', array(
+ $get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
- ));
+ ]);
$this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__);
$this->assertEquals(1, $get['values'][$emailID]['is_primary']);
}
public function testEmailOnHold() {
- $params = array();
- $params_change = array();
- $params = array(
+ $params = [];
+ $params_change = [];
+ $params = [
'contact_id' => $this->_contactID,
'email' => 'api@a-team.com',
'on_hold' => '2',
- );
+ ];
$result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['id']);
// set on_hold is '0'
// if isMultipleBulkMail is active, the value in On-hold select is string
- $params_change = array(
+ $params_change = [
'id' => $result['id'],
'contact_id' => $this->_contactID,
'email' => 'api@a-team.com',
'is_primary' => 1,
'on_hold' => '0',
- );
- $result_change = $this->callAPISuccess('email', 'create', $params_change + array('action' => 'get'));
+ ];
+ $result_change = $this->callAPISuccess('email', 'create', $params_change + ['action' => 'get']);
$this->assertEquals(1, $result_change['count']);
$this->assertEquals($result['id'], $result_change['id']);
$this->assertEmpty($result_change['values'][$result_change['id']]['on_hold']);
$this->assertEquals(date('Y-m-d H:i'), date('Y-m-d H:i', strtotime($result_change['values'][$result_change['id']]['reset_date'])));
$this->assertEmpty($result_change['values'][$result_change['id']]['hold_date']);
- $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
+ $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]);
}
}
parent::setUp();
$this->useTransaction(TRUE);
- $entityParams = array('contact_id' => 1);
+ $entityParams = ['contact_id' => 1];
$this->_entity = 'EntityBatch';
$this->_entityID = $this->contributionCreate($entityParams);
$this->_batchID = $this->batchCreate();
- $this->params = array(
+ $this->params = [
'entity_id' => $this->_entityID,
'batch_id' => $this->_batchID,
'entity_table' => 'civicrm_financial_trxn',
- );
+ ];
}
public function testCreateEntityBatch() {
$result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
}
public function testDeleteEntityBatch() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => $result['id']);
+ $deleteParams = ['id' => $result['id']];
$result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testJoinEmailToContact() {
$first = 'firstthisisatest';
$last = 'lastthisisatest';
- $org = $this->organizationCreate(array('organization_name' => 'Employer of one'));
- $person1 = $this->individualCreate(array('employer_id' => $org, 'first_name' => $first, 'last_name' => $last, 'gender_id' => 1));
- $person2 = $this->individualCreate(array(), 1);
- $result = $this->callAPISuccessGetSingle('Email', array(
+ $org = $this->organizationCreate(['organization_name' => 'Employer of one']);
+ $person1 = $this->individualCreate(['employer_id' => $org, 'first_name' => $first, 'last_name' => $last, 'gender_id' => 1]);
+ $person2 = $this->individualCreate([], 1);
+ $result = $this->callAPISuccessGetSingle('Email', [
'return' => 'contact_id.employer_id.display_name,contact_id.gender_id.label',
'contact_id.last_name' => $last,
'contact_id.first_name' => $first,
- ));
+ ]);
$this->assertEquals('Employer of one', $result['contact_id.employer_id.display_name']);
$this->assertEquals('Female', $result['contact_id.gender_id.label']);
}
parent::setUp();
$individualID = $this->individualCreate();
$daoObj = new CRM_Core_DAO();
- $this->callAPISuccess('Attachment', 'create', array(
+ $this->callAPISuccess('Attachment', 'create', [
'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);
+ ]);
+ $daoObj->createTestObject('CRM_Activity_BAO_Activity', [], 1, 0);
+ $daoObj->createTestObject('CRM_Case_BAO_Case', [], 1, 0);
$entities = $this->getTagOptions();
foreach ($entities as $key => $entity) {
- $this->callAPISuccess('Tag', 'create', array(
+ $this->callAPISuccess('Tag', 'create', [
'used_for' => $key,
'name' => $entity,
'description' => $entity,
- ));
+ ]);
}
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
}
/**
* @return array
*/
public function getTagOptions() {
- $options = $this->callAPISuccess('Tag', 'getoptions', array('field' => 'used_for'));
+ $options = $this->callAPISuccess('Tag', 'getoptions', ['field' => 'used_for']);
return $options['values'];
}
* Get entities which can be tagged in data provider format.
*/
public function taggableEntities() {
- $return = array();
+ $return = [];
foreach ($this->getTagOptions() as $entity) {
- $return[] = array($entity);
+ $return[] = [$entity];
}
return $return;
}
*/
public function testThatForEntitiesEditAllContactsCanAddTags($entity) {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts', 'access CiviCRM');
- $this->callAPISuccess('EntityTag', 'create', array(
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit all contacts', 'access CiviCRM'];
+ $this->callAPISuccess('EntityTag', 'create', [
'entity_id' => 1,
'tag_id' => $entity,
'check_permissions' => TRUE,
'entity_table' => $this->getTableForTag($entity),
- ));
- $this->callAPISuccessGetCount('EntityTag', array(
+ ]);
+ $this->callAPISuccessGetCount('EntityTag', [
'entity_id' => 1,
'entity_table' => $this->getTableForTag($entity),
- ), 1);
+ ], 1);
}
/**
*/
public function testThatForEntityWithoutACLOrEditAllThereIsNoAccess($entity) {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view all contacts');
- $this->callAPIFailure('EntityTag', 'create', array(
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view all contacts'];
+ $this->callAPIFailure('EntityTag', 'create', [
'entity_id' => 1,
'tag_id' => $entity,
'check_permissions' => TRUE,
'entity_table' => $this->getTableForTag($entity),
- ));
+ ]);
}
/**
*/
public function testCheckPermissionsOffWorks($entity) {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view all contacts');
- $result = $this->callAPISuccess('EntityTag', 'create', array(
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view all contacts'];
+ $result = $this->callAPISuccess('EntityTag', 'create', [
'entity_id' => 1,
'tag_id' => $entity,
'check_permissions' => 0,
'entity_table' => $this->getTableForTag($entity),
- ));
+ ]);
$this->assertEquals(1, $result['added']);
- $this->callAPISuccessGetCount('EntityTag', array(
+ $this->callAPISuccessGetCount('EntityTag', [
'entity_id' => 1,
'entity_table' => $this->getTableForTag($entity),
'check_permissions' => 0,
- ), 1);
+ ], 1);
}
/**
*/
public function testThatForEntitiesACLApplies($entity) {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view all contacts');
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
- civicrm_api('EntityTag', 'create', array(
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view all contacts'];
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookAllResults']);
+ civicrm_api('EntityTag', 'create', [
'version' => 3,
'entity_id' => 1,
'tag_id' => $entity,
'entity_table' => $this->getTableForTag($entity),
'check_permissions' => TRUE,
- ));
- $this->callAPISuccessGetCount('EntityTag', array(
+ ]);
+ $this->callAPISuccessGetCount('EntityTag', [
'entity_id' => 1,
'entity_table' => $this->getTableForTag($entity),
- ), ($entity == 'Contacts' ? 1 : 0));
+ ], ($entity == 'Contacts' ? 1 : 0));
}
}
*
* @var array
*/
- protected $_params = array();
+ protected $_params = [];
/**
* Set up for test.
$this->useTransaction(TRUE);
$this->_individualID = $this->individualCreate();
- $this->_tag = $this->tagCreate(array('name' => 'EntityTagTest'));
+ $this->_tag = $this->tagCreate(['name' => 'EntityTagTest']);
$this->_tagID = $this->_tag['id'];
$this->_householdID = $this->houseHoldCreate();
$this->_organizationID = $this->organizationCreate();
- $this->_params = array(
+ $this->_params = [
'entity_id' => $this->_individualID,
'tag_id' => $this->_tagID,
- );
+ ];
}
/**
* These failure tests are low value and may not be worth putting in v4.
*/
public function testFailureTests() {
- $this->callAPIFailure('entity_tag', 'create', array('contact_id' => $this->_individualID),
+ $this->callAPIFailure('entity_tag', 'create', ['contact_id' => $this->_individualID],
'tag_id is a required field'
);
- $this->callAPIFailure('entity_tag', 'create', array('tag_id' => $this->_tagID),
+ $this->callAPIFailure('entity_tag', 'create', ['tag_id' => $this->_tagID],
'contact_id is a required field'
);
}
$result = $this->callAPISuccess('entity_tag', 'create', $this->_params);
$this->assertEquals($result['added'], 1);
- $params = array(
+ $params = [
'contact_id_i' => $this->_individualID,
'contact_id_o' => $this->_organizationID,
'tag_id' => $this->_tagID,
- );
+ ];
$result = $this->callAPISuccess('entity_tag', 'create', $params);
$this->assertEquals($result['added'], 1);
*/
public function testGetNoEntityID() {
$this->callAPISuccess('entity_tag', 'create', $this->_params);
- $result = $this->callAPISuccess($this->_entity, 'get', array('sequential' => 1, 'tag_id' => $this->_tagID));
+ $result = $this->callAPISuccess($this->_entity, 'get', ['sequential' => 1, 'tag_id' => $this->_tagID]);
$this->assertEquals($this->_individualID, $result['values'][0]['entity_id']);
}
$this->_apiversion = $version;
$individualEntity = $this->callAPISuccess('entity_tag', 'create', $this->_params);
- $paramsEntity = array(
+ $paramsEntity = [
'contact_id' => $this->_individualID,
- );
+ ];
$result = $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertEquals($this->_tagID, $result['values'][$result['id']]['tag_id']);
* Test tag can be added to a household.
*/
public function testHouseholdEntityCreate() {
- $params = array(
+ $params = [
'contact_id' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
$this->assertEquals($householdEntity['added'], 1);
public function testOrganizationEntityGet($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'entity_id' => $this->_organizationID,
'tag_id' => $this->_tagID,
- );
+ ];
$this->callAPISuccess('entity_tag', 'create', $params);
- $tag = $this->callAPISuccess('entity_tag', 'getsingle', array('contact_id' => $this->_organizationID));
+ $tag = $this->callAPISuccess('entity_tag', 'getsingle', ['contact_id' => $this->_organizationID]);
$this->assertEquals($this->_organizationID, $tag['entity_id']);
$this->assertEquals($this->_tagID, $tag['tag_id']);
}
* Civicrm_entity_tag_Delete methods.
*/
public function testEntityTagDeleteNoTagId() {
- $entityTagParams = array(
+ $entityTagParams = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$this->entityTagAdd($entityTagParams);
- $params = array(
+ $params = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
- );
+ ];
$result = $this->callAPISuccess('entity_tag', 'delete', $params);
}
public function testEntityTagDeleteINDHH() {
- $entityTagParams = array(
+ $entityTagParams = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$this->entityTagAdd($entityTagParams);
- $params = array(
+ $params = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$result = $this->callAPISuccess('entity_tag', 'delete', $params);
}
public function testEntityTagDeleteHH() {
- $entityTagParams = array(
+ $entityTagParams = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$this->entityTagAdd($entityTagParams);
- $params = array(
+ $params = [
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['removed'], 1);
}
public function testEntityTagDeleteHHORG() {
- $entityTagParams = array(
+ $entityTagParams = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$this->entityTagAdd($entityTagParams);
- $params = array(
+ $params = [
'contact_id_h' => $this->_householdID,
'contact_id_o' => $this->_organizationID,
'tag_id' => $this->_tagID,
- );
+ ];
$result = $this->callAPISuccess('entity_tag', 'delete', $params);
$this->assertEquals($result['removed'], 1);
}
public function testEntityTagCommonDeleteINDHH() {
- $entityTagParams = array(
+ $entityTagParams = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$this->entityTagAdd($entityTagParams);
- $params = array(
+ $params = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$result = $this->callAPISuccess('entity_tag', 'delete', $params);
$this->assertEquals($result['removed'], 2);
}
public function testEntityTagCommonDeleteHH() {
- $entityTagParams = array(
+ $entityTagParams = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$this->entityTagAdd($entityTagParams);
- $params = array(
+ $params = [
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$result = $this->callAPISuccess('entity_tag', 'delete', $params);
$this->assertEquals($result['removed'], 1);
}
public function testEntityTagCommonDeleteHHORG() {
- $entityTagParams = array(
+ $entityTagParams = [
'contact_id_i' => $this->_individualID,
'contact_id_h' => $this->_householdID,
'tag_id' => $this->_tagID,
- );
+ ];
$this->entityTagAdd($entityTagParams);
- $params = array(
+ $params = [
'contact_id_h' => $this->_householdID,
'contact_id_o' => $this->_organizationID,
'tag_id' => $this->_tagID,
- );
+ ];
$result = $this->callAPISuccess('entity_tag', 'delete', $params);
$this->assertEquals($result['removed'], 1);
}
public function testEntityTagJoin() {
- $org = $this->callAPISuccess('Contact', 'create', array(
+ $org = $this->callAPISuccess('Contact', 'create', [
'contact_type' => 'Organization',
'organization_name' => 'Org123',
- 'api.EntityTag.create' => array(
+ 'api.EntityTag.create' => [
'tag_id' => $this->_tagID,
- ),
- ));
+ ],
+ ]);
// Fetch contact info via join
- $result = $this->callAPISuccessGetSingle('EntityTag', array(
- 'return' => array("entity_id.organization_name", "tag_id.name"),
+ $result = $this->callAPISuccessGetSingle('EntityTag', [
+ 'return' => ["entity_id.organization_name", "tag_id.name"],
'entity_id' => $org['id'],
'entity_table' => "civicrm_contact",
- ));
+ ]);
$this->assertEquals('Org123', $result['entity_id.organization_name']);
$this->assertEquals('EntityTagTest', $result['tag_id.name']);
// This should return no results by restricting contact_type
- $result = $this->callAPISuccess('EntityTag', 'get', array(
- 'return' => array("entity_id.organization_name"),
+ $result = $this->callAPISuccess('EntityTag', 'get', [
+ 'return' => ["entity_id.organization_name"],
'entity_id' => $org['id'],
'entity_table' => "civicrm_contact",
'entity_id.contact_type' => "Individual",
- ));
+ ]);
$this->assertEquals(0, $result['count']);
}
parent::setUp();
$this->_apiversion = 3;
$this->_entity = 'event';
- $this->_params = array(
- array(
+ $this->_params = [
+ [
'title' => 'Annual CiviCRM meet',
'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now',
'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues',
'is_monetary' => 0,
'is_active' => 1,
'is_show_location' => 0,
- ),
- array(
+ ],
+ [
'title' => 'Annual CiviCRM meet 2',
'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now',
'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues',
'is_monetory' => 0,
'is_active' => 1,
'is_show_location' => 0,
- ),
- );
+ ],
+ ];
- $params = array(
- array(
+ $params = [
+ [
'title' => 'Annual CiviCRM meet',
'event_type_id' => 1,
'start_date' => 20081021,
- ),
- array(
+ ],
+ [
'title' => 'Annual CiviCRM meet 2',
'event_type_id' => 1,
'start_date' => 20101021,
- ),
- );
+ ],
+ ];
- $this->events = array();
- $this->eventIds = array();
+ $this->events = [];
+ $this->eventIds = [];
foreach ($params as $event) {
$result = $this->callAPISuccess('Event', 'Create', $event);
$this->_events[] = $result;
foreach ($this->eventIds as $eventId) {
$this->eventDelete($eventId);
}
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_participant',
'civicrm_event',
- );
+ ];
$this->quickCleanup($tablesToTruncate, TRUE);
}
* civicrm_event_get methods.
*/
public function testGetEventById() {
- $params = array(
+ $params = [
'id' => $this->_events[1]['id'],
- );
+ ];
$result = $this->callAPISuccess('event', 'get', $params);
$this->assertEquals($result['values'][$this->_eventIds[1]]['event_title'], 'Annual CiviCRM meet 2');
}
* Test getLocationEvents() function invokes selectWhereClause() hook
*/
public function testGetEventWithPermissionHook() {
- $address = $this->callAPISuccess('address', 'create', array(
+ $address = $this->callAPISuccess('address', 'create', [
'contact_id' => 'null',
'location_type_id' => 1,
'street_address' => '1234567',
- ));
- $params = array(
+ ]);
+ $params = [
'address_id' => $address['id'],
- );
+ ];
$result = $this->callAPISuccess('loc_block', 'create', $params);
- $params = array(
+ $params = [
'id' => $this->_events[1]['id'],
'loc_block_id' => $result['id'],
- );
+ ];
$this->callAPISuccess('Event', 'create', $params);
$result = CRM_Event_BAO_Event::getLocationEvents();
$this->assertEquals(1, count($result));
- $this->hookClass->setHook('civicrm_selectWhereClause', array($this, 'selectWhereClauseHook'));
+ $this->hookClass->setHook('civicrm_selectWhereClause', [$this, 'selectWhereClauseHook']);
$result = CRM_Event_BAO_Event::getLocationEvents();
$this->assertEquals(0, count($result));
}
public function testGetEventByEventTitle() {
- $params = array(
+ $params = [
'event_title' => 'Annual CiviCRM meet',
'sequential' => TRUE,
- );
+ ];
$result = $this->callAPIAndDocument('event', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
*/
public function testGetEventByWrongTitle($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'title' => 'No event with that title',
- );
+ ];
$result = $this->callAPISuccess('Event', 'Get', $params);
$this->assertEquals(0, $result['count']);
}
* Skip api4 - this api uses deprecated query syntax
*/
public function testGetEventByIdSort() {
- $params = array(
+ $params = [
'return.sort' => 'id ASC',
'return.max_results' => 1,
- );
+ ];
$result = $this->callAPISuccess('Event', 'Get', $params);
$this->assertEquals(1, $result['id'], ' in line ' . __LINE__);
- $params = array(
- 'options' => array(
+ $params = [
+ 'options' => [
'sort' => 'id DESC',
'limit' => 1,
- ),
- );
+ ],
+ ];
$result = $this->callAPISuccess('Event', 'Get', $params);
$this->assertAPISuccess($result, ' in line ' . __LINE__);
$this->assertEquals(2, $result['id'], ' in line ' . __LINE__);
- $params = array(
- 'options' => array(
+ $params = [
+ 'options' => [
'sort' => 'id ASC',
'limit' => 1,
- ),
- );
+ ],
+ ];
$result = $this->callAPISuccess('Event', 'Get', $params);
$this->assertEquals(1, $result['id'], ' in line ' . __LINE__);
* FIXME: Api4
*/
public function testGetIsCurrent() {
- $params = array(
+ $params = [
'isCurrent' => 1,
- );
- $currentEventParams = array(
+ ];
+ $currentEventParams = [
'start_date' => date('Y-m-d', strtotime('+ 1 day')),
'end_date' => date('Y-m-d', strtotime('+ 1 week')),
- );
+ ];
$currentEventParams = array_merge($this->_params[1], $currentEventParams);
$currentEvent = $this->callAPISuccess('Event', 'Create', $currentEventParams);
$description = "Demonstrates use of is.Current option.";
$subfile = "IsCurrentOption";
$result = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $allEvents = $this->callAPISuccess('Event', 'Get', array());
- $this->callAPISuccess('Event', 'Delete', array('id' => $currentEvent['id']));
+ $allEvents = $this->callAPISuccess('Event', 'Get', []);
+ $this->callAPISuccess('Event', 'Delete', ['id' => $currentEvent['id']]);
$this->assertEquals(1, $result['count'], 'confirm only one event found in line ' . __LINE__);
$this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__);
$this->assertEquals($currentEvent['id'], $result['id'], '');
*/
public function testGetSingleReturnIsFull() {
$contactID = $this->individualCreate();
- $params = array(
+ $params = [
'id' => $this->_eventIds[0],
'max_participants' => 1,
- );
+ ];
$result = $this->callAPISuccess('Event', 'Create', $params);
- $getEventParams = array(
+ $getEventParams = [
'id' => $this->_eventIds[0],
'return.is_full' => 1,
- );
+ ];
$currentEvent = $this->callAPISuccess('Event', 'getsingle', $getEventParams);
$description = "Demonstrates use of return is_full .";
$subfile = "IsFullOption";
$this->assertEquals(0, $currentEvent['is_full'], ' is full is set in line ' . __LINE__);
$this->assertEquals(1, $currentEvent['available_places'], 'available places is set in line ' . __LINE__);
- $participant = $this->callAPISuccess('Participant', 'create', array(
+ $participant = $this->callAPISuccess('Participant', 'create', [
'participant_status' => 1,
'role_id' => 1,
'contact_id' => $contactID,
'event_id' => $this->_eventIds[0],
- ));
+ ]);
$currentEvent = $this->callAPIAndDocument('Event', 'getsingle', $getEventParams, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(1, $currentEvent['is_full'], ' is full is set in line ' . __LINE__);
$this->assertEquals(0, $currentEvent['available_places'], 'available places is set in line ' . __LINE__);
* We need to ensure this is supported as an alias for financial_type_id.
*/
public function testCreateGetEventLegacyContributionTypeID() {
- $contributionTypeArray = array('contribution_type_id' => 3);
+ $contributionTypeArray = ['contribution_type_id' => 3];
if (isset($this->_params[0]['financial_type_id'])) {
//in case someone edits $this->_params & invalidates this test :-)
unset($this->_params[0]['financial_type_id']);
}
$result = $this->callAPISuccess('event', 'create', $this->_params[0] + $contributionTypeArray);
- $getresult = $this->callAPISuccess('event', 'get', array() + $contributionTypeArray);
+ $getresult = $this->callAPISuccess('event', 'get', [] + $contributionTypeArray);
$this->assertEquals($getresult['values'][$getresult['id']]['contribution_type_id'], 3);
$this->assertEquals($result['id'], $getresult['id']);
- $this->callAPISuccess('event', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('event', 'delete', ['id' => $result['id']]);
}
/**
// create a loc block and an event for that loc block.
$eventParams = $this->_params[0];
$eventParams['loc_bloc_id'] = '$value.id';
- $locBlockParams = array(
- 'address' => array(
+ $locBlockParams = [
+ 'address' => [
'street_address' => 'Kipdorp 24',
'postal_code' => '2000',
'city' => 'Antwerpen',
'country_id' => '1020',
'location_type_id' => '1',
- ),
+ ],
'api.Event.create' => $eventParams,
'sequential' => 1,
- );
+ ];
$createResult = $this->callAPISuccess('LocBlock', 'create', $locBlockParams);
$locBlockId = $createResult['id'];
$eventId = $createResult['values'][0]['api.Event.create']['id'];
// request the event with its loc block:
- $check = $this->callAPISuccess($this->_entity, 'getsingle', array(
+ $check = $this->callAPISuccess($this->_entity, 'getsingle', [
'id' => $eventId,
- 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
+ 'api.LocBlock.get' => ['id' => '$value.loc_block_id'],
'sequential' => 1,
- ));
+ ]);
// assert
$this->assertEquals($eventId, $check['id'], ' in line ' . __LINE__);
$this->assertEquals($locBlockId, $check['api.LocBlock.get']['id'], ' in line ' . __LINE__);
// cleanup
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $eventId));
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $eventId]);
}
/**
$params = $this->_params[0];
$result = $this->callAPISuccess($this->_entity, 'create', $params);
- $check = $this->callAPISuccess($this->_entity, 'get', array(
+ $check = $this->callAPISuccess($this->_entity, 'get', [
'id' => $result['id'],
// this chaining request should not break things:
- 'api.LocBlock.get' => array('id' => '$value.loc_block_id'),
- ));
+ 'api.LocBlock.get' => ['id' => '$value.loc_block_id'],
+ ]);
$this->assertEquals($result['id'], $check['id']);
- $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]);
}
/**
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
- $check = $this->callAPISuccess($this->_entity, 'get', array(
+ $check = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
$this->customFieldDelete($ids['custom_field_id']);
$this->customGroupDelete($ids['custom_group_id']);
- $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]);
}
/**
// Search for events having CRM-16036 as the value for this custom
// field. This should not return anything.
- $check = $this->callAPISuccess($this->_entity, 'get', array(
+ $check = $this->callAPISuccess($this->_entity, 'get', [
'custom_' . $ids['custom_field_id'] => 'CRM-16036',
- ));
+ ]);
$this->assertEquals(0, $check['count']);
// Search for events having NULL as the value for this custom
// field. This should return all events created in setUp.
- $check = $this->callAPISuccess($this->_entity, 'get', array(
- 'custom_' . $ids['custom_field_id'] => array('IS NULL' => 1),
- ));
+ $check = $this->callAPISuccess($this->_entity, 'get', [
+ 'custom_' . $ids['custom_field_id'] => ['IS NULL' => 1],
+ ]);
$this->assertGreaterThan(0, $check['count']);
public function testEventGetCustomContactRefFieldCRM16036() {
// Create some contact.
$test_contact_name = 'Contact, Test';
- $contact_save_result = $this->callAPISuccess('contact', 'create', array(
+ $contact_save_result = $this->callAPISuccess('contact', 'create', [
'sort_name' => $test_contact_name,
'contact_type' => 'Individual',
'display_name' => $test_contact_name,
- ));
+ ]);
$contact_id = $contact_save_result['id'];
// I have no clue what this $subfile is about. I just copied it from another
// Create a custom group, and add a custom contact reference field.
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
- $params = array(
+ $params = [
'custom_group_id' => $ids['custom_group_id'],
'name' => 'Worker_Lookup',
'label' => 'Worker Lookup',
'weight' => 4,
'is_searchable' => 1,
'is_active' => 1,
- );
+ ];
$customField = $this->callAPISuccess('custom_field', 'create', $params);
// Create an event, and add the contact as custom value.
$this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
// Retrieve the activity, search for the contact.
- $result = $this->callAPIAndDocument($this->_entity, 'get', array(
+ $result = $this->callAPIAndDocument($this->_entity, 'get', [
'return.custom_' . $customField['id'] => 1,
'custom_' . $customField['id'] => $contact_id,
- ), __FUNCTION__, __FILE__, $description, $subfile);
+ ], __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($test_contact_name, $result['values'][$result['id']]['custom_' . $customField['id']]);
$this->assertEquals($contact_id, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__);
$this->customFieldDelete($ids['custom_field_id']);
$this->customGroupDelete($ids['custom_group_id']);
- $this->callAPISuccess('contact', 'delete', array(
+ $this->callAPISuccess('contact', 'delete', [
'id' => $contact_id,
'skip_undelete' => TRUE,
- ));
+ ]);
}
/**
$save_result = $this->callApiSuccess($this->_entity, 'create', $params);
// Retrieve the activity, search for custom field < 'BBBB'
- $get_result = $this->callAPISuccess($this->_entity, 'get', array(
+ $get_result = $this->callAPISuccess($this->_entity, 'get', [
'return.custom_' . $ids['custom_field_id'] => 1,
- 'custom_' . $ids['custom_field_id'] => array('<=' => 'BBBB'),
- ));
+ 'custom_' . $ids['custom_field_id'] => ['<=' => 'BBBB'],
+ ]);
// Expect that we find the saved event.
$this->assertArrayKeyExists($save_result['id'], $get_result['values']);
- $this->callAPISuccess($this->_entity, 'Delete', array('id' => $save_result['id']));
+ $this->callAPISuccess($this->_entity, 'Delete', ['id' => $save_result['id']]);
}
/**
$this->callAPISuccess($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
// Retrieve the activity, and chain loc block using $value.
- $result = $this->callAPISuccess($this->_entity, 'get', array(
+ $result = $this->callAPISuccess($this->_entity, 'get', [
'custom_' . $custom_field_id => "12345",
- 'api.LocBlock.get' => array("id" => '$value.loc_block_id'),
- ));
+ 'api.LocBlock.get' => ["id" => '$value.loc_block_id'],
+ ]);
$this->assertEquals(1, $result['count']);
$this->customFieldDelete($ids['custom_field_id']);
$this->customGroupDelete($ids['custom_group_id']);
- $this->callAPISuccess('event', 'delete', array(
+ $this->callAPISuccess('event', 'delete', [
'id' => $result['id'],
'skip_undelete' => TRUE,
- ));
+ ]);
}
/**
*/
public function testCreatePaidEvent() {
//@todo alter API so that an integer is converted to an array
- $priceSetParams = array('price_set_id' => (array) 1, 'is_monetary' => 1);
+ $priceSetParams = ['price_set_id' => (array) 1, 'is_monetary' => 1];
$result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params[0], $priceSetParams));
- $event = $this->callAPISuccess('Event', 'getsingle', array('id' => $result['id'], 'return' => 'price_set_id'));
+ $event = $this->callAPISuccess('Event', 'getsingle', ['id' => $result['id'], 'return' => 'price_set_id']);
$this->assertArrayKeyExists('price_set_id', $event);
}
*/
public function testCreateEventEmptyParams($version) {
$this->_apiversion = $version;
- $params = array();
+ $params = [];
$result = $this->callAPIFailure('event', 'create', $params);
}
$this->_apiversion = $version;
$result = $this->callAPIAndDocument('Event', 'Create', $this->_params[0], __FUNCTION__, __FILE__);
$this->assertArrayHasKey('id', $result['values'][$result['id']]);
- $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id']));
- $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'Get', ['id' => $result['id']]);
+ $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]);
$this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set');
$this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set');
$this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set');
$result = $this->callAPISuccess('Event', 'Create', $this->_params[0]);
$this->assertAPISuccess($result);
$this->assertArrayHasKey('id', $result['values'][$result['id']]);
- $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id']));
- $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'Get', ['id' => $result['id']]);
+ $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]);
$this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__);
$this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__);
$this->_apiversion = $version;
$result = $this->callAPISuccess('event', 'create', $this->_params[1]);
- $params = array(
+ $params = [
'id' => $result['id'],
'max_participants' => 150,
- );
+ ];
$this->callAPISuccess('Event', 'Create', $params);
$updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__, __FILE__);
$this->assertEquals(150, $updated['values'][$result['id']]['max_participants']);
$this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']);
- $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'Delete', ['id' => $result['id']]);
}
/**
*/
public function testDeleteEmptyParams($version) {
$this->_apiversion = $version;
- $result = $this->callAPIFailure('Event', 'Delete', array());
+ $result = $this->callAPIFailure('Event', 'Delete', []);
}
/**
*/
public function testDelete($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'id' => $this->_eventIds[0],
- );
+ ];
$this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__, __FILE__);
}
*/
public function testDeleteWithEventId($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'event_id' => $this->_eventIds[0],
- );
+ ];
$result = $this->callAPISuccess('Event', 'Delete', $params);
$this->assertAPISuccess($result);
}
$this->_apiversion = $version;
$contactID = $this->individualCreate();
$this->participantCreate(
- array(
+ [
'contactID' => $contactID,
'eventID' => $this->_eventIds[0],
- )
+ ]
);
- $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds[0]));
+ $this->callAPISuccess('Event', 'Delete', ['id' => $this->_eventIds[0]]);
}
/**
*/
public function testDeleteWithWrongEventId($version) {
$this->_apiversion = $version;
- $params = array('event_id' => $this->_eventIds[0]);
+ $params = ['event_id' => $this->_eventIds[0]];
$result = $this->callAPISuccess('Event', 'Delete', $params);
// try to delete again - there's no such event anymore
- $params = array('event_id' => $this->_eventIds[0]);
+ $params = ['event_id' => $this->_eventIds[0]];
$result = $this->callAPIFailure('Event', 'Delete', $params);
}
$this->_apiversion = $version;
$this->callAPISuccess('event', 'create', $this->_params[1]);
- $getParams = array(
+ $getParams = [
'sequential' => 1,
- );
+ ];
$result = $this->callAPISuccess('event', 'get', $getParams);
$this->assertEquals($result['count'], 3);
$res = $result['values'][0];
*/
public function testSearch($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'event_type_id' => 1,
'return.title' => 1,
'return.id' => 1,
'return.start_date' => 1,
- );
+ ];
$result = $this->callAPISuccess('event', 'get', $params);
$this->assertEquals($result['values'][$this->_eventIds[0]]['id'], $this->_eventIds[0]);
*/
public function testSearchWithOffsetAndMaxResults() {
$maxEvents = 5;
- $events = array();
+ $events = [];
while ($maxEvents > 0) {
- $params = array(
+ $params = [
'title' => 'Test Event' . $maxEvents,
'event_type_id' => 2,
'start_date' => 20081021,
- );
+ ];
$events[$maxEvents] = $this->callAPISuccess('event', 'create', $params);
$maxEvents--;
}
- $params = array(
+ $params = [
'event_type_id' => 2,
'return.id' => 1,
'return.title' => 1,
'return.offset' => 2,
'return.max_results' => 2,
- );
+ ];
$result = $this->callAPISuccess('event', 'get', $params);
$this->assertAPISuccess($result);
$this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__);
*/
public function testEventCreationPermissions($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'event_type_id' => 1,
'start_date' => '2010-10-03',
'title' => 'le cake is a tie',
'check_permissions' => TRUE,
- );
+ ];
$config = CRM_Core_Config::singleton();
- $config->userPermissionClass->permissions = array('access CiviCRM');
+ $config->userPermissionClass->permissions = ['access CiviCRM'];
$result = $this->callAPIFailure('event', 'create', $params, 'failed');
- $config->userPermissionClass->permissions = array(
+ $config->userPermissionClass->permissions = [
'access CiviEvent',
'edit all events',
'access CiviCRM',
- );
+ ];
$result = $this->callAPISuccess('event', 'create', $params);
}
public function testgetfields($version) {
$this->_apiversion = $version;
$description = "Demonstrate use of getfields to interrogate api.";
- $params = array('action' => 'create');
+ $params = ['action' => 'create'];
$result = $this->callAPISuccess('event', 'getfields', $params);
$this->assertEquals('is_active', $result['values']['is_active']['name']);
}
*/
public function testgetfieldsRest() {
$description = "Demonstrate use of getfields to interrogate api.";
- $params = array('api_action' => 'create');
+ $params = ['api_action' => 'create'];
$result = $this->callAPISuccess('event', 'getfields', $params);
$this->assertEquals(1, $result['values']['is_active']['api.default']);
}
*/
public function testgetfieldsGet() {
$description = "Demonstrate use of getfields to interrogate api.";
- $params = array('action' => 'get');
+ $params = ['action' => 'get'];
$result = $this->callAPISuccess('event', 'getfields', $params);
$this->assertEquals('title', $result['values']['event_title']['name']);
}
*/
public function testgetfieldsDelete() {
$description = "Demonstrate use of getfields to interrogate api.";
- $params = array('action' => 'delete');
+ $params = ['action' => 'delete'];
$result = $this->callAPISuccess('event', 'getfields', $params);
$this->assertEquals(1, $result['values']['id']['api.required']);
}
*/
public function testCreateFromTemplate($version) {
$this->_apiversion = $version;
- $templateParams = array(
+ $templateParams = [
'summary' => 'Sign up now to learn the results of this unit test',
'description' => 'This event is created from a template, so all the values should be the same as the original ones.',
'event_type_id' => 1,
'registration_end_date' => '2018-06-25 17:00:00',
'max_participants' => 100,
'event_full_text' => 'Sorry! We are already full',
- );
- $templateResult = $this->callAPISuccess('Event', 'create', array('is_template' => 1, 'template_title' => 'Test tpl') + $templateParams);
- $eventResult = $this->callAPISuccess('Event', 'create', array(
+ ];
+ $templateResult = $this->callAPISuccess('Event', 'create', ['is_template' => 1, 'template_title' => 'Test tpl'] + $templateParams);
+ $eventResult = $this->callAPISuccess('Event', 'create', [
'template_id' => $templateResult['id'],
'title' => 'Clone1',
'start_date' => '2018-06-25 16:00:00',
- ));
- $eventResult = $this->callAPISuccess('Event', 'getsingle', array('id' => $eventResult['id']));
+ ]);
+ $eventResult = $this->callAPISuccess('Event', 'getsingle', ['id' => $eventResult['id']]);
foreach ($templateParams as $param => $value) {
$this->assertEquals($value, $eventResult[$param]);
}
* Test getremote.
*/
public function testGetremote() {
- $result = $this->callAPISuccess('extension', 'getremote', array());
+ $result = $this->callAPISuccess('extension', 'getremote', []);
$this->assertEquals('org.civicrm.module.cividiscount', $result['values'][0]['key']);
$this->assertEquals('module', $result['values'][0]['type']);
$this->assertEquals('CiviDiscount', $result['values'][0]['name']);
* CRM-20532
*/
public function testExtensionGetSingleExtension() {
- $result = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.moduletest'));
+ $result = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.moduletest']);
$this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']);
$this->assertEquals('module', $result['values'][$result['id']]['type']);
$this->assertEquals('test_extension_manager_moduletest', $result['values'][$result['id']]['name']);
* CRM-20532
*/
public function testSingleExtensionGetWithReturnFields() {
- $result = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.moduletest', 'return' => array('name', 'status', 'key')));
+ $result = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.moduletest', 'return' => ['name', 'status', 'key']]);
$this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']);
$this->assertFalse(isset($result['values'][$result['id']]['type']));
$this->assertEquals('test_extension_manager_moduletest', $result['values'][$result['id']]['name']);
* CRM-20532
*/
public function testExtensionGet() {
- $result = $this->callAPISuccess('extension', 'get', array());
- $testExtensionResult = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.paymenttest'));
+ $result = $this->callAPISuccess('extension', 'get', []);
+ $testExtensionResult = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.paymenttest']);
$this->assertNotNull($result['values'][$testExtensionResult['id']]['typeInfo']);
$this->assertTrue($result['count'] >= 6);
}
* Filtering by status=installed or status=uninstalled should produce different results.
*/
public function testExtensionGetByStatus() {
- $installed = $this->callAPISuccess('extension', 'get', array('status' => 'installed'));
- $uninstalled = $this->callAPISuccess('extension', 'get', array('status' => 'uninstalled'));
+ $installed = $this->callAPISuccess('extension', 'get', ['status' => 'installed']);
+ $uninstalled = $this->callAPISuccess('extension', 'get', ['status' => 'uninstalled']);
// If the filter works, then results should be strictly independent.
$this->assertEquals(
- array(),
+ [],
array_intersect(
CRM_Utils_Array::collect('key', $installed['values']),
CRM_Utils_Array::collect('key', $uninstalled['values'])
)
);
- $all = $this->callAPISuccess('extension', 'get', array());
+ $all = $this->callAPISuccess('extension', 'get', []);
$this->assertEquals($all['count'], $installed['count'] + $uninstalled['count']);
}
public function testGetMultipleExtensions() {
- $result = $this->callAPISuccess('extension', 'get', array('key' => array('test.extension.manager.paymenttest', 'test.extension.manager.moduletest')));
+ $result = $this->callAPISuccess('extension', 'get', ['key' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]);
$this->assertEquals(2, $result['count']);
}
* Test that extension get works with api request with parameter full_name as build by api explorer.
*/
public function testGetMultipleExtensionsApiExplorer() {
- $result = $this->callAPISuccess('extension', 'get', array('full_name' => array('test.extension.manager.paymenttest', 'test.extension.manager.moduletest')));
+ $result = $this->callAPISuccess('extension', 'get', ['full_name' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]);
$this->assertEquals(2, $result['count']);
}
* Test that extension get can be filtered by id.
*/
public function testGetExtensionByID() {
- $result = $this->callAPISuccess('extension', 'get', array('id' => 2, 'return' => array('label')));
+ $result = $this->callAPISuccess('extension', 'get', ['id' => 2, 'return' => ['label']]);
$this->assertEquals(1, $result['count']);
}
protected $_entity = 'Contribution';
public $debug = 0;
protected $_params;
- protected $_ids = array();
- protected $_pageParams = array();
+ protected $_ids = [];
+ protected $_pageParams = [];
/**
* Parameters to create payment processor.
*
* @var array
*/
- protected $_processorParams = array();
+ protected $_processorParams = [];
/**
* ID of created event.
$this->_apiversion = 3;
$this->_individualId = $this->individualCreate();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'net_amount' => 95.00,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
- $this->_processorParams = array(
+ ];
+ $this->_processorParams = [
'domain_id' => 1,
'name' => 'Dummy',
'payment_processor_type_id' => 10,
'url_site' => 'http://dummy.com',
'url_recur' => 'http://dummy.com',
'billing_mode' => 1,
- );
- $this->_pageParams = array(
+ ];
+ $this->_pageParams = [
'title' => 'Test Contribution Page',
'financial_type_id' => 1,
'currency' => 'USD',
'is_allow_other_amount' => 1,
'min_amount' => 10,
'max_amount' => 1000,
- );
+ ];
}
/**
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
- $this->quickCleanup(array('civicrm_uf_match'));
+ $this->quickCleanup(['civicrm_uf_match']);
$this->disableFinancialACLs();
parent::tearDown();
}
*/
public function testCreateACLContribution() {
$this->enableFinancialACLs();
- $p = array(
+ $p = [
'contact_id' => $this->_individualId,
'receive_date' => '2010-01-20',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 1,
'check_permissions' => TRUE,
- );
+ ];
$this->setPermissions([
'access CiviCRM',
$contribution = $this->callAPISuccess('contribution', 'create', $p);
- $params = array(
+ $params = [
'contribution_id' => $contribution['id'],
- );
+ ];
$this->setPermissions([
'access CiviCRM',
$this->assertEquals($contribution['values'][$contribution['id']]['invoice_id'], 78910);
$this->assertEquals($contribution['values'][$contribution['id']]['contribution_source'], 'SSF');
$this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution['id'],
- ));
+ ]);
}
/**
$contribution = $this->callAPISuccess('Contribution', 'create', $this->_params);
$this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['financial_type_id' => 'Member Dues']));
- $params = array(
+ $params = [
'id' => $contribution['id'],
'check_permissions' => TRUE,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'get', $params);
$this->assertEquals($contribution['count'], 0);
*/
public function testCreateACLContributionChainedLineItems() {
$this->enableFinancialACLs();
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'source' => 'SSF',
'contribution_status_id' => 1,
'check_permissions' => TRUE,
- 'api.line_item.create' => array(
- array(
+ 'api.line_item.create' => [
+ [
'price_field_id' => 1,
'qty' => 2,
'line_total' => '20',
'unit_price' => '10',
'financial_type_id' => 1,
- ),
- array(
+ ],
+ [
'price_field_id' => 1,
'qty' => 1,
'line_total' => '80',
'unit_price' => '80',
'financial_type_id' => 2,
- ),
- ),
- );
+ ],
+ ],
+ ];
$this->setPermissions([
'access CiviCRM',
$this->callAPIFailure('contribution', 'create', $params, 'Error in call to LineItem_create : You do not have permission to create this line item');
// Check that the entire contribution has rolled back.
- $contribution = $this->callAPISuccess('contribution', 'get', array());
+ $contribution = $this->callAPISuccess('contribution', 'get', []);
$this->assertEquals(0, $contribution['count']);
$this->addFinancialAclPermissions([
]);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $lineItemParams = array(
+ $lineItemParams = [
'contribution_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
- );
+ ];
$lineItems = $this->callAPISuccess('LineItem', 'get', $lineItemParams);
$this->assertEquals(3, $lineItems['count']);
$this->assertEquals(100.00, $lineItems['values'][3]['line_total']);
$this->assertEquals(1, $lineItems['values'][4]['financial_type_id']);
$this->assertEquals(2, $lineItems['values'][5]['financial_type_id']);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution['id'],
- ));
+ ]);
}
/**
$this->enableFinancialACLs();
$contribution = $this->callAPISuccess('Contribution', 'create', $this->_params);
- $params = array(
+ $params = [
'id' => $contribution['id'],
'check_permissions' => TRUE,
'total_amount' => 200.00,
- );
+ ];
$this->setPermissions([
'access CiviCRM',
]);
$contribution = $this->callAPISuccess('Contribution', 'create', $this->_params);
- $params = array(
+ $params = [
'contribution_id' => $contribution['id'],
'check_permissions' => TRUE,
- );
+ ];
$this->addPermissions(['delete in CiviContribute']);
$this->callAPIFailure('Contribution', 'delete', $params);
class api_v3_GrantTest extends CiviUnitTestCase {
protected $_apiversion = 3;
protected $params;
- protected $ids = array();
+ protected $ids = [];
protected $_entity = 'Grant';
public $DBResetRequired = FALSE;
public function setUp() {
parent::setUp();
$this->ids['contact'][0] = $this->individualCreate();
- $this->params = array(
+ $this->params = [
'contact_id' => $this->ids['contact'][0],
'application_received_date' => 'now',
'decision_date' => 'next Monday',
'rationale' => 'Just Because',
'currency' => 'USD',
'grant_type_id' => 1,
- );
+ ];
}
/**
public function tearDown() {
foreach ($this->ids as $entity => $entities) {
foreach ($entities as $id) {
- $this->callAPISuccess($entity, 'delete', array('id' => $id));
+ $this->callAPISuccess($entity, 'delete', ['id' => $id]);
}
}
$this->quickCleanup(['civicrm_grant']);
* We want to ensure they are saved with separators as appropriate
*/
public function testCreateCustomCheckboxGrant() {
- $ids = array();
- $result = $this->customGroupCreate(array('extends' => 'Grant'));
+ $ids = [];
+ $result = $this->customGroupCreate(['extends' => 'Grant']);
$ids['custom_group_id'] = $result['id'];
$customTable = $result['values'][$result['id']]['table_name'];
- $result = $this->customFieldCreate(array(
+ $result = $this->customFieldCreate([
'html_type' => 'CheckBox',
'custom_group_id' => $ids['custom_group_id'],
- 'option_values' => array(
- array('label' => 'my valley', 'value' => 'valley', 'is_active' => TRUE, 'weight' => 1),
- array('label' => 'my goat', 'value' => 'goat', 'is_active' => TRUE, 'weight' => 2),
- array('label' => 'mohair', 'value' => 'wool', 'is_active' => TRUE, 'weight' => 3),
- array('label' => 'hungry', 'value' => '', 'is_active' => TRUE, 'weight' => 3),
- ),
- ));
+ 'option_values' => [
+ ['label' => 'my valley', 'value' => 'valley', 'is_active' => TRUE, 'weight' => 1],
+ ['label' => 'my goat', 'value' => 'goat', 'is_active' => TRUE, 'weight' => 2],
+ ['label' => 'mohair', 'value' => 'wool', 'is_active' => TRUE, 'weight' => 3],
+ ['label' => 'hungry', 'value' => '', 'is_active' => TRUE, 'weight' => 3],
+ ],
+ ]);
$columnName = $result['values'][$result['id']]['column_name'];
$ids['custom_field_id'] = $result['id'];
$customFieldLabel = 'custom_' . $ids['custom_field_id'];
$this->assertEquals($expectedValue, $savedValue);
//& an array for good measure
- $this->params[$customFieldLabel] = array('valley', 'goat');
+ $this->params[$customFieldLabel] = ['valley', 'goat'];
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
$savedValue = CRM_Core_DAO::singleValueQuery("SELECT {$columnName} FROM $customTable WHERE entity_id = {$result['id']}");
$this->assertEquals($expectedValue, $savedValue);
public function testGetGrant() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
$this->ids['grant'][0] = $result['id'];
- $result = $this->callAPIAndDocument($this->_entity, 'get', array('rationale' => 'Just Because'), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument($this->_entity, 'get', ['rationale' => 'Just Because'], __FUNCTION__, __FILE__);
$this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
$this->assertEquals(1, $result['count']);
}
public function testDeleteGrant() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $result = $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument($this->_entity, 'delete', ['id' => $result['id']], __FUNCTION__, __FILE__);
$this->assertAPISuccess($result);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
* Test Grant status with `0` value.
*/
public function testGrantWithZeroStatus() {
- $params = array(
+ $params = [
'action' => 'create',
'grant_type_id' => "Emergency",
'amount_total' => 100,
'contact_id' => "1",
'status_id' => 0,
'id' => 1,
- );
+ ];
$validation = $this->callAPISuccess('Grant', 'validate', $params);
- $expectedOut = array(
- 'status_id' => array(
+ $expectedOut = [
+ 'status_id' => [
'message' => "'0' is not a valid option for field status_id",
'code' => "incorrect_value",
- ),
- );
+ ],
+ ];
$this->assertEquals($validation['values'][0], $expectedOut);
}
$this->_groupId1 = $this->groupCreate();
- $this->callAPISuccess('group_contact', 'create', array(
+ $this->callAPISuccess('group_contact', 'create', [
'contact_id' => $this->_contactId,
'group_id' => $this->_groupId1,
- ));
+ ]);
- $this->_groupId2 = $this->groupCreate(array(
+ $this->_groupId2 = $this->groupCreate([
'name' => 'Test Group 2',
'domain_id' => 1,
'title' => 'New Test Group2 Created',
'description' => 'New Test Group2 Created',
'is_active' => 1,
'visibility' => 'User and User Admin Only',
- ));
+ ]);
- $this->_group = array(
- $this->_groupId1 => array(
+ $this->_group = [
+ $this->_groupId1 => [
'title' => 'New Test Group Created',
'visibility' => 'Public Pages',
'in_method' => 'API',
- ),
- $this->_groupId2 => array(
+ ],
+ $this->_groupId2 => [
'title' => 'New Test Group2 Created',
'visibility' => 'User and User Admin Only',
'in_method' => 'API',
- ),
- );
+ ],
+ ];
}
/**
* Test GroupContact.get by ID.
*/
public function testGet() {
- $params = array(
+ $params = [
'contact_id' => $this->_contactId,
- );
+ ];
$result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__);
foreach ($result['values'] as $v) {
$this->assertEquals($v['title'], $this->_group[$v['group_id']]['title']);
public function testGetGroupID() {
$description = "Get all from group and display contacts.";
$subfile = "GetWithGroupID";
- $params = array(
+ $params = [
'group_id' => $this->_groupId1,
'api.group.get' => 1,
'sequential' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
foreach ($result['values'][0]['api.group.get']['values'] as $values) {
$key = $values['id'];
}
public function testCreateWithEmptyParams() {
- $params = array();
+ $params = [];
$groups = $this->callAPIFailure('group_contact', 'create', $params);
$this->assertEquals($groups['error_message'],
'Mandatory key(s) missing from params array: group_id, contact_id'
}
public function testCreateWithoutGroupIdParams() {
- $params = array(
+ $params = [
'contact_id' => $this->_contactId,
- );
+ ];
$groups = $this->callAPIFailure('group_contact', 'create', $params);
$this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
}
public function testCreateWithoutContactIdParams() {
- $params = array(
+ $params = [
'group_id' => $this->_groupId1,
- );
+ ];
$groups = $this->callAPIFailure('group_contact', 'create', $params);
$this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
}
public function testCreate() {
- $cont = array(
+ $cont = [
'first_name' => 'Amiteshwar',
'middle_name' => 'L.',
'last_name' => 'Prasad',
'suffix_id' => 3,
'email' => 'amiteshwar.prasad@civicrm.org',
'contact_type' => 'Individual',
- );
+ ];
$this->_contactId1 = $this->individualCreate($cont);
- $params = array(
+ $params = [
'contact_id' => $this->_contactId,
'contact_id.2' => $this->_contactId1,
'group_id' => $this->_groupId1,
- );
+ ];
$result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['not_added'], 1);
* Test GroupContact.delete by contact+group ID.
*/
public function testDelete() {
- $params = array(
+ $params = [
'contact_id' => $this->_contactId,
'group_id' => $this->_groupId1,
- );
+ ];
$result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['removed'], 1);
}
public function testDeletePermanent() {
- $result = $this->callAPISuccess('group_contact', 'get', array('contact_id' => $this->_contactId));
- $params = array(
+ $result = $this->callAPISuccess('group_contact', 'get', ['contact_id' => $this->_contactId]);
+ $params = [
'id' => $result['id'],
'skip_undelete' => TRUE,
- );
+ ];
$this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__);
$result = $this->callAPISuccess('group_contact', 'get', $params);
$this->assertEquals(0, $result['count']);
*
*/
public function testDeleteWithId() {
- $groupContactParams = array(
+ $groupContactParams = [
'contact_id' => $this->_contactId,
'group_id' => $this->_groupId1,
- );
+ ];
$groupContact = $this->callAPISuccess('group_contact', 'get', $groupContactParams);
- $params = array(
+ $params = [
'id' => $groupContact['id'],
'status' => 'Removed',
- );
+ ];
$result = $this->callAPISuccess('group_contact', 'delete', $params);
$this->assertEquals($result['removed'], 1);
$this->assertEquals($result['total_count'], 1);
*
*/
public function testDeleteAndReAddWithId() {
- $groupContactParams = array(
+ $groupContactParams = [
'contact_id' => $this->_contactId,
'group_id' => $this->_groupId1,
- );
+ ];
$groupContact = $this->callAPISuccess('group_contact', 'get', $groupContactParams);
- $params = array(
+ $params = [
'id' => $groupContact['id'],
'status' => 'Removed',
- );
+ ];
$result = $this->callAPISuccess('group_contact', 'delete', $params);
$this->assertEquals($result['removed'], 1);
$this->assertEquals($result['total_count'], 1);
- $params = array_merge($params, array('status' => 'Added'));
+ $params = array_merge($params, ['status' => 'Added']);
$result2 = $this->callAPISuccess('group_contact', 'delete', $params);
$this->assertEquals($result2['added'], 1);
$this->assertEquals($result2['total_count'], 1);
* CRM-19979 test that group cotnact delete action works when contact is in status of pendin.
*/
public function testDeleteWithPending() {
- $groupId3 = $this->groupCreate(array(
+ $groupId3 = $this->groupCreate([
'name' => 'Test Group 3',
'domain_id' => 1,
'title' => 'New Test Group3 Created',
'description' => 'New Test Group3 Created',
'is_active' => 1,
'visibility' => 'User and User Admin Only',
- ));
- $groupContactCreateParams = array(
+ ]);
+ $groupContactCreateParams = [
'contact_id' => $this->_contactId,
'group_id' => $groupId3,
'status' => 'Pending',
- );
+ ];
$groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
$groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams);
- $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'status' => 'Removed'));
- $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'skip_undelete' => TRUE));
- $this->callAPISuccess('group', 'delete', array('id' => $groupId3));
+ $this->callAPISuccess('groupContact', 'delete', ['id' => $groupGetContact['id'], 'status' => 'Removed']);
+ $this->callAPISuccess('groupContact', 'delete', ['id' => $groupGetContact['id'], 'skip_undelete' => TRUE]);
+ $this->callAPISuccess('group', 'delete', ['id' => $groupId3]);
}
/**
* CRM-19979 test that group cotnact delete action works when contact is in status of pendin and is a permanent delete.
*/
public function testPermanentDeleteWithPending() {
- $groupId3 = $this->groupCreate(array(
+ $groupId3 = $this->groupCreate([
'name' => 'Test Group 3',
'domain_id' => 1,
'title' => 'New Test Group3 Created',
'description' => 'New Test Group3 Created',
'is_active' => 1,
'visibility' => 'User and User Admin Only',
- ));
- $groupContactCreateParams = array(
+ ]);
+ $groupContactCreateParams = [
'contact_id' => $this->_contactId,
'group_id' => $groupId3,
'status' => 'Pending',
- );
+ ];
$groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
$groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams);
- $this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'skip_undelete' => TRUE));
- $this->callAPISuccess('group', 'delete', array('id' => $groupId3));
+ $this->callAPISuccess('groupContact', 'delete', ['id' => $groupGetContact['id'], 'skip_undelete' => TRUE]);
+ $this->callAPISuccess('group', 'delete', ['id' => $groupId3]);
}
/**
* Test illustrates this (& ensures once fixed it will stay fixed).
*/
public function testAccurateCountWithSmartGroups() {
- $childGroupID = $this->groupCreate(array(
+ $childGroupID = $this->groupCreate([
'name' => 'Child group',
'domain_id' => 1,
'title' => 'Child group',
'is_active' => 1,
'parents' => $this->_groupId1,
'visibility' => 'User and User Admin Only',
- ));
+ ]);
- $params = array(
+ $params = [
'name' => 'Individuals',
'title' => 'Individuals',
'is_active' => 1,
'parents' => $this->_groupId1,
- 'formValues' => array('contact_type' => 'Goat'),
- );
+ 'formValues' => ['contact_type' => 'Goat'],
+ ];
$smartGroup2 = CRM_Contact_BAO_Group::createSmartGroup($params);
- $this->callAPISuccess('GroupContact', 'create', array('contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $this->_groupId2));
- $this->callAPISuccess('GroupContact', 'create', array('contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $smartGroup2->id));
- $this->callAPISuccess('GroupContact', 'create', array('contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $childGroupID));
- $groups = $this->callAPISuccess('GroupContact', 'get', array('contact_id' => $this->_contactId));
+ $this->callAPISuccess('GroupContact', 'create', ['contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $this->_groupId2]);
+ $this->callAPISuccess('GroupContact', 'create', ['contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $smartGroup2->id]);
+ $this->callAPISuccess('GroupContact', 'create', ['contact_id' => $this->_contactId, 'status' => 'Added', 'group_id' => $childGroupID]);
+ $groups = $this->callAPISuccess('GroupContact', 'get', ['contact_id' => $this->_contactId]);
// Although the contact is actually hard-added to 4 groups the smart groups are conventionally not returned by the api or displayed
// on the main part of the groups tab on the contact (which calls the same function. So, 3 groups is an OK number to return.
*/
public function testGroupOrganizationGet() {
- $params = array(
+ $params = [
'organization_id' => $this->_orgID,
'group_id' => $this->_groupID,
- );
+ ];
$result = $this->callAPISuccess('group_organization', 'create', $params);
- $paramsGet = array(
+ $paramsGet = [
'organization_id' => $result['id'],
- );
+ ];
$result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__);
}
* Test civicrm_group_organization_get with group_id.
*/
public function testGroupOrganizationGetWithGroupId() {
- $createParams = array(
+ $createParams = [
'organization_id' => $this->_orgID,
'group_id' => $this->_groupID,
- );
+ ];
$createResult = $this->callAPISuccess('group_organization', 'create', $createParams);
- $getParams = array(
+ $getParams = [
'group_id' => $this->_groupID,
'sequential' => 1,
- );
+ ];
$getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
$this->assertEquals($createResult['values'][$createResult['id']], $getResult['values'][0]);
}
* Test civicrm_group_organization_get with empty params.
*/
public function testGroupOrganizationGetWithEmptyParams() {
- $params = array();
+ $params = [];
$result = $this->callAPISuccess('group_organization', 'get', $params);
$this->assertAPISuccess($result);
* Test civicrm_group_organization_get invalid keys.
*/
public function testGroupOrganizationGetWithInvalidKeys() {
- $params = array(
+ $params = [
'invalid_key' => 1,
- );
+ ];
$result = $this->callAPISuccess('group_organization', 'get', $params);
$this->assertAPISuccess($result);
* Check with valid params.
*/
public function testGroupOrganizationCreate() {
- $params = array(
+ $params = [
'organization_id' => $this->_orgID,
'group_id' => $this->_groupID,
- );
+ ];
$result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__);
}
* CRM-13841 - Load Group Org before save
*/
public function testGroupOrganizationCreateTwice() {
- $params = array(
+ $params = [
'organization_id' => $this->_orgID,
'group_id' => $this->_groupID,
- );
+ ];
$result = $this->callAPISuccess('group_organization', 'create', $params);
$result2 = $this->callAPISuccess('group_organization', 'create', $params);
$this->assertEquals($result['values'], $result2['values']);
* Check with empty params array.
*/
public function testGroupOrganizationCreateWithEmptyParams() {
- $params = array();
+ $params = [];
$result = $this->callAPIFailure('group_organization', 'create', $params);
$this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
}
* Check with invalid params keys.
*/
public function testGroupOrganizationCreateWithInvalidKeys() {
- $params = array(
+ $params = [
'invalid_key' => 1,
- );
+ ];
$result = $this->callAPIFailure('group_organization', 'create', $params);
$this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
}
* Test civicrm_group_organization_remove with empty params.
*/
public function testGroupOrganizationDeleteWithEmptyParams() {
- $params = array();
+ $params = [];
$result = $this->callAPIFailure('group_organization', 'delete', $params);
$this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
}
* Test civicrm_group_organization_remove with valid params.
*/
public function testGroupOrganizationDelete() {
- $paramsC = array(
+ $paramsC = [
'organization_id' => $this->_orgID,
'group_id' => $this->_groupID,
- );
+ ];
$result = $this->callAPISuccess('group_organization', 'create', $paramsC);
- $params = array(
+ $params = [
'id' => $result['id'],
- );
+ ];
$result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__);
}
* Test civicrm_group_organization_remove with invalid params key.
*/
public function testGroupOrganizationDeleteWithInvalidKey() {
- $paramsDelete = array(
+ $paramsDelete = [
'invalid_key' => 1,
- );
+ ];
$result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
$this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
}
public $DBResetRequired = FALSE;
public $_entity = 'Job';
- public $_params = array();
+ public $_params = [];
private $_groupID;
private $_email;
CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0;
$this->_groupID = $this->groupCreate();
$this->_email = 'test@test.test';
- $this->_params = array(
+ $this->_params = [
'subject' => 'Accidents in cars cause children',
'body_text' => 'BEWARE children need regular infusions of toys. Santa knows your {domain.address}. There is no {action.optOutUrl}.',
'name' => 'mailing name',
'created_id' => 1,
- 'groups' => array('include' => array($this->_groupID)),
+ 'groups' => ['include' => [$this->_groupID]],
'scheduled_date' => 'now',
- );
- $this->defaultSettings = array(
+ ];
+ $this->defaultSettings = [
// int, #mailings to send
'mailings' => 1,
// int, #contacts to receive mailing
'mailerJobSize' => 0,
// int, microseconds separating messages
'mailThrottleTime' => 0,
- );
+ ];
$this->_mut = new CiviMailUtils($this, TRUE);
- $this->callAPISuccess('mail_settings', 'get', array('api.mail_settings.create' => array('domain' => 'chaos.org')));
+ $this->callAPISuccess('mail_settings', 'get', ['api.mail_settings.create' => ['domain' => 'chaos.org']]);
}
/**
public function testBasic() {
$this->createContactsInGroup(10, $this->_groupID);
- Civi::settings()->add(array(
+ Civi::settings()->add([
'mailerBatchLimit' => 2,
- ));
+ ]);
$this->callAPISuccess('mailing', 'create', $this->_params);
- $this->_mut->assertRecipients(array());
- $this->callAPISuccess('job', 'process_mailing', array());
+ $this->_mut->assertRecipients([]);
+ $this->callAPISuccess('job', 'process_mailing', []);
$this->_mut->assertRecipients($this->getRecipients(1, 2));
}
*/
public function testPauseAndResumeMailing() {
$this->createContactsInGroup(10, $this->_groupID);
- Civi::settings()->add(array(
+ Civi::settings()->add([
'mailerBatchLimit' => 2,
- ));
+ ]);
$this->_mut->clearMessages();
//Create a test mailing and check if the status is set to Scheduled.
$result = $this->callAPISuccess('mailing', 'create', $this->_params);
- $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
+ $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]);
$this->assertEquals('Scheduled', $jobs['values'][$jobs['id']]['status']);
//Pause the mailing.
CRM_Mailing_BAO_MailingJob::pause($result['id']);
- $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
+ $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]);
$this->assertEquals('Paused', $jobs['values'][$jobs['id']]['status']);
//Verify if Paused mailing isn't considered in process_mailing job.
- $this->callAPISuccess('job', 'process_mailing', array());
+ $this->callAPISuccess('job', 'process_mailing', []);
//Check if mail log is empty.
$this->_mut->assertMailLogEmpty();
- $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
+ $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]);
$this->assertEquals('Paused', $jobs['values'][$jobs['id']]['status']);
//Resume should set the status back to Scheduled.
CRM_Mailing_BAO_MailingJob::resume($result['id']);
- $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
+ $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]);
$this->assertEquals('Scheduled', $jobs['values'][$jobs['id']]['status']);
//Execute the job and it should send the mailing to the recipients now.
- $this->callAPISuccess('job', 'process_mailing', array());
+ $this->callAPISuccess('job', 'process_mailing', []);
$this->_mut->assertRecipients($this->getRecipients(1, 2));
}
*/
public function testMailNonProductionRun() {
// Test in non-production mode.
- $params = array(
+ $params = [
'environment' => 'Staging',
- );
+ ];
$this->callAPISuccess('Setting', 'create', $params);
//Assert if outbound mail is disabled.
$mailingBackend = Civi::settings()->get('mailing_backend');
$this->assertEquals($mailingBackend['outBound_option'], CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED);
$this->createContactsInGroup(10, $this->_groupID);
- Civi::settings()->add(array(
+ Civi::settings()->add([
'mailerBatchLimit' => 2,
- ));
+ ]);
$this->callAPISuccess('mailing', 'create', $this->_params);
- $this->_mut->assertRecipients(array());
+ $this->_mut->assertRecipients([]);
$this->callAPIFailure('job', 'process_mailing', "Failure in api call for job process_mailing: Job has not been executed as it is a non-production environment.");
// Test with runInNonProductionEnvironment param.
- $this->callAPISuccess('job', 'process_mailing', array('runInNonProductionEnvironment' => TRUE));
+ $this->callAPISuccess('job', 'process_mailing', ['runInNonProductionEnvironment' => TRUE]);
$this->_mut->assertRecipients($this->getRecipients(1, 2));
- $jobId = $this->callAPISuccessGetValue('Job', array(
+ $jobId = $this->callAPISuccessGetValue('Job', [
'return' => "id",
'api_action' => "group_rebuild",
- ));
- $this->callAPISuccess('Job', 'create', array(
+ ]);
+ $this->callAPISuccess('Job', 'create', [
'id' => $jobId,
'parameters' => "runInNonProductionEnvironment=TRUE",
- ));
+ ]);
$jobManager = new CRM_Core_JobManager();
$jobManager->executeJobById($jobId);
$this->assertEquals($mailingBackend['outBound_option'], CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED);
// Test in production mode.
- $params = array(
+ $params = [
'environment' => 'Production',
- );
+ ];
$this->callAPISuccess('Setting', 'create', $params);
- $this->callAPISuccess('job', 'process_mailing', array());
+ $this->callAPISuccess('job', 'process_mailing', []);
$this->_mut->assertRecipients($this->getRecipients(1, 2));
}
public function concurrencyExamples() {
- $es = array();
+ $es = [];
// Launch 3 workers, but mailerJobsMax limits us to 1 worker.
- $es[0] = array(
- array(
+ $es[0] = [
+ [
'recipients' => 20,
'workers' => 3,
// FIXME: lockHold is unrealistic/unrepresentative. In reality, this situation fails because
'lockHold' => 10,
'mailerBatchLimit' => 4,
'mailerJobsMax' => 1,
- ),
- array(
+ ],
+ [
// 2 jobs which produce 0 messages
0 => 2,
// 1 job which produces 4 messages
4 => 1,
- ),
+ ],
4,
- );
+ ];
// Launch 3 workers, but mailerJobsMax limits us to 2 workers.
- $es[1] = array(
+ $es[1] = [
// Settings.
- array(
+ [
'recipients' => 20,
'workers' => 3,
// FIXME: lockHold is unrealistic/unrepresentative. In reality, this situation fails because
'lockHold' => 10,
'mailerBatchLimit' => 5,
'mailerJobsMax' => 2,
- ),
+ ],
// Tallies.
- array(
+ [
// 1 job which produce 0 messages
0 => 1,
// 2 jobs which produce 5 messages
5 => 2,
- ),
+ ],
// Total sent.
10,
- );
+ ];
// Launch 3 workers and saturate them (mailerJobsMax=3)
- $es[2] = array(
+ $es[2] = [
// Settings.
- array(
+ [
'recipients' => 20,
'workers' => 3,
'mailerBatchLimit' => 6,
'mailerJobsMax' => 3,
- ),
+ ],
// Tallies.
- array(
+ [
// 3 jobs which produce 6 messages
6 => 3,
- ),
+ ],
// Total sent.
18,
- );
+ ];
// Launch 4 workers and saturate them (mailerJobsMax=0)
- $es[3] = array(
+ $es[3] = [
// Settings.
- array(
+ [
'recipients' => 20,
'workers' => 4,
'mailerBatchLimit' => 6,
'mailerJobsMax' => 0,
- ),
+ ],
// Tallies.
- array(
+ [
// 3 jobs which produce 6 messages
6 => 3,
// 1 job which produces 2 messages
2 => 1,
- ),
+ ],
// Total sent.
20,
- );
+ ];
// Launch 1 worker, 3 times in a row. Deliver everything.
- $es[4] = array(
+ $es[4] = [
// Settings.
- array(
+ [
'recipients' => 10,
'workers' => 1,
'iterations' => 3,
'mailerBatchLimit' => 7,
- ),
+ ],
// Tallies.
- array(
+ [
// 1 job which produces 7 messages
7 => 1,
// 1 job which produces 3 messages
3 => 1,
// 1 job which produces 0 messages
0 => 1,
- ),
+ ],
// Total sent.
10,
- );
+ ];
// Launch 2 worker, 3 times in a row. Deliver everything.
- $es[5] = array(
+ $es[5] = [
// Settings.
- array(
+ [
'recipients' => 10,
'workers' => 2,
'iterations' => 3,
'mailerBatchLimit' => 3,
- ),
+ ],
// Tallies.
- array(
+ [
// 3 jobs which produce 3 messages
3 => 3,
// 1 job which produces 1 messages
1 => 1,
// 2 jobs which produce 0 messages
0 => 2,
- ),
+ ],
// Total sent.
10,
- );
+ ];
// For two mailings, launch 1 worker, 5 times in a row. Deliver everything.
- $es[6] = array(
+ $es[6] = [
// Settings.
- array(
+ [
'mailings' => 2,
'recipients' => 10,
'workers' => 1,
'iterations' => 5,
'mailerBatchLimit' => 6,
- ),
+ ],
// Tallies.
- array(
+ [
// x6 => x4+x2 => x6 => x2 => x0
// 3 jobs which produce 6 messages
6 => 3,
2 => 1,
// 1 job which produces 0 messages
0 => 1,
- ),
+ ],
// Total sent.
20,
- );
+ ];
return $es;
}
$settings = array_merge($this->defaultSettings, $settings);
$this->createContactsInGroup($settings['recipients'], $this->_groupID);
- Civi::settings()->add(CRM_Utils_Array::subset($settings, array(
+ Civi::settings()->add(CRM_Utils_Array::subset($settings, [
'mailerBatchLimit',
'mailerJobsMax',
'mailThrottleTime',
- )));
+ ]));
for ($i = 0; $i < $settings['mailings']; $i++) {
$this->callAPISuccess('mailing', 'create', $this->_params);
}
- $this->_mut->assertRecipients(array());
+ $this->_mut->assertRecipients([]);
- $allApiResults = array();
+ $allApiResults = [];
for ($iterationId = 0; $iterationId < $settings['iterations']; $iterationId++) {
$apiCalls = $this->createExternalAPI();
- $apiCalls->addEnv(array('CIVICRM_CRON_HOLD' => $settings['lockHold']));
+ $apiCalls->addEnv(['CIVICRM_CRON_HOLD' => $settings['lockHold']]);
for ($workerId = 0; $workerId < $settings['workers']; $workerId++) {
- $apiCalls->addCall('job', 'process_mailing', array());
+ $apiCalls->addCall('job', 'process_mailing', []);
}
$apiCalls->start();
$this->assertEquals($settings['workers'], $apiCalls->getRunningCount());
}
$actualTallies = $this->tallyApiResults($allApiResults);
- $this->assertEquals($expectedTallies, $actualTallies, 'API tallies should match.' . print_r(array(
+ $this->assertEquals($expectedTallies, $actualTallies, 'API tallies should match.' . print_r([
'expectedTallies' => $expectedTallies,
'actualTallies' => $actualTallies,
'apiResults' => $allApiResults,
- ), TRUE));
+ ], TRUE));
$this->_mut->assertRecipients($this->getRecipients(1, $expectedTotal / $settings['mailings'], 'nul.example.com', $settings['mailings']));
$this->assertEquals(0, $apiCalls->getRunningCount());
}
*/
public function createContactsInGroup($count, $groupID, $domain = 'nul.example.com') {
for ($i = 1; $i <= $count; $i++) {
- $contactID = $this->individualCreate(array('first_name' => $count, 'email' => 'mail' . $i . '@' . $domain));
- $this->callAPISuccess('group_contact', 'create', array(
+ $contactID = $this->individualCreate(['first_name' => $count, 'email' => 'mail' . $i . '@' . $domain]);
+ $this->callAPISuccess('group_contact', 'create', [
'contact_id' => $contactID,
'group_id' => $groupID,
'status' => 'Added',
- ));
+ ]);
}
}
* @return array
*/
public function getRecipients($start, $count, $domain = 'nul.example.com', $mailings = 1) {
- $recipients = array();
+ $recipients = [];
for ($m = 0; $m < $mailings; $m++) {
for ($i = $start; $i < ($start + $count); $i++) {
$recipients[][0] = 'mail' . $i . '@' . $domain;
}
protected function cleanupMailingTest() {
- $this->quickCleanup(array(
+ $this->quickCleanup([
'civicrm_mailing',
'civicrm_mailing_job',
'civicrm_mailing_spool',
'civicrm_group',
'civicrm_group_contact',
'civicrm_contact',
- ));
+ ]);
}
/**
* A separate key for each distinct quantity.
*/
protected function tallyApiResults($apiResults) {
- $ret = array();
+ $ret = [];
foreach ($apiResults as $apiResult) {
$key = !empty($apiResult['is_error']) ? 'error' : $apiResult['values']['processed'];
$ret[$key] = !empty($ret[$key]) ? 1 + $ret[$key] : 1;
parent::setUp();
$customGroup = $this->customGroupCreate();
$this->customGroupID = $customGroup['id'];
- $customField = $this->customFieldCreate(array(
+ $customField = $this->customFieldCreate([
'custom_group_id' => $this->customGroupID,
'data_type' => 'Date',
'html_type' => 'Select Date',
'default_value' => '',
- ));
+ ]);
$this->customFieldID = $customField['id'];
- $customField = $this->customFieldCreate(array(
+ $customField = $this->customFieldCreate([
'custom_group_id' => $this->customGroupID,
'data_type' => 'Integer',
'html_type' => 'Text',
'default_value' => '',
'label' => 'Int Field',
- ));
+ ]);
$this->customIntFieldID = $customField['id'];
- $customField = $this->customFieldCreate(array(
+ $customField = $this->customFieldCreate([
'custom_group_id' => $this->customGroupID,
'data_type' => 'Boolean',
'html_type' => 'Radio',
'default_value' => '',
'label' => 'Radio Field',
- ));
+ ]);
$this->customBoolFieldID = $customField['id'];
- $customField = $this->customFieldCreate(array(
+ $customField = $this->customFieldCreate([
'custom_group_id' => $this->customGroupID,
'data_type' => 'String',
'html_type' => 'CheckBox',
'default_value' => NULL,
'label' => 'checkbox Field',
- 'option_values' => array('black' => 'black', 'white' => 'white'),
- ));
+ 'option_values' => ['black' => 'black', 'white' => 'white'],
+ ]);
$this->customStringCheckboxID = $customField['id'];
}
* Cleanup after tests.
*/
public function tearDown() {
- $this->quickCleanup(array('civicrm_contact'), TRUE);
+ $this->quickCleanup(['civicrm_contact'], TRUE);
parent::tearDown();
}
*/
public function testBatchMergeCheckboxCustomFieldHandling($dataSet) {
$customFieldLabel = 'custom_' . $this->customStringCheckboxID;
- $contact1Params = is_array($dataSet['contacts'][0]) ? array($customFieldLabel => $dataSet['contacts'][0]) : array();
- $contact2Params = is_array($dataSet['contacts'][1]) ? array($customFieldLabel => $dataSet['contacts'][1]) : array();
+ $contact1Params = is_array($dataSet['contacts'][0]) ? [$customFieldLabel => $dataSet['contacts'][0]] : [];
+ $contact2Params = is_array($dataSet['contacts'][1]) ? [$customFieldLabel => $dataSet['contacts'][1]] : [];
$contactID = $this->individualCreate($contact1Params);
$this->individualCreate($contact2Params);
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array('mode' => $dataSet['mode']));
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', ['mode' => $dataSet['mode']]);
$this->assertEquals($dataSet['merged'], count($result['values']['merged']));
$this->assertEquals($dataSet['skipped'], count($result['values']['skipped']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals($dataSet['expected'], $contact[$customFieldLabel]);
}
* @return array
*/
public function getCheckboxData() {
- $data = array(
- array(
- 'null_merges_with_set' => array(
+ $data = [
+ [
+ 'null_merges_with_set' => [
'mode' => 'safe',
- 'contacts' => array(
+ 'contacts' => [
NULL,
- array('black'),
- ),
+ ['black'],
+ ],
'skipped' => 0,
'merged' => 1,
- 'expected' => array('black'),
- ),
- ),
- array(
- 'null_merges_with_set_reverse' => array(
+ 'expected' => ['black'],
+ ],
+ ],
+ [
+ 'null_merges_with_set_reverse' => [
'mode' => 'safe',
- 'contacts' => array(
- array('black'),
+ 'contacts' => [
+ ['black'],
NULL,
- ),
+ ],
'skipped' => 0,
'merged' => 1,
- 'expected' => array('black'),
+ 'expected' => ['black'],
- ),
- ),
- array(
- 'empty_conflicts_with_set' => array(
+ ],
+ ],
+ [
+ 'empty_conflicts_with_set' => [
'mode' => 'safe',
- 'contacts' => array(
- array('white'),
- array('black'),
- ),
+ 'contacts' => [
+ ['white'],
+ ['black'],
+ ],
'skipped' => 1,
'merged' => 0,
- 'expected' => array('white'),
- ),
- ),
- array(
- 'empty_conflicts_with_set' => array(
+ 'expected' => ['white'],
+ ],
+ ],
+ [
+ 'empty_conflicts_with_set' => [
'mode' => 'aggressive',
- 'contacts' => array(
- array('white'),
- array('black'),
- ),
+ 'contacts' => [
+ ['white'],
+ ['black'],
+ ],
'skipped' => 0,
'merged' => 1,
- 'expected' => array('white'),
- ),
- ),
- );
+ 'expected' => ['white'],
+ ],
+ ],
+ ];
return $data;
}
public function testBatchMergeDateCustomFieldHandling() {
$customFieldLabel = 'custom_' . $this->customFieldID;
$contactID = $this->individualCreate();
- $this->individualCreate(array($customFieldLabel => '2012-12-03'));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $this->individualCreate([$customFieldLabel => '2012-12-03']);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(1, count($result['values']['merged']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals('2012-12-03 00:00:00', $contact[$customFieldLabel]);
}
* Test CRM-18674 date custom field handling.
*/
public function testBatchMergeDateCustomFieldHandlingIsView() {
- $this->customFieldCreate(array(
+ $this->customFieldCreate([
'label' => 'OnlyView',
'custom_group_id' => $this->customGroupID,
'is_view' => 1,
- ));
+ ]);
$customFieldLabel = 'custom_' . $this->customFieldID;
$contactID = $this->individualCreate();
- $this->individualCreate(array($customFieldLabel => '2012-11-03'));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $this->individualCreate([$customFieldLabel => '2012-11-03']);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(1, count($result['values']['merged']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]);
}
*/
public function testBatchMergeDateCustomFieldConflict() {
$customFieldLabel = 'custom_' . $this->customFieldID;
- $contactID = $this->individualCreate(array($customFieldLabel => '2012-11-03'));
- $this->individualCreate(array($customFieldLabel => '2013-11-03'));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $contactID = $this->individualCreate([$customFieldLabel => '2012-11-03']);
+ $this->individualCreate([$customFieldLabel => '2013-11-03']);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(0, count($result['values']['merged']));
$this->assertEquals(1, count($result['values']['skipped']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]);
}
*/
public function testBatchMergeDateCustomFieldNoConflict() {
$customFieldLabel = 'custom_' . $this->customFieldID;
- $contactID = $this->individualCreate(array($customFieldLabel => '2012-11-03'));
- $this->individualCreate(array($customFieldLabel => '2012-11-03'));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $contactID = $this->individualCreate([$customFieldLabel => '2012-11-03']);
+ $this->individualCreate([$customFieldLabel => '2012-11-03']);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(1, count($result['values']['merged']));
$this->assertEquals(0, count($result['values']['skipped']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]);
}
*/
public function testBatchMergeIntCustomFieldNoConflict() {
$customFieldLabel = 'custom_' . $this->customIntFieldID;
- $contactID = $this->individualCreate(array());
- $this->individualCreate(array($customFieldLabel => 20));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $contactID = $this->individualCreate([]);
+ $this->individualCreate([$customFieldLabel => 20]);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(1, count($result['values']['merged']));
$this->assertEquals(0, count($result['values']['skipped']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals(20, $contact[$customFieldLabel]);
}
*/
public function testBatchMergeIntCustomFieldConflict() {
$customFieldLabel = 'custom_' . $this->customIntFieldID;
- $contactID = $this->individualCreate(array($customFieldLabel => 20));
- $this->individualCreate(array($customFieldLabel => 1));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $contactID = $this->individualCreate([$customFieldLabel => 20]);
+ $this->individualCreate([$customFieldLabel => 1]);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(0, count($result['values']['merged']));
$this->assertEquals(1, count($result['values']['skipped']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals(20, $contact[$customFieldLabel]);
}
*/
public function testBatchMergeIntCustomFieldConflictZero() {
$customFieldLabel = 'custom_' . $this->customIntFieldID;
- $contactID = $this->individualCreate(array($customFieldLabel => 0));
- $this->individualCreate(array($customFieldLabel => 20));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $contactID = $this->individualCreate([$customFieldLabel => 0]);
+ $this->individualCreate([$customFieldLabel => 20]);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(0, count($result['values']['merged']));
$this->assertEquals(1, count($result['values']['skipped']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals(0, $contact[$customFieldLabel]);
}
* Test CRM-18674 date custom field handling.
*/
public function testBatchMergeDateCustomFieldConflictAndNoCheckPerms() {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit my contact');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit my contact'];
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_cache");
CRM_Utils_System::flushCache();
$customFieldLabel = 'custom_' . $this->customFieldID;
- $contactID = $this->individualCreate(array($customFieldLabel => '2012-11-03'));
- $this->individualCreate(array($customFieldLabel => '2013-11-03'));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array('check_permissions' => 0));
+ $contactID = $this->individualCreate([$customFieldLabel => '2012-11-03']);
+ $this->individualCreate([$customFieldLabel => '2013-11-03']);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', ['check_permissions' => 0]);
$this->assertEquals(0, count($result['values']['merged']));
$this->assertEquals(1, count($result['values']['skipped']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]);
}
* Test CRM-18674 date custom field handling.
*/
public function testBatchMergeDateCustomFieldNoConflictAndNoCheckPerms() {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit my contact');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit my contact'];
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_cache");
CRM_Utils_System::flushCache();
$customFieldLabel = 'custom_' . $this->customFieldID;
$contactID = $this->individualCreate();
- $this->individualCreate(array($customFieldLabel => '2013-11-03'));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array('check_permissions' => 0));
+ $this->individualCreate([$customFieldLabel => '2013-11-03']);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', ['check_permissions' => 0]);
$this->assertEquals(1, count($result['values']['merged']));
$this->assertEquals(0, count($result['values']['skipped']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel));
+ $contact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contactID, 'return' => $customFieldLabel]);
$this->assertEquals('2013-11-03 00:00:00', $contact[$customFieldLabel]);
}
* Test CRM-19113 custom data lost when permissions in play.
*/
public function testBatchMergeIntCustomFieldNoConflictAndNoCheckPerms() {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit my contact');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'edit my contact'];
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_cache");
CRM_Utils_System::flushCache();
$customFieldLabel = 'custom_' . $this->customIntFieldID;
- $contactID = $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1));
- $this->individualCreate(array($customFieldLabel => 1, 'custom_' . $this->customBoolFieldID => 1));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array('check_permissions' => 0));
+ $contactID = $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]);
+ $this->individualCreate([$customFieldLabel => 1, 'custom_' . $this->customBoolFieldID => 1]);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', ['check_permissions' => 0]);
$this->assertEquals(1, count($result['values']['merged']));
$this->assertEquals(0, count($result['values']['skipped']));
- $contact = $this->callAPISuccess('Contact', 'getsingle', array(
+ $contact = $this->callAPISuccess('Contact', 'getsingle', [
'id' => $contactID,
- 'return' => array($customFieldLabel, 'custom_' . $this->customBoolFieldID),
- ));
+ 'return' => [$customFieldLabel, 'custom_' . $this->customBoolFieldID],
+ ]);
$this->assertEquals(1, $contact[$customFieldLabel]);
$this->assertEquals(1, $contact['custom_' . $this->customBoolFieldID]);
}
* Check we get a conflict on the customs field when the data conflicts for booleans.
*/
public function testBatchMergeCustomFieldConflicts() {
- $this->individualCreate(array('custom_' . $this->customBoolFieldID => 0));
- $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $this->individualCreate(['custom_' . $this->customBoolFieldID => 0]);
+ $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(0, count($result['values']['merged']));
$this->assertEquals(1, count($result['values']['skipped']));
}
* Check we get a conflict on the customs field when the data conflicts for booleans (reverse).
*/
public function testBatchMergeCustomFieldConflictsReverse() {
- $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1));
- $this->individualCreate(array('custom_' . $this->customBoolFieldID => 0));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]);
+ $this->individualCreate(['custom_' . $this->customBoolFieldID => 0]);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(0, count($result['values']['merged']));
$this->assertEquals(1, count($result['values']['skipped']));
}
* Check we get a conflict on the customs field when the data conflicts for booleans (reverse).
*/
public function testBatchMergeCustomFieldConflictsOneBlank() {
- $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1));
+ $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]);
$this->individualCreate();
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(1, count($result['values']['merged']));
$this->assertEquals(0, count($result['values']['skipped']));
}
*/
public function testBatchMergeCustomFieldConflictsOneBlankReverse() {
$this->individualCreate();
- $this->individualCreate(array('custom_' . $this->customBoolFieldID => 1));
- $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+ $this->individualCreate(['custom_' . $this->customBoolFieldID => 1]);
+ $result = $this->callAPISuccess('Job', 'process_batch_merge', []);
$this->assertEquals(1, count($result['values']['merged']));
$this->assertEquals(0, count($result['values']['skipped']));
}
protected $testAmount = 34567;
protected $params;
protected $id = 0;
- protected $contactIds = array();
+ protected $contactIds = [];
protected $_entity = 'line_item';
protected $contribution_result = NULL;
parent::setUp();
$this->useTransaction(TRUE);
$this->_individualId = $this->individualCreate();
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'net_amount' => 91.00,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
- $this->params = array(
+ $this->params = [
'price_field_value_id' => 1,
'price_field_id' => 1,
'entity_table' => 'civicrm_contribution',
'qty' => 1,
'unit_price' => 50,
'line_total' => 50,
- );
+ ];
}
public function testCreateLineItem() {
- $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params + array('debug' => 1), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params + ['debug' => 1], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
$this->getAndCheck($this->params, $result['id'], $this->_entity);
}
public function testGetBasicLineItem() {
- $getParams = array(
+ $getParams = [
'entity_table' => 'civicrm_contribution',
- );
+ ];
$getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
$this->assertEquals(1, $getResult['count']);
}
public function testDeleteLineItem() {
- $getParams = array(
+ $getParams = [
'entity_table' => 'civicrm_contribution',
- );
+ ];
$getResult = $this->callAPISuccess($this->_entity, 'get', $getParams);
- $deleteParams = array('id' => $getResult['id']);
+ $deleteParams = ['id' => $getResult['id']];
$deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testGetFieldsLineItem() {
- $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
+ $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
$this->assertEquals(1, $result['values']['entity_id']['api.required']);
}
* Clean up log tables.
*/
protected function tearDown() {
- $this->quickCleanup(array('civicrm_email', 'civicrm_address'));
+ $this->quickCleanup(['civicrm_email', 'civicrm_address']);
parent::tearDown();
- $this->callAPISuccess('Setting', 'create', array('logging' => FALSE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => FALSE]);
$schema = new CRM_Logging_Schema();
$schema->dropAllLogTables();
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_setting WHERE name LIKE 'logg%'");
* Test that logging is successfully enabled and disabled.
*/
public function testEnableDisableLogging() {
- $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging')));
+ $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', ['name' => 'logging']));
$this->assertLoggingEnabled(FALSE);
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
$this->assertLoggingEnabled(TRUE);
$this->checkLogTableCreated();
$this->checkTriggersCreated(TRUE);
// Create a contact to make sure they aren't borked.
$this->individualCreate();
- $this->assertTrue($this->callAPISuccessGetValue('Setting', array('name' => 'logging')));
- $this->assertEquals(1, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid')));
+ $this->assertTrue($this->callAPISuccessGetValue('Setting', ['name' => 'logging']));
+ $this->assertEquals(1, $this->callAPISuccessGetValue('Setting', ['name' => 'logging_all_tables_uniquid']));
$this->assertEquals(
date('Y-m-d'),
- date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date'))))
+ date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', ['name' => 'logging_uniqueid_date'])))
);
- $this->callAPISuccess('Setting', 'create', array('logging' => FALSE));
- $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging')));
+ $this->callAPISuccess('Setting', 'create', ['logging' => FALSE]);
+ $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', ['name' => 'logging']));
$this->assertLoggingEnabled(FALSE);
}
* Test that logging is successfully enabled and disabled.
*/
public function testEnableDisableLoggingWithTriggerHook() {
- $this->hookClass->setHook('civicrm_alterLogTables', array($this, 'innodbLogTableSpec'));
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'innodbLogTableSpec']);
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
$this->checkINNODBLogTableCreated();
$this->checkTriggersCreated(TRUE);
// Create a contact to make sure they aren't borked.
$this->individualCreate();
- $this->callAPISuccess('Setting', 'create', array('logging' => FALSE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => FALSE]);
}
/**
*/
public function testEnableLoggingLegacyLogTableExists() {
$this->createLegacyStyleContactLogTable();
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
$this->checkTriggersCreated(FALSE);
- $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid')));
- $this->assertEmpty($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date')));
+ $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', ['name' => 'logging_all_tables_uniquid']));
+ $this->assertEmpty($this->callAPISuccessGetValue('Setting', ['name' => 'logging_uniqueid_date']));
}
/**
*/
public function testUpdateLegacyLogTable() {
$this->createLegacyStyleContactLogTable();
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
- $this->callAPISuccess('System', 'updatelogtables', array());
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
+ $this->callAPISuccess('System', 'updatelogtables', []);
$this->checkLogTableCreated();
$this->checkTriggersCreated(TRUE);
- $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', array('name' => 'logging_all_tables_uniquid')));
+ $this->assertEquals(0, $this->callAPISuccessGetValue('Setting', ['name' => 'logging_all_tables_uniquid']));
$this->assertEquals(
date('Y-m-d'),
- date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', array('name' => 'logging_uniqueid_date'))))
+ date('Y-m-d', strtotime($this->callAPISuccessGetValue('Setting', ['name' => 'logging_uniqueid_date'])))
);
}
* Check if we can create missing log tables using api.
*/
public function testCreateMissingLogTables() {
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
CRM_Core_DAO::executeQuery("DROP TABLE log_civicrm_contact");
- $this->callAPISuccess('System', 'createmissinglogtables', array());
+ $this->callAPISuccess('System', 'createmissinglogtables', []);
//Assert if log_civicrm_contact is created.
$this->checkLogTableCreated();
*/
public function testUpdateLogTableHookINNODB() {
$this->createLegacyStyleContactLogTable();
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
- $this->hookClass->setHook('civicrm_alterLogTables', array($this, 'innodbLogTableSpec'));
- $this->callAPISuccess('System', 'updatelogtables', array());
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
+ $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'innodbLogTableSpec']);
+ $this->callAPISuccess('System', 'updatelogtables', []);
$this->checkINNODBLogTableCreated();
$this->checkTriggersCreated(TRUE);
// Make sure that the absence of a hook specifying INNODB does not cause revert to archive.
// Only a positive action, like specifying ARCHIVE in a hook should trigger a change back to archive.
- $this->hookClass->setHook('civicrm_alterLogTables', array());
+ $this->hookClass->setHook('civicrm_alterLogTables', []);
$schema = new CRM_Logging_Schema();
$spec = $schema->getLogTableSpec();
- $this->assertEquals(array(), $spec['civicrm_contact']);
- $this->callAPISuccess('System', 'updatelogtables', array());
+ $this->assertEquals([], $spec['civicrm_contact']);
+ $this->callAPISuccess('System', 'updatelogtables', []);
$this->checkINNODBLogTableCreated();
// Check if API creates new indexes when they're added by hook
$this->hookClass->setHook('civicrm_alterLogTables', [$this, 'innodbLogTableSpecNewIndex']);
- $this->callAPISuccess('System', 'updatelogtables', array());
+ $this->callAPISuccess('System', 'updatelogtables', []);
$this->checkINNODBLogTableCreated();
$this->assertContains('KEY `index_log_user_id` (`log_user_id`)', $this->checkLogTableCreated());
}
* Check that if a field is added then the trigger is updated on refresh.
*/
public function testRebuildTriggerAfterSchemaChange() {
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
- $tables = array('civicrm_acl', 'civicrm_website');
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
+ $tables = ['civicrm_acl', 'civicrm_website'];
foreach ($tables as $table) {
CRM_Core_DAO::executeQuery("ALTER TABLE $table ADD column temp_col INT(10)");
}
* @param array $logTableSpec
*/
public function innodbLogTableSpec(&$logTableSpec) {
- $logTableSpec['civicrm_contact'] = array(
+ $logTableSpec['civicrm_contact'] = [
'engine' => 'InnoDB',
'engine_config' => 'ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4',
- 'indexes' => array(
+ 'indexes' => [
'index_id' => 'id',
'index_log_conn_id' => 'log_conn_id',
'index_log_date' => 'log_date',
- ),
- );
+ ],
+ ];
}
/**
* @param array $logTableSpec
*/
public function innodbLogTableSpecNewIndex(&$logTableSpec) {
- $logTableSpec['civicrm_contact'] = array(
+ $logTableSpec['civicrm_contact'] = [
'engine' => 'InnoDB',
'engine_config' => 'ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4',
- 'indexes' => array(
+ 'indexes' => [
'index_id' => 'id',
'index_log_conn_id' => 'log_conn_id',
'index_log_date' => 'log_date',
// new index
'index_log_user_id' => 'log_user_id',
- ),
- );
+ ],
+ ];
}
/**
*/
public function testRevert() {
$contactId = $this->individualCreate();
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
// Pause for one second here to ensure the timestamps between the first create action
// and the second differ.
sleep(1);
CRM_Core_DAO::executeQuery("SET @uniqueID = 'woot'");
$timeStamp = date('Y-m-d H:i:s');
- $this->callAPISuccess('Contact', 'create', array(
+ $this->callAPISuccess('Contact', 'create', [
'id' => $contactId,
'first_name' => 'Dopey',
- 'api.email.create' => array('email' => 'dopey@mail.com'),
- )
+ 'api.email.create' => ['email' => 'dopey@mail.com'],
+ ]
);
- $email = $this->callAPISuccessGetSingle('email', array('email' => 'dopey@mail.com'));
- $this->callAPIAndDocument('Logging', 'revert', array('log_conn_id' => 'woot', 'log_date' => $timeStamp), __FILE__, 'Revert');
- $this->assertEquals('Anthony', $this->callAPISuccessGetValue('contact', array('id' => $contactId, 'return' => 'first_name')));
- $this->callAPISuccessGetCount('Email', array('id' => $email['id']), 0);
+ $email = $this->callAPISuccessGetSingle('email', ['email' => 'dopey@mail.com']);
+ $this->callAPIAndDocument('Logging', 'revert', ['log_conn_id' => 'woot', 'log_date' => $timeStamp], __FILE__, 'Revert');
+ $this->assertEquals('Anthony', $this->callAPISuccessGetValue('contact', ['id' => $contactId, 'return' => 'first_name']));
+ $this->callAPISuccessGetCount('Email', ['id' => $email['id']], 0);
}
/**
*/
public function testRevertNoDate() {
$contactId = $this->individualCreate();
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
// Pause for one second here to ensure the timestamps between the first create action
// and the second differ.
sleep(1);
CRM_Core_DAO::executeQuery("SET @uniqueID = 'Wot woot'");
- $this->callAPISuccess('Contact', 'create', array(
+ $this->callAPISuccess('Contact', 'create', [
'id' => $contactId,
'first_name' => 'Dopey',
- 'api.email.create' => array('email' => 'dopey@mail.com'),
- ));
- $email = $this->callAPISuccessGetSingle('email', array('email' => 'dopey@mail.com'));
- $this->callAPISuccess('Logging', 'revert', array('log_conn_id' => 'Wot woot'));
- $this->assertEquals('Anthony', $this->callAPISuccessGetValue('contact', array('id' => $contactId, 'return' => 'first_name')));
- $this->callAPISuccessGetCount('Email', array('id' => $email['id']), 0);
+ 'api.email.create' => ['email' => 'dopey@mail.com'],
+ ]);
+ $email = $this->callAPISuccessGetSingle('email', ['email' => 'dopey@mail.com']);
+ $this->callAPISuccess('Logging', 'revert', ['log_conn_id' => 'Wot woot']);
+ $this->assertEquals('Anthony', $this->callAPISuccessGetValue('contact', ['id' => $contactId, 'return' => 'first_name']));
+ $this->callAPISuccessGetCount('Email', ['id' => $email['id']], 0);
}
/**
public function testRevertRestrictedTables() {
CRM_Core_DAO::executeQuery("SET @uniqueID = 'temp name'");
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
- $contactId = $this->individualCreate(array('address' => array(array('street_address' => '27 Cool way', 'location_type_id' => 1))));
- $contact = $this->callAPISuccessGetSingle('contact', array('id' => $contactId));
+ $contactId = $this->individualCreate(['address' => [['street_address' => '27 Cool way', 'location_type_id' => 1]]]);
+ $contact = $this->callAPISuccessGetSingle('contact', ['id' => $contactId]);
$this->assertEquals('Anthony', $contact['first_name']);
$this->assertEquals('anthony_anderson@civicrm.org', $contact['email']);
$this->assertEquals('27 Cool way', $contact['street_address']);
sleep(1);
CRM_Core_DAO::executeQuery("SET @uniqueID = 'bitty bot bot'");
- $this->callAPISuccess('Contact', 'create', array(
+ $this->callAPISuccess('Contact', 'create', [
'id' => $contactId,
'first_name' => 'Dopey',
- 'address' => array(array('street_address' => '25 Dorky way', 'location_type_id' => 1)),
- 'email' => array('email' => array('email' => 'dopey@mail.com', 'location_type_id' => 1)),
- 'api.contribution.create' => array('financial_type_id' => 'Donation', 'receive_date' => 'now', 'total_amount' => 10),
- ));
- $contact = $this->callAPISuccessGetSingle('contact', array('id' => $contactId, 'return' => array('first_name', 'email', 'modified_date', 'street_address')));
+ 'address' => [['street_address' => '25 Dorky way', 'location_type_id' => 1]],
+ 'email' => ['email' => ['email' => 'dopey@mail.com', 'location_type_id' => 1]],
+ 'api.contribution.create' => ['financial_type_id' => 'Donation', 'receive_date' => 'now', 'total_amount' => 10],
+ ]);
+ $contact = $this->callAPISuccessGetSingle('contact', ['id' => $contactId, 'return' => ['first_name', 'email', 'modified_date', 'street_address']]);
$this->assertEquals('Dopey', $contact['first_name']);
$this->assertEquals('dopey@mail.com', $contact['email']);
$this->assertEquals('25 Dorky way', $contact['street_address']);
$modifiedDate = $contact['modified_date'];
// To protect against the modified date not changing due to the updates being too close together.
sleep(1);
- $loggings = $this->callAPISuccess('Logging', 'get', array('log_conn_id' => 'bitty bot bot', 'tables' => array('civicrm_address')));
+ $loggings = $this->callAPISuccess('Logging', 'get', ['log_conn_id' => 'bitty bot bot', 'tables' => ['civicrm_address']]);
$this->assertEquals('civicrm_address', $loggings['values'][0]['table'], CRM_Core_DAO::executeQuery('SELECT * FROM log_civicrm_address')->toArray());
$this->assertEquals(1, $loggings['count'], CRM_Core_DAO::executeQuery('SELECT * FROM log_civicrm_address')->toArray());
$this->assertEquals('27 Cool way', $loggings['values'][0]['from']);
$this->assertEquals('25 Dorky way', $loggings['values'][0]['to']);
- $this->callAPISuccess('Logging', 'revert', array('log_conn_id' => 'bitty bot bot', 'tables' => array('civicrm_address')));
+ $this->callAPISuccess('Logging', 'revert', ['log_conn_id' => 'bitty bot bot', 'tables' => ['civicrm_address']]);
- $contact = $this->callAPISuccessGetSingle('contact', array('id' => $contactId, 'return' => array('first_name', 'email', 'modified_date', 'street_address')));
+ $contact = $this->callAPISuccessGetSingle('contact', ['id' => $contactId, 'return' => ['first_name', 'email', 'modified_date', 'street_address']]);
$this->assertEquals('Dopey', $contact['first_name']);
$this->assertEquals('dopey@mail.com', $contact['email']);
$this->assertEquals('27 Cool way', $contact['street_address']);
- $this->callAPISuccessGetCount('Contribution', array('contact_id' => $contactId), 1);
+ $this->callAPISuccessGetCount('Contribution', ['contact_id' => $contactId], 1);
$this->assertTrue(strtotime($modifiedDate) < strtotime($contact['modified_date']));
}
*/
public function testRevertNoDateNotUnique() {
$contactId = $this->individualCreate();
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
CRM_Core_DAO::executeQuery("SET @uniqueID = 'Wopity woot'");
- $this->callAPISuccess('Contact', 'create', array(
+ $this->callAPISuccess('Contact', 'create', [
'id' => $contactId,
'first_name' => 'Dopey',
- 'api.email.create' => array('email' => 'dopey@mail.com'),
- ));
- $this->callAPISuccess('Setting', 'create', array('logging_all_tables_uniquid' => FALSE));
- $this->callAPISuccess('Setting', 'create', array('logging_uniqueid_date' => date('Y-m-d H:i:s', strtotime('+ 1 hour'))));
+ 'api.email.create' => ['email' => 'dopey@mail.com'],
+ ]);
+ $this->callAPISuccess('Setting', 'create', ['logging_all_tables_uniquid' => FALSE]);
+ $this->callAPISuccess('Setting', 'create', ['logging_uniqueid_date' => date('Y-m-d H:i:s', strtotime('+ 1 hour'))]);
$this->callAPIFailure(
'Logging',
'revert',
- array('log_conn_id' => 'Wopity woot'),
+ ['log_conn_id' => 'Wopity woot'],
'The connection date must be passed in to disambiguate this logging entry per CRM-18193'
);
}
*/
public function testGet() {
$contactId = $this->individualCreate();
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
CRM_Core_DAO::executeQuery("SET @uniqueID = 'wooty woot'");
// Add delay so the update is actually enough after the create that the timestamps differ
sleep(1);
$timeStamp = date('Y-m-d H:i:s');
- $this->callAPISuccess('Contact', 'create', array(
+ $this->callAPISuccess('Contact', 'create', [
'id' => $contactId,
'first_name' => 'Dopey',
'last_name' => 'Dwarf',
- 'api.email.create' => array('email' => 'dopey@mail.com'),
- ));
- $this->callAPISuccessGetSingle('email', array('email' => 'dopey@mail.com'));
- $diffs = $this->callAPISuccess('Logging', 'get', array('log_conn_id' => 'wooty woot', 'log_date' => $timeStamp), __FUNCTION__, __FILE__);
- $this->assertLoggingIncludes($diffs['values'], array('to' => 'Dwarf, Dopey'));
- $this->assertLoggingIncludes($diffs['values'], array('to' => 'Mr. Dopey Dwarf II', 'table' => 'civicrm_contact', 'action' => 'Update', 'field' => 'display_name'));
- $this->assertLoggingIncludes($diffs['values'], array('to' => 'dopey@mail.com', 'table' => 'civicrm_email', 'action' => 'Insert', 'field' => 'email'));
+ 'api.email.create' => ['email' => 'dopey@mail.com'],
+ ]);
+ $this->callAPISuccessGetSingle('email', ['email' => 'dopey@mail.com']);
+ $diffs = $this->callAPISuccess('Logging', 'get', ['log_conn_id' => 'wooty woot', 'log_date' => $timeStamp], __FUNCTION__, __FILE__);
+ $this->assertLoggingIncludes($diffs['values'], ['to' => 'Dwarf, Dopey']);
+ $this->assertLoggingIncludes($diffs['values'], ['to' => 'Mr. Dopey Dwarf II', 'table' => 'civicrm_contact', 'action' => 'Update', 'field' => 'display_name']);
+ $this->assertLoggingIncludes($diffs['values'], ['to' => 'dopey@mail.com', 'table' => 'civicrm_email', 'action' => 'Insert', 'field' => 'email']);
}
/**
*/
public function testGetNoDate() {
$contactId = $this->individualCreate();
- $this->callAPISuccess('Setting', 'create', array('logging' => TRUE));
+ $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
CRM_Core_DAO::executeQuery("SET @uniqueID = 'wooty wop wop'");
// Perhaps if initialize & create are exactly the same time it can't cope.
// 1 second delay
sleep(1);
- $this->callAPISuccess('Contact', 'create', array(
+ $this->callAPISuccess('Contact', 'create', [
'id' => $contactId,
'first_name' => 'Dopey',
'last_name' => 'Dwarf',
- 'api.email.create' => array('email' => 'dopey@mail.com'),
- ));
- $this->callAPISuccessGetSingle('email', array('email' => 'dopey@mail.com'));
- $diffs = $this->callAPIAndDocument('Logging', 'get', array('log_conn_id' => 'wooty wop wop'), __FUNCTION__, __FILE__);
- $this->assertLoggingIncludes($diffs['values'], array('to' => 'Dwarf, Dopey'));
- $this->assertLoggingIncludes($diffs['values'], array('to' => 'Mr. Dopey Dwarf II', 'table' => 'civicrm_contact', 'action' => 'Update', 'field' => 'display_name'));
- $this->assertLoggingIncludes($diffs['values'], array('to' => 'dopey@mail.com', 'table' => 'civicrm_email', 'action' => 'Insert', 'field' => 'email'));
+ 'api.email.create' => ['email' => 'dopey@mail.com'],
+ ]);
+ $this->callAPISuccessGetSingle('email', ['email' => 'dopey@mail.com']);
+ $diffs = $this->callAPIAndDocument('Logging', 'get', ['log_conn_id' => 'wooty wop wop'], __FUNCTION__, __FILE__);
+ $this->assertLoggingIncludes($diffs['values'], ['to' => 'Dwarf, Dopey']);
+ $this->assertLoggingIncludes($diffs['values'], ['to' => 'Mr. Dopey Dwarf II', 'table' => 'civicrm_contact', 'action' => 'Update', 'field' => 'display_name']);
+ $this->assertLoggingIncludes($diffs['values'], ['to' => 'dopey@mail.com', 'table' => 'civicrm_email', 'action' => 'Insert', 'field' => 'email']);
}
/**
]);
$this->_groupID = $this->groupCreate();
- $this->_params = array(
+ $this->_params = [
'mailing_id_a' => $this->_mailingID_A,
'mailing_id_b' => $this->_mailingID_B,
'mailing_id_c' => $this->_mailingID_C,
'winner_criteria' => 'open',
'declare_winning_time' => '+2 days',
'group_percentage' => 10,
- );
+ ];
}
/**
public function testMailerDeleteSuccess() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $this->assertDBQuery(1, "SELECT count(*) FROM civicrm_mailing_abtest WHERE id = %1", array(
- 1 => array($result['id'], 'Integer'),
- ));
- $this->assertDBQuery(3, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", array(
- 1 => array($this->_mailingID_A, 'Integer'),
- 2 => array($this->_mailingID_B, 'Integer'),
- 3 => array($this->_mailingID_C, 'Integer'),
- ));
+ $this->assertDBQuery(1, "SELECT count(*) FROM civicrm_mailing_abtest WHERE id = %1", [
+ 1 => [$result['id'], 'Integer'],
+ ]);
+ $this->assertDBQuery(3, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", [
+ 1 => [$this->_mailingID_A, 'Integer'],
+ 2 => [$this->_mailingID_B, 'Integer'],
+ 3 => [$this->_mailingID_C, 'Integer'],
+ ]);
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
- $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing_abtest WHERE id = %1", array(
- 1 => array($result['id'], 'Integer'),
- ));
- $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", array(
- 1 => array($this->_mailingID_A, 'Integer'),
- 2 => array($this->_mailingID_B, 'Integer'),
- 3 => array($this->_mailingID_C, 'Integer'),
- ));
+ $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing_abtest WHERE id = %1", [
+ 1 => [$result['id'], 'Integer'],
+ ]);
+ $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_mailing WHERE id IN (%1,%2,%3)", [
+ 1 => [$this->_mailingID_A, 'Integer'],
+ 2 => [$this->_mailingID_B, 'Integer'],
+ 3 => [$this->_mailingID_C, 'Integer'],
+ ]);
}
/**
*/
public function groupPctProvider() {
// array(int $totalSize, int $groupPct, int $expectedCountA, $expectedCountB, $expectedCountC)
- $cases = array();
- $cases[] = array(400, 7, 28, 28, 344);
- $cases[] = array(100, 10, 10, 10, 80);
- $cases[] = array(50, 20, 10, 10, 30);
- $cases[] = array(50, 10, 5, 5, 40);
- $cases[] = array(3, 10, 1, 1, 1);
- $cases[] = array(2, 10, 1, 1, 0);
- $cases[] = array(1, 10, 1, 0, 0);
+ $cases = [];
+ $cases[] = [400, 7, 28, 28, 344];
+ $cases[] = [100, 10, 10, 10, 80];
+ $cases[] = [50, 20, 10, 10, 30];
+ $cases[] = [50, 10, 5, 5, 40];
+ $cases[] = [3, 10, 1, 1, 1];
+ $cases[] = [2, 10, 1, 1, 0];
+ $cases[] = [1, 10, 1, 0, 0];
return $cases;
}
$params['group_percentage'] = $groupPct;
$result = $this->callAPISuccess($this->_entity, 'create', $params);
- $this->callAPISuccess('Mailing', 'create', array(
+ $this->callAPISuccess('Mailing', 'create', [
'id' => $this->_mailingID_A,
- 'groups' => array('include' => array($this->_groupID)),
- ));
+ 'groups' => ['include' => [$this->_groupID]],
+ ]);
$this->assertJobCounts(0, 0, 0);
- $this->callAPISuccess('MailingAB', 'submit', array(
+ $this->callAPISuccess('MailingAB', 'submit', [
'id' => $result['id'],
'status' => 'Testing',
'scheduled_date' => date('YmdHis'),
'approval_date' => date('YmdHis'),
- ));
+ ]);
$this->assertRecipientCounts($expectedCountA, $expectedCountB, $expectedCountC);
$this->assertJobCounts(1, 1, 0);
- $this->callAPISuccess('MailingAB', 'submit', array(
+ $this->callAPISuccess('MailingAB', 'submit', [
'id' => $result['id'],
'status' => 'Final',
'scheduled_date' => date('YmdHis'),
'approval_date' => date('YmdHis'),
- ));
+ ]);
$this->assertRecipientCounts($expectedCountA, $expectedCountB, $expectedCountC);
$this->assertJobCounts(1, 1, 1);
}
* @param $expectedCountC
*/
protected function assertRecipientCounts($expectedCountA, $expectedCountB, $expectedCountC) {
- $countA = $this->callAPISuccess('MailingRecipients', 'getcount', array('mailing_id' => $this->_mailingID_A));
- $countB = $this->callAPISuccess('MailingRecipients', 'getcount', array('mailing_id' => $this->_mailingID_B));
- $countC = $this->callAPISuccess('MailingRecipients', 'getcount', array('mailing_id' => $this->_mailingID_C));
+ $countA = $this->callAPISuccess('MailingRecipients', 'getcount', ['mailing_id' => $this->_mailingID_A]);
+ $countB = $this->callAPISuccess('MailingRecipients', 'getcount', ['mailing_id' => $this->_mailingID_B]);
+ $countC = $this->callAPISuccess('MailingRecipients', 'getcount', ['mailing_id' => $this->_mailingID_C]);
$this->assertEquals($expectedCountA, $countA, "check mailing recipients A in line " . __LINE__);
$this->assertEquals($expectedCountB, $countB, "check mailing recipients B in line " . __LINE__);
$this->assertEquals($expectedCountC, $countC, "check mailing recipients C in line " . __LINE__);
* @param $expectedC
*/
protected function assertJobCounts($expectedA, $expectedB, $expectedC) {
- $this->assertDBQuery($expectedA, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array(
- 1 => array(
+ $this->assertDBQuery($expectedA, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [
+ 1 => [
$this->_mailingID_A,
'Integer',
- ),
- ));
- $this->assertDBQuery($expectedB, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array(
- 1 => array(
+ ],
+ ]);
+ $this->assertDBQuery($expectedB, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [
+ 1 => [
$this->_mailingID_B,
'Integer',
- ),
- ));
- $this->assertDBQuery($expectedC, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array(
- 1 => array(
+ ],
+ ]);
+ $this->assertDBQuery($expectedC, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [
+ 1 => [
$this->_mailingID_C,
'Integer',
- ),
- ));
+ ],
+ ]);
}
}
}
public function testMailingContactGetFields() {
- $result = $this->callAPISuccess('MailingContact', 'getfields', array(
+ $result = $this->callAPISuccess('MailingContact', 'getfields', [
'action' => 'get',
- ));
+ ]);
$this->assertEquals('Delivered', $result['values']['type']['api.default']);
}
* Test that invalid types are returned with appropriate errors.
*/
public function testMailingContactInvalidType() {
- $params = array(
+ $params = [
'contact_id' => 23,
'type' => 'invalid',
- );
+ ];
$this->callAPIFailure('MailingContact', 'get', $params);
}
* Test for success result when there are no mailings for a the given contact.
*/
public function testMailingContactNoMailings() {
- $params = array(
+ $params = [
'contact_id' => $this->_contact['id'],
- );
+ ];
$result = $this->callAPISuccess('MailingContact', 'get', $params);
$this->assertEquals($result['count'], 0);
$this->assertTrue(empty($result['values']));
* Test civicrm_mailing_group_event_subscribe with wrong params.
*/
public function testMailerGroupSubscribeWrongParams() {
- $params = array(
+ $params = [
'email' => $this->_email,
'group_id' => 'Wrong Group ID',
'contact_id' => '2121',
'time_stamp' => '20111111010101',
'hash' => 'sasa',
- );
+ ];
$this->callAPIFailure('mailing_event_subscribe', 'create', $params);
}
* Test civicrm_mailing_group_event_subscribe with given contact ID.
*/
public function testMailerGroupSubscribeGivenContactId() {
- $params = array(
+ $params = [
'first_name' => 'Test',
'last_name' => 'Test',
'email' => $this->_email,
'contact_type' => 'Individual',
- );
+ ];
$contactID = $this->individualCreate($params);
- $params = array(
+ $params = [
'email' => $this->_email,
'group_id' => $this->_groupID,
'contact_id' => $contactID,
'hash' => 'b15de8b64e2cec34',
'time_stamp' => '20101212121212',
- );
+ ];
$result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
* Test civicrm_mailing_group_event_unsubscribe with wrong params.
*/
public function testMailerGroupUnsubscribeWrongParams() {
- $params = array(
+ $params = [
'job_id' => 'Wrong ID',
'event_queue_id' => 'Wrong ID',
'hash' => 'Wrong Hash',
'time_stamp' => '20101212121212',
- );
+ ];
$this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
}
* Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
*/
public function testMailerGroupDomainUnsubscribeWrongParams() {
- $params = array(
+ $params = [
'job_id' => 'Wrong ID',
'event_queue_id' => 'Wrong ID',
'hash' => 'Wrong Hash',
'org_unsubscribe' => 1,
'time_stamp' => '20101212121212',
- );
+ ];
$this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
}
* Test civicrm_mailing_group_event_resubscribe with wrong params.
*/
public function testMailerGroupResubscribeWrongParams() {
- $params = array(
+ $params = [
'job_id' => 'Wrong ID',
'event_queue_id' => 'Wrong ID',
'hash' => 'Wrong Hash',
'org_unsubscribe' => 'test',
'time_stamp' => '20101212121212',
- );
+ ];
$this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
}
* Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
*/
public function testMailerProcess() {
- $params = array(
+ $params = [
'first_name' => 'Test',
'last_name' => 'Test',
'email' => $this->_email,
'contact_type' => 'Individual',
- );
+ ];
$contactID = $this->individualCreate($params);
- $params = array(
+ $params = [
'email' => $this->_email,
'group_id' => $this->_groupID,
'contact_id' => $contactID,
'hash' => 'b15de8b64e2cec34',
'time_stamp' => '20101212121212',
- );
+ ];
$result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
$this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
- $params = array(
+ $params = [
'contact_id' => $result['values'][$result['id']]['contact_id'],
'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
'hash' => $result['values'][$result['id']]['hash'],
'time_stamp' => '20101212121212',
'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
- );
+ ];
$this->callAPISuccess('mailing_event_confirm', 'create', $params);
$this->contactDelete($contactID);
protected $_groupID;
protected $_email;
protected $_apiversion = 3;
- protected $_params = array();
+ protected $_params = [];
protected $_entity = 'Mailing';
protected $_contactID;
$this->_contactID = $this->individualCreate();
$this->_groupID = $this->groupCreate();
$this->_email = 'test@test.test';
- $this->_params = array(
+ $this->_params = [
'subject' => 'Hello {contact.display_name}',
'body_text' => "This is {contact.display_name}.\nhttps://civicrm.org\n{domain.address}{action.optOutUrl}",
'body_html' => "<link href='https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700|Zilla+Slab:500,700' rel='stylesheet' type='text/css'><p><a href=\"http://{action.forward}\">Forward this email</a><a href=\"{action.forward}\">Forward this email with no protocol</a></p<p>This is {contact.display_name}.</p><p><a href='https://civicrm.org/'>CiviCRM.org</a></p><p>{domain.address}{action.optOutUrl}</p>",
'created_id' => $this->_contactID,
'header_id' => '',
'footer_id' => '',
- );
+ ];
- $this->footer = civicrm_api3('MailingComponent', 'create', array(
+ $this->footer = civicrm_api3('MailingComponent', 'create', [
'name' => 'test domain footer',
'component_type' => 'footer',
'body_html' => '<p>From {domain.address}. To opt out, go to {action.optOutUrl}.</p>',
'body_text' => 'From {domain.address}. To opt out, go to {action.optOutUrl}.',
- ));
+ ]);
}
public function tearDown() {
* Test civicrm_mailing_create.
*/
public function testMailerCreateSuccess() {
- $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
- $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
+ $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + ['scheduled_date' => 'now'], __FUNCTION__, __FILE__);
+ $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]);
$this->assertEquals(1, $jobs['count']);
// return isn't working on this in getAndCheck so lets not check it for now
unset($this->_params['created_id']);
public function testMailerCreateCompleted() {
$this->_params['body_html'] = 'I am completed so it does not matter if there is an opt out link since I have already been sent by another system';
$this->_params['is_completed'] = 1;
- $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
- $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
+ $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + ['scheduled_date' => 'now'], __FUNCTION__, __FILE__);
+ $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $result['id']]);
$this->assertEquals(1, $jobs['count']);
$this->assertEquals('Complete', $jobs['values'][$jobs['id']]['status']);
// return isn't working on this in getAndCheck so lets not check it for now
*/
public function testMailerCreateSuccessNoCreatedID() {
unset($this->_params['created_id']);
- $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + ['scheduled_date' => 'now'], __FUNCTION__, __FILE__);
$this->getAndCheck($this->_params, $result['id'], 'mailing');
}
*
*/
public function testTemplateTypeOptions() {
- $types = $this->callAPISuccess('Mailing', 'getoptions', array('field' => 'template_type'));
+ $types = $this->callAPISuccess('Mailing', 'getoptions', ['field' => 'template_type']);
$this->assertTrue(isset($types['values']['traditional']));
}
public function testMailerCreateTemplateOptions() {
// 1. Create mailing with template_options.
$params = $this->_params;
- $params['template_options'] = json_encode(array('foo' => 'bar_1'));
+ $params['template_options'] = json_encode(['foo' => 'bar_1']);
$createResult = $this->callAPISuccess('mailing', 'create', $params);
$id = $createResult['id'];
- $this->assertDBQuery('{"foo":"bar_1"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', array(
- 1 => array($id, 'Int'),
- ));
+ $this->assertDBQuery('{"foo":"bar_1"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', [
+ 1 => [$id, 'Int'],
+ ]);
$this->assertEquals('bar_1', $createResult['values'][$id]['template_options']['foo']);
// 2. Get mailing with template_options.
- $getResult = $this->callAPISuccess('mailing', 'get', array(
+ $getResult = $this->callAPISuccess('mailing', 'get', [
'id' => $id,
- ));
+ ]);
$this->assertEquals('bar_1', $getResult['values'][$id]['template_options']['foo']);
- $getValueResult = $this->callAPISuccess('mailing', 'getvalue', array(
+ $getValueResult = $this->callAPISuccess('mailing', 'getvalue', [
'id' => $id,
'return' => 'template_options',
- ));
+ ]);
$this->assertEquals('bar_1', $getValueResult['foo']);
// 3. Update mailing with template_options.
- $updateResult = $this->callAPISuccess('mailing', 'create', array(
+ $updateResult = $this->callAPISuccess('mailing', 'create', [
'id' => $id,
- 'template_options' => array('foo' => 'bar_2'),
- ));
- $this->assertDBQuery('{"foo":"bar_2"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', array(
- 1 => array($id, 'Int'),
- ));
+ 'template_options' => ['foo' => 'bar_2'],
+ ]);
+ $this->assertDBQuery('{"foo":"bar_2"}', 'SELECT template_options FROM civicrm_mailing WHERE id = %1', [
+ 1 => [$id, 'Int'],
+ ]);
$this->assertEquals('bar_2', $updateResult['values'][$id]['template_options']['foo']);
}
*/
public function testMagicGroups_create_update() {
// BEGIN SAMPLE DATA
- $groupIDs['a'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
- $groupIDs['b'] = $this->groupCreate(array('name' => 'Example exclude group', 'title' => 'Example exclude group'));
- $contactIDs['a'] = $this->individualCreate(array(
+ $groupIDs['a'] = $this->groupCreate(['name' => 'Example include group', 'title' => 'Example include group']);
+ $groupIDs['b'] = $this->groupCreate(['name' => 'Example exclude group', 'title' => 'Example exclude group']);
+ $contactIDs['a'] = $this->individualCreate([
'email' => 'include.me@example.org',
'first_name' => 'Includer',
'last_name' => 'Person',
- ));
- $contactIDs['b'] = $this->individualCreate(array(
+ ]);
+ $contactIDs['b'] = $this->individualCreate([
'email' => 'exclude.me@example.org',
'last_name' => 'Excluder',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['a'],
'contact_id' => $contactIDs['a'],
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['b'],
'contact_id' => $contactIDs['b'],
- ));
+ ]);
// END SAMPLE DATA
// ** Pass 1: Create
$createParams['mailings']['exclude'] = [];
$createParams['scheduled_date'] = 'now';
$createResult = $this->callAPISuccess('Mailing', 'create', $createParams);
- $getGroup1 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id']));
+ $getGroup1 = $this->callAPISuccess('MailingGroup', 'get', ['mailing_id' => $createResult['id']]);
$getGroup1_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup1['values']));
- $this->assertEquals(array($groupIDs['a']), $getGroup1_ids);
- $getRecipient1 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id']));
+ $this->assertEquals([$groupIDs['a']], $getGroup1_ids);
+ $getRecipient1 = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $createResult['id']]);
$getRecipient1_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient1['values']));
- $this->assertEquals(array($contactIDs['a']), $getRecipient1_ids);
+ $this->assertEquals([$contactIDs['a']], $getRecipient1_ids);
// ** Pass 2: Update without any changes to groups[include]
$nullOpParams = $createParams;
$updateParams['api.mailing_job.create'] = 1;
unset($nullOpParams['groups']['include']);
$this->callAPISuccess('Mailing', 'create', $nullOpParams);
- $getGroup2 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id']));
+ $getGroup2 = $this->callAPISuccess('MailingGroup', 'get', ['mailing_id' => $createResult['id']]);
$getGroup2_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup2['values']));
- $this->assertEquals(array($groupIDs['a']), $getGroup2_ids);
- $getRecipient2 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id']));
+ $this->assertEquals([$groupIDs['a']], $getGroup2_ids);
+ $getRecipient2 = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $createResult['id']]);
$getRecip2_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient2['values']));
- $this->assertEquals(array($contactIDs['a']), $getRecip2_ids);
+ $this->assertEquals([$contactIDs['a']], $getRecip2_ids);
// ** Pass 3: Update with different groups[include]
$updateParams = $createParams;
$updateParams['id'] = $createResult['id'];
- $updateParams['groups']['include'] = array($groupIDs['b']);
+ $updateParams['groups']['include'] = [$groupIDs['b']];
$updateParams['scheduled_date'] = 'now';
$this->callAPISuccess('Mailing', 'create', $updateParams);
- $getGroup3 = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $createResult['id']));
+ $getGroup3 = $this->callAPISuccess('MailingGroup', 'get', ['mailing_id' => $createResult['id']]);
$getGroup3_ids = array_values(CRM_Utils_Array::collect('entity_id', $getGroup3['values']));
- $this->assertEquals(array($groupIDs['b']), $getGroup3_ids);
- $getRecipient3 = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $createResult['id']));
+ $this->assertEquals([$groupIDs['b']], $getGroup3_ids);
+ $getRecipient3 = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $createResult['id']]);
$getRecipient3_ids = array_values(CRM_Utils_Array::collect('contact_id', $getRecipient3['values']));
- $this->assertEquals(array($contactIDs['b']), $getRecipient3_ids);
+ $this->assertEquals([$contactIDs['b']], $getRecipient3_ids);
}
public function testMailerPreview() {
// BEGIN SAMPLE DATA
$contactID = $this->individualCreate();
- $displayName = $this->callAPISuccess('contact', 'get', array('id' => $contactID));
+ $displayName = $this->callAPISuccess('contact', 'get', ['id' => $contactID]);
$displayName = $displayName['values'][$contactID]['display_name'];
$this->assertTrue(!empty($displayName));
$params = $this->_params;
- $params['api.Mailing.preview'] = array(
+ $params['api.Mailing.preview'] = [
'id' => '$value.id',
'contact_id' => $contactID,
- );
+ ];
$params['options']['force_rollback'] = 1;
// END SAMPLE DATA
- $maxIDs = array(
+ $maxIDs = [
'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'),
'job' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_job'),
'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'),
'recipient' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_recipients'),
- );
+ ];
$result = $this->callAPISuccess('mailing', 'create', $params);
// 'Preview should not create any mailing records'
$this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing');
public function testMailerPreviewUnknownContact() {
$params = $this->_params;
- $params['api.Mailing.preview'] = array(
+ $params['api.Mailing.preview'] = [
'id' => '$value.id',
- );
+ ];
$result = $this->callAPISuccess('mailing', 'create', $params);
public function testMailerPreviewRecipients() {
// BEGIN SAMPLE DATA
- $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
- $groupIDs['exc'] = $this->groupCreate(array('name' => 'Example exclude group', 'title' => 'Example exclude group'));
- $contactIDs['include_me'] = $this->individualCreate(array(
+ $groupIDs['inc'] = $this->groupCreate(['name' => 'Example include group', 'title' => 'Example include group']);
+ $groupIDs['exc'] = $this->groupCreate(['name' => 'Example exclude group', 'title' => 'Example exclude group']);
+ $contactIDs['include_me'] = $this->individualCreate([
'email' => 'include.me@example.org',
'first_name' => 'Includer',
'last_name' => 'Person',
- ));
- $contactIDs['exclude_me'] = $this->individualCreate(array(
+ ]);
+ $contactIDs['exclude_me'] = $this->individualCreate([
'email' => 'exclude.me@example.org',
'last_name' => 'Excluder',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['inc'],
'contact_id' => $contactIDs['include_me'],
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['inc'],
'contact_id' => $contactIDs['exclude_me'],
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['exc'],
'contact_id' => $contactIDs['exclude_me'],
- ));
+ ]);
$params = $this->_params;
- $params['groups']['include'] = array($groupIDs['inc']);
- $params['groups']['exclude'] = array($groupIDs['exc']);
- $params['mailings']['include'] = array();
- $params['mailings']['exclude'] = array();
+ $params['groups']['include'] = [$groupIDs['inc']];
+ $params['groups']['exclude'] = [$groupIDs['exc']];
+ $params['mailings']['include'] = [];
+ $params['mailings']['exclude'] = [];
$params['options']['force_rollback'] = 1;
- $params['api.MailingRecipients.get'] = array(
+ $params['api.MailingRecipients.get'] = [
'mailing_id' => '$value.id',
- 'api.contact.getvalue' => array(
+ 'api.contact.getvalue' => [
'return' => 'display_name',
- ),
- 'api.email.getvalue' => array(
+ ],
+ 'api.email.getvalue' => [
'return' => 'email',
- ),
- );
+ ],
+ ];
// END SAMPLE DATA
- $maxIDs = array(
+ $maxIDs = [
'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'),
'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'),
- );
+ ];
$create = $this->callAPIAndDocument('Mailing', 'create', $params, __FUNCTION__, __FILE__);
// 'Preview should not create any mailing records'
$this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing');
$preview = $create['values'][$create['id']]['api.MailingRecipients.get'];
$previewIds = array_values(CRM_Utils_Array::collect('contact_id', $preview['values']));
- $this->assertEquals(array((string) $contactIDs['include_me']), $previewIds);
+ $this->assertEquals([(string) $contactIDs['include_me']], $previewIds);
$previewEmails = array_values(CRM_Utils_Array::collect('api.email.getvalue', $preview['values']));
- $this->assertEquals(array('include.me@example.org'), $previewEmails);
+ $this->assertEquals(['include.me@example.org'], $previewEmails);
$previewNames = array_values(CRM_Utils_Array::collect('api.contact.getvalue', $preview['values']));
$this->assertTrue((bool) preg_match('/Includer Person/', $previewNames[0]), "Name 'Includer Person' should appear in '" . $previewNames[0] . '"');
}
*/
public function testMailerPreviewRecipientsDeduplicateAndOnholdEmails() {
// BEGIN SAMPLE DATA
- $groupIDs['grp'] = $this->groupCreate(array('name' => 'Example group', 'title' => 'Example group'));
- $contactIDs['include_me'] = $this->individualCreate(array(
+ $groupIDs['grp'] = $this->groupCreate(['name' => 'Example group', 'title' => 'Example group']);
+ $contactIDs['include_me'] = $this->individualCreate([
'email' => 'include.me@example.org',
'first_name' => 'Includer',
'last_name' => 'Person',
- ));
- $contactIDs['include_me_duplicate'] = $this->individualCreate(array(
+ ]);
+ $contactIDs['include_me_duplicate'] = $this->individualCreate([
'email' => 'include.me@example.org',
'first_name' => 'IncluderDuplicate',
'last_name' => 'Person',
- ));
+ ]);
- $contactIDs['include_me_onhold'] = $this->individualCreate(array(
+ $contactIDs['include_me_onhold'] = $this->individualCreate([
'email' => 'onholdinclude.me@example.org',
'first_name' => 'Onhold',
'last_name' => 'Person',
- ));
- $emailId = $this->callAPISuccessGetValue('Email', array(
+ ]);
+ $emailId = $this->callAPISuccessGetValue('Email', [
'return' => 'id',
'contact_id' => $contactIDs['include_me_onhold'],
- ));
- $this->callAPISuccess('Email', 'create', array(
+ ]);
+ $this->callAPISuccess('Email', 'create', [
'id' => $emailId,
'on_hold' => 1,
- ));
+ ]);
- $this->callAPISuccess('GroupContact', 'create', array(
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['grp'],
'contact_id' => $contactIDs['include_me'],
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['grp'],
'contact_id' => $contactIDs['include_me_duplicate'],
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['grp'],
'contact_id' => $contactIDs['include_me_onhold'],
- ));
+ ]);
$params = $this->_params;
- $params['groups']['include'] = array($groupIDs['grp']);
- $params['mailings']['include'] = array();
+ $params['groups']['include'] = [$groupIDs['grp']];
+ $params['mailings']['include'] = [];
$params['options']['force_rollback'] = 1;
$params['dedupe_email'] = 1;
- $params['api.MailingRecipients.get'] = array(
+ $params['api.MailingRecipients.get'] = [
'mailing_id' => '$value.id',
- 'api.contact.getvalue' => array(
+ 'api.contact.getvalue' => [
'return' => 'display_name',
- ),
- 'api.email.getvalue' => array(
+ ],
+ 'api.email.getvalue' => [
'return' => 'email',
- ),
- );
+ ],
+ ];
// END SAMPLE DATA
$create = $this->callAPISuccess('Mailing', 'create', $params);
$preview = $create['values'][$create['id']]['api.MailingRecipients.get'];
$this->assertEquals(1, $preview['count']);
$previewEmails = array_values(CRM_Utils_Array::collect('api.email.getvalue', $preview['values']));
- $this->assertEquals(array('include.me@example.org'), $previewEmails);
+ $this->assertEquals(['include.me@example.org'], $previewEmails);
}
/**
* Test sending a test mailing.
*/
public function testMailerSendTest_email() {
- $contactIDs['alice'] = $this->individualCreate(array(
+ $contactIDs['alice'] = $this->individualCreate([
'email' => 'alice@example.org',
'first_name' => 'Alice',
'last_name' => 'Person',
- ));
+ ]);
$mail = $this->callAPISuccess('mailing', 'create', $this->_params);
- $params = array('mailing_id' => $mail['id'], 'test_email' => 'ALicE@example.org', 'test_group' => NULL);
+ $params = ['mailing_id' => $mail['id'], 'test_email' => 'ALicE@example.org', 'test_group' => NULL];
// Per https://lab.civicrm.org/dev/core/issues/229 ensure this is not passed through!
// Per https://lab.civicrm.org/dev/mail/issues/32 test non-lowercase email
$params['id'] = $mail['id'];
$this->assertEquals(1, $deliveredInfo['count']);
$deliveredContacts = array_values(CRM_Utils_Array::collect('contact_id', $deliveredInfo['values']));
- $this->assertEquals(array($contactIDs['alice']), $deliveredContacts);
+ $this->assertEquals([$contactIDs['alice']], $deliveredContacts);
$deliveredEmails = array_values(CRM_Utils_Array::collect('email', $deliveredInfo['values']));
- $this->assertEquals(array('alice@example.org'), $deliveredEmails);
+ $this->assertEquals(['alice@example.org'], $deliveredEmails);
}
/**
*/
public function testMailerSendTest_group() {
// BEGIN SAMPLE DATA
- $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
- $contactIDs['alice'] = $this->individualCreate(array(
+ $groupIDs['inc'] = $this->groupCreate(['name' => 'Example include group', 'title' => 'Example include group']);
+ $contactIDs['alice'] = $this->individualCreate([
'email' => 'alice@example.org',
'first_name' => 'Alice',
'last_name' => 'Person',
- ));
- $contactIDs['bob'] = $this->individualCreate(array(
+ ]);
+ $contactIDs['bob'] = $this->individualCreate([
'email' => 'bob@example.org',
'first_name' => 'Bob',
'last_name' => 'Person',
- ));
- $contactIDs['carol'] = $this->individualCreate(array(
+ ]);
+ $contactIDs['carol'] = $this->individualCreate([
'email' => 'carol@example.org',
'first_name' => 'Carol',
'last_name' => 'Person',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['inc'],
'contact_id' => $contactIDs['alice'],
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['inc'],
'contact_id' => $contactIDs['bob'],
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['inc'],
'contact_id' => $contactIDs['carol'],
- ));
+ ]);
// END SAMPLE DATA
$mail = $this->callAPISuccess('mailing', 'create', $this->_params);
- $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', array(
+ $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', [
'mailing_id' => $mail['id'],
'test_email' => NULL,
'test_group' => $groupIDs['inc'],
- ));
+ ]);
// verify mail has been sent to user by count
$this->assertEquals(3, $deliveredInfo['count'], "in line " . __LINE__);
$deliveredContacts = array_values(CRM_Utils_Array::collect('contact_id', $deliveredInfo['values']));
- $this->assertEquals(array($contactIDs['alice'], $contactIDs['bob'], $contactIDs['carol']), $deliveredContacts);
+ $this->assertEquals([$contactIDs['alice'], $contactIDs['bob'], $contactIDs['carol']], $deliveredContacts);
$deliveredEmails = array_values(CRM_Utils_Array::collect('email', $deliveredInfo['values']));
- $this->assertEquals(array('alice@example.org', 'bob@example.org', 'carol@example.org'), $deliveredEmails);
+ $this->assertEquals(['alice@example.org', 'bob@example.org', 'carol@example.org'], $deliveredEmails);
}
/**
*/
public function submitProvider() {
// $useLogin, $params, $expectedFailure, $expectedJobCount
- $cases = array();
- $cases[] = array(
+ $cases = [];
+ $cases[] = [
//useLogin
TRUE,
// createParams
- array(),
- array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
+ [],
+ ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'],
// expectedFailure
FALSE,
// expectedJobCount
1,
- );
- $cases[] = array(
+ ];
+ $cases[] = [
//useLogin
FALSE,
// createParams
- array(),
- array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
+ [],
+ ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'],
// expectedFailure
"/Failed to determine current user/",
// expectedJobCount
0,
- );
- $cases[] = array(
+ ];
+ $cases[] = [
//useLogin
TRUE,
// createParams
- array(),
- array('scheduled_date' => '2014-12-13 10:00:00'),
+ [],
+ ['scheduled_date' => '2014-12-13 10:00:00'],
// expectedFailure
FALSE,
// expectedJobCount
1,
- );
- $cases[] = array(
+ ];
+ $cases[] = [
//useLogin
TRUE,
// createParams
- array(),
- array(),
+ [],
+ [],
// expectedFailure
"/Missing parameter scheduled_date and.or approval_date/",
// expectedJobCount
0,
- );
- $cases[] = array(
+ ];
+ $cases[] = [
//useLogin
TRUE,
// createParams
- array('name' => ''),
- array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
+ ['name' => ''],
+ ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'],
// expectedFailure
"/Mailing cannot be sent. There are missing or invalid fields \\(name\\)./",
// expectedJobCount
0,
- );
- $cases[] = array(
+ ];
+ $cases[] = [
//useLogin
TRUE,
// createParams
- array('body_html' => '', 'body_text' => ''),
- array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
+ ['body_html' => '', 'body_text' => ''],
+ ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'],
// expectedFailure
"/Mailing cannot be sent. There are missing or invalid fields \\(body\\)./",
// expectedJobCount
0,
- );
- $cases[] = array(
+ ];
+ $cases[] = [
//useLogin
TRUE,
// createParams
- array('body_html' => 'Oops, did I leave my tokens at home?'),
- array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
+ ['body_html' => 'Oops, did I leave my tokens at home?'],
+ ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'],
// expectedFailure
"/Mailing cannot be sent. There are missing or invalid fields \\(.*body_html.*optOut.*\\)./",
// expectedJobCount
0,
- );
- $cases[] = array(
+ ];
+ $cases[] = [
//useLogin
TRUE,
// createParams
- array('body_text' => 'Oops, did I leave my tokens at home?'),
- array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
+ ['body_text' => 'Oops, did I leave my tokens at home?'],
+ ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'],
// expectedFailure
"/Mailing cannot be sent. There are missing or invalid fields \\(.*body_text.*optOut.*\\)./",
// expectedJobCount
0,
- );
- $cases[] = array(
+ ];
+ $cases[] = [
//useLogin
TRUE,
// createParams
- array('body_text' => 'Look ma, magic tokens in the text!', 'footer_id' => '%FOOTER%'),
- array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
+ ['body_text' => 'Look ma, magic tokens in the text!', 'footer_id' => '%FOOTER%'],
+ ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'],
// expectedFailure
FALSE,
// expectedJobCount
1,
- );
- $cases[] = array(
+ ];
+ $cases[] = [
//useLogin
TRUE,
// createParams
- array('body_html' => '<p>Look ma, magic tokens in the markup!</p>', 'footer_id' => '%FOOTER%'),
- array('scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'),
+ ['body_html' => '<p>Look ma, magic tokens in the markup!</p>', 'footer_id' => '%FOOTER%'],
+ ['scheduled_date' => '2014-12-13 10:00:00', 'approval_date' => '2014-12-13 00:00:00'],
// expectedFailure
FALSE,
// expectedJobCount
1,
- );
+ ];
return $cases;
}
$this->assertTrue(is_numeric($submitResult['values'][$id]['scheduled_id']));
$this->assertEquals($submitParams['scheduled_date'], $submitResult['values'][$id]['scheduled_date']);
}
- $this->assertDBQuery($expectedJobCount, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array(
- 1 => array($id, 'Integer'),
- ));
+ $this->assertDBQuery($expectedJobCount, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [
+ 1 => [$id, 'Integer'],
+ ]);
}
/**
*/
public function testUnsubscribeGroupList() {
// Create set of groups and add a contact to both of them.
- $groupID2 = $this->groupCreate(array('name' => 'Test group 2', 'title' => 'group title 2'));
- $groupID3 = $this->groupCreate(array('name' => 'Test group 3', 'title' => 'group title 3'));
+ $groupID2 = $this->groupCreate(['name' => 'Test group 2', 'title' => 'group title 2']);
+ $groupID3 = $this->groupCreate(['name' => 'Test group 3', 'title' => 'group title 3']);
$contactId = $this->individualCreate();
- foreach (array($groupID2, $groupID3) as $grp) {
- $params = array(
+ foreach ([$groupID2, $groupID3] as $grp) {
+ $params = [
'contact_id' => $contactId,
'group_id' => $grp,
- );
+ ];
$this->callAPISuccess('GroupContact', 'create', $params);
}
//Send mail to groupID3
$mail = $this->callAPISuccess('mailing', 'create', $this->_params);
- $params = array('mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $groupID3);
+ $params = ['mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $groupID3];
$this->callAPISuccess($this->_entity, 'send_test', $params);
- $mgParams = array(
+ $mgParams = [
'mailing_id' => $mail['id'],
'entity_table' => 'civicrm_group',
'entity_id' => $groupID3,
'group_type' => 'Include',
- );
+ ];
$mailingGroup = $this->callAPISuccess('MailingGroup', 'create', $mgParams);
//Include previous mail in the mailing group.
$mail2 = $this->callAPISuccess('mailing', 'create', $this->_params);
- $params = array('mailing_id' => $mail2['id'], 'test_email' => NULL, 'test_group' => $groupID3);
+ $params = ['mailing_id' => $mail2['id'], 'test_email' => NULL, 'test_group' => $groupID3];
$this->callAPISuccess($this->_entity, 'send_test', $params);
- $mgParams = array(
+ $mgParams = [
'mailing_id' => $mail2['id'],
'entity_table' => 'civicrm_mailing',
'entity_id' => $mail['id'],
'group_type' => 'Include',
- );
+ ];
$mailingGroup = $this->callAPISuccess('MailingGroup', 'create', $mgParams);
//CRM-20431 - Delete group id that matches first mailing id.
- $this->callAPISuccess('Group', 'delete', array('id' => $this->_groupID));
+ $this->callAPISuccess('Group', 'delete', ['id' => $this->_groupID]);
$jobId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_MailingJob', $mail2['id'], 'id', 'mailing_id');
$hash = CRM_Core_DAO::getFieldValue('CRM_Mailing_Event_DAO_Queue', $jobId, 'hash', 'job_id');
$queueId = CRM_Core_DAO::getFieldValue('CRM_Mailing_Event_DAO_Queue', $jobId, 'id', 'job_id');
//Create and send test mail first and change the mail job to live,
//because stats api only works on live mail
$mail = $this->callAPISuccess('mailing', 'create', $this->_params);
- $params = array('mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $this->_groupID);
+ $params = ['mailing_id' => $mail['id'], 'test_email' => NULL, 'test_group' => $this->_groupID];
$deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params);
$deliveredIds = implode(',', array_keys($deliveredInfo['values']));
$sql = "UPDATE civicrm_mailing_job SET is_test = 0 WHERE mailing_id = {$mail['id']}";
CRM_Core_DAO::executeQuery($sql);
- foreach (array('bounce', 'unsubscribe', 'opened') as $type) {
+ foreach (['bounce', 'unsubscribe', 'opened'] as $type) {
$sql = "CREATE TEMPORARY TABLE mail_{$type}_temp
(event_queue_id int, time_stamp datetime, delivered_id int)
SELECT event_queue_id, time_stamp, id
CRM_Core_DAO::executeQuery($sql);
}
- $result = $this->callAPISuccess('mailing', 'stats', array('mailing_id' => $mail['id']));
- $expectedResult = array(
+ $result = $this->callAPISuccess('mailing', 'stats', ['mailing_id' => $mail['id']]);
+ $expectedResult = [
//since among 100 mails 20 has been bounced
'Delivered' => 80,
'Bounces' => 20,
'delivered_rate' => '80%',
'opened_rate' => '25%',
'clickthrough_rate' => '0%',
- );
+ ];
$this->checkArrayEquals($expectedResult, $result['values'][$mail['id']]);
}
*/
public function testMailerDeleteSuccess() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
+ $this->callAPIAndDocument($this->_entity, 'delete', ['id' => $result['id']], __FUNCTION__, __FILE__);
$this->assertAPIDeleted($this->_entity, $result['id']);
}
public function testMailGetTokens() {
$description = "Demonstrates fetching tokens for one or more entities (in this case \"Contact\" and \"Mailing\").
Optionally pass sequential=1 to have output ready-formatted for the select2 widget.";
- $result = $this->callAPIAndDocument($this->_entity, 'gettokens', array('entity' => array('Contact', 'Mailing')), __FUNCTION__, __FILE__, $description);
+ $result = $this->callAPIAndDocument($this->_entity, 'gettokens', ['entity' => ['Contact', 'Mailing']], __FUNCTION__, __FILE__, $description);
$this->assertContains('Contact Type', $result['values']);
// Check that passing "sequential" correctly outputs a hierarchical array
- $result = $this->callAPISuccess($this->_entity, 'gettokens', array('entity' => 'contact', 'sequential' => 1));
+ $result = $this->callAPISuccess($this->_entity, 'gettokens', ['entity' => 'contact', 'sequential' => 1]);
$this->assertArrayHasKey('text', $result['values'][0]);
$this->assertArrayHasKey('id', $result['values'][0]['children'][0]);
}
public function testClone() {
// BEGIN SAMPLE DATA
- $groupIDs['inc'] = $this->groupCreate(array('name' => 'Example include group', 'title' => 'Example include group'));
- $contactIDs['include_me'] = $this->individualCreate(array(
+ $groupIDs['inc'] = $this->groupCreate(['name' => 'Example include group', 'title' => 'Example include group']);
+ $contactIDs['include_me'] = $this->individualCreate([
'email' => 'include.me@example.org',
'first_name' => 'Includer',
'last_name' => 'Person',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupIDs['inc'],
'contact_id' => $contactIDs['include_me'],
- ));
+ ]);
$params = $this->_params;
- $params['groups']['include'] = array($groupIDs['inc']);
- $params['groups']['exclude'] = array();
- $params['mailings']['include'] = array();
- $params['mailings']['exclude'] = array();
+ $params['groups']['include'] = [$groupIDs['inc']];
+ $params['groups']['exclude'] = [];
+ $params['mailings']['include'] = [];
+ $params['mailings']['exclude'] = [];
// END SAMPLE DATA
$create = $this->callAPISuccess('Mailing', 'create', $params);
$created = $this->callAPISuccess('Mailing', 'get', []);
$createId = $create['id'];
$this->createLoggedInUser();
- $clone = $this->callAPIAndDocument('Mailing', 'clone', array('id' => $create['id']), __FUNCTION__, __FILE__);
+ $clone = $this->callAPIAndDocument('Mailing', 'clone', ['id' => $create['id']], __FUNCTION__, __FILE__);
$cloneId = $clone['id'];
$this->assertNotEquals($createId, $cloneId, 'Create and clone should return different records');
$this->assertNotEquals($create['values'][$createId]['created_id'], $clone['values'][$cloneId]['created_id'], 'Clone should be created by a different person');
// Target groups+mailings are special.
- $cloneGroups = $this->callAPISuccess('MailingGroup', 'get', array('mailing_id' => $cloneId, 'sequential' => 1));
+ $cloneGroups = $this->callAPISuccess('MailingGroup', 'get', ['mailing_id' => $cloneId, 'sequential' => 1]);
$this->assertEquals(1, $cloneGroups['count']);
$this->assertEquals($cloneGroups['values'][0]['group_type'], 'Include');
$this->assertEquals($cloneGroups['values'][0]['entity_table'], 'civicrm_group');
* success test
*/
public function testMailerBounceWrongParams() {
- $params = array(
+ $params = [
'job_id' => 'Wrong ID',
'event_queue_id' => 'Wrong ID',
'hash' => 'Wrong Hash',
'body' => 'Body...',
'time_stamp' => '20111109212100',
- );
+ ];
$this->callAPIFailure('mailing_event', 'bounce', $params,
'Queue event could not be found'
);
* success test
*/
public function testMailerConfirmWrongParams() {
- $params = array(
+ $params = [
'contact_id' => 'Wrong ID',
'subscribe_id' => 'Wrong ID',
'hash' => 'Wrong Hash',
'event_subscribe_id' => '123',
'time_stamp' => '20111111010101',
- );
+ ];
$this->callAPIFailure('mailing_event', 'confirm', $params,
'contact_id is not a valid integer'
);
* success test
*/
public function testMailerReplyWrongParams() {
- $params = array(
+ $params = [
'job_id' => 'Wrong ID',
'event_queue_id' => 'Wrong ID',
'hash' => 'Wrong Hash',
'bodyTxt' => 'Body...',
'replyTo' => $this->_email,
'time_stamp' => '20111111010101',
- );
+ ];
$this->callAPIFailure('mailing_event', 'reply', $params,
'Queue event could not be found'
);
* success test
*/
public function testMailerForwardWrongParams() {
- $params = array(
+ $params = [
'job_id' => 'Wrong ID',
'event_queue_id' => 'Wrong ID',
'hash' => 'Wrong Hash',
'email' => $this->_email,
'time_stamp' => '20111111010101',
- );
+ ];
$this->callAPIFailure('mailing_event', 'forward', $params,
'Queue event could not be found'
);
* Extra parameters for the draft mailing.
* @return array|int
*/
- public function createDraftMailing($params = array()) {
+ public function createDraftMailing($params = []) {
$createParams = array_merge($this->_params, $params);
$createResult = $this->callAPISuccess('mailing', 'create', $createParams, __FUNCTION__, __FILE__);
$this->assertTrue(is_numeric($createResult['id']));
- $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', array(
- 1 => array($createResult['id'], 'Integer'),
- ));
+ $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_mailing_job WHERE mailing_id = %1', [
+ 1 => [$createResult['id'], 'Integer'],
+ ]);
return $createResult['id'];
}
* we can still have working click-trough URLs working (CRM-17959).
*/
public function testUrlWithMissingTrackingHash() {
- $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
- $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $mail['id']));
+ $mail = $this->callAPISuccess('mailing', 'create', $this->_params + ['scheduled_date' => 'now'], __FUNCTION__, __FILE__);
+ $jobs = $this->callAPISuccess('mailing_job', 'get', ['mailing_id' => $mail['id']]);
$this->assertEquals(1, $jobs['count']);
- $params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL);
+ $params = ['mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL];
$deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params);
$sql = "SELECT turl.id as url_id, turl.url, q.id as queue_id
$this->_params['body_text'] = str_replace("https://civicrm.org", $unicodeURL, $this->_params['body_text']);
$this->_params['body_html'] = str_replace("https://civicrm.org", $unicodeURL, $this->_params['body_html']);
- $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('scheduled_date' => 'now'));
+ $mail = $this->callAPISuccess('mailing', 'create', $this->_params + ['scheduled_date' => 'now']);
- $params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL);
+ $params = ['mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL];
$this->callAPISuccess($this->_entity, 'send_test', $params);
$sql = "SELECT turl.id as url_id, turl.url, q.id as queue_id
* if modified_date less then the date when the mail was last updated/created
*/
public function testModifiedDateMismatchOnMailingUpdate() {
- $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('modified_date' => 'now'));
+ $mail = $this->callAPISuccess('mailing', 'create', $this->_params + ['modified_date' => 'now']);
try {
- $this->callAPISuccess('mailing', 'create', $this->_params + array('id' => $mail['id'], 'modified_date' => '2 seconds ago'));
+ $this->callAPISuccess('mailing', 'create', $this->_params + ['id' => $mail['id'], 'modified_date' => '2 seconds ago']);
}
catch (Exception $e) {
$this->assertRegExp("/Failure in api call for mailing create: Mailing has not been saved, Content maybe out of date, please refresh the page and try again/", $e->getMessage());
$this->_entity = 'mapping_field';
$mappingID = $this->mappingCreate();
- $this->params = array(
+ $this->params = [
'mapping_id' => $mappingID->id,
'name' => 'last_name',
'contact_type' => 'Individual',
'column_number' => 2,
'grouping' => 1,
- );
+ ];
}
public function testCreateMappingField() {
$result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
}
public function testDeleteMappingField() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => $result['id']);
+ $deleteParams = ['id' => $result['id']];
$result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testDeleteMappingFieldInvalid() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => 600);
+ $deleteParams = ['id' => 600];
$result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(1, $checkDeleted['count']);
}
$this->useTransaction(TRUE);
$this->_entity = 'mapping';
- $this->params = array(
+ $this->params = [
'name' => 'Mapping name',
'description' => 'Mapping description',
// 'Export Contact' mapping.
'mapping_type_id' => 7,
- );
+ ];
}
public function testCreateMapping() {
$result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
}
public function testDeleteMapping() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => $result['id']);
+ $deleteParams = ['id' => $result['id']];
$result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testDeleteMappingInvalid() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => 600);
+ $deleteParams = ['id' => 600];
$result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(1, $checkDeleted['count']);
}
protected $_contributionTypeID;
protected $_membershipTypeID;
protected $_membershipStatusID;
- protected $_contribution = array();
+ protected $_contribution = [];
public function setUp() {
parent::setUp();
$this->useTransaction(TRUE);
$this->_contactID = $this->organizationCreate(NULL);
- $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
+ $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]);
$this->_membershipStatusID = $this->membershipStatusCreate('test status');
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name');
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'currency' => 'USD',
'financial_type_id' => 1,
'trxn_id' => '22ereerwww322323',
'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
'thankyou_date' => '20080522',
- );
+ ];
$this->_contribution = $this->callAPISuccess('contribution', 'create', $params);
}
* Test civicrm_membership_payment_create with empty params.
*/
public function testCreateEmptyParams() {
- $this->callAPIFailure('membership_payment', 'create', array(), 'Mandatory key(s) missing from params array: membership_id, contribution_id');
+ $this->callAPIFailure('membership_payment', 'create', [], 'Mandatory key(s) missing from params array: membership_id, contribution_id');
}
/**
public function testCreate() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2006-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$membership = $this->callAPISuccess('membership', 'create', $params);
- $params = array(
+ $params = [
'contribution_id' => $this->_contribution['id'],
'membership_id' => $membership['id'],
- );
+ ];
$result = $this->callAPIAndDocument('membership_payment', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][$result['id']]['membership_id'], $membership['id'], 'Check Membership Id in line ' . __LINE__);
$this->assertEquals($result['values'][$result['id']]['contribution_id'], $this->_contribution['id'], 'Check Contribution Id in line ' . __LINE__);
*/
public function testGet() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID,
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$membership = $this->callAPISuccess('membership', 'create', $params);
- $params = array(
+ $params = [
'contribution_id' => $this->_contribution['id'],
'membership_id' => $membership['id'],
- );
+ ];
$this->callAPISuccess('membership_payment', 'create', $params);
$result = $this->callAPIAndDocument('membership_payment', 'get', $params, __FUNCTION__, __FILE__);
public function setUp() {
parent::setUp();
$this->_contactID = $this->individualCreate();
- $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
+ $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]);
$this->_membershipStatusID = $this->membershipStatusCreate('test status');
CRM_Member_PseudoConstant::membershipType($this->_membershipTypeID, TRUE);
* Test civicrm_membership_status_get with empty params.
*/
public function testGetEmptyParams() {
- $result = $this->callAPISuccess('membership_status', 'get', array());
+ $result = $this->callAPISuccess('membership_status', 'get', []);
// It should be 8 statuses, 7 default from mysql_data
// plus one test status added in setUp
$this->assertEquals(8, $result['count']);
* Test civicrm_membership_status_get. Success expected.
*/
public function testGet() {
- $params = array(
+ $params = [
'name' => 'test status',
- );
+ ];
$result = $this->callAPIAndDocument('membership_status', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][$this->_membershipStatusID]['name'], "test status", "In line " . __LINE__);
}
* Test civicrm_membership_status_get. Success expected.
*/
public function testGetLimit() {
- $result = $this->callAPISuccess('membership_status', 'get', array());
+ $result = $this->callAPISuccess('membership_status', 'get', []);
$this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__);
$params['option.limit'] = 1;
$result = $this->callAPISuccess('membership_status', 'get', $params);
}
public function testCreateDuplicateName() {
- $params = array('name' => 'name');
+ $params = ['name' => 'name'];
$result = $this->callAPISuccess('membership_status', 'create', $params);
$result = $this->callAPIFailure('membership_status', 'create', $params,
'A membership status with this name already exists.'
}
public function testCreateWithMissingRequired() {
- $params = array('title' => 'Does not make sense');
+ $params = ['title' => 'Does not make sense'];
$this->callAPIFailure('membership_status', 'create', $params, 'Mandatory key(s) missing from params array: name');
}
public function testCreate() {
- $params = array(
+ $params = [
'name' => 'test membership status',
- );
+ ];
$result = $this->callAPIAndDocument('membership_status', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($result['id']);
}
public function testUpdate() {
- $params = array(
+ $params = [
'name' => 'test membership status',
- );
+ ];
$result = $this->callAPISuccess('membership_status', 'create', $params);
$id = $result['id'];
$result = $this->callAPISuccess('membership_status', 'get', $params);
$this->assertEquals('test membership status', $result['values'][$id]['name']);
- $newParams = array(
+ $newParams = [
'id' => $id,
'name' => 'renamed',
- );
+ ];
$result = $this->callAPISuccess('membership_status', 'create', $newParams);
- $result = $this->callAPISuccess('membership_status', 'get', array('id' => $id));
+ $result = $this->callAPISuccess('membership_status', 'get', ['id' => $id]);
$this->assertEquals('renamed', $result['values'][$id]['name']);
$this->membershipStatusDelete($result['id']);
}
* Attempt (and fail) to delete membership status without an parameters.
*/
public function testDeleteEmptyParams() {
- $result = $this->callAPIFailure('membership_status', 'delete', array());
+ $result = $this->callAPIFailure('membership_status', 'delete', []);
}
public function testDeleteWithMissingRequired() {
- $params = array('title' => 'Does not make sense');
+ $params = ['title' => 'Does not make sense'];
$result = $this->callAPIFailure('membership_status', 'delete', $params);
}
public function testDelete() {
$membershipID = $this->membershipStatusCreate();
- $params = array(
+ $params = [
'id' => $membershipID,
- );
+ ];
$result = $this->callAPISuccess('membership_status', 'delete', $params);
}
$membershipStatusID = $this->membershipStatusCreate();
$this->_contactID = $this->individualCreate();
$this->_entity = 'membership';
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2009-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $membershipStatusID,
- );
+ ];
$result = $this->callAPISuccess('membership', 'create', $params);
$membershipID = $result['id'];
- $params = array(
+ $params = [
'id' => $membershipStatusID,
- );
+ ];
$result = $this->callAPIFailure('membership_status', 'delete', $params);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $membershipID,
- ));
+ ]);
$result = $this->callAPISuccess('membership_status', 'delete', $params);
}
parent::setUp();
$this->_apiversion = 3;
$this->_contactID = $this->individualCreate();
- $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
- $this->_membershipTypeID2 = $this->membershipTypeCreate(array(
+ $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]);
+ $this->_membershipTypeID2 = $this->membershipTypeCreate([
'period_type' => 'fixed',
// Ie. 1 March.
'fixed_period_start_day' => '301',
// Ie. 11 Nov.
'fixed_period_rollover_day' => '1111',
'name' => 'Another one',
- ));
+ ]);
$this->_membershipStatusID = $this->membershipStatusCreate('test status');
CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name');
$this->_entity = 'Membership';
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_contactID,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2009-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
}
/**
public function testMembershipDelete() {
$membershipID = $this->contactMembershipCreate($this->_params);
$this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
- $params = array(
+ $params = [
'id' => $membershipID,
- );
+ ];
$this->callAPIAndDocument('membership', 'delete', $params, __FUNCTION__, __FILE__);
$this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID);
}
public function testMembershipDeleteEmpty() {
- $this->callAPIFailure('membership', 'delete', array());
+ $this->callAPIFailure('membership', 'delete', []);
}
public function testMembershipDeleteInvalidID() {
- $this->callAPIFailure('membership', 'delete', array('id' => 'blah'));
+ $this->callAPIFailure('membership', 'delete', ['id' => 'blah']);
}
/**
$membershipID = $this->contactMembershipCreate($this->_params);
//DELETE
$this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
- $ContributionCreate = $this->callAPISuccess('Contribution', 'create', array(
+ $ContributionCreate = $this->callAPISuccess('Contribution', 'create', [
'sequential' => 1,
'financial_type_id' => "Member Dues",
'total_amount' => 100,
'contact_id' => $this->_params['contact_id'],
- ));
- $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', array(
+ ]);
+ $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', [
'sequential' => 1,
'contribution_id' => $ContributionCreate['values'][0]['id'],
'membership_id' => $membershipID,
- ));
- $memParams = array(
+ ]);
+ $memParams = [
'id' => $membershipID,
'preserve_contribution' => 1,
- );
- $contribParams = array(
+ ];
+ $contribParams = [
'id' => $ContributionCreate['values'][0]['id'],
- );
+ ];
$this->callAPIAndDocument('membership', 'delete', $memParams, __FUNCTION__, __FILE__);
$this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID);
$this->assertDBRowExist('CRM_Contribute_DAO_Contribution', $ContributionCreate['values'][0]['id']);
$membershipID = $this->contactMembershipCreate($this->_params);
$this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
- $ContributionCreate = $this->callAPISuccess('Contribution', 'create', array(
+ $ContributionCreate = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => "Member Dues",
'total_amount' => 100,
'contact_id' => $this->_params['contact_id'],
- ));
- $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', array(
+ ]);
+ $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', [
'sequential' => 1,
'contribution_id' => $ContributionCreate['id'],
'membership_id' => $membershipID,
- ));
- $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
+ ]);
+ $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
$this->paymentInstruments = $instruments['values'];
$form = new CRM_Contribute_Form_Contribution();
$form->_id = $ContributionCreate['id'];
- $form->testSubmit(array(
+ $form->testSubmit([
'total_amount' => 100,
'financial_type_id' => 1,
'contact_id' => $contactId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'contribution_status_id' => 3,
- ),
+ ],
CRM_Core_Action::UPDATE);
- $activity = $this->callAPISuccess('Activity', 'get', array(
+ $activity = $this->callAPISuccess('Activity', 'get', [
'activity_type_id' => "Change Membership Status",
'source_record_id' => $membershipID,
- ));
+ ]);
$this->assertNotEmpty($activity['values']);
}
*/
public function testContactMembershipsGet() {
$this->_membershipID = $this->contactMembershipCreate($this->_params);
- $this->callAPISuccess('membership', 'get', array());
- $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID));
+ $this->callAPISuccess('membership', 'get', []);
+ $this->callAPISuccess('Membership', 'Delete', ['id' => $this->_membershipID]);
}
/**
*/
public function testGetWithParamsContactId() {
$this->_membershipID = $this->contactMembershipCreate($this->_params);
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
- );
+ ];
$membership = $this->callAPISuccess('membership', 'get', $params);
$result = $membership['values'][$this->_membershipID];
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $this->_membershipID,
- ));
+ ]);
$this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__);
$this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__);
$this->assertEquals($result['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
$this->_membershipID = $this->contactMembershipCreate($this->_params);
$this->_membershipID2 = $this->contactMembershipCreate($this->_params);
$this->_membershipID3 = $this->contactMembershipCreate($this->_params);
- $params = array(
- 'id' => array('IN' => array($this->_membershipID, $this->_membershipID3)),
- );
+ $params = [
+ 'id' => ['IN' => [$this->_membershipID, $this->_membershipID3]],
+ ];
$membership = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(2, $membership['count']);
- $this->assertEquals(array($this->_membershipID, $this->_membershipID3), array_keys($membership['values']));
- $params = array(
- 'id' => array('NOT IN' => array($this->_membershipID, $this->_membershipID3)),
- );
+ $this->assertEquals([$this->_membershipID, $this->_membershipID3], array_keys($membership['values']));
+ $params = [
+ 'id' => ['NOT IN' => [$this->_membershipID, $this->_membershipID3]],
+ ];
$membership = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(1, $membership['count']);
- $this->assertEquals(array($this->_membershipID2), array_keys($membership['values']));
+ $this->assertEquals([$this->_membershipID2], array_keys($membership['values']));
}
/**
public function testGetInSyntaxOnContactID() {
$this->_membershipID = $this->contactMembershipCreate($this->_params);
$contact2 = $this->individualCreate();
- $contact3 = $this->individualCreate(array('first_name' => 'Scout', 'last_name' => 'Canine'));
- $this->_membershipID2 = $this->contactMembershipCreate(array_merge($this->_params, array('contact_id' => $contact2)));
- $this->_membershipID3 = $this->contactMembershipCreate(array_merge($this->_params, array('contact_id' => $contact3)));
- $params = array(
- 'contact_id' => array('IN' => array($this->_contactID, $contact3)),
- );
+ $contact3 = $this->individualCreate(['first_name' => 'Scout', 'last_name' => 'Canine']);
+ $this->_membershipID2 = $this->contactMembershipCreate(array_merge($this->_params, ['contact_id' => $contact2]));
+ $this->_membershipID3 = $this->contactMembershipCreate(array_merge($this->_params, ['contact_id' => $contact3]));
+ $params = [
+ 'contact_id' => ['IN' => [$this->_contactID, $contact3]],
+ ];
$membership = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(2, $membership['count']);
- $this->assertEquals(array($this->_membershipID, $this->_membershipID3), array_keys($membership['values']));
- $params = array(
- 'contact_id' => array('NOT IN' => array($this->_contactID, $contact3)),
- );
+ $this->assertEquals([$this->_membershipID, $this->_membershipID3], array_keys($membership['values']));
+ $params = [
+ 'contact_id' => ['NOT IN' => [$this->_contactID, $contact3]],
+ ];
$membership = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(1, $membership['count']);
- $this->assertEquals(array($this->_membershipID2), array_keys($membership['values']));
+ $this->assertEquals([$this->_membershipID2], array_keys($membership['values']));
}
/**
*/
public function testGetWithParamsMemberShipTypeId() {
$this->callAPISuccess($this->_entity, 'create', $this->_params);
- $params = array(
+ $params = [
'membership_type_id' => $this->_membershipTypeID,
- );
+ ];
$membership = $this->callAPISuccess('membership', 'get', $params);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $membership['id'],
- ));
+ ]);
$result = $membership['values'][$membership['id']];
$this->assertEquals($result['contact_id'], $this->_contactID);
$this->assertEquals($result['membership_type_id'], $this->_membershipTypeID);
$this->callAPISuccess($this->_entity, 'create', $params);
$params['membership_type_id'] = $this->_membershipTypeID2;
$this->callAPISuccess($this->_entity, 'create', $params);
- $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_contactID), 2);
- $params = array(
+ $this->callAPISuccessGetCount('membership', ['contact_id' => $this->_contactID], 2);
+ $params = [
'membership_type_id' => $this->_membershipTypeID,
'contact_id' => $this->_contactID,
- );
+ ];
$result = $this->callAPISuccess('membership', 'getsingle', $params);
$this->assertEquals($result['contact_id'], $this->_contactID);
$this->assertEquals($result['membership_type_id'], $this->_membershipTypeID);
- $params = array(
+ $params = [
'membership_type_id' => $this->_membershipTypeID2,
'contact_id' => $this->_contactID,
- );
+ ];
$result = $this->callAPISuccess('membership', 'getsingle', $params);
$this->assertEquals($result['contact_id'], $this->_contactID);
$this->assertEquals($result['membership_type_id'], $this->_membershipTypeID2);
$result = $this->callAPISuccess($this->_entity, 'create', $params);
- $getParams = array('membership_type_id' => $params['membership_type_id']);
+ $getParams = ['membership_type_id' => $params['membership_type_id']];
$check = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
$this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $result['id'],
- ));
+ ]);
}
/**
*/
public function testGet() {
$membershipID = $this->contactMembershipCreate($this->_params);
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
- );
+ ];
$membership = $this->callAPISuccess('membership', 'get', $params);
$result = $membership['values'][$membershipID];
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $membership['id'],
- ));
+ ]);
$this->assertEquals($result['join_date'], '2009-01-21');
$this->assertEquals($result['contact_id'], $this->_contactID);
$this->assertEquals($result['membership_type_id'], $this->_membershipTypeID);
*/
public function testGetWithId() {
$membershipID = $this->contactMembershipCreate($this->_params);
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'id' => $this->_membershipID,
'return' => 'id',
- );
+ ];
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals($membershipID, $result['id']);
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'membership_id' => $this->_membershipID,
'return' => 'membership_id',
- );
+ ];
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals($membershipID, $result['id']);
}
public function testGetOnlyActive() {
$description = "Demonstrates use of 'filter' active_only' param.";
$this->_membershipID = $this->contactMembershipCreate($this->_params);
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'active_only' => 1,
- );
+ ];
$membership = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID);
$this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID);
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
- 'filters' => array(
+ 'filters' => [
'is_current' => 1,
- ),
- );
+ ],
+ ];
$membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__, __FILE__, $description, 'FilterIsCurrent');
$this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID);
$this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID);
- $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID));
+ $this->callAPISuccess('Membership', 'Delete', ['id' => $this->_membershipID]);
}
/**
* empty Memberships.
*/
public function testGetNoContactExists() {
- $params = array(
+ $params = [
'contact_id' => 55555,
- );
+ ];
$membership = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals($membership['count'], 0);
$membershipOrgId = $this->organizationCreate(NULL);
$memberContactId = $this->individualCreate();
- $relTypeParams = array(
+ $relTypeParams = [
'name_a_b' => 'Relation 1',
'name_b_a' => 'Relation 2',
'description' => 'Testing relationship type',
'contact_type_b' => 'Individual',
'is_reserved' => 1,
'is_active' => 1,
- );
+ ];
$relTypeID = $this->relationshipTypeCreate($relTypeParams);
- $params = array(
+ $params = [
'name' => 'test General',
'duration_unit' => 'year',
'duration_interval' => 1,
'relationship_type_id' => $relTypeID,
'relationship_direction' => 'b_a',
'is_active' => 1,
- );
+ ];
$memType = $this->callAPISuccess('membership_type', 'create', $params);
- $params = array(
+ $params = [
'contact_id' => $memberContactId,
'membership_type_id' => $memType['id'],
'join_date' => '2009-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$membershipID = $this->contactMembershipCreate($params);
- $params = array(
+ $params = [
'contact_id' => $memberContactId,
'membership_type_id' => $memType['id'],
- );
+ ];
$result = $this->callAPISuccess('membership', 'get', $params);
$membership = $result['values'][$membershipID];
$this->assertEquals($this->_membershipStatusID, $membership['status_id']);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $membership['id'],
- ));
- $this->membershipTypeDelete(array('id' => $memType['id']));
+ ]);
+ $this->membershipTypeDelete(['id' => $memType['id']]);
$this->relationshipTypeDelete($relTypeID);
$this->contactDelete($membershipOrgId);
$this->contactDelete($memberContactId);
*/
public function testCreateWithRelationship() {
// Create membership type: inherited through employment, max_related = 2
- $params = array(
+ $params = [
'name_a_b' => 'Employee of',
- );
+ ];
$result = $this->callAPISuccess('relationship_type', 'get', $params);
$relationshipTypeId = $result['id'];
$membershipOrgId = $this->organizationCreate();
- $params = array(
+ $params = [
'name' => 'Corporate Membership',
'duration_unit' => 'year',
'duration_interval' => 1,
'relationship_direction' => 'b_a',
'max_related' => 2,
'is_active' => 1,
- );
+ ];
$result = $this->callAPISuccess('membership_type', 'create', $params);
$membershipTypeId = $result['id'];
// Create employer and first employee
- $employerId[0] = $this->organizationCreate(array(), 1);
- $memberContactId[0] = $this->individualCreate(array('employer_id' => $employerId[0]), 0);
+ $employerId[0] = $this->organizationCreate([], 1);
+ $memberContactId[0] = $this->individualCreate(['employer_id' => $employerId[0]], 0);
// Create organization's membership
- $params = array(
+ $params = [
'contact_id' => $employerId[0],
'membership_type_id' => $membershipTypeId,
'source' => 'Test suite',
'start_date' => date('Y-m-d'),
'end_date' => "+1 year",
- );
+ ];
$OrganizationMembershipID = $this->contactMembershipCreate($params);
// Check that the employee inherited the membership
- $params = array(
+ $params = [
'contact_id' => $memberContactId[0],
'membership_type_id' => $membershipTypeId,
- );
+ ];
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
// Create second employee
- $memberContactId[1] = $this->individualCreate(array('employer_id' => $employerId[0]), 1);
+ $memberContactId[1] = $this->individualCreate(['employer_id' => $employerId[0]], 1);
// Check that the employee inherited the membership
- $params = array(
+ $params = [
'contact_id' => $memberContactId[1],
'membership_type_id' => $membershipTypeId,
- );
+ ];
$result = $this->callAPISuccess('membership', 'get', $params);
// If it fails here CRM-14758 is not fixed
$this->assertEquals(1, $result['count']);
$this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
// Create third employee
- $memberContactId[2] = $this->individualCreate(array('employer_id' => $employerId[0]), 2);
+ $memberContactId[2] = $this->individualCreate(['employer_id' => $employerId[0]], 2);
// Check that employee does NOT inherit the membership (max_related = 2)
- $params = array(
+ $params = [
'contact_id' => $memberContactId[2],
'membership_type_id' => $membershipTypeId,
- );
+ ];
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(0, $result['count']);
// Increase max_related for the employer's membership
- $params = array(
+ $params = [
'id' => $OrganizationMembershipID,
'max_related' => 3,
- );
+ ];
$this->callAPISuccess('Membership', 'create', $params);
// Check that the employee inherited the membership
- $params = array(
+ $params = [
'contact_id' => $memberContactId[2],
'membership_type_id' => $membershipTypeId,
- );
+ ];
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(1, $result['count']);
$result = $result['values'][$result['id']];
$this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
// First employee moves to a new job
- $employerId[1] = $this->organizationCreate(array(), 2);
- $params = array(
+ $employerId[1] = $this->organizationCreate([], 2);
+ $params = [
'id' => $memberContactId[0],
'employer_id' => $employerId[1],
- );
+ ];
$this->callAPISuccess('contact', 'create', $params);
// Check that employee does NO LONGER inherit the membership
- $params = array(
+ $params = [
'contact_id' => $memberContactId[0],
'membership_type_id' => $membershipTypeId,
- );
+ ];
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(0, $result['count']);
//Create pay_later membership for organization.
- $employerId[2] = $this->organizationCreate(array(), 1);
- $params = array(
+ $employerId[2] = $this->organizationCreate([], 1);
+ $params = [
'contact_id' => $employerId[2],
'membership_type_id' => $membershipTypeId,
'source' => 'Test pay later suite',
'is_pay_later' => 1,
'status_id' => 5,
- );
+ ];
$organizationMembership = CRM_Member_BAO_Membership::add($params);
$organizationMembershipID = $organizationMembership->id;
- $memberContactId[3] = $this->individualCreate(array('employer_id' => $employerId[2]), 0);
+ $memberContactId[3] = $this->individualCreate(['employer_id' => $employerId[2]], 0);
// Check that the employee inherited the membership
- $params = array(
+ $params = [
'contact_id' => $memberContactId[3],
'membership_type_id' => $membershipTypeId,
- );
+ ];
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(1, $result['count']);
$result = $result['values'][$result['id']];
$this->assertEquals($organizationMembershipID, $result['owner_membership_id']);
// Set up params for enable/disable checks
- $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1]));
- $params = array(
+ $relationship1 = $this->callAPISuccess('relationship', 'get', ['contact_id_a' => $memberContactId[1]]);
+ $params = [
'contact_id' => $memberContactId[1],
'membership_type_id' => $membershipTypeId,
- );
+ ];
// Deactivate relationship using create and assert membership is not inherited
- $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 0));
+ $this->callAPISuccess('relationship', 'create', ['id' => $relationship1['id'], 'is_active' => 0]);
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(0, $result['count']);
// Re-enable relationship using create and assert membership is inherited
- $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 1));
+ $this->callAPISuccess('relationship', 'create', ['id' => $relationship1['id'], 'is_active' => 1]);
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(1, $result['count']);
// Deactivate relationship using setvalue and assert membership is not inherited
- $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0));
+ $this->callAPISuccess('relationship', 'setvalue', ['id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0]);
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(0, $result['count']);
// Re-enable relationship using setvalue and assert membership is inherited
- $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1));
+ $this->callAPISuccess('relationship', 'setvalue', ['id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1]);
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(1, $result['count']);
// Delete relationship and assert membership is not inherited
- $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id']));
+ $this->callAPISuccess('relationship', 'delete', ['id' => $relationship1['id']]);
$result = $this->callAPISuccess('membership', 'get', $params);
$this->assertEquals(0, $result['count']);
$this->contactDelete($memberContactId[0]);
$this->contactDelete($employerId[1]);
$this->contactDelete($employerId[0]);
- $this->membershipTypeDelete(array('id' => $membershipTypeId));
+ $this->membershipTypeDelete(['id' => $membershipTypeId]);
$this->contactDelete($membershipOrgId);
}
*/
public function testMembershipGetWithReturn() {
$this->contactMembershipCreate($this->_params);
- $result = $this->callAPISuccess('membership', 'get', array('return' => 'end_date'));
+ $result = $this->callAPISuccess('membership', 'get', ['return' => 'end_date']);
foreach ($result['values'] as $membership) {
- $this->assertEquals(array('id', 'end_date'), array_keys($membership));
+ $this->assertEquals(['id', 'end_date'], array_keys($membership));
}
}
* Error expected.
*/
public function testCreateWithEmptyParams() {
- $params = array();
+ $params = [];
$this->callAPIFailure('membership', 'create', $params);
}
}
public function testMembershipCreateMissingRequired() {
- $params = array(
+ $params = [
'membership_type_id' => '1',
'join_date' => '2006-01-21',
'start_date' => '2006-01-21',
'end_date' => '2006-12-21',
'source' => 'Payment',
'status_id' => '2',
- );
+ ];
$this->callAPIFailure('membership', 'create', $params);
}
public function testMembershipCreate() {
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2006-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__, __FILE__);
$this->getAndCheck($params, $result['id'], $this->_entity);
* Check for useful message if contact doesn't exist
*/
public function testMembershipCreateWithInvalidContact() {
- $params = array(
+ $params = [
'contact_id' => 999,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2006-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$this->callAPIFailure('membership', 'create', $params,
'contact_id is not valid : 999'
$params['custom_' . $ids['custom_field_id']] = "custom string";
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'CreateWithCustomData');
- $check = $this->callAPISuccess($this->_entity, 'get', array(
+ $check = $this->callAPISuccess($this->_entity, 'get', [
'id' => $result['id'],
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
}
// search memberships with CRM-16036 as custom field value.
// Since we did not touch the custom field of any membership,
// this should not return any results.
- $check = $this->callAPISuccess($this->_entity, 'get', array(
+ $check = $this->callAPISuccess($this->_entity, 'get', [
'custom_' . $ids['custom_field_id'] => "CRM-16036",
- ));
+ ]);
// Cleanup.
- $this->callAPISuccess($this->_entity, 'delete', array(
+ $this->callAPISuccess($this->_entity, 'delete', [
'id' => $result['id'],
- ));
+ ]);
// Assert.
$this->assertEquals(0, $check['count']);
*/
public function testMembershipCreateWithId() {
$membershipID = $this->contactMembershipCreate($this->_params);
- $params = array(
+ $params = [
'id' => $membershipID,
'contact_id' => $this->_contactID,
'membership_type_id' => $this->_membershipTypeID,
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$result = $this->callAPISuccess('membership', 'create', $params);
//Update Status and check activities created.
- $updateStatus = array(
+ $updateStatus = [
'id' => $result['id'],
'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Cancelled'),
- );
+ ];
$this->callAPISuccess('Membership', 'create', $updateStatus);
$activities = CRM_Activity_BAO_Activity::getContactActivity($this->_contactID);
$this->assertEquals(2, count($activities));
$this->assertArrayHasKey('Membership Signup', $activityNames);
$this->assertArrayHasKey('Change Membership Status', $activityNames);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
}
*/
public function testMembershipCreateUpdateWithIdNoContact() {
$membershipID = $this->contactMembershipCreate($this->_params);
- $params = array(
+ $params = [
'id' => $membershipID,
'membership_type_id' => $this->_membershipTypeID,
'contact_id' => $this->_contactID,
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$result = $this->callAPISuccess('membership', 'create', $params);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
}
*/
public function testMembershipCreateUpdateWithIdNoDates() {
$membershipID = $this->contactMembershipCreate($this->_params);
- $params = array(
+ $params = [
'id' => $membershipID,
'contact_id' => $this->_contactID,
'membership_type_id' => $this->_membershipTypeID,
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$result = $this->callAPISuccess('membership', 'create', $params);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
}
*/
public function testMembershipCreateUpdateWithIdNoDatesNoType() {
$membershipID = $this->contactMembershipCreate($this->_params);
- $params = array(
+ $params = [
'id' => $membershipID,
'source' => 'not much here',
'contact_id' => $this->_contactID,
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$result = $this->callAPISuccess('membership', 'create', $params);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $result['id'],
- ));
+ ]);
$this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
}
*/
public function testMembershipCreateUpdateWithIDAndSource() {
$membershipID = $this->contactMembershipCreate($this->_params);
- $params = array(
+ $params = [
'id' => $membershipID,
'source' => 'changed',
'contact_id' => $this->_contactID,
'status_id' => $this->_membershipStatusID,
'membership_type_id' => $this->_membershipTypeID,
'skipStatusCal' => 1,
- );
+ ];
$result = $this->callAPISuccess('membership', 'create', $params);
$this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $result['id'],
- ));
+ ]);
}
/**
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'UpdateCustomData');
- $result = $this->callAPISuccess($this->_entity, 'create', array(
+ $result = $this->callAPISuccess($this->_entity, 'create', [
'id' => $result['id'],
'custom_' . $ids['custom_field_id'] => "new custom",
- ));
- $check = $this->callAPISuccess($this->_entity, 'get', array(
+ ]);
+ $check = $this->callAPISuccess($this->_entity, 'get', [
'id' => $result['id'],
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $check['id'],
- ));
+ ]);
$this->customFieldDelete($ids['custom_field_id']);
$this->customGroupDelete($ids['custom_group_id']);
* per CRM-15746 check that the id can be altered in an update hook
*/
public function testMembershipUpdateCreateHookCRM15746() {
- $this->hookClass->setHook('civicrm_pre', array($this, 'hook_civicrm_pre_update_create_membership'));
+ $this->hookClass->setHook('civicrm_pre', [$this, 'hook_civicrm_pre_update_create_membership']);
$result = $this->callAPISuccess('membership', 'create', $this->_params);
- $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
- $this->callAPISuccessGetCount('membership', array(), 2);
+ $this->callAPISuccess('membership', 'create', ['id' => $result['id'], 'end_date' => '1 year ago']);
+ $this->callAPISuccessGetCount('membership', [], 2);
$this->hookClass->reset();
- $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
- $this->callAPISuccessGetCount('membership', array(), 2);
+ $this->callAPISuccess('membership', 'create', ['id' => $result['id'], 'end_date' => '1 year ago']);
+ $this->callAPISuccessGetCount('membership', [], 2);
}
/**
*/
public function hook_civicrm_pre_update_create_membership($op, $objectName, $id, &$params) {
if ($objectName == 'Membership' && $op == 'edit') {
- $existingMembership = $this->callAPISuccessGetSingle('membership', array('id' => $params['id']));
+ $existingMembership = $this->callAPISuccessGetSingle('membership', ['id' => $params['id']]);
unset($params['id'], $params['membership_id']);
$params['join_date'] = $params['membership_start_date'] = $params['start_date'] = date('Ymd000000', strtotime($existingMembership['start_date']));
$params = array_merge($existingMembership, $params);
*/
public function testMembershipCreateInvalidMemData() {
//membership_contact_id as string
- $params = array(
+ $params = [
'membership_contact_id' => 'Invalid',
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2011-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$this->callAPIFailure('membership', 'create', $params);
* Success expected.
*/
public function testMembershipCreateWithMemContact() {
- $params = array(
+ $params = [
'membership_contact_id' => $this->_contactID,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2011-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$result = $this->callAPISuccess('membership', 'create', $params);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $result['id'],
- ));
+ ]);
}
/**
* Success expected.
*/
public function testMembershipCreateValidMembershipTypeString() {
- $params = array(
+ $params = [
'membership_contact_id' => $this->_contactID,
'membership_type_id' => 'General',
'join_date' => '2011-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$result = $this->callAPISuccess('membership', 'create', $params);
$this->assertEquals($this->_membershipTypeID, $result['values'][$result['id']]['membership_type_id']);
- $this->callAPISuccess('Membership', 'Delete', array(
+ $this->callAPISuccess('Membership', 'Delete', [
'id' => $result['id'],
- ));
+ ]);
}
/**
* Success expected.
*/
public function testMembershipCreateInValidMembershipTypeString() {
- $params = array(
+ $params = [
'membership_contact_id' => $this->_contactID,
'membership_type_id' => 'invalid',
'join_date' => '2011-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
- );
+ ];
$this->callAPIFailure('membership', 'create', $params);
}
public function testEmptyJoinDate() {
unset($this->_params['join_date'], $this->_params['is_override']);
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals(date('Y-m-d', strtotime('now')), $result['join_date']);
$this->assertEquals('2009-01-21', $result['start_date']);
$this->assertEquals('2009-12-21', $result['end_date']);
unset($this->_params['start_date'], $this->_params['is_override']);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2009-01-21', $result['join_date']);
$this->assertEquals('2008-03-01', $result['start_date']);
$this->assertEquals('2009-12-21', $result['end_date']);
*/
public function testEmptyStartEndDateFixedOneYear() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 1));
+ $this->callAPISuccess('membership_type', 'create', ['id' => $this->_membershipTypeID2, 'duration_interval' => 1]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2009-01-21', $result['join_date']);
$this->assertEquals('2008-03-01', $result['start_date']);
$this->assertEquals('2010-02-28', $result['end_date']);
*/
public function testEmptyStartEndDateFixedMultiYear() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 5));
+ $this->callAPISuccess('membership_type', 'create', ['id' => $this->_membershipTypeID2, 'duration_interval' => 5]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2009-01-21', $result['join_date']);
$this->assertEquals('2008-03-01', $result['start_date']);
$this->assertEquals('2014-02-28', $result['end_date']);
public function testMembershipJoinDateFixed() {
$memStatus = CRM_Member_PseudoConstant::membershipStatus();
// Update the fixed membership type to 1 year duration.
- $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 1));
+ $this->callAPISuccess('membership_type', 'create', ['id' => $this->_membershipTypeID2, 'duration_interval' => 1]);
$contactId = $this->createLoggedInUser();
// Create membership with 'Pending' status.
- $params = array(
+ $params = [
'contact_id' => $contactId,
'membership_type_id' => $this->_membershipTypeID2,
'source' => 'test membership',
'status_id' => array_search('Pending', $memStatus),
'skipStatusCal' => 1,
'is_for_organization' => 1,
- );
- $ids = array();
+ ];
+ $ids = [];
$membership = CRM_Member_BAO_Membership::create($params, $ids);
// Update membership to 'Completed' and check the dates.
- $memParams = array(
+ $memParams = [
'id' => $membership->id,
'contact_id' => $contactId,
'is_test' => 0,
'membership_type_id' => $this->_membershipTypeID2,
'num_terms' => 1,
'status_id' => array_search('New', $memStatus),
- );
+ ];
$result = $this->callAPISuccess('Membership', 'create', $memParams);
// Extend duration interval if join_date exceeds the rollover period.
$y += 1;
}
- $expectedDates = array(
+ $expectedDates = [
'join_date' => date('Ymd'),
'start_date' => str_replace('-', '', $startDate),
'end_date' => date('Ymd', strtotime(date('Y-03-01') . "+ {$y} year - 1 day")),
- );
+ ];
foreach ($result['values'] as $values) {
foreach ($expectedDates as $date => $val) {
$this->assertEquals($val, $values[$date], "Failed asserting {$date} values");
public function testFixedMultiYearDateSetTwoEmptyStartEndDate() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array(
+ $this->callAPISuccess('membership_type', 'create', [
'id' => $this->_membershipTypeID2,
'duration_interval' => 5,
// Ie 1 Jan.
'fixed_period_start_day' => '101',
// Ie. 1 Nov.
'fixed_period_rollover_day' => '1101',
- ));
+ ]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
- $dates = array(
+ $dates = [
'join_date' => '28-Jan 2015',
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2015-01-28', $result['join_date']);
$this->assertEquals('2015-01-01', $result['start_date']);
$this->assertEquals('2019-12-31', $result['end_date']);
public function testFixedMultiYearDateSetTwoEmptyEndDate() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array(
+ $this->callAPISuccess('membership_type', 'create', [
'id' => $this->_membershipTypeID2,
'duration_interval' => 5,
// Ie 1 Jan.
'fixed_period_start_day' => '101',
// Ie. 1 Nov.
'fixed_period_rollover_day' => '1101',
- ));
+ ]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
- $dates = array(
+ $dates = [
'start_date' => '28-Jan 2015',
'join_date' => '28-Jan 2015',
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2015-01-28', $result['join_date']);
$this->assertEquals('2015-01-28', $result['start_date']);
$this->assertEquals('2019-12-31', $result['end_date']);
public function testFixedSingleYearDateSetTwoEmptyStartEndDate() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array(
+ $this->callAPISuccess('membership_type', 'create', [
'id' => $this->_membershipTypeID2,
'duration_interval' => 1,
// Ie 1 Jan.
'fixed_period_start_day' => '101',
// Ie. 1 Nov.
'fixed_period_rollover_day' => '1101',
- ));
+ ]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
- $dates = array(
+ $dates = [
'join_date' => '28-Jan 2015',
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2015-01-28', $result['join_date']);
$this->assertEquals('2015-01-01', $result['start_date']);
$this->assertEquals('2015-12-31', $result['end_date']);
public function testFixedSingleYearDateSetTwoEmptyEndDate() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array(
+ $this->callAPISuccess('membership_type', 'create', [
'id' => $this->_membershipTypeID2,
'duration_interval' => 1,
// Ie 1 Jan.
'fixed_period_start_day' => '101',
// Ie. 1 Nov.
'fixed_period_rollover_day' => '1101',
- ));
+ ]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
- $dates = array(
+ $dates = [
'start_date' => '28-Jan 2015',
'join_date' => '28-Jan 2015',
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2015-01-28', $result['join_date']);
$this->assertEquals('2015-01-28', $result['start_date']);
$this->assertEquals('2015-12-31', $result['end_date']);
public function testFixedSingleYearDateSetThreeEmptyEndDate() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array(
+ $this->callAPISuccess('membership_type', 'create', [
'id' => $this->_membershipTypeID2,
'duration_interval' => 1,
// Ie. 1 Nov.
'fixed_period_start_day' => '1101',
// Ie 1 Jan.
'fixed_period_rollover_day' => '101',
- ));
+ ]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
- $dates = array(
+ $dates = [
'start_date' => '28-Jan 2015',
'join_date' => '28-Jan 2015',
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2015-01-28', $result['join_date']);
$this->assertEquals('2015-01-28', $result['start_date']);
$this->assertEquals('2016-10-31', $result['end_date']);
public function testFixedSingleYearDateSetThreeEmptyStartEndDate() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array(
+ $this->callAPISuccess('membership_type', 'create', [
'id' => $this->_membershipTypeID2,
'duration_interval' => 1,
// Ie. 1 Nov.
'fixed_period_start_day' => '1101',
// Ie 1 Jan.
'fixed_period_rollover_day' => '101',
- ));
+ ]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
- $dates = array(
+ $dates = [
'join_date' => '28-Jan 2015',
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2015-01-28', $result['join_date']);
$this->assertEquals('2014-11-01', $result['start_date']);
$this->assertEquals('2016-10-31', $result['end_date']);
public function testFixedMultiYearDateSetThreeEmptyEndDate() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array(
+ $this->callAPISuccess('membership_type', 'create', [
'id' => $this->_membershipTypeID2,
'duration_interval' => 5,
// Ie. 1 Nov.
'fixed_period_start_day' => '1101',
// Ie 1 Jan.
'fixed_period_rollover_day' => '101',
- ));
+ ]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
- $dates = array(
+ $dates = [
'start_date' => '28-Jan 2015',
'join_date' => '28-Jan 2015',
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2015-01-28', $result['join_date']);
$this->assertEquals('2015-01-28', $result['start_date']);
$this->assertEquals('2020-10-31', $result['end_date']);
public function testFixedMultiYearDateSetThreeEmptyStartEndDate() {
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
- $this->callAPISuccess('membership_type', 'create', array(
+ $this->callAPISuccess('membership_type', 'create', [
'id' => $this->_membershipTypeID2,
'duration_interval' => 5,
// Ie. 1 Nov.
'fixed_period_start_day' => '1101',
// Ie 1 Jan.
'fixed_period_rollover_day' => '101',
- ));
+ ]);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
- $dates = array(
+ $dates = [
'join_date' => '28-Jan 2015',
- );
+ ];
$result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2015-01-28', $result['join_date']);
$this->assertEquals('2014-11-01', $result['start_date']);
$this->assertEquals('2020-10-31', $result['end_date']);
public function testEmptyStartDateRolling() {
unset($this->_params['start_date'], $this->_params['is_override']);
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2009-01-21', $result['join_date']);
$this->assertEquals('2009-01-21', $result['start_date']);
$this->assertEquals('2009-12-21', $result['end_date']);
unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
$this->_params['membership_type_id'] = $this->_membershipTypeID2;
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2009-01-21', $result['join_date']);
$this->assertEquals('2008-03-01', $result['start_date']);
$this->assertEquals('2010-02-28', $result['end_date']);
unset($this->_params['is_override'], $this->_params['end_date']);
$this->_params['membership_type_id'] = $this->_membershipTypeID;
$result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2009-01-21', $result['join_date']);
$this->assertEquals('2009-01-21', $result['start_date']);
$this->assertEquals('2010-01-20', $result['end_date']);
unset($this->_params['end_date'], $this->_params['start_date']);
$this->_params['id'] = $result['id'];
$this->callAPISuccess($this->_entity, 'create', $this->_params);
- $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
+ $result = $this->callAPISuccess($this->_entity, 'getsingle', ['id' => $result['id']]);
$this->assertEquals('2009-01-21', $result['join_date']);
$this->assertEquals('2009-01-21', $result['start_date']);
$this->assertEquals('2009-12-21', $result['end_date']);
* See CRM-17075.
*/
public function testGetOptionsMembershipTypeID() {
- $options = $this->callAPISuccess('Membership', 'getoptions', array('field' => 'membership_type_id'));
+ $options = $this->callAPISuccess('Membership', 'getoptions', ['field' => 'membership_type_id']);
$this->assertEquals('Another one', array_pop($options['values']));
$this->assertEquals('General', array_pop($options['values']));
$this->assertEquals(NULL, array_pop($options['values']));
* This should return an empty array but not an error.
*/
public function testGetWithoutId() {
- $params = array(
+ $params = [
'name' => '60+ Membership',
'description' => 'people above 60 are given health instructions',
'financial_type_id' => 1,
'duration_unit' => 'month',
'duration_interval' => '10',
'visibility' => 'public',
- );
+ ];
$membershipType = $this->callAPISuccess('membership_type', 'get', $params);
$this->assertEquals($membershipType['count'], 0);
* Test get works.
*/
public function testGet() {
- $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
+ $id = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]);
- $params = array(
+ $params = [
'id' => $id,
- );
+ ];
$membershipType = $this->callAPIAndDocument('membership_type', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($membershipType['values'][$id]['name'], 'General');
$this->assertEquals($membershipType['values'][$id]['member_of_contact_id'], $this->_contactID);
* Test create with missing mandatory field.
*/
public function testCreateWithoutMemberOfContactId() {
- $params = array(
+ $params = [
'name' => '60+ Membership',
'description' => 'people above 60 are given health instructions',
'financial_type_id' => 1,
'duration_interval' => '10',
'period_type' => 'rolling',
'visibility' => 'public',
- );
+ ];
$this->callAPIFailure('membership_type', 'create', $params, 'Mandatory key(s) missing from params array: member_of_contact_id');
}
* Test successful create.
*/
public function testCreate() {
- $params = array(
+ $params = [
'name' => '40+ Membership',
'description' => 'people above 40 are given health instructions',
'member_of_contact_id' => $this->_contactID,
'duration_interval' => '10',
'period_type' => 'rolling',
'visibility' => 'public',
- );
+ ];
$membershipType = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($membershipType['values']);
- $this->membershipTypeDelete(array('id' => $membershipType['id']));
+ $this->membershipTypeDelete(['id' => $membershipType['id']]);
}
/**
* DomainID is now optional on API, check that it gets set correctly and that the domain_id is not overwritten when not specified in create.
*/
public function testCreateWithoutDomainId() {
- $params = array(
+ $params = [
'name' => '60+ Membership',
'description' => 'people above 60 are given health instructions',
'member_of_contact_id' => $this->_contactID,
'duration_interval' => '10',
'period_type' => 'rolling',
'visibility' => 'public',
- );
+ ];
$membershipType = $this->callAPISuccess('membership_type', 'create', $params);
$domainID = $this->callAPISuccessGetValue('MembershipType', ['return' => 'domain_id', 'id' => $membershipType['id']]);
* CRM-20010 Tests period_type is required for MemberType create
*/
public function testMemberTypePeriodiTypeRequired() {
- $this->callAPIFailure('MembershipType', 'create', array(
+ $this->callAPIFailure('MembershipType', 'create', [
'domain_id' => "Default Domain Name",
'member_of_contact_id' => 1,
'financial_type_id' => "Member Dues",
'duration_interval' => 1,
'name' => "Standard Member",
'minimum_fee' => 100,
- ));
+ ]);
}
/**
* Test update.
*/
public function testUpdate() {
- $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID, 'financial_type_id' => 2));
- $newMemberOrgParams = array(
+ $id = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID, 'financial_type_id' => 2]);
+ $newMemberOrgParams = [
'organization_name' => 'New membership organisation',
'contact_type' => 'Organization',
'visibility' => 1,
- );
+ ];
- $params = array(
+ $params = [
'id' => $id,
'name' => 'Updated General',
'member_of_contact_id' => $this->organizationCreate($newMemberOrgParams),
'duration_interval' => '10',
'period_type' => 'fixed',
'domain_id' => 1,
- );
+ ];
$this->callAPISuccess('membership_type', 'update', $params);
* Test successful delete.
*/
public function testDelete() {
- $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->organizationCreate()));
- $params = array(
+ $membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->organizationCreate()]);
+ $params = [
'id' => $membershipTypeID,
- );
+ ];
$this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__, __FILE__);
}
* I can't skim this & understand it so if anyone does explain it here.
*/
public function testDeleteRelationshipTypesUsedByMembershipType() {
- $rel1 = $this->relationshipTypeCreate(array(
+ $rel1 = $this->relationshipTypeCreate([
'name_a_b' => 'abcde',
'name_b_a' => 'abcde',
- ));
- $rel2 = $this->relationshipTypeCreate(array(
+ ]);
+ $rel2 = $this->relationshipTypeCreate([
'name_a_b' => 'fghij',
'name_b_a' => 'fghij',
- ));
- $rel3 = $this->relationshipTypeCreate(array(
+ ]);
+ $rel3 = $this->relationshipTypeCreate([
'name_a_b' => 'lkmno',
'name_b_a' => 'lkmno',
- ));
- $id = $this->membershipTypeCreate(array(
+ ]);
+ $id = $this->membershipTypeCreate([
'member_of_contact_id' => $this->_contactID,
- 'relationship_type_id' => array($rel1, $rel2, $rel3),
- 'relationship_direction' => array('a_b', 'a_b', 'b_a'),
- ));
-
- $this->callAPISuccess('RelationshipType', 'delete', array('id' => $rel2));
- $newValues = $this->callAPISuccess('MembershipType', 'getsingle', array('id' => $id));
- $this->assertEquals(array($rel1, $rel3), $newValues['relationship_type_id']);
- $this->assertEquals(array('a_b', 'b_a'), $newValues['relationship_direction']);
-
- $this->callAPISuccess('RelationshipType', 'delete', array('id' => $rel1));
- $newValues = $this->callAPISuccess('MembershipType', 'getsingle', array('id' => $id));
- $this->assertEquals(array($rel3), $newValues['relationship_type_id']);
- $this->assertEquals(array('b_a'), $newValues['relationship_direction']);
-
- $this->callAPISuccess('RelationshipType', 'delete', array('id' => $rel3));
- $newValues = $this->callAPISuccess('MembershipType', 'getsingle', array('id' => $id));
+ 'relationship_type_id' => [$rel1, $rel2, $rel3],
+ 'relationship_direction' => ['a_b', 'a_b', 'b_a'],
+ ]);
+
+ $this->callAPISuccess('RelationshipType', 'delete', ['id' => $rel2]);
+ $newValues = $this->callAPISuccess('MembershipType', 'getsingle', ['id' => $id]);
+ $this->assertEquals([$rel1, $rel3], $newValues['relationship_type_id']);
+ $this->assertEquals(['a_b', 'b_a'], $newValues['relationship_direction']);
+
+ $this->callAPISuccess('RelationshipType', 'delete', ['id' => $rel1]);
+ $newValues = $this->callAPISuccess('MembershipType', 'getsingle', ['id' => $id]);
+ $this->assertEquals([$rel3], $newValues['relationship_type_id']);
+ $this->assertEquals(['b_a'], $newValues['relationship_direction']);
+
+ $this->callAPISuccess('RelationshipType', 'delete', ['id' => $rel3]);
+ $newValues = $this->callAPISuccess('MembershipType', 'getsingle', ['id' => $id]);
$this->assertTrue(empty($newValues['relationship_type_id']));
$this->assertTrue(empty($newValues['relationship_direction']));
}
*/
public function testMembershipTypeGetList() {
$this->membershipTypeCreate();
- $this->membershipTypeCreate(array('name' => 'cheap-skates'));
- $this->membershipTypeCreate(array('name' => 'disabled cheap-skates', 'is_active' => 0));
- $result = $this->callAPISuccess('MembershipType', 'getlist', array());
+ $this->membershipTypeCreate(['name' => 'cheap-skates']);
+ $this->membershipTypeCreate(['name' => 'disabled cheap-skates', 'is_active' => 0]);
+ $result = $this->callAPISuccess('MembershipType', 'getlist', []);
$this->assertEquals(2, $result['count']);
$this->assertEquals('cheap-skates', $result['values'][0]['label']);
$this->assertEquals('General', $result['values'][1]['label']);
* selected in contribution pages.
*/
public function testEnableMembershipTypeOnContributionPage() {
- $memType = array();
- $memType[1] = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID, 'minimum_fee' => 100));
- $priceSet = $this->callAPISuccess('price_set', 'create', array(
+ $memType = [];
+ $memType[1] = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID, 'minimum_fee' => 100]);
+ $priceSet = $this->callAPISuccess('price_set', 'create', [
'title' => "test priceset",
'name' => "test_priceset",
'extends' => "CiviMember",
'is_quick_config' => 1,
'financial_type_id' => "Member Dues",
- ));
+ ]);
$priceSet = $priceSet['id'];
- $field = $this->callAPISuccess('price_field', 'create', array(
+ $field = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => $priceSet,
'name' => 'membership_amount',
'label' => 'Membership Amount',
'html_type' => 'Radio',
- ));
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ ]);
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'name' => 'membership_amount',
'label' => 'Membership Amount',
'amount' => 100,
'format.only_id' => TRUE,
'membership_type_id' => $memType[1],
'price_field_id' => $field['id'],
- ));
+ ]);
- $memType[2] = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID, 'minimum_fee' => 200));
- $fieldParams = array(
+ $memType[2] = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID, 'minimum_fee' => 200]);
+ $fieldParams = [
'id' => $field['id'],
'label' => 'Membership Amount',
'html_type' => 'Radio',
- );
+ ];
foreach ($memType as $rowCount => $type) {
$membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($type);
- $fieldParams['option_id'] = array(1 => $priceFieldValue['id']);
+ $fieldParams['option_id'] = [1 => $priceFieldValue['id']];
$fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
$fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
$fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
$this->assertEquals($priceField->id, $fieldParams['id']);
//Update membership type name and visibility
- $updateParams = array(
+ $updateParams = [
'id' => $memType[1],
'name' => 'General - Edited',
'visibility' => 'Admin',
'financial_type_id' => 1,
'minimum_fee' => 300,
'description' => 'Test edit description',
- );
+ ];
$this->callAPISuccess('membership_type', 'create', $updateParams);
- $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', array(
+ $priceFieldValue = $this->callAPISuccess('PriceFieldValue', 'get', [
'sequential' => 1,
'membership_type_id' => $memType[1],
- ));
+ ]);
//Verify if membership type updates are copied to pricefield value.
foreach ($priceFieldValue['values'] as $key => $value) {
- $setId = $this->callAPISuccessGetValue('PriceField', array('return' => "price_set_id", 'id' => $value['price_field_id']));
+ $setId = $this->callAPISuccessGetValue('PriceField', ['return' => "price_set_id", 'id' => $value['price_field_id']]);
if ($setId == $priceSet) {
$this->assertEquals($value['label'], $updateParams['name']);
$this->assertEquals($value['description'], $updateParams['description']);
}
foreach ($memType as $type) {
- $this->callAPISuccess('membership_type', 'delete', array('id' => $type));
+ $this->callAPISuccess('membership_type', 'delete', ['id' => $type]);
}
}
parent::setUp();
$this->useTransaction(TRUE);
$template = CRM_Core_DAO::createTestObject('CRM_Core_DAO_MessageTemplate')->toArray();
- $this->params = array(
+ $this->params = [
'msg_title' => $template['msg_title'],
'msg_subject' => $template['msg_subject'],
'msg_text' => $template['msg_text'],
'workflow_id' => $template['workflow_id'],
'is_default' => $template['is_default'],
'is_reserved' => $template['is_reserved'],
- );
+ ];
}
public function tearDown() {
*/
public function testDelete() {
$entity = $this->createTestEntity();
- $result = $this->callAPIAndDocument('MessageTemplate', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->entity, 'get', array(
+ $result = $this->callAPIAndDocument('MessageTemplate', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__);
+ $checkDeleted = $this->callAPISuccess($this->entity, 'get', [
'id' => $entity['id'],
- ));
+ ]);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testPermissionChecks() {
$entity = $this->createTestEntity();
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit user-driven message templates');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit user-driven message templates'];
// Ensure that it cannot create a system message or update a system message tempalte given current permissions.
- $this->callAPIFailure('MessageTemplate', 'create', ['id' => $entity['id'], 'msg_subject' => 'test msg permission subject', 'check_permissions' => TRUE]);
+ $this->callAPIFailure('MessageTemplate', 'create', [
+ 'id' => $entity['id'],
+ 'msg_subject' => 'test msg permission subject',
+ 'check_permissions' => TRUE,
+ ]);
$testUserEntity = $entity['values'][$entity['id']];
unset($testUserEntity['id']);
$testUserEntity['msg_subject'] = 'Test user message template';
$testuserEntity['check_permissions'] = TRUE;
// ensure that it can create user templates;
$userEntity = $this->callAPISuccess('MessageTemplate', 'create', $testUserEntity);
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit system workflow message templates');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit system workflow message templates'];
// Now check that when its swapped around permissions that the correct reponses are detected.
- $this->callAPIFailure('MessageTemplate', 'create', ['id' => $userEntity['id'], 'msg_subject' => 'User template updated by system message permission', 'check_permissions' => TRUE]);
- $this->callAPISuccess('MessageTemplate', 'create', ['id' => $entity['id'], 'msg_subject' => 'test msg permission subject', 'check_permissions' => TRUE]);
+ $this->callAPIFailure('MessageTemplate', 'create', [
+ 'id' => $userEntity['id'],
+ 'msg_subject' => 'User template updated by system message permission',
+ 'check_permissions' => TRUE,
+ ]);
+ $this->callAPISuccess('MessageTemplate', 'create', [
+ 'id' => $entity['id'],
+ 'msg_subject' => 'test msg permission subject',
+ 'check_permissions' => TRUE,
+ ]);
// verify with all 3 permissions someone can do everything.
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit system workflow message templates', 'edit user-driven message templates');
- $this->callAPISuccess('MessageTemplate', 'create', ['id' => $userEntity['id'], 'msg_subject' => 'User template updated by system message permission', 'check_permissions' => TRUE]);
- $this->callAPISuccess('MessageTemplate', 'create', ['id' => $entity['id'], 'msg_subject' => 'test msg permission subject', 'check_permissions' => TRUE]);
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = [
+ 'edit system workflow message templates',
+ 'edit user-driven message templates',
+ ];
+ $this->callAPISuccess('MessageTemplate', 'create', [
+ 'id' => $userEntity['id'],
+ 'msg_subject' => 'User template updated by system message permission',
+ 'check_permissions' => TRUE,
+ ]);
+ $this->callAPISuccess('MessageTemplate', 'create', [
+ 'id' => $entity['id'],
+ 'msg_subject' => 'test msg permission subject',
+ 'check_permissions' => TRUE,
+ ]);
// Verify that the backwards compatabiltiy still works i.e. having edit message templates allows for editing of both kinds of message templates
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit message templates');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['edit message templates'];
$this->callAPISuccess('MessageTemplate', 'create', ['id' => $userEntity['id'], 'msg_subject' => 'User template updated by edit message permission', 'check_permissions' => TRUE]);
$this->callAPISuccess('MessageTemplate', 'create', ['id' => $entity['id'], 'msg_subject' => 'test msg permission subject backwards compatabilty', 'check_permissions' => TRUE]);
}
// Take a semi-random OptionGroup and test manually changing its label
// in one language, while making sure it stays the same in English.
- $group = $this->callAPISuccess('OptionGroup', 'getsingle', array(
+ $group = $this->callAPISuccess('OptionGroup', 'getsingle', [
'name' => 'contact_edit_options',
- ));
+ ]);
- $english_original = $this->callAPISuccess('OptionValue', 'getsingle', array(
+ $english_original = $this->callAPISuccess('OptionValue', 'getsingle', [
'option_group_id' => $group['id'],
'name' => 'IM',
- ));
+ ]);
- $this->callAPISuccess('OptionValue', 'create', array(
+ $this->callAPISuccess('OptionValue', 'create', [
'id' => $english_original['id'],
'name' => 'IM',
'label' => 'Messagerie instantanée',
'option.language' => 'fr_CA',
- ));
+ ]);
- $french = $this->callAPISuccess('OptionValue', 'getsingle', array(
+ $french = $this->callAPISuccess('OptionValue', 'getsingle', [
'option_group_id' => $group['id'],
'name' => 'IM',
'options' => ['language' => 'fr_CA'],
- ));
+ ]);
// Ensure that after language is changed in previous call it will go back to the default.
- $default = $this->callAPISuccess('OptionValue', 'getsingle', array(
+ $default = $this->callAPISuccess('OptionValue', 'getsingle', [
'option_group_id' => $group['id'],
'name' => 'IM',
- ));
+ ]);
$this->assertEquals($french['label'], 'Messagerie instantanée');
$this->assertEquals($default['label'], $english_original['label']);
$this->enableMultilingual();
// list of entities which has mandatory attributes
- $specialEntities = array(
- 'Attachment' => array('id' => 13),
- 'CustomValue' => array('entity_id' => 13),
- 'MailingContact' => array('contact_id' => 13),
- 'Profile' => array('profile_id' => 13),
- 'MailingGroup' => array('mailing_id' => 13),
- );
+ $specialEntities = [
+ 'Attachment' => ['id' => 13],
+ 'CustomValue' => ['entity_id' => 13],
+ 'MailingContact' => ['contact_id' => 13],
+ 'Profile' => ['profile_id' => 13],
+ 'MailingGroup' => ['mailing_id' => 13],
+ ];
// deprecated or API.Get is not supported/implemented
- $skippableEntities = array(
+ $skippableEntities = [
'Logging',
'MailingEventConfirm',
'MailingEventResubscribe',
'UFGroup',
// need loggedIn user id
'User',
- );
+ ];
// fetch all entities
- $entities = $this->callAPISuccess('Entity', 'get', array());
+ $entities = $this->callAPISuccess('Entity', 'get', []);
$skippableEntities = array_merge($skippableEntities, $entities['deprecated']);
foreach ($entities['values'] as $entity) {
- $params = array('check_permissions' => 1);
+ $params = ['check_permissions' => 1];
if (in_array($entity, $skippableEntities) && $entity != 'MailingGroup') {
continue;
}
*/
public function testGet($version) {
$this->_apiversion = $version;
- $this->callAPISuccess($this->_entity, 'getsingle', array('label' => 'Manage Groups', 'domain_id' => 1));
+ $this->callAPISuccess($this->_entity, 'getsingle', ['label' => 'Manage Groups', 'domain_id' => 1]);
}
/**
*/
public function testGetByParent() {
// get by name
- $this->callAPISuccess($this->_entity, 'get', array('parentID' => 'Administer', 'domain_id' => 1));
+ $this->callAPISuccess($this->_entity, 'get', ['parentID' => 'Administer', 'domain_id' => 1]);
- $params = array(
+ $params = [
'name' => 'Administer',
'domain_id' => 1,
'return' => 'id',
- );
+ ];
$adminId = $this->callAPISuccess($this->_entity, 'getvalue', $params);
- $this->callAPISuccess($this->_entity, 'get', array('parentID' => $adminId, 'domain_id' => 1));
+ $this->callAPISuccess($this->_entity, 'get', ['parentID' => $adminId, 'domain_id' => 1]);
}
/**
*/
public function testCreate($version) {
$this->_apiversion = $version;
- $params = array('label' => 'Feed the Goats', 'domain_id' => 1);
+ $params = ['label' => 'Feed the Goats', 'domain_id' => 1];
$result = $this->callAPISuccess($this->_entity, 'create', $params);
$this->getAndCheck($params, $result['id'], $this->_entity, TRUE);
}
*/
public function testDefaultDomain($version) {
$this->_apiversion = $version;
- $params = array('label' => 'Herd the Cats');
+ $params = ['label' => 'Herd the Cats'];
$result = $this->callAPISuccess($this->_entity, 'create', $params);
// Check domain_id has been set per default
$params['domain_id'] = CRM_Core_Config::domainID();
*/
public function testDelete($version) {
$this->_apiversion = $version;
- $getParams = array(
+ $getParams = [
'return' => 'id',
- 'options' => array('limit' => 1),
- );
+ 'options' => ['limit' => 1],
+ ];
$result = $this->callAPISuccess('Navigation', 'getvalue', $getParams);
- $this->callAPISuccess('Navigation', 'delete', array('id' => $result));
- $this->callAPIFailure('Navigation', 'getvalue', array('id' => $result));
+ $this->callAPISuccess('Navigation', 'delete', ['id' => $result]);
+ $this->callAPIFailure('Navigation', 'getvalue', ['id' => $result]);
}
}
$this->_contactID = $this->organizationCreate(NULL);
- $this->_params = array(
+ $this->_params = [
'entity_table' => 'civicrm_contact',
'entity_id' => $this->_contactID,
'note' => 'Hello!!! m testing Note',
'contact_id' => $this->_contactID,
'modified_date' => '2011-01-31',
'subject' => 'Test Note',
- );
+ ];
$this->_note = $this->noteCreate($this->_contactID);
$this->_noteID = $this->_note['id'];
}
*/
public function testGetWithEmptyParams($version) {
$this->_apiversion = $version;
- $this->callAPISuccess('note', 'get', array());
+ $this->callAPISuccess('note', 'get', []);
}
/**
*/
public function testGetWithoutEntityId($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'entity_table' => 'civicrm_contact',
- );
+ ];
$this->callAPISuccess('note', 'get', $params);
}
public function testGet($version) {
$this->_apiversion = $version;
$entityId = $this->_noteID;
- $params = array(
+ $params = [
'entity_table' => 'civicrm_contact',
'entity_id' => $entityId,
- );
+ ];
$this->callAPIAndDocument('note', 'get', $params, __FUNCTION__, __FILE__);
}
*/
public function testCreateWithApostropheInString($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'entity_table' => 'civicrm_contact',
'entity_id' => $this->_contactID,
'note' => "Hello!!! ' testing Note",
'modified_date' => '2011-01-31',
'subject' => "With a '",
'sequential' => 1,
- );
+ ];
$result = $this->callAPISuccess('Note', 'Create', $params);
$this->assertAPISuccess($result);
$this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note");
*/
public function testUpdateWithEmptyParams($version) {
$this->_apiversion = $version;
- $this->callAPIFailure('note', 'create', array());
+ $this->callAPIFailure('note', 'create', []);
}
/**
*/
public function testUpdateWithoutContactId($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'entity_id' => $this->_contactID,
'entity_table' => 'civicrm_contact',
- );
+ ];
$this->callAPIFailure('note', 'create', $params,
'missing'
);
*/
public function testUpdate($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'id' => $this->_noteID,
'contact_id' => $this->_contactID,
'note' => 'Note1',
'subject' => 'Hello World',
- );
+ ];
// Update Note.
$this->callAPISuccess('note', 'create', $params);
- $note = $this->callAPISuccess('Note', 'Get', array());
+ $note = $this->callAPISuccess('Note', 'Get', []);
$this->assertEquals($note['id'], $this->_noteID);
$this->assertEquals($note['values'][$this->_noteID]['entity_id'], $this->_contactID);
$this->assertEquals($note['values'][$this->_noteID]['entity_table'], 'civicrm_contact');
* Error expected.
*/
public function testDeleteWithEmptyParams() {
- $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id');
+ $this->callAPIFailure('note', 'delete', [], 'Mandatory key(s) missing from params array: id');
}
/**
*/
public function testDeleteWithWrongID($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'id' => 99999,
- );
+ ];
$this->callAPIFailure('note', 'delete', $params, 'Note');
}
$this->_apiversion = $version;
$additionalNote = $this->noteCreate($this->_contactID);
- $params = array(
+ $params = [
'id' => $additionalNote['id'],
- );
+ ];
$this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__, __FILE__);
}
public function testNoteJoin() {
- $org = $this->callAPISuccess('Contact', 'create', array(
+ $org = $this->callAPISuccess('Contact', 'create', [
'contact_type' => 'Organization',
'organization_name' => 'Org123',
- 'api.Note.create' => array(
+ 'api.Note.create' => [
'note' => 'Hello join',
- ),
- ));
+ ],
+ ]);
// Fetch contact info via join
- $result = $this->callAPISuccessGetSingle('Note', array(
- 'return' => array("entity_id.organization_name", "note"),
+ $result = $this->callAPISuccessGetSingle('Note', [
+ 'return' => ["entity_id.organization_name", "note"],
'entity_id' => $org['id'],
'entity_table' => "civicrm_contact",
- ));
+ ]);
$this->assertEquals('Org123', $result['entity_id.organization_name']);
$this->assertEquals('Hello join', $result['note']);
// This should return no results by restricting contact_type
- $result = $this->callAPISuccess('Note', 'get', array(
- 'return' => array("entity_id.organization_name"),
+ $result = $this->callAPISuccess('Note', 'get', [
+ 'return' => ["entity_id.organization_name"],
'entity_id' => $org['id'],
'entity_table' => "civicrm_contact",
'entity_id.contact_type' => "Individual",
- ));
+ ]);
$this->assertEquals(0, $result['count']);
}
$this->_entity = 'OpenID';
$this->_contactID = $this->organizationCreate();
- $this->params = array(
+ $this->params = [
'contact_id' => $this->_contactID,
'openid' => 'My OpenID handle',
'location_type_id' => 1,
- );
+ ];
}
/**
$result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
}
/**
public function testDeleteOpenID($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => $result['id']);
+ $deleteParams = ['id' => $result['id']];
$result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
}
public function testDeleteOpenIDInvalid($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => 600);
+ $deleteParams = ['id' => 600];
$result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(1, $checkDeleted['count'], 'In line ' . __LINE__);
}
}
public function testGetCount() {
- $result = $this->callAPISuccess('option_value', 'getcount', array());
+ $result = $this->callAPISuccess('option_value', 'getcount', []);
$this->assertGreaterThan(100, $result);
}
public function testGetOptionValueByID() {
- $result = $this->callAPISuccess('option_value', 'get', array('id' => 1));
+ $result = $this->callAPISuccess('option_value', 'get', ['id' => 1]);
$this->assertEquals(1, $result['count']);
$this->assertEquals(1, $result['id']);
}
public function testGetOptionValueByValue() {
- $result = $this->callAPISuccess('option_value', 'get', array('option_group_id' => 1, 'value' => '1'));
+ $result = $this->callAPISuccess('option_value', 'get', ['option_group_id' => 1, 'value' => '1']);
$this->assertEquals(1, $result['count']);
$this->assertEquals(1, $result['id']);
}
* Test limit param.
*/
public function testGetOptionValueLimit() {
- $params = array();
+ $params = [];
$result = $this->callAPISuccess('option_value', 'get', $params);
$this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__);
$params['options']['limit'] = 1;
*/
public function testGetOptionValueOffSet() {
- $result = $this->callAPISuccess('option_value', 'get', array(
+ $result = $this->callAPISuccess('option_value', 'get', [
'option_group_id' => 1,
'value' => '1',
- ));
- $result2 = $this->callAPISuccess('option_value', 'get', array(
+ ]);
+ $result2 = $this->callAPISuccess('option_value', 'get', [
'option_group_id' => 1,
'value' => '1',
- 'options' => array('offset' => 1),
- ));
+ 'options' => ['offset' => 1],
+ ]);
$this->assertGreaterThan($result2['count'], $result['count']);
}
public function testGetSingleValueOptionValueSort() {
$description = "Demonstrates use of Sort param (available in many api functions). Also, getsingle.";
$subfile = 'SortOption';
- $result = $this->callAPISuccess('option_value', 'getsingle', array(
+ $result = $this->callAPISuccess('option_value', 'getsingle', [
'option_group_id' => 1,
- 'options' => array(
+ 'options' => [
'sort' => 'label ASC',
'limit' => 1,
- ),
- ));
- $params = array(
+ ],
+ ]);
+ $params = [
'option_group_id' => 1,
- 'options' => array(
+ 'options' => [
'sort' => 'label DESC',
'limit' => 1,
- ),
- );
+ ],
+ ];
$result2 = $this->callAPIAndDocument('option_value', 'getsingle', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertGreaterThan($result['label'], $result2['label']);
}
*/
public function testGetValueOptionPagination() {
$pageSize = 10;
- $page1 = $this->callAPISuccess('option_value', 'get', array('options' => array('limit' => $pageSize)));
- $page2 = $this->callAPISuccess('option_value', 'get', array(
- 'options' => array(
+ $page1 = $this->callAPISuccess('option_value', 'get', ['options' => ['limit' => $pageSize]]);
+ $page2 = $this->callAPISuccess('option_value', 'get', [
+ 'options' => [
'limit' => $pageSize,
// if you use it for pagination, option.offset=pageSize*pageNumber
'offset' => $pageSize - 1,
- ),
- ));
+ ],
+ ]);
$this->assertEquals($pageSize, $page1['count'], "Check only 10 retrieved in the 1st page " . __LINE__);
$this->assertEquals($pageSize, $page2['count'], "Check only 10 retrieved in the 2nd page " . __LINE__);
}
public function testGetOptionGroup() {
- $params = array('option_group_id' => 1);
+ $params = ['option_group_id' => 1];
$result = $this->callAPIAndDocument('option_value', 'get', $params, __FUNCTION__, __FILE__);
$this->assertGreaterThan(1, $result['count']);
}
* Test that using option_group_name returns more than 1 & less than all
*/
public function testGetOptionGroupByName() {
- $activityTypesParams = array('option_group_name' => 'activity_type', 'option.limit' => 100);
- $params = array('option.limit' => 100);
+ $activityTypesParams = ['option_group_name' => 'activity_type', 'option.limit' => 100];
+ $params = ['option.limit' => 100];
$activityTypes = $this->callAPISuccess('option_value', 'get', $activityTypesParams);
$result = $this->callAPISuccess('option_value', 'get', $params);
$this->assertGreaterThan(1, $activityTypes['count']);
}
public function testGetOptionDoesNotExist() {
- $result = $this->callAPISuccess('option_value', 'get', array('label' => 'FSIGUBSFGOMUUBSFGMOOUUBSFGMOOBUFSGMOOIIB'));
+ $result = $this->callAPISuccess('option_value', 'get', ['label' => 'FSIGUBSFGOMUUBSFGMOOUUBSFGMOOBUFSGMOOIIB']);
$this->assertEquals(0, $result['count']);
}
* Check that domain_id is honoured.
*/
public function testCreateOptionSpecifyDomain() {
- $result = $this->callAPISuccess('option_group', 'get', array(
+ $result = $this->callAPISuccess('option_group', 'get', [
'name' => 'from_email_address',
'sequential' => 1,
- 'api.option_value.create' => array('domain_id' => 2, 'name' => 'my@y.com', 'value' => '10'),
- ));
+ 'api.option_value.create' => ['domain_id' => 2, 'name' => 'my@y.com', 'value' => '10'],
+ ]);
$optionValueId = $result['values'][0]['api.option_value.create']['id'];
- $domain_id = $this->callAPISuccess('option_value', 'getvalue', array(
+ $domain_id = $this->callAPISuccess('option_value', 'getvalue', [
'id' => $optionValueId,
'return' => 'domain_id',
- ));
+ ]);
$this->assertEquals(2, $domain_id);
- $this->callAPISuccess('option_value', 'delete', array('id' => $optionValueId));
+ $this->callAPISuccess('option_value', 'delete', ['id' => $optionValueId]);
}
/**
* Check that component_id is honoured.
*/
public function testCreateOptionSpecifyComponentID() {
- $result = $this->callAPISuccess('option_group', 'get', array(
+ $result = $this->callAPISuccess('option_group', 'get', [
'name' => 'from_email_address',
'sequential' => 1,
- 'api.option_value.create' => array('component_id' => 2, 'name' => 'my@y.com'),
- ));
+ 'api.option_value.create' => ['component_id' => 2, 'name' => 'my@y.com'],
+ ]);
$this->assertAPISuccess($result);
$optionValueId = $result['values'][0]['api.option_value.create']['id'];
- $component_id = $this->callAPISuccess('option_value', 'getvalue', array(
+ $component_id = $this->callAPISuccess('option_value', 'getvalue', [
'id' => $optionValueId,
'return' => 'component_id',
- ));
+ ]);
$this->assertEquals(2, $component_id);
- $this->callAPISuccess('option_value', 'delete', array('id' => $optionValueId));
+ $this->callAPISuccess('option_value', 'delete', ['id' => $optionValueId]);
}
/**
* Check that component string is honoured.
*/
public function testCreateOptionSpecifyComponentString() {
- $result = $this->callAPISuccess('option_group', 'get', array(
+ $result = $this->callAPISuccess('option_group', 'get', [
'name' => 'from_email_address',
'sequential' => 1,
- 'api.option_value.create' => array(
+ 'api.option_value.create' => [
'component_id' => 'CiviContribute',
'name' => 'my@y.com',
- ),
- ));
+ ],
+ ]);
$this->assertAPISuccess($result);
$optionValueId = $result['values'][0]['api.option_value.create']['id'];
- $component_id = $this->callAPISuccess('option_value', 'getvalue', array(
+ $component_id = $this->callAPISuccess('option_value', 'getvalue', [
'id' => $optionValueId,
'return' => 'component_id',
- ));
+ ]);
$this->assertEquals(2, $component_id);
- $this->callAPISuccess('option_value', 'delete', array('id' => $optionValueId));
+ $this->callAPISuccess('option_value', 'delete', ['id' => $optionValueId]);
}
/**
public function testGetOptionWithComponent() {
$components = Civi::settings()->get('enable_components');
CRM_Core_BAO_ConfigSetting::enableComponent('CiviContribute');
- $this->callAPISuccess('option_group', 'get', array(
+ $this->callAPISuccess('option_group', 'get', [
'name' => 'gender',
- 'api.option_value.create' => array(
+ 'api.option_value.create' => [
'component_id' => 'CiviContribute',
'name' => 'Contrib',
- ),
- ));
+ ],
+ ]);
// Verify new option is present
- $genders = $this->callAPISuccess('contact', 'getoptions', array(
+ $genders = $this->callAPISuccess('contact', 'getoptions', [
'field' => 'gender_id',
'context' => 'create',
- ));
+ ]);
$this->assertContains('Contrib', $genders['values']);
// Disable relevant component
CRM_Core_BAO_ConfigSetting::disableComponent('CiviContribute');
CRM_Core_PseudoConstant::flush();
// New option should now be hidden for "create" context
- $genders = $this->callAPISuccess('contact', 'getoptions', array(
+ $genders = $this->callAPISuccess('contact', 'getoptions', [
'field' => 'gender_id',
'context' => 'create',
- ));
+ ]);
$this->assertNotContains('Contrib', $genders['values']);
// New option should be visible for "get" context even with component disabled
- $genders = $this->callAPISuccess('contact', 'getoptions', array(
+ $genders = $this->callAPISuccess('contact', 'getoptions', [
'field' => 'gender_id',
'context' => 'get',
- ));
+ ]);
$this->assertContains('Contrib', $genders['values']);
// Now disable all components and ensure we can still fetch options with no errors
- CRM_Core_BAO_ConfigSetting::setEnabledComponents(array());
+ CRM_Core_BAO_ConfigSetting::setEnabledComponents([]);
CRM_Core_PseudoConstant::flush();
// New option should still be hidden for "create" context
- $genders = $this->callAPISuccess('contact', 'getoptions', array(
+ $genders = $this->callAPISuccess('contact', 'getoptions', [
'field' => 'gender_id',
'context' => 'create',
- ));
+ ]);
$this->assertNotContains('Contrib', $genders['values']);
// Restore original state
*/
public function testCRM12133CreateOptionWeightNoValue() {
$optionGroup = $this->callAPISuccess(
- 'option_group', 'get', array(
+ 'option_group', 'get', [
'name' => 'gender',
'sequential' => 1,
- )
+ ]
);
$this->assertAPISuccess($optionGroup);
- $params = array(
+ $params = [
'option_group_id' => $optionGroup['id'],
'label' => 'my@y.com',
'weight' => 3,
- );
+ ];
$optionValue = $this->callAPISuccess('option_value', 'create', $params);
$this->assertAPISuccess($optionValue);
$params['weight'] = 4;
$optionValue2 = $this->callAPISuccess('option_value', 'create', $params);
$this->assertAPISuccess($optionValue2);
- $options = $this->callAPISuccess('option_value', 'get', array('option_group_id' => $optionGroup['id']));
+ $options = $this->callAPISuccess('option_value', 'get', ['option_group_id' => $optionGroup['id']]);
$this->assertNotEquals($options['values'][$optionValue['id']]['value'], $options['values'][$optionValue2['id']]['value']);
//cleanup
- $this->callAPISuccess('option_value', 'delete', array('id' => $optionValue['id']));
- $this->callAPISuccess('option_value', 'delete', array('id' => $optionValue2['id']));
+ $this->callAPISuccess('option_value', 'delete', ['id' => $optionValue['id']]);
+ $this->callAPISuccess('option_value', 'delete', ['id' => $optionValue2['id']]);
}
/**
* Check that domain_id is honoured.
*/
public function testCreateOptionNoName() {
- $optionGroup = $this->callAPISuccess('option_group', 'get', array(
+ $optionGroup = $this->callAPISuccess('option_group', 'get', [
'name' => 'gender',
'sequential' => 1,
- ));
+ ]);
- $params = array('option_group_id' => $optionGroup['id'], 'label' => 'my@y.com');
+ $params = ['option_group_id' => $optionGroup['id'], 'label' => 'my@y.com'];
$optionValue = $this->callAPISuccess('option_value', 'create', $params);
$this->assertAPISuccess($optionValue);
$this->getAndCheck($params, $optionValue['id'], 'option_value');
* Check that pseudoconstant reflects new value added.
*/
public function testCRM11876CreateOptionPseudoConstantUpdated() {
- $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', array(
+ $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', [
'name' => 'payment_instrument',
'return' => 'id',
- ));
+ ]);
$newOption = (string) time();
- $apiResult = $this->callAPISuccess('option_value', 'create', array(
+ $apiResult = $this->callAPISuccess('option_value', 'create', [
'option_group_id' => $optionGroupID,
'label' => $newOption,
- ));
+ ]);
- $fields = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
+ $fields = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
$this->assertTrue(in_array($newOption, $fields['values']));
- $this->callAPISuccess('option_value', 'delete', array('id' => $apiResult['id']));
+ $this->callAPISuccess('option_value', 'delete', ['id' => $apiResult['id']]);
- $fields = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
+ $fields = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
$this->assertFalse(in_array($newOption, $fields['values']));
}
*/
public function testUpdateOptionValueNoGroupId() {
// create a option group
- $og = $this->callAPISuccess('option_group', 'create', array('name' => 'our test Option Group', 'is_active' => 1));
+ $og = $this->callAPISuccess('option_group', 'create', ['name' => 'our test Option Group', 'is_active' => 1]);
// create a option value
$ov = $this->callAPISuccess('option_value', 'create',
- array('option_group_id' => $og['id'], 'label' => 'test option value')
+ ['option_group_id' => $og['id'], 'label' => 'test option value']
);
// update option value without 'option_group_id'
- $res = $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'is_active' => 0));
- $val = $this->callAPISuccess('option_value', 'getvalue', array(
+ $res = $this->callAPISuccess('option_value', 'create', ['id' => $ov['id'], 'is_active' => 0]);
+ $val = $this->callAPISuccess('option_value', 'getvalue', [
'id' => $ov['id'],
'return' => 'is_active',
- ));
+ ]);
$this->assertEquals($val, 0, "update with no group id is not proper" . __LINE__);
}
*/
public function testUpdateOptionValueWithGroupId() {
// create a option group
- $og = $this->callAPISuccess('option_group', 'create', array(
+ $og = $this->callAPISuccess('option_group', 'create', [
'name' => 'our test Option Group for with group id',
'is_active' => 1,
- ));
+ ]);
// create a option value
$ov = $this->callAPISuccess('option_value', 'create',
- array('option_group_id' => $og['id'], 'label' => 'test option value')
+ ['option_group_id' => $og['id'], 'label' => 'test option value']
);
// update option value without 'option_group_id'
- $this->callAPISuccess('option_value', 'create', array(
+ $this->callAPISuccess('option_value', 'create', [
'id' => $ov['id'],
'option_group_id' => $og['id'],
'is_active' => 0,
- ));
- $val = $this->callAPISuccess('option_value', 'getvalue', array(
+ ]);
+ $val = $this->callAPISuccess('option_value', 'getvalue', [
'id' => $ov['id'],
'return' => 'is_active',
- ));
+ ]);
$this->assertEquals($val, 0, "update with group id is not proper " . __LINE__);
}
* CRM-19346 Ensure that Option Values cannot share same value in the same option value group
*/
public function testCreateOptionValueWithSameValue() {
- $og = $this->callAPISuccess('option_group', 'create', array(
+ $og = $this->callAPISuccess('option_group', 'create', [
'name' => 'our test Option Group for with group id',
'is_active' => 1,
- ));
+ ]);
// create a option value
$ov = $this->callAPISuccess('option_value', 'create',
- array('option_group_id' => $og['id'], 'label' => 'test option value')
+ ['option_group_id' => $og['id'], 'label' => 'test option value']
);
// update option value without 'option_group_id'
$this->callAPIFailure('option_value', 'create',
- array('option_group_id' => $og['id'], 'label' => 'Test 2nd option value', 'value' => $ov['values'][$ov['id']]['value'])
+ ['option_group_id' => $og['id'], 'label' => 'Test 2nd option value', 'value' => $ov['values'][$ov['id']]['value']]
);
}
}
public function testCreateOptionValueWithSameValueDiffOptionGroup() {
- $og = $this->callAPISuccess('option_group', 'create', array(
+ $og = $this->callAPISuccess('option_group', 'create', [
'name' => 'our test Option Group for with group id',
'is_active' => 1,
- ));
+ ]);
// create a option value
$ov = $this->callAPISuccess('option_value', 'create',
- array('option_group_id' => $og['id'], 'label' => 'test option value')
+ ['option_group_id' => $og['id'], 'label' => 'test option value']
);
- $og2 = $this->callAPISuccess('option_group', 'create', array(
+ $og2 = $this->callAPISuccess('option_group', 'create', [
'name' => 'our test Option Group for with group id 2',
'is_active' => 1,
- ));
+ ]);
// update option value without 'option_group_id'
$ov2 = $this->callAPISuccess('option_value', 'create',
- array('option_group_id' => $og2['id'], 'label' => 'Test 2nd option value', 'value' => $ov['values'][$ov['id']]['value'])
+ ['option_group_id' => $og2['id'], 'label' => 'Test 2nd option value', 'value' => $ov['values'][$ov['id']]['value']]
);
}
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
- $this->quickCleanup(array('civicrm_uf_match'));
+ $this->quickCleanup(['civicrm_uf_match']);
}
/**
public function testGetOrder() {
$contribution = $this->addOrder(FALSE, 100);
- $params = array(
+ $params = [
'contribution_id' => $contribution['id'],
- );
+ ];
$order = $this->callAPIAndDocument('Order', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $order['count']);
- $expectedResult = array(
- $contribution['id'] => array(
+ $expectedResult = [
+ $contribution['id'] => [
'total_amount' => 100,
'contribution_id' => $contribution['id'],
'contribution_status' => 'Completed',
'net_amount' => 100,
- ),
- );
- $lineItems[] = array(
+ ],
+ ];
+ $lineItems[] = [
'entity_table' => 'civicrm_contribution',
'entity_id' => $contribution['id'],
'contribution_id' => $contribution['id'],
'unit_price' => 100,
'line_total' => 100,
'financial_type_id' => 1,
- );
+ ];
$this->checkPaymentResult($order, $expectedResult, $lineItems);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution['id'],
- ));
+ ]);
}
/**
$this->addOrder(FALSE, 100);
list($items, $contribution) = $this->createParticipantWithContribution();
- $params = array(
+ $params = [
'contribution_id' => $contribution['id'],
- );
+ ];
$order = $this->callAPISuccess('Order', 'get', $params);
$this->assertEquals(2, count($order['values'][$contribution['id']]['line_items']));
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution['id'],
- ));
+ ]);
}
/**
*
* @return array
*/
- public function addOrder($isPriceSet, $amount = 300.00, $extraParams = array()) {
- $p = array(
+ public function addOrder($isPriceSet, $amount = 300.00, $extraParams = []) {
+ $p = [
'contact_id' => $this->_individualId,
'receive_date' => '2010-01-20',
'total_amount' => $amount,
'financial_type_id' => $this->_financialTypeId,
'contribution_status_id' => 1,
- );
+ ];
if ($isPriceSet) {
$priceFields = $this->createPriceSet();
foreach ($priceFields['values'] as $key => $priceField) {
- $lineItems[1][$key] = array(
+ $lineItems[1][$key] = [
'price_field_id' => $priceField['price_field_id'],
'price_field_value_id' => $priceField['id'],
'label' => $priceField['label'],
'unit_price' => $priceField['amount'],
'line_total' => $priceField['amount'],
'financial_type_id' => $priceField['financial_type_id'],
- );
+ ];
}
$p['line_item'] = $lineItems;
}
*/
public function testAddOrder() {
$order = $this->addOrder(FALSE, 100);
- $params = array(
+ $params = [
'contribution_id' => $order['id'],
- );
+ ];
$order = $this->callAPISuccess('order', 'get', $params);
- $expectedResult = array(
- $order['id'] => array(
+ $expectedResult = [
+ $order['id'] => [
'total_amount' => 100,
'contribution_id' => $order['id'],
'contribution_status' => 'Completed',
'net_amount' => 100,
- ),
- );
- $lineItems[] = array(
+ ],
+ ];
+ $lineItems[] = [
'entity_table' => 'civicrm_contribution',
'entity_id' => $order['id'],
'contribution_id' => $order['id'],
'unit_price' => 100,
'line_total' => 100,
'financial_type_id' => 1,
- );
+ ];
$this->checkPaymentResult($order, $expectedResult, $lineItems);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $order['id'],
- ));
+ ]);
}
/**
public function testAddOrderForMembership() {
$membershipType = $this->membershipTypeCreate();
$membershipType1 = $this->membershipTypeCreate();
- $membershipType = $membershipTypes = array($membershipType, $membershipType1);
- $p = array(
+ $membershipType = $membershipTypes = [$membershipType, $membershipType1];
+ $p = [
'contact_id' => $this->_individualId,
'receive_date' => '2010-01-20',
'total_amount' => 200,
'financial_type_id' => 'Event Fee',
'contribution_status_id' => 1,
- );
+ ];
$priceFields = $this->createPriceSet();
foreach ($priceFields['values'] as $key => $priceField) {
- $lineItems[$key] = array(
+ $lineItems[$key] = [
'price_field_id' => $priceField['price_field_id'],
'price_field_value_id' => $priceField['id'],
'label' => $priceField['label'],
'financial_type_id' => $priceField['financial_type_id'],
'entity_table' => 'civicrm_membership',
'membership_type_id' => array_pop($membershipType),
- );
+ ];
}
- $p['line_items'][] = array(
- 'line_item' => array(array_pop($lineItems)),
- 'params' => array(
+ $p['line_items'][] = [
+ 'line_item' => [array_pop($lineItems)],
+ 'params' => [
'contact_id' => $this->_individualId,
'membership_type_id' => array_pop($membershipTypes),
'join_date' => '2006-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => 1,
- ),
- );
+ ],
+ ];
$order = $this->callAPIAndDocument('order', 'create', $p, __FUNCTION__, __FILE__);
- $params = array(
+ $params = [
'contribution_id' => $order['id'],
- );
+ ];
$order = $this->callAPISuccess('order', 'get', $params);
- $expectedResult = array(
- $order['id'] => array(
+ $expectedResult = [
+ $order['id'] => [
'total_amount' => 200,
'contribution_id' => $order['id'],
'contribution_status' => 'Completed',
'net_amount' => 200,
- ),
- );
+ ],
+ ];
$this->checkPaymentResult($order, $expectedResult);
$this->callAPISuccessGetCount('MembershipPayment', $params, 1);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $order['id'],
- ));
- $p['line_items'][] = array(
- 'line_item' => array(array_pop($lineItems)),
- 'params' => array(
+ ]);
+ $p['line_items'][] = [
+ 'line_item' => [array_pop($lineItems)],
+ 'params' => [
'contact_id' => $this->_individualId,
'membership_type_id' => array_pop($membershipTypes),
'join_date' => '2006-01-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => 1,
- ),
- );
+ ],
+ ];
$p['total_amount'] = 300;
$order = $this->callAPISuccess('order', 'create', $p);
- $expectedResult = array(
- $order['id'] => array(
+ $expectedResult = [
+ $order['id'] => [
'total_amount' => 300,
'contribution_status' => 'Completed',
'net_amount' => 300,
- ),
- );
- $paymentMembership = array(
+ ],
+ ];
+ $paymentMembership = [
'contribution_id' => $order['id'],
- );
+ ];
$order = $this->callAPISuccess('order', 'get', $paymentMembership);
$this->checkPaymentResult($order, $expectedResult);
$this->callAPISuccessGetCount('MembershipPayment', $paymentMembership, 2);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $order['id'],
- ));
+ ]);
}
/**
public function testAddOrderForParticipant() {
$event = $this->eventCreate();
$this->_eventId = $event['id'];
- $p = array(
+ $p = [
'contact_id' => $this->_individualId,
'receive_date' => '2010-01-20',
'total_amount' => 300,
'financial_type_id' => $this->_financialTypeId,
'contribution_status_id' => 1,
- );
+ ];
$priceFields = $this->createPriceSet();
foreach ($priceFields['values'] as $key => $priceField) {
- $lineItems[$key] = array(
+ $lineItems[$key] = [
'price_field_id' => $priceField['price_field_id'],
'price_field_value_id' => $priceField['id'],
'label' => $priceField['label'],
'line_total' => $priceField['amount'],
'financial_type_id' => $priceField['financial_type_id'],
'entity_table' => 'civicrm_participant',
- );
+ ];
}
- $p['line_items'][] = array(
+ $p['line_items'][] = [
'line_item' => $lineItems,
- 'params' => array(
+ 'params' => [
'contact_id' => $this->_individualId,
'event_id' => $this->_eventId,
'status_id' => 1,
'role_id' => 1,
'register_date' => '2007-07-21 00:00:00',
'source' => 'Online Event Registration: API Testing',
- ),
- );
+ ],
+ ];
$order = $this->callAPIAndDocument('order', 'create', $p, __FUNCTION__, __FILE__, 'Create order for participant', 'CreateOrderParticipant');
- $params = array(
+ $params = [
'contribution_id' => $order['id'],
- );
+ ];
$order = $this->callAPISuccess('order', 'get', $params);
- $expectedResult = array(
- $order['id'] => array(
+ $expectedResult = [
+ $order['id'] => [
'total_amount' => 300,
'contribution_id' => $order['id'],
'contribution_status' => 'Completed',
'net_amount' => 300,
- ),
- );
+ ],
+ ];
$this->checkPaymentResult($order, $expectedResult);
$this->callAPISuccessGetCount('ParticipantPayment', $params, 1);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $order['id'],
- ));
- $p['line_items'][] = array(
+ ]);
+ $p['line_items'][] = [
'line_item' => $lineItems,
- 'params' => array(
+ 'params' => [
'contact_id' => $this->individualCreate(),
'event_id' => $this->_eventId,
'status_id' => 1,
'role_id' => 1,
'register_date' => '2007-07-21 00:00:00',
'source' => 'Online Event Registration: API Testing',
- ),
- );
+ ],
+ ];
$p['total_amount'] = 600;
$order = $this->callAPISuccess('order', 'create', $p);
- $expectedResult = array(
- $order['id'] => array(
+ $expectedResult = [
+ $order['id'] => [
'total_amount' => 600,
'contribution_status' => 'Completed',
'net_amount' => 600,
- ),
- );
- $paymentParticipant = array(
+ ],
+ ];
+ $paymentParticipant = [
'contribution_id' => $order['id'],
- );
+ ];
$order = $this->callAPISuccess('order', 'get', $paymentParticipant);
$this->checkPaymentResult($order, $expectedResult);
$this->callAPISuccessGetCount('ParticipantPayment', $paymentParticipant, 2);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $order['id'],
- ));
+ ]);
}
/**
*/
public function testAddOrderWithLineItems() {
$order = $this->addOrder(TRUE);
- $params = array(
+ $params = [
'contribution_id' => $order['id'],
- );
+ ];
$order = $this->callAPISuccess('order', 'get', $params);
- $expectedResult = array(
- $order['id'] => array(
+ $expectedResult = [
+ $order['id'] => [
'total_amount' => 300,
'contribution_id' => $order['id'],
'contribution_status' => 'Completed',
'net_amount' => 300,
- ),
- );
- $items[] = array(
+ ],
+ ];
+ $items[] = [
'entity_table' => 'civicrm_contribution',
'entity_id' => $order['id'],
'contribution_id' => $order['id'],
'unit_price' => 100,
'line_total' => 100,
- );
- $items[] = array(
+ ];
+ $items[] = [
'entity_table' => 'civicrm_contribution',
'entity_id' => $order['id'],
'contribution_id' => $order['id'],
'unit_price' => 200,
'line_total' => 200,
- );
+ ];
$this->checkPaymentResult($order, $expectedResult, $items);
- $params = array(
+ $params = [
'entity_table' => 'civicrm_contribution',
'entity_id' => $order['id'],
- );
+ ];
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
$this->assertEquals($eft['values'][$eft['id']]['amount'], 300);
- $params = array(
+ $params = [
'entity_table' => 'civicrm_financial_item',
'financial_trxn_id' => $eft['values'][$eft['id']]['financial_trxn_id'],
- );
+ ];
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
- $amounts = array(200, 100);
+ $amounts = [200, 100];
foreach ($eft['values'] as $value) {
$this->assertEquals($value['amount'], array_pop($amounts));
}
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $order['id'],
- ));
+ ]);
}
/**
*/
public function testDeleteOrder() {
$order = $this->addOrder(FALSE, 100);
- $params = array(
+ $params = [
'contribution_id' => $order['id'],
- );
+ ];
try {
$this->callAPISuccess('order', 'delete', $params);
$this->fail("Missed expected exception");
}
catch (Exception $expected) {
- $this->callAPISuccess('Contribution', 'create', array(
+ $this->callAPISuccess('Contribution', 'create', [
'contribution_id' => $order['id'],
'is_test' => TRUE,
- ));
+ ]);
$this->callAPIAndDocument('order', 'delete', $params, __FUNCTION__, __FILE__);
$order = $this->callAPISuccess('order', 'get', $params);
$this->assertEquals(0, $order['count']);
*/
public function testCancelOrder() {
$contribution = $this->addOrder(FALSE, 100);
- $params = array(
+ $params = [
'contribution_id' => $contribution['id'],
- );
+ ];
$this->callAPIAndDocument('order', 'cancel', $params, __FUNCTION__, __FILE__);
$order = $this->callAPISuccess('Order', 'get', $params);
- $expectedResult = array(
- $contribution['id'] => array(
+ $expectedResult = [
+ $contribution['id'] => [
'total_amount' => 100,
'contribution_id' => $contribution['id'],
'contribution_status' => 'Cancelled',
'net_amount' => 100,
- ),
- );
+ ],
+ ];
$this->checkPaymentResult($order, $expectedResult);
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution['id'],
- ));
+ ]);
}
/**
public function testCancelWithParticipant() {
$event = $this->eventCreate();
$this->_eventId = $event['id'];
- $eventParams = array(
+ $eventParams = [
'id' => $this->_eventId,
'financial_type_id' => 4,
'is_monetary' => 1,
- );
+ ];
$this->callAPISuccess('event', 'create', $eventParams);
- $participantParams = array(
+ $participantParams = [
'financial_type_id' => 4,
'event_id' => $this->_eventId,
'role_id' => 1,
'status_id' => 1,
'fee_currency' => 'USD',
'contact_id' => $this->_individualId,
- );
+ ];
$participant = $this->callAPISuccess('Participant', 'create', $participantParams);
- $extraParams = array(
+ $extraParams = [
'contribution_mode' => 'participant',
'participant_id' => $participant['id'],
- );
+ ];
$contribution = $this->addOrder(TRUE, 100, $extraParams);
- $paymentParticipant = array(
+ $paymentParticipant = [
'participant_id' => $participant['id'],
'contribution_id' => $contribution['id'],
- );
+ ];
$this->callAPISuccess('ParticipantPayment', 'create', $paymentParticipant);
- $params = array(
+ $params = [
'contribution_id' => $contribution['id'],
- );
+ ];
$this->callAPISuccess('order', 'cancel', $params);
$order = $this->callAPISuccess('Order', 'get', $params);
- $expectedResult = array(
- $contribution['id'] => array(
+ $expectedResult = [
+ $contribution['id'] => [
'total_amount' => 100,
'contribution_id' => $contribution['id'],
'contribution_status' => 'Cancelled',
'net_amount' => 100,
- ),
- );
+ ],
+ ];
$this->checkPaymentResult($order, $expectedResult);
$participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $params);
- $participant = $this->callAPISuccess('participant', 'get', array('id' => $participantPayment['participant_id']));
+ $participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]);
$this->assertEquals($participant['values'][$participant['id']]['participant_status'], 'Cancelled');
- $this->callAPISuccess('Contribution', 'Delete', array(
+ $this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution['id'],
- ));
+ ]);
}
/**
$event = $this->eventCreate(NULL);
$this->_eventID = $event['id'];
$this->_contactID = $this->individualCreate();
- $this->_createdParticipants = array();
+ $this->_createdParticipants = [];
$this->_individualId = $this->individualCreate();
$this->_financialTypeId = 1;
- $this->_participantID = $this->participantCreate(array(
+ $this->_participantID = $this->participantCreate([
'contactID' => $this->_contactID,
'eventID' => $this->_eventID,
- ));
+ ]);
$this->_contactID2 = $this->individualCreate();
- $this->_participantID2 = $this->participantCreate(array(
+ $this->_participantID2 = $this->participantCreate([
'contactID' => $this->_contactID2,
'eventID' => $this->_eventID,
- ));
- $this->_participantID3 = $this->participantCreate(array(
+ ]);
+ $this->_participantID3 = $this->participantCreate([
'contactID' => $this->_contactID2,
'eventID' => $this->_eventID,
- ));
+ ]);
$this->_contactID3 = $this->individualCreate();
- $this->_participantID4 = $this->participantCreate(array(
+ $this->_participantID4 = $this->participantCreate([
'contactID' => $this->_contactID3,
'eventID' => $this->_eventID,
- ));
+ ]);
}
/**
* Test civicrm_participant_payment_create with empty params.
*/
public function testPaymentCreateEmptyParams() {
- $params = array();
+ $params = [];
$this->callAPIFailure('participant_payment', 'create', $params);
}
*/
public function testPaymentCreateMissingContributionId() {
//Without Payment EntityID
- $params = array(
+ $params = [
'participant_id' => $this->_participantID,
- );
+ ];
$this->callAPIFailure('participant_payment', 'create', $params);
}
*/
public function testPaymentCreate() {
//Create Contribution & get contribution ID
- $contributionID = $this->contributionCreate(array('contact_id' => $this->_contactID));
+ $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]);
//Create Participant Payment record With Values
- $params = array(
+ $params = [
'participant_id' => $this->_participantID,
'contribution_id' => $contributionID,
- );
+ ];
$result = $this->callAPIAndDocument('participant_payment', 'create', $params, __FUNCTION__, __FILE__);
$this->assertTrue(array_key_exists('id', $result));
*/
public function testPaymentInfoForEvent() {
//Create Contribution & get contribution ID
- $contributionID = $this->contributionCreate(array('contact_id' => $this->_contactID));
+ $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]);
//Create Participant Payment record With Values
- $params = array(
+ $params = [
'participant_id' => $this->_participantID4,
'contribution_id' => $contributionID,
- );
+ ];
$this->callAPISuccess('participant_payment', 'create', $params);
//Check if participant payment is correctly retrieved.
* Check with empty array.
*/
public function testPaymentUpdateEmpty() {
- $this->callAPIFailure('participant_payment', 'create', array());
+ $this->callAPIFailure('participant_payment', 'create', []);
}
/**
* Check with missing participant_id.
*/
public function testPaymentUpdateMissingParticipantId() {
- $params = array(
+ $params = [
'contribution_id' => '3',
- );
+ ];
$this->callAPIFailure('participant_payment', 'create', $params);
}
* Check with missing contribution_id.
*/
public function testPaymentUpdateMissingContributionId() {
- $params = array(
+ $params = [
'participant_id' => $this->_participantID,
- );
+ ];
$participantPayment = $this->callAPIFailure('participant_payment', 'create', $params);
}
public function testPaymentOffline() {
// create contribution w/o fee
- $contributionID = $this->contributionCreate(array(
+ $contributionID = $this->contributionCreate([
'contact_id' => $this->_contactID,
'financial_type_id' => $this->_financialTypeId,
'payment_instrument_id' => 4,
'fee_amount' => 0,
'net_amount' => 100,
- ));
+ ]);
$this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID);
- $params = array(
+ $params = [
'id' => $this->_participantPaymentID,
'participant_id' => $this->_participantID,
'contribution_id' => $contributionID,
- );
+ ];
// Update Payment
$participantPayment = $this->callAPISuccess('participant_payment', 'create', $params);
$this->assertTrue(array_key_exists('id', $participantPayment));
// check Financial records
$this->_checkFinancialRecords($params, 'offline');
- $params = array(
+ $params = [
'id' => $this->_participantPaymentID,
- );
+ ];
$deletePayment = $this->callAPISuccess('participant_payment', 'delete', $params);
}
$pageParams['processor_id'] = $this->processorCreate();
$contributionPage = $this->contributionPageCreate($pageParams);
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_contactID,
'contribution_page_id' => $contributionPage['id'],
'payment_processor' => $pageParams['processor_id'],
'financial_type_id' => 1,
- );
+ ];
$contributionID = $this->contributionCreate($contributionParams);
$this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID);
- $params = array(
+ $params = [
'id' => $this->_participantPaymentID,
'participant_id' => $this->_participantID,
'contribution_id' => $contributionID,
- );
+ ];
// Update Payment
$participantPayment = $this->callAPISuccess('participant_payment', 'create', $params);
$this->assertTrue(array_key_exists('id', $participantPayment));
// check Financial records
$this->_checkFinancialRecords($params, 'online');
- $params = array(
+ $params = [
'id' => $this->_participantPaymentID,
- );
+ ];
$this->callAPISuccess('participant_payment', 'delete', $params);
}
$pageParams['processor_id'] = $this->processorCreate();
$pageParams['is_pay_later'] = 1;
$contributionPage = $this->contributionPageCreate($pageParams);
- $contributionParams = array(
+ $contributionParams = [
'contact_id' => $this->_contactID,
'contribution_page_id' => $contributionPage['id'],
'contribution_status_id' => 2,
'is_pay_later' => 1,
'financial_type_id' => 1,
- );
+ ];
$contributionID = $this->contributionCreate($contributionParams);
$this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID);
- $params = array(
+ $params = [
'id' => $this->_participantPaymentID,
'participant_id' => $this->_participantID,
'contribution_id' => $contributionID,
- );
+ ];
// Update Payment
$participantPayment = $this->callAPISuccess('participant_payment', 'create', $params);
$this->_checkFinancialRecords($params, 'payLater');
$this->assertEquals($participantPayment['id'], $this->_participantPaymentID);
$this->assertTrue(array_key_exists('id', $participantPayment));
- $params = array(
+ $params = [
'id' => $this->_participantPaymentID,
- );
+ ];
$this->callAPISuccess('participant_payment', 'delete', $params);
}
* Check with empty array.
*/
public function testPaymentDeleteWithEmptyParams() {
- $params = array();
+ $params = [];
$deletePayment = $this->callAPIFailure('participant_payment', 'delete', $params);
$this->assertEquals('Mandatory key(s) missing from params array: id', $deletePayment['error_message']);
}
* Check with wrong id.
*/
public function testPaymentDeleteWithWrongID() {
- $params = array(
+ $params = [
'id' => 0,
- );
+ ];
$deletePayment = $this->callAPIFailure('participant_payment', 'delete', $params);
$this->assertEquals($deletePayment['error_message'], 'Error while deleting participantPayment');
}
* Check with valid array.
*/
public function testPaymentDelete() {
- $contributionID = $this->contributionCreate(array(
+ $contributionID = $this->contributionCreate([
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID);
- $params = array(
+ $params = [
'id' => $this->_participantPaymentID,
- );
+ ];
$this->callAPIAndDocument('participant_payment', 'delete', $params, __FUNCTION__, __FILE__);
}
* Test civicrm_participantPayment_get - success expected.
*/
public function testGet() {
- $contributionID = $this->contributionCreate(array('contact_id' => $this->_contactID3));
+ $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID3]);
$this->participantPaymentCreate($this->_participantID4, $contributionID);
//Create Participant Payment record With Values
- $params = array(
+ $params = [
'participant_id' => $this->_participantID4,
'contribution_id' => $contributionID,
- );
+ ];
$result = $this->callAPIAndDocument('participant_payment', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][$result['id']]['participant_id'], $this->_participantID4, 'Check Participant Id');
* @param $context
*/
public function _checkFinancialRecords($params, $context) {
- $entityParams = array(
+ $entityParams = [
'entity_id' => $params['id'],
'entity_table' => 'civicrm_contribution',
- );
+ ];
$trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
- $trxnParams = array(
+ $trxnParams = [
'id' => $trxn['financial_trxn_id'],
- );
+ ];
switch ($context) {
case 'online':
- $compareParams = array(
+ $compareParams = [
'to_financial_account_id' => 12,
'total_amount' => 100,
'status_id' => 1,
- );
+ ];
break;
case 'offline':
- $compareParams = array(
+ $compareParams = [
'to_financial_account_id' => 6,
'total_amount' => 100,
'status_id' => 1,
- );
+ ];
break;
case 'payLater':
- $compareParams = array(
+ $compareParams = [
'to_financial_account_id' => 7,
'total_amount' => 100,
'status_id' => 2,
- );
+ ];
break;
}
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
- $entityParams = array(
+ $entityParams = [
'financial_trxn_id' => $trxn['financial_trxn_id'],
'entity_table' => 'civicrm_financial_item',
- );
+ ];
$entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
- $fitemParams = array(
+ $fitemParams = [
'id' => $entityTrxn['entity_id'],
- );
+ ];
if ($context == 'offline' || $context == 'online') {
- $compareParams = array(
+ $compareParams = [
'amount' => 100,
'status_id' => 1,
'financial_account_id' => 1,
- );
+ ];
}
elseif ($context == 'payLater') {
- $compareParams = array(
+ $compareParams = [
'amount' => 100,
'status_id' => 3,
'financial_account_id' => 1,
- );
+ ];
}
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
}
* test getParticipantIds() function
*/
public function testGetParticipantIds() {
- $contributionID = $this->contributionCreate(array('contact_id' => $this->_contactID));
- $expectedParticipants = array($this->_participantID, $this->_participantID2);
+ $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]);
+ $expectedParticipants = [$this->_participantID, $this->_participantID2];
//Create Participant Payment record With Values
foreach ($expectedParticipants as $pid) {
- $params = array(
+ $params = [
'participant_id' => $pid,
'contribution_id' => $contributionID,
- );
+ ];
$this->callAPISuccess('participant_payment', 'create', $params);
}
//Check if all participants are listed.
public function setUp() {
$this->_apiversion = 3;
- $this->params = array(
+ $this->params = [
'name' => 'test status',
'label' => 'I am a test',
'class' => 'Positive',
'is_counted' => 1,
'visibility_id' => 1,
'weight' => 10,
- );
+ ];
parent::setUp();
$this->useTransaction(TRUE);
}
public function testDeleteParticipantStatusType() {
$ParticipantStatusType = $this->callAPISuccess('ParticipantStatusType', 'Create', $this->params);
- $entity = $this->callAPISuccess('participant_status_type', 'get', array());
- $result = $this->callAPIAndDocument('participant_status_type', 'delete', array('id' => $ParticipantStatusType['id']), __FUNCTION__, __FILE__);
- $getCheck = $this->callAPISuccess('ParticipantStatusType', 'GET', array('id' => $ParticipantStatusType['id']));
- $checkDeleted = $this->callAPISuccess('ParticipantStatusType', 'Get', array());
+ $entity = $this->callAPISuccess('participant_status_type', 'get', []);
+ $result = $this->callAPIAndDocument('participant_status_type', 'delete', ['id' => $ParticipantStatusType['id']], __FUNCTION__, __FILE__);
+ $getCheck = $this->callAPISuccess('ParticipantStatusType', 'GET', ['id' => $ParticipantStatusType['id']]);
+ $checkDeleted = $this->callAPISuccess('ParticipantStatusType', 'Get', []);
$this->assertEquals($entity['count'] - 1, $checkDeleted['count']);
}
$this->_contactID = $this->individualCreate();
- $this->_createdParticipants = array();
+ $this->_createdParticipants = [];
$this->_individualId = $this->individualCreate();
- $this->_participantID = $this->participantCreate(array(
+ $this->_participantID = $this->participantCreate([
'contact_id' => $this->_contactID,
'event_id' => $this->_eventID,
- ));
+ ]);
$this->_contactID2 = $this->individualCreate();
- $this->_participantID2 = $this->participantCreate(array(
+ $this->_participantID2 = $this->participantCreate([
'contact_id' => $this->_contactID2,
'event_id' => $this->_eventID,
'registered_by_id' => $this->_participantID,
- ));
- $this->_participantID3 = $this->participantCreate(array(
+ ]);
+ $this->_participantID3 = $this->participantCreate([
'contact_id' => $this->_contactID2,
'event_id' => $this->_eventID,
- ));
- $this->_params = array(
+ ]);
+ $this->_params = [
'contact_id' => $this->_contactID,
'event_id' => $this->_eventID,
'status_id' => 1,
// to ensure it matches later on
'register_date' => '2007-07-21 00:00:00',
'source' => 'Online Event Registration: API Testing',
- );
+ ];
}
public function tearDown() {
$this->eventDelete($this->_eventID);
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_custom_group',
'civicrm_custom_field',
'civicrm_contact',
'civicrm_participant',
- );
+ ];
// true tells quickCleanup to drop any tables that might have been created in the test
$this->quickCleanup($tablesToTruncate, TRUE);
}
* Test get participants with role_id.
*/
public function testGetParticipantWithRole() {
- $roleId = array(1, 2, 3);
+ $roleId = [1, 2, 3];
foreach ($roleId as $role) {
- $this->participantCreate(array(
+ $this->participantCreate([
'contact_id' => $this->individualCreate(),
'role_id' => $role,
'event_id' => $this->_eventID,
- ));
+ ]);
}
- $params = array(
+ $params = [
'role_id' => 2,
- );
+ ];
$result = $this->callAPISuccess('participant', 'get', $params);
//Assert all the returned participants has a role_id of 2
foreach ($result['values'] as $pid => $values) {
$this->assertEquals($values['participant_role_id'], 2);
}
- $this->participantCreate(array(
+ $this->participantCreate([
'id' => $this->_participantID,
'role_id' => NULL,
'event_id' => $this->_eventID,
- ));
+ ]);
- $params['role_id'] = array(
+ $params['role_id'] = [
'IS NULL' => 1,
- );
+ ];
$result = $this->callAPISuccess('participant', 'get', $params);
foreach ($result['values'] as $pid => $values) {
$this->assertEquals($values['participant_role_id'], NULL);
$this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
- $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id']));
+ $check = $this->callAPISuccess($this->_entity, 'get', ['id' => $result['id']]);
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
$this->customFieldDelete($ids['custom_field_id']);
* Check with participant_id.
*/
public function testGetParticipantIdOnly() {
- $params = array(
+ $params = [
'participant_id' => $this->_participantID,
- 'return' => array(
+ 'return' => [
'participant_id',
'event_id',
'participant_register_date',
'participant_source',
- ),
- );
+ ],
+ ];
$result = $this->callAPISuccess('participant', 'get', $params);
$this->assertAPISuccess($result, " in line " . __LINE__);
$this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID);
$this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00');
$this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon');
- $params = array(
+ $params = [
'id' => $this->_participantID,
'return' => 'id,participant_register_date,event_id',
- );
+ ];
$result = $this->callAPISuccess('participant', 'get', $params);
$this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID);
$this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00');
*/
public function testGetParticipantWithPermission() {
$config = CRM_Core_Config::singleton();
- $config->userPermissionClass->permissions = array();
- $params = array(
+ $config->userPermissionClass->permissions = [];
+ $params = [
'event_id' => $this->_eventID,
'check_permissions' => TRUE,
- 'return' => array(
+ 'return' => [
'participant_id',
'event_id',
'participant_register_date',
'participant_source',
- ),
- );
+ ],
+ ];
$this->callAPIFailure('participant', 'get', $params);
$params['check_permissions'] = FALSE;
* Check with params id.
*/
public function testGetParamsAsIdOnly() {
- $params = array(
+ $params = [
'id' => $this->_participantID,
- );
+ ];
$result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID);
$this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00');
public function testGetNestedEventGet() {
//create a second event & add participant to it.
$event = $this->eventCreate(NULL);
- $this->callAPISuccess('participant', 'create', array(
+ $this->callAPISuccess('participant', 'create', [
'event_id' => $event['id'],
'contact_id' => $this->_contactID,
- ));
+ ]);
$description = "Demonstrates use of nested get to fetch event data with participant records.";
$subfile = "NestedEventGet";
- $params = array(
+ $params = [
'id' => $this->_participantID,
'api.event.get' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID);
$this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00');
* Check Participant Get respects return properties.
*/
public function testGetWithReturnProperties() {
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'return.status_id' => 1,
'return.participant_status_id' => 1,
- 'options' => array('limit' => 1),
- );
+ 'options' => ['limit' => 1],
+ ];
$result = $this->callAPISuccess('participant', 'get', $params);
$this->assertArrayHasKey('participant_status_id', $result['values'][$result['id']]);
}
* Check with contact_id.
*/
public function testGetContactIdOnly() {
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'get', $params);
$this->assertEquals($this->_participantID, $participant['id']);
* fetch first record
*/
public function testGetMultiMatchReturnFirst() {
- $params = array(
+ $params = [
'event_id' => $this->_eventID,
'rowCount' => 1,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'get', $params);
$this->assertNotNull($participant['id']);
* in v3 this should return all participants
*/
public function testGetMultiMatchNoReturnFirst() {
- $params = array(
+ $params = [
'event_id' => $this->_eventID,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'get', $params);
$this->assertNotNull($participant['count'], 3);
}
* In this case all the participant records are returned.
*/
public function testSearchEmptyParams() {
- $result = $this->callAPISuccess('participant', 'get', array());
+ $result = $this->callAPISuccess('participant', 'get', []);
// expecting 3 participant records
$this->assertEquals($result['count'], 3);
}
* Check with participant_id.
*/
public function testSearchParticipantIdOnly() {
- $params = array(
+ $params = [
'participant_id' => $this->_participantID,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'get', $params);
$this->assertEquals($participant['values'][$this->_participantID]['event_id'], $this->_eventID);
$this->assertEquals($participant['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00');
*/
public function testSearchContactIdOnly() {
// Should get 2 participant records for this contact.
- $params = array(
+ $params = [
'contact_id' => $this->_contactID2,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'get', $params);
$this->assertEquals($participant['count'], 2);
*/
public function testSearchByEvent() {
// Should get >= 3 participant records for this event. Also testing that last_name and event_title are returned.
- $params = array(
+ $params = [
'event_id' => $this->_eventID,
'return.last_name' => 1,
'return.event_title' => 1,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'get', $params);
if ($participant['count'] < 3) {
$this->fail("Event search returned less than expected miniumum of 3 records.");
*/
public function testSearchByEventWithLimit() {
// Should 2 participant records since we're passing rowCount = 2.
- $params = array(
+ $params = [
'event_id' => $this->_eventID,
'rowCount' => 2,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'get', $params);
$this->assertEquals($participant['count'], 2);
* Test search by lead booker (registered by ID)
*/
public function testSearchByRegisteredById() {
- $params = array(
+ $params = [
'registered_by_id' => $this->_participantID,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'get', $params);
$this->assertEquals($participant['count'], 1);
* Test civicrm_participant_create with empty params.
*/
public function testCreateEmptyParams() {
- $params = array();
+ $params = [];
$result = $this->callAPIFailure('participant', 'create', $params);
}
* Check with contact_id & event_id
*/
public function testCreateEventIdOnly() {
- $params = array(
+ $params = [
'contact_id' => $this->_contactID,
'event_id' => $this->_eventID,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'create', $params);
$this->getAndCheck($params, $participant['id'], 'participant');
}
*/
public function testCreateUpdateReceiveDate() {
$participant = $this->callAPISuccess('participant', 'create', $this->_params);
- $update = array(
+ $update = [
'id' => $participant['id'],
'status_id' => 2,
- );
+ ];
$this->callAPISuccess('participant', 'create', $update);
$this->getAndCheck(array_merge($this->_params, $update), $participant['id'], 'participant');
}
* Test to check if participant fee level is being changed per CRM-9781
*/
public function testCreateUpdateParticipantFeeLevel() {
- $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "fee" . CRM_Core_DAO::VALUE_SEPARATOR);
+ $myParams = $this->_params + ['participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "fee" . CRM_Core_DAO::VALUE_SEPARATOR];
$participant = $this->callAPISuccess('participant', 'create', $myParams);
- $update = array(
+ $update = [
'id' => $participant['id'],
'status_id' => 2,
- );
+ ];
$update = $this->callAPISuccess('participant', 'create', $update);
$this->assertEquals($participant['values'][$participant['id']]['fee_level'],
$update['values'][$participant['id']]['fee_level']
);
- $this->callAPISuccess('participant', 'delete', array('id' => $participant['id']));
+ $this->callAPISuccess('participant', 'delete', ['id' => $participant['id']]);
}
/**
public function testCreateParticipantLineItems() {
// Create a price set for this event.
- $priceset = $this->callAPISuccess('PriceSet', 'create', array(
+ $priceset = $this->callAPISuccess('PriceSet', 'create', [
'name' => 'my_price_set',
'title' => 'My Price Set',
'is_active' => 1,
'extends' => 1,
'financial_type_id' => 4,
// 'entity' => array('civicrm_event' => array($this->_eventID)),
- ));
+ ]);
// Add the price set to the event with another API call.
// I tried to do this at once, but it did not work.
- $priceset = $this->callAPISuccess('PriceSet', 'create', array(
+ $priceset = $this->callAPISuccess('PriceSet', 'create', [
'entity_table' => 'civicrm_event',
'entity_id' => $this->_eventID,
'id' => $priceset['id'],
- ));
+ ]);
- $pricefield = $this->callAPISuccess('PriceField', 'create', array(
+ $pricefield = $this->callAPISuccess('PriceField', 'create', [
'price_set_id' => $priceset['id'],
'name' => 'mypricefield',
'label' => 'My Price Field',
'is_enter_qty' => 1,
'is_display_amounts' => 1,
'is_active' => 1,
- ));
+ ]);
- $pfv1 = $this->callAPISuccess('PriceFieldValue', 'create', array(
+ $pfv1 = $this->callAPISuccess('PriceFieldValue', 'create', [
'price_field_id' => $pricefield['id'],
'name' => 'pricefieldvalue1',
'label' => 'pricefieldvalue1',
'amount' => 20,
'is_active' => 1,
'financial_type_id' => 4,
- ));
+ ]);
- $pfv2 = $this->callAPISuccess('PriceFieldValue', 'create', array(
+ $pfv2 = $this->callAPISuccess('PriceFieldValue', 'create', [
'price_field_id' => $pricefield['id'],
'name' => 'pricefieldvalue2',
'label' => 'pricefieldvalue2',
'amount' => 5,
'is_active' => 1,
'financial_type_id' => 4,
- ));
+ ]);
// pay 2 times price field value 1, and 2 times price field value 2.
- $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue1 - 2" . CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue2 - 2" . CRM_Core_DAO::VALUE_SEPARATOR);
+ $myParams = $this->_params + ['participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue1 - 2" . CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue2 - 2" . CRM_Core_DAO::VALUE_SEPARATOR];
$participant = $this->callAPISuccess('participant', 'create', $myParams);
// expect 2 line items.
- $lineItems = $this->callAPISuccess('LineItem', 'get', array(
+ $lineItems = $this->callAPISuccess('LineItem', 'get', [
'entity_id' => $participant['id'],
'entity_table' => 'civicrm_participant',
- ));
+ ]);
$this->assertEquals(2, $lineItems['count']);
$this->assertEquals('pricefieldvalue1', $lineItem['label']);
// Cleanup
- $this->callAPISuccess('participant', 'delete', array('id' => $participant['id']));
+ $this->callAPISuccess('participant', 'delete', ['id' => $participant['id']]);
// TODO: I think the price set should be removed, but I don't know how
// to decouple it properly from the event. For the moment, I'll just comment
* Check with complete array.
*/
public function testUpdate() {
- $participantId = $this->participantCreate(array(
+ $participantId = $this->participantCreate([
'contactID' => $this->_individualId,
'eventID' => $this->_eventID,
- ));
- $params = array(
+ ]);
+ $params = [
'id' => $participantId,
'contact_id' => $this->_individualId,
'event_id' => $this->_eventID,
'role_id' => 3,
'register_date' => '2006-01-21',
'source' => 'US Open',
- );
+ ];
$participant = $this->callAPISuccess('participant', 'create', $params);
$this->getAndCheck($params, $participant['id'], 'participant');
$result = $this->participantDelete($params['id']);
*/
public function testUpdateCreateParticipantFeeLevelNoSeparator() {
- $myParams = $this->_params + array('participant_fee_level' => "fee");
+ $myParams = $this->_params + ['participant_fee_level' => "fee"];
$participant = $this->callAPISuccess('participant', 'create', $myParams);
$this->assertAPISuccess($participant);
- $update = array(
+ $update = [
'id' => $participant['id'],
'status_id' => 2,
- );
+ ];
$this->callAPISuccess('participant', 'create', $update);
$this->assertEquals($participant['values'][$participant['id']]['fee_level'],
$myParams['participant_fee_level']
* Check with empty array.
*/
public function testUpdateEmptyParams() {
- $params = array();
+ $params = [];
$participant = $this->callAPIFailure('participant', 'create', $params);
$this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id, contact_id');
}
* Check without event_id.
*/
public function testUpdateWithoutEventId() {
- $participantId = $this->participantCreate(array('contactID' => $this->_individualId, 'eventID' => $this->_eventID));
- $params = array(
+ $participantId = $this->participantCreate(['contactID' => $this->_individualId, 'eventID' => $this->_eventID]);
+ $params = [
'contact_id' => $this->_individualId,
'status_id' => 3,
'role_id' => 3,
'register_date' => '2006-01-21',
'source' => 'US Open',
'event_level' => 'Donation',
- );
+ ];
$participant = $this->callAPIFailure('participant', 'create', $params);
$this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id');
// Cleanup created participant records.
* Check with Invalid participantId.
*/
public function testUpdateWithWrongParticipantId() {
- $params = array(
+ $params = [
'id' => 1234,
'status_id' => 3,
'role_id' => 3,
'register_date' => '2006-01-21',
'source' => 'US Open',
'event_level' => 'Donation',
- );
+ ];
$participant = $this->callAPIFailure('Participant', 'update', $params);
}
* Check with Invalid ContactId.
*/
public function testUpdateWithWrongContactId() {
- $participantId = $this->participantCreate(array(
+ $participantId = $this->participantCreate([
'contactID' => $this->_individualId,
'eventID' => $this->_eventID,
- ), $this->_apiversion);
- $params = array(
+ ], $this->_apiversion);
+ $params = [
'id' => $participantId,
'contact_id' => 12345,
'status_id' => 3,
'register_date' => '2006-01-21',
'source' => 'US Open',
'event_level' => 'Donation',
- );
+ ];
$participant = $this->callAPIFailure('participant', 'create', $params);
$result = $this->participantDelete($participantId);
}
* Test civicrm_participant_delete with empty params.
*/
public function testDeleteEmptyParams() {
- $params = array();
+ $params = [];
$result = $this->callAPIFailure('participant', 'delete', $params);
}
* Check with participant_id.
*/
public function testParticipantDelete() {
- $params = array(
+ $params = [
'id' => $this->_participantID,
- );
+ ];
$participant = $this->callAPISuccess('participant', 'delete', $params);
$this->assertAPISuccess($participant);
$this->assertDBState('CRM_Event_DAO_Participant', $this->_participantID, NULL, TRUE);
* This should return an error because required param is missing..
*/
public function testParticipantDeleteMissingID() {
- $params = array(
+ $params = [
'event_id' => $this->_eventID,
- );
+ ];
$participant = $this->callAPIFailure('participant', 'delete', $params);
$this->assertNotNull($participant['error_message']);
}
public function testNestedDelete() {
$description = "Criteria delete by nesting a GET & a DELETE.";
$subfile = "NestedDelete";
- $participants = $this->callAPISuccess('Participant', 'Get', array());
+ $participants = $this->callAPISuccess('Participant', 'Get', []);
$this->assertEquals($participants['count'], 3);
- $params = array('contact_id' => $this->_contactID2, 'api.participant.delete' => 1);
+ $params = ['contact_id' => $this->_contactID2, 'api.participant.delete' => 1];
$this->callAPIAndDocument('Participant', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $check = $this->callAPISuccess('participant', 'getcount', array());
+ $check = $this->callAPISuccess('participant', 'getcount', []);
$this->assertEquals(1, $check, "only one participant should be left");
}
$description = "Single function to create contact with partipation & contribution.
Note that in the case of 'contribution' the 'create' is implied (api.contribution.create)";
$subfile = "CreateParticipantPayment";
- $params = array(
+ $params = [
'contact_type' => 'Individual',
'display_name' => 'dlobo',
- 'api.participant' => array(
+ 'api.participant' => [
'event_id' => $this->_eventID,
'status_id' => 1,
'role_id' => 1,
'format.only_id' => 1,
- ),
- 'api.contribution.create' => array(
+ ],
+ 'api.contribution.create' => [
'financial_type_id' => 1,
'total_amount' => 100,
'format.only_id' => 1,
- ),
- 'api.participant_payment.create' => array(
+ ],
+ 'api.participant_payment.create' => [
'contribution_id' => '$value.api.contribution.create',
'participant_id' => '$value.api.participant',
- ),
- );
+ ],
+ ];
$result = $this->callAPIAndDocument('contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(1, $result['values'][$result['id']]['api.participant_payment.create']['count']);
- $this->callAPISuccess('contact', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('contact', 'delete', ['id' => $result['id']]);
}
/**
* Test participant invoke post hook after status update.
*/
public function testPostHookForAdditionalParticipant() {
- $participantID = $this->participantCreate(array(
+ $participantID = $this->participantCreate([
'contact_id' => $this->_contactID,
'status_id' => 5,
'event_id' => $this->_eventID,
- ));
- $participantID2 = $this->participantCreate(array(
+ ]);
+ $participantID2 = $this->participantCreate([
'contact_id' => $this->_contactID2,
'event_id' => $this->_eventID,
'status_id' => 5,
'registered_by_id' => $participantID,
- ));
+ ]);
- $this->hookClass->setHook('civicrm_post', array($this, 'onPost'));
- $params = array(
+ $this->hookClass->setHook('civicrm_post', [$this, 'onPost']);
+ $params = [
'id' => $participantID,
'status_id' => 1,
- );
+ ];
$this->callAPISuccess('Participant', 'create', $params);
- $result = $this->callAPISuccess('Participant', 'get', array('source' => 'Post Hook Update'));
+ $result = $this->callAPISuccess('Participant', 'get', ['source' => 'Post Hook Update']);
$this->assertEquals(2, $result['count']);
- $expected = array($participantID, $participantID2);
+ $expected = [$participantID, $participantID2];
$actual = array_keys($result['values']);
$this->checkArrayEquals($expected, $actual);
}
parent::setUp();
$this->useTransaction(TRUE);
// Create dummy processor
- $params = array(
+ $params = [
'name' => 'API_Test_PP_Type',
'title' => 'API Test Payment Processor Type',
'class_name' => 'CRM_Core_Payment_APITest',
'billing_mode' => 'form',
'is_recur' => 0,
- );
+ ];
$result = $this->callAPISuccess('payment_processor_type', 'create', $params);
$this->_paymentProcessorType = $result['id'];
- $this->_params = array(
+ $this->_params = [
'name' => 'API Test PP',
'payment_processor_type_id' => $this->_paymentProcessorType,
'class_name' => 'CRM_Core_Payment_APITest',
'is_recur' => 0,
'domain_id' => 1,
- );
+ ];
}
/**
* Check with no name.
*/
public function testPaymentProcessorCreateWithoutName() {
- $payProcParams = array(
+ $payProcParams = [
'is_active' => 1,
- );
+ ];
$this->callAPIFailure('payment_processor', 'create', $payProcParams);
}
$result = $this->callAPISuccess('payment_processor', 'create', $params);
$this->assertNotNull($result['id']);
- $updateParams = array(
+ $updateParams = [
'id' => $result['id'],
'name' => 'Update API Test',
- );
+ ];
$this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
$this->callAPISuccess('payment_processor', 'create', $updateParams);
- $result = $this->callAPISuccess('payment_processor', 'get', array('id' => $result['id']));
+ $result = $this->callAPISuccess('payment_processor', 'get', ['id' => $result['id']]);
- $expectedResult = array(
+ $expectedResult = [
'id' => $result['id'],
'domain_id' => $params['domain_id'],
'name' => $updateParams['name'],
'payment_type' => 1,
'payment_instrument_id' => 1,
'is_active' => 1,
- );
+ ];
$this->checkArrayEquals($expectedResult, $result['values'][$result['id']]);
}
*/
public function testPaymentProcessorDelete() {
$result = $this->callAPISuccess('payment_processor', 'create', $this->_params);
- $params = array(
+ $params = [
'id' => $result['id'],
- );
+ ];
$this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__);
}
$params['user_name'] = 'test@test.com';
$this->callAPISuccess('payment_processor', 'create', $params);
- $params = array(
+ $params = [
'user_name' => 'test@test.com',
- );
+ ];
$results = $this->callAPISuccess('payment_processor', 'get', $params);
$this->assertEquals(1, $results['count']);
* Check with no name.
*/
public function testPaymentProcessorTypeCreateWithoutName() {
- $payProcParams = array(
+ $payProcParams = [
'is_active' => 1,
- );
+ ];
$result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams);
$this->assertEquals($result['error_message'],
'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'
* Create payment processor type.
*/
public function testPaymentProcessorTypeCreate() {
- $params = array(
+ $params = [
'sequential' => 1,
'name' => 'API_Test_PP',
'title' => 'API Test Payment Processor',
'class_name' => 'CRM_Core_Payment_APITest',
'billing_mode' => 'form',
'is_recur' => 0,
- );
+ ];
$result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($result['values'][0]['id']);
* Check with empty array.
*/
public function testPaymentProcessorTypeDeleteEmpty() {
- $params = array();
+ $params = [];
$result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
}
* Check if required fields are not passed.
*/
public function testPaymentProcessorTypeDeleteWithoutRequired() {
- $params = array(
+ $params = [
'name' => 'API_Test_PP',
'title' => 'API Test Payment Processor',
'class_name' => 'CRM_Core_Payment_APITest',
- );
+ ];
$result = $this->callAPIFailure('payment_processor_type', 'delete', $params);
$this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
* Check with incorrect required fields.
*/
public function testPaymentProcessorTypeDeleteWithIncorrectData() {
- $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd'));
+ $result = $this->callAPIFailure('payment_processor_type', 'delete', ['id' => 'abcd']);
}
/**
*/
public function testPaymentProcessorTypeDelete() {
$payProcType = $this->paymentProcessorTypeCreate();
- $params = array(
+ $params = [
'id' => $payProcType,
- );
+ ];
$result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__);
}
* Check with empty array.
*/
public function testPaymentProcessorTypeUpdateEmpty() {
- $params = array();
+ $params = [];
$result = $this->callAPIFailure('payment_processor_type', 'create', $params);
$this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode');
}
// create sample payment processor type.
$this->_ppTypeID = $this->paymentProcessorTypeCreate(NULL);
- $params = array(
+ $params = [
'id' => $this->_ppTypeID,
// keep the same
'name' => 'API_Test_PP',
'class_name' => 'CRM_Core_Payment_APITest 2',
'billing_mode' => 2,
'is_recur' => 0,
- );
+ ];
$result = $this->callAPISuccess('payment_processor_type', 'create', $params);
$this->assertNotNull($result['id']);
* Check with empty array.
*/
public function testPaymentProcessorTypesGetEmptyParams() {
- $results = $this->callAPISuccess('payment_processor_type', 'get', array());
+ $results = $this->callAPISuccess('payment_processor_type', 'get', []);
$baselineCount = $results['count'];
- $firstRelTypeParams = array(
+ $firstRelTypeParams = [
'name' => 'API_Test_PP',
'title' => 'API Test Payment Processor',
'class_name' => 'CRM_Core_Payment_APITest',
'billing_mode' => 1,
'is_recur' => 0,
- );
+ ];
$first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
- $secondRelTypeParams = array(
+ $secondRelTypeParams = [
'name' => 'API_Test_PP2',
'title' => 'API Test Payment Processor 2',
'class_name' => 'CRM_Core_Payment_APITest 2',
'billing_mode' => 2,
'is_recur' => 0,
- );
+ ];
$second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
- $result = $this->callAPISuccess('payment_processor_type', 'get', array());
+ $result = $this->callAPISuccess('payment_processor_type', 'get', []);
$this->assertEquals($baselineCount + 2, $result['count']);
$this->assertAPISuccess($result);
* Check with valid params array.
*/
public function testPaymentProcessorTypesGet() {
- $firstRelTypeParams = array(
+ $firstRelTypeParams = [
'name' => 'API_Test_PP_11',
'title' => 'API Test Payment Processor 11',
'class_name' => 'CRM_Core_Payment_APITest_11',
'billing_mode' => 1,
'is_recur' => 0,
- );
+ ];
$first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams);
- $secondRelTypeParams = array(
+ $secondRelTypeParams = [
'name' => 'API_Test_PP_12',
'title' => 'API Test Payment Processor 12',
'class_name' => 'CRM_Core_Payment_APITest_12',
'billing_mode' => 2,
'is_recur' => 0,
- );
+ ];
$second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams);
- $params = array(
+ $params = [
'name' => 'API_Test_PP_12',
- );
+ ];
$result = $this->callAPISuccess('payment_processor_type', 'get', $params);
$this->assertAPISuccess($result);
$this->useTransaction(TRUE);
parent::setUp();
$contactID = $this->individualCreate();
- $this->params = array(
+ $this->params = [
'token' => "fancy-token-xxxx",
'contact_id' => $contactID,
'created_id' => $contactID,
'payment_processor_id' => $this->processorCreate(),
- );
+ ];
}
public function testCreatePaymentToken() {
$result = $this->callAPIAndDocument('payment_token', 'create', $this->params, __FUNCTION__, __FILE__, $description);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->getAndCheck(array_merge($this->params, array($this->params)), $result['id'], 'payment_token', TRUE);
+ $this->getAndCheck(array_merge($this->params, [$this->params]), $result['id'], 'payment_token', TRUE);
}
public function testGetPaymentToken() {
public function testDeletePaymentToken() {
$this->callAPISuccess('payment_token', 'create', $this->params);
$entity = $this->callAPISuccess('payment_token', 'get', ($this->params));
- $delete = array('id' => $entity['id']);
+ $delete = ['id' => $entity['id']];
$result = $this->callAPIAndDocument('payment_token', 'delete', $delete, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess('payment_token', 'get', array());
+ $checkDeleted = $this->callAPISuccess('payment_token', 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
public $DBResetRequired = TRUE;
public function setUp() {
- $this->params = array(
+ $this->params = [
'title' => "Pcp title",
'contact_id' => 1,
'page_id' => 1,
'pcp_block_id' => 1,
- );
+ ];
parent::setUp();
}
*/
public function testDisablePcp() {
$result = civicrm_api3('Pcp', 'create', $this->params);
- civicrm_api3('Pcp', 'create', array('id' => $result['id'], 'is_active' => 0));
- $this->getAndCheck($this->params + array('is_active' => 0), $result['id'], $this->entity);
+ civicrm_api3('Pcp', 'create', ['id' => $result['id'], 'is_active' => 0]);
+ $this->getAndCheck($this->params + ['is_active' => 0], $result['id'], $this->entity);
}
/**
public function testDeletePcp() {
$entity = $this->createTestEntity();
$checkCreated = $this->callAPISuccess($this->entity, 'get',
- array('id' => $entity['id']));
+ ['id' => $entity['id']]);
$this->assertEquals(1, $checkCreated['count']);
$this->callAPIAndDocument('Pcp', 'delete',
- array('id' => $entity['id']), __FUNCTION__, __FILE__);
+ ['id' => $entity['id']], __FUNCTION__, __FILE__);
$checkDeleted = $this->callAPISuccess($this->entity, 'get',
- array('id' => $entity['id']));
+ ['id' => $entity['id']]);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testGetPcpChainDelete() {
$description = "Demonstrates get + delete in the same call.";
$subfile = 'ChainedGetDelete';
- $params = array('title' => "Pcp title", 'api.Pcp.delete' => 1);
+ $params = ['title' => "Pcp title", 'api.Pcp.delete' => 1];
$this->callAPISuccess('Pcp', 'create', $this->params);
$this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__,
__FILE__, $description, $subfile);
- $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', array()));
+ $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', []));
}
}
$loc = $this->locationTypeCreate();
$this->_locationType = $loc->id;
CRM_Core_PseudoConstant::flush();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType,
'phone' => '(123) 456-7890',
'is_primary' => 1,
'phone_type_id' => 1,
- );
+ ];
}
/**
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->callAPISuccess('phone', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('phone', 'delete', ['id' => $result['id']]);
}
/**
//create one
$create = $this->callAPISuccess('phone', 'create', $this->_params);
- $result = $this->callAPIAndDocument('phone', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('phone', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
- $get = $this->callAPISuccess('phone', 'get', array(
+ $get = $this->callAPISuccess('phone', 'get', [
'id' => $create['id'],
'location_type_id' => $this->_locationType,
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'Phone not successfully deleted In line ' . __LINE__);
}
*/
public function testGetEmptyParams($version) {
$this->_apiversion = $version;
- $result = $this->callAPISuccess('Phone', 'Get', array());
+ $result = $this->callAPISuccess('Phone', 'Get', []);
}
/**
* Test civicrm_phone_get with wrong params.
*/
public function testGetWrongParams() {
- $this->callAPIFailure('Phone', 'Get', array('contact_id' => 'abc'));
- $this->callAPIFailure('Phone', 'Get', array('location_type_id' => 'abc'));
- $this->callAPIFailure('Phone', 'Get', array('phone_type_id' => 'abc'));
+ $this->callAPIFailure('Phone', 'Get', ['contact_id' => 'abc']);
+ $this->callAPIFailure('Phone', 'Get', ['location_type_id' => 'abc']);
+ $this->callAPIFailure('Phone', 'Get', ['phone_type_id' => 'abc']);
}
/**
public function testGet($version) {
$this->_apiversion = $version;
$phone = $this->callAPISuccess('phone', 'create', $this->_params);
- $params = array(
+ $params = [
'contact_id' => $this->_params['contact_id'],
'phone' => $phone['values'][$phone['id']]['phone'],
- );
+ ];
$result = $this->callAPIAndDocument('Phone', 'Get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($phone['values'][$phone['id']]['location_type_id'], $result['values'][$phone['id']]['location_type_id']);
$this->assertEquals($phone['values'][$phone['id']]['phone_type_id'], $result['values'][$phone['id']]['phone_type_id']);
$this->_apiversion = $version;
$result = $this->callAPISuccess('phone', 'create', $this->_params);
$id = $result['id'];
- $params = array('id' => $id, 'return.phone_numeric' => 1);
+ $params = ['id' => $id, 'return.phone_numeric' => 1];
$result = $this->callAPISuccess('phone', 'get', $params);
$this->assertEquals('1234567890', $result['values'][$id]['phone_numeric']);
}
unset($params['is_primary']);
$phone1 = $this->callAPISuccess('phone', 'create', $params);
//now we check & make sure it has been set to primary
- $check = $this->callAPISuccess('phone', 'getcount', array(
+ $check = $this->callAPISuccess('phone', 'getcount', [
'is_primary' => 1,
'id' => $phone1['id'],
- ));
+ ]);
$this->assertEquals(1, $check);
}
$this->_apiversion = $version;
$phone1 = $this->callAPISuccess('phone', 'create', $this->_params);
$phone2 = $this->callAPISuccess('phone', 'create', $this->_params);
- $check = $this->callAPISuccess('phone', 'getcount', array(
+ $check = $this->callAPISuccess('phone', 'getcount', [
'is_primary' => 1,
'contact_id' => $this->_contactID,
- ));
+ ]);
$this->assertEquals(1, $check);
}
public function setUp() {
parent::setUp();
$this->_individualId = $this->individualCreate();
- $this->_pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId));
- $this->_contributionID = $this->contributionCreate(array('contact_id' => $this->_individualId));
+ $this->_pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]);
+ $this->_contributionID = $this->contributionCreate(['contact_id' => $this->_individualId]);
}
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contribution',
'civicrm_contact',
'civicrm_pledge',
'civicrm_pledge_payment',
'civicrm_line_item',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
parent::tearDown();
}
public function testGetPledgePayment() {
- $params = array();
+ $params = [];
$result = $this->callAPIAndDocument('pledge_payment', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals(5, $result['count'], " in line " . __LINE__);
}
* Test that passing in a single variable works.
*/
public function testGetSinglePledgePayment() {
- $createparams = array(
+ $createparams = [
'contact_id' => $this->_individualId,
'pledge_id' => $this->_pledgeID,
'contribution_id' => $this->_contributionID,
'status_id' => 1,
- );
+ ];
$createResult = $this->callAPISuccess('pledge_payment', 'create', $createparams);
- $params = array(
+ $params = [
'contribution_id' => $this->_contributionID,
- );
+ ];
$result = $this->callAPISuccess('pledge_payment', 'get', $params);
$this->assertEquals(1, $result['count'], " in line " . __LINE__);
}
FALSE, FALSE, FALSE, NULL, 'name'
);
//Make first payment.
- $paymentParams = array(
+ $paymentParams = [
'contact_id' => $this->_individualId,
'pledge_id' => $this->_pledgeID,
'contribution_id' => $this->_contributionID,
'scheduled_date' => date('Ymd', strtotime("-1 days")),
'status_id' => array_search('Pending', $pledgeStatuses),
- );
+ ];
$firstPayment = $this->callAPISuccess('pledge_payment', 'create', $paymentParams);
//Status should be 'Pending' after first incomplete payment.
- $checkStatus = $this->callAPISuccess('pledge', 'getsingle', array(
+ $checkStatus = $this->callAPISuccess('pledge', 'getsingle', [
'id' => $this->_pledgeID,
'return' => 'pledge_status',
- ));
+ ]);
$this->assertEquals('Pending', $checkStatus['pledge_status']);
//Execute process_pledge job log.
- $result = $this->callAPISuccess('Job', 'process_pledge', array());
+ $result = $this->callAPISuccess('Job', 'process_pledge', []);
$this->assertEquals("Checking if status update is needed for Pledge Id: {$this->_pledgeID} (current status is Pending)\n\r- status updated to: Overdue\n\r1 records updated.", $result['values']);
//Status should be 'Overdue' after processing.
- $statusAfterProcessing = $this->callAPISuccess('pledge', 'getsingle', array(
+ $statusAfterProcessing = $this->callAPISuccess('pledge', 'getsingle', [
'id' => $this->_pledgeID,
'return' => 'pledge_status',
- ));
+ ]);
$this->assertEquals('Overdue', $statusAfterProcessing['pledge_status']);
}
*/
public function testPledgeStatus() {
//Status should initially be Pending.
- $checkStatus = $this->callAPISuccess('pledge', 'getsingle', array(
+ $checkStatus = $this->callAPISuccess('pledge', 'getsingle', [
'id' => $this->_pledgeID,
'return' => 'pledge_status',
- ));
+ ]);
$this->assertEquals('Pending', $checkStatus['pledge_status']);
//Make first payment.
- $paymentParams = array(
+ $paymentParams = [
'contact_id' => $this->_individualId,
'pledge_id' => $this->_pledgeID,
'contribution_id' => $this->_contributionID,
'status_id' => 1,
- );
+ ];
$firstPayment = $this->callAPISuccess('pledge_payment', 'create', $paymentParams);
//Status should be 'In Progress' after first payment.
- $checkStatus = $this->callAPISuccess('pledge', 'getsingle', array(
+ $checkStatus = $this->callAPISuccess('pledge', 'getsingle', [
'id' => $this->_pledgeID,
'return' => 'pledge_status',
- ));
+ ]);
$this->assertEquals('In Progress', $checkStatus['pledge_status']);
//Cancel the Pledge.
$paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
- $updateParams = array(
+ $updateParams = [
'id' => $this->_pledgeID,
'status_id' => array_search('Cancelled', $paymentStatusTypes),
- );
+ ];
$this->callAPISuccess('pledge', 'create', $updateParams);
//Status should be calculated as Cancelled.
$this->assertEquals('Cancelled', $paymentStatusTypes[$pledgeStatus]);
//Already completed payments should not be cancelled.
- $checkPaymentStatus = $this->callAPISuccess('pledge_payment', 'getsingle', array(
+ $checkPaymentStatus = $this->callAPISuccess('pledge_payment', 'getsingle', [
'id' => $firstPayment['id'],
'return' => 'status_id',
- ));
+ ]);
$this->assertEquals(array_search('Completed', $paymentStatusTypes), $checkPaymentStatus['status_id']);
}
* Test that passing in a single variable works:: status_id
*/
public function testGetSinglePledgePaymentByStatusID() {
- $createparams = array(
+ $createparams = [
'contact_id' => $this->_individualId,
'pledge_id' => $this->_pledgeID,
'contribution_id' => $this->_contributionID,
'status_id' => 1,
- );
+ ];
$createResult = $this->callAPISuccess('pledge_payment', 'create', $createparams);
- $params = array(
+ $params = [
'status_id' => 1,
- );
+ ];
$result = $this->callAPISuccess('pledge_payment', 'get', $params);
$this->assertEquals(1, $result['count'], " in line " . __LINE__);
*/
public function testCreatePledgePayment() {
//check that 5 pledge payments exist at the start
- $beforeAdd = $this->callAPISuccess('pledge_payment', 'get', array());
+ $beforeAdd = $this->callAPISuccess('pledge_payment', 'get', []);
$this->assertEquals(5, $beforeAdd['count'], " in line " . __LINE__);
//test the pledge_payment_create function
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'pledge_id' => $this->_pledgeID,
'contribution_id' => $this->_contributionID,
'status_id' => 1,
'actual_amount' => 20,
- );
+ ];
$result = $this->callAPIAndDocument('pledge_payment', 'create', $params, __FUNCTION__, __FILE__);
//check existing updated not new one created - 'create' means add contribution_id in this context
- $afterAdd = $this->callAPISuccess('pledge_payment', 'get', array());
+ $afterAdd = $this->callAPISuccess('pledge_payment', 'get', []);
$this->assertEquals(5, $afterAdd['count'], " in line " . __LINE__);
//get the created payment & check it out
$this->assertEquals(20, $getIndPayment['values'][$result['id']]['actual_amount'], " in line " . __LINE__);
//create a second pledge payment - need a contribution first &can't use the CiviUnitTest case function as invoice is hard-coded
- $contributionParams = array(
+ $contributionParams = [
'total_amount' => 20,
'contact_id' => $this->_individualId,
'financial_type_id' => $this->_financialTypeId,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
$params['contribution_id'] = $contribution['id'];
* Test checks behaviour when more payments are created than should be possible.
*/
public function testCreatePledgePaymentAllCreated() {
- $params = array(
+ $params = [
'pledge_id' => $this->_pledgeID,
'status_id' => 1,
- );
+ ];
// create one more pledge than there are spaces for
$i = 0;
while ($i <= 5) {
- $contributionParams = array(
+ $contributionParams = [
'total_amount' => 20,
'contact_id' => $this->_individualId,
'financial_type_id' => $this->_financialTypeId,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
$params['contribution_id'] = $contribution['id'];
- $resultCont2 = civicrm_api('pledge_payment', 'create', $params + array('version' => $this->_apiversion));
+ $resultCont2 = civicrm_api('pledge_payment', 'create', $params + ['version' => $this->_apiversion]);
$i++;
}
// check that only 5 exist & we got an error setting the 6th
- $result = $this->callAPISuccess('PledgePayment', 'Get', array(
+ $result = $this->callAPISuccess('PledgePayment', 'Get', [
'pledge_id' => $this->_pledgeID,
- ));
+ ]);
// the last one above should result in an error
$this->assertEquals("There are no unmatched payment on this pledge. Pass in the pledge_payment id to specify one or 'option.create_new' to create one", $resultCont2['error_message']);
$this->assertEquals(5, $result['count']);
$params['scheduled_amount'] = 20;
$params['scheduled_date'] = '20131212';
$resultcreatenew = $this->callAPISuccess('pledge_payment', 'create', $params);
- $result = $this->callAPISuccess('PledgePayment', 'Get', array(
+ $result = $this->callAPISuccess('PledgePayment', 'Get', [
'pledge_id' => $this->_pledgeID,
- ));
+ ]);
$this->assertEquals(6, $result['count']);
}
* Test that creating a payment adds the contribution ID where only one pledge payment is in schedule.
*/
public function testCreatePledgePaymentWhereOnlyOnePayment() {
- $pledgeParams = array(
+ $pledgeParams = [
'contact_id' => $this->_individualId,
'pledge_create_date' => date('Ymd'),
'start_date' => date('Ymd'),
'frequency_day' => 15,
'installments' => 1,
'sequential' => 1,
- );
+ ];
- $contributionID = $this->contributionCreate(array(
+ $contributionID = $this->contributionCreate([
'contact_id' => $this->_individualId,
'financial_type_id' => $this->_financialTypeId,
'invoice_id' => 45,
'trxn_id' => 45,
- ));
+ ]);
$pledge = $this->callAPISuccess('Pledge', 'Create', $pledgeParams);
//test the pledge_payment_create function
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'pledge_id' => $pledge['id'],
'contribution_id' => $contributionID,
'status_id' => 1,
'actual_amount' => 20,
- );
+ ];
$result = $this->callAPISuccess('pledge_payment', 'create', $params);
//check existing updated not new one created - 'create' means add contribution_id in this context
- $afterAdd = $this->callAPISuccess('pledge_payment', 'get', array(
+ $afterAdd = $this->callAPISuccess('pledge_payment', 'get', [
'contribution_id' => $contributionID,
- ));
+ ]);
$this->assertEquals(1, $afterAdd['count'], " in line " . __LINE__);
}
public function testUpdatePledgePayment() {
- $params = array(
+ $params = [
'pledge_id' => $this->_pledgeID,
'contribution_id' => $this->_contributionID,
'status_id' => 2,
'actual_amount' => 20,
- );
+ ];
$result = $this->callAPISuccess('pledge_payment', 'create', $params);
- $updateparams = array(
+ $updateparams = [
'id' => $result['id'],
'status_id' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('pledge_payment', 'update', $updateparams, __FUNCTION__, __FILE__);
$this->getAndCheck(array_merge($params, $updateparams), $result['id'], $this->_entity);
}
public function testDeletePledgePayment() {
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'pledge_id' => $this->_pledgeID,
'contribution_id' => $this->_contributionID,
'status_id' => 1,
'sequential' => 1,
'actual_amount' => 20,
- );
+ ];
$pledgePayment = $this->callAPISuccess('pledge_payment', 'create', $params);
- $deleteParams = array(
+ $deleteParams = [
'id' => $pledgePayment['id'],
- );
+ ];
$result = $this->callAPIAndDocument('pledge_payment', 'delete', $deleteParams, __FUNCTION__, __FILE__);
}
public function testGetFields() {
- $result = $this->callAPISuccess('PledgePayment', 'GetFields', array());
+ $result = $this->callAPISuccess('PledgePayment', 'GetFields', []);
$this->assertType('array', $result);
}
public function setUp() {
$this->_apiversion = 3;
parent::setUp();
- $this->quickCleanup(array('civicrm_pledge', 'civicrm_pledge_payment'));
+ $this->quickCleanup(['civicrm_pledge', 'civicrm_pledge_payment']);
//need to set scheduled payment in advance we are running test @ midnight & it becomes unexpectedly overdue
//due to timezone issues
$this->scheduled_date = date('Ymd', mktime(0, 0, 0, date("m"), date("d") + 2, date("y")));
$this->_entity = 'Pledge';
$this->_individualId = $this->individualCreate();
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_individualId,
'pledge_create_date' => date('Ymd'),
'start_date' => date('Ymd'),
'frequency_day' => 15,
'installments' => 5,
'sequential' => 1,
- );
+ ];
}
public function tearDown() {
$result = $this->callAPISuccess($this->_entity, 'create', $params);
$this->assertAPISuccess($result, " testCreateWithCustom ");
$this->assertAPISuccess($result);
- $getParams = array('id' => $result['id'], 'return.custom_' . $ids['custom_field_id'] => 1);
+ $getParams = ['id' => $result['id'], 'return.custom_' . $ids['custom_field_id'] => 1];
$check = $this->callAPISuccess($this->_entity, 'get', $getParams);
- $this->callAPISuccess('pledge', 'delete', array('id' => $check['id']));
+ $this->callAPISuccess('pledge', 'delete', ['id' => $check['id']]);
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]);
$this->customFieldDelete($ids['custom_field_id']);
* Test getfields function for pledge.
*/
public function testGetfieldsPledge() {
- $result = $this->callAPISuccess('pledge', 'getfields', array('action' => 'get'));
+ $result = $this->callAPISuccess('pledge', 'getfields', ['action' => 'get']);
$this->assertEquals(1, $result['values']['next_pay_date']['api.return']);
}
public function testGetPledge() {
$this->_pledge = $this->callAPISuccess('pledge', 'create', $this->_params);
- $params = array(
+ $params = [
'pledge_id' => $this->_pledge['id'],
- );
+ ];
$result = $this->callAPIAndDocument('pledge', 'get', $params, __FUNCTION__, __FILE__);
$pledge = $result['values'][$this->_pledge['id']];
$this->assertEquals($this->_individualId, $pledge['contact_id']);
$this->assertEquals(date('Y-m-d', strtotime($this->scheduled_date)) . ' 00:00:00', $pledge['pledge_next_pay_date']);
$this->assertEquals($pledge['pledge_next_pay_amount'], 20.00);
- $params2 = array(
+ $params2 = [
'pledge_id' => $this->_pledge['id'],
- );
+ ];
$pledge = $this->callAPISuccess('pledge', 'delete', $params2);
}
public function testGetPledgeWithReturn() {
$this->_pledge = $this->callAPISuccess('pledge', 'create', $this->_params);
- $params = array(
+ $params = [
'pledge_id' => $this->_pledge['id'],
'return.pledge_financial_type' => 1,
- );
+ ];
$result = $this->callAPISuccess('pledge', 'get', $params);
$pledge = $result['values'][$this->_pledge['id']];
$this->callAPISuccess('pledge', 'delete', $pledge);
public function testGetPledgeWithReturnLegacy() {
$this->_pledge = $this->callAPISuccess('pledge', 'create', $this->_params);
- $params = array(
+ $params = [
'pledge_id' => $this->_pledge['id'],
'return.pledge_financial_type' => 1,
- );
+ ];
$result = $this->callAPISuccess('pledge', 'get', $params);
$pledge = $result['values'][$this->_pledge['id']];
$this->callAPISuccess('pledge', 'delete', $pledge);
public function testPledgeGetReturnFilters() {
$this->callAPISuccess('pledge', 'create', $this->_params);
- $overdueParams = array(
+ $overdueParams = [
'scheduled_date' => 'first saturday of march last year',
'start_date' => 'first saturday of march last year',
- );
+ ];
$oldPledge = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams));
- $pledgeGetParams = array();
+ $pledgeGetParams = [];
$allPledges = $this->callAPISuccess('pledge', 'getcount', $pledgeGetParams);
$this->assertEquals(2, $allPledges, 'Check we have 2 pledges to place with in line ' . __LINE__);
* Create 2 pledges - see if we can get by status id.
*/
public function testGetOverduePledge() {
- $overdueParams = array(
+ $overdueParams = [
'scheduled_date' => 'first saturday of march last year',
'start_date' => 'first saturday of march last year',
- );
+ ];
$this->_pledge = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams));
- $result = $this->callAPISuccess('pledge', 'get', array('status_id' => 'Overdue'));
- $emptyResult = $this->callAPISuccess('pledge', 'get', array(
+ $result = $this->callAPISuccess('pledge', 'get', ['status_id' => 'Overdue']);
+ $emptyResult = $this->callAPISuccess('pledge', 'get', [
'pledge_status_id' => '1',
- ));
+ ]);
$pledge = $result['values'][$this->_pledge['id']];
$this->callAPISuccess('pledge', 'delete', $pledge);
$this->assertEquals(1, $result['count']);
* Test pledge_status option group
*/
public function testOptionGroupForPledgeStatus() {
- $pledgeOg = $this->callAPISuccess('OptionGroup', 'get', array(
+ $pledgeOg = $this->callAPISuccess('OptionGroup', 'get', [
'name' => "pledge_status",
- ));
+ ]);
$this->assertEquals(1, $pledgeOg['count']);
- $pledgeOv = $this->callAPISuccess('OptionValue', 'get', array(
+ $pledgeOv = $this->callAPISuccess('OptionValue', 'get', [
'sequential' => 1,
'option_group_id' => "pledge_status",
- ));
+ ]);
$this->assertEquals(5, $pledgeOv['count']);
$pledgeStatus = CRM_Utils_Array::collect('name', $pledgeOv['values']);
- $expected = array('Completed', 'Pending', 'Cancelled', 'In Progress', 'Overdue');
+ $expected = ['Completed', 'Pending', 'Cancelled', 'In Progress', 'Overdue'];
$this->assertEquals($expected, $pledgeStatus);
}
*/
public function testSortParamPledge() {
$pledge1 = $this->callAPISuccess('pledge', 'create', $this->_params);
- $overdueParams = array(
+ $overdueParams = [
'scheduled_date' => 'first saturday of march last year',
'start_date' => 'first saturday of march last year',
'create_date' => 'first saturday of march last year',
- );
+ ];
$pledge2 = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams));
- $params = array(
+ $params = [
'pledge_is_test' => 0,
'rowCount' => 1,
- );
+ ];
$result = $this->callAPISuccess('pledge', 'get', $params);
- $resultSortedAsc = $this->callAPISuccess('pledge', 'get', array(
+ $resultSortedAsc = $this->callAPISuccess('pledge', 'get', [
'rowCount' => 1,
'sort' => 'start_date ASC',
- ));
- $resultSortedDesc = $this->callAPISuccess('pledge', 'get', array(
+ ]);
+ $resultSortedDesc = $this->callAPISuccess('pledge', 'get', [
'rowCount' => 1,
'sort' => 'start_date DESC',
- ));
+ ]);
$this->assertEquals($pledge1['id'], $result['id'], 'pledge get gets first created pledge in line ' . __LINE__);
$this->assertEquals($pledge2['id'], $resultSortedAsc['id'], 'Ascending pledge sort works');
$this->assertEquals($pledge1['id'], $resultSortedDesc['id'], 'Decending pledge sort works');
- $this->callAPISuccess('pledge', 'delete', array('id' => $pledge1['id']));
- $this->callAPISuccess('pledge', 'delete', array('id' => $pledge2['id']));
+ $this->callAPISuccess('pledge', 'delete', ['id' => $pledge1['id']]);
+ $this->callAPISuccess('pledge', 'delete', ['id' => $pledge2['id']]);
}
public function testCreatePledge() {
$this->assertEquals($result['values'][0]['create_date'], date('Ymd') . '000000');
$this->assertEquals($result['values'][0]['start_date'], date('Ymd') . '000000');
$this->assertAPISuccess($result);
- $payments = $this->callAPISuccess('PledgePayment', 'Get', array('pledge_id' => $result['id'], 'sequential' => 1));
+ $payments = $this->callAPISuccess('PledgePayment', 'Get', ['pledge_id' => $result['id'], 'sequential' => 1]);
$this->assertAPISuccess($payments);
$this->assertEquals($payments['count'], 5);
$shouldBeDate = CRM_Utils_Date::format(CRM_Utils_Date::intervalAdd('year', 5 * 4, $this->scheduled_date), "-");
$this->assertEquals(substr($shouldBeDate, 0, 10), substr($payments['values'][4]['scheduled_date'], 0, 10));
- $pledgeID = array('id' => $result['id']);
+ $pledgeID = ['id' => $result['id']];
$pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID);
}
* Test that pledge with weekly schedule calculates dates correctly.
*/
public function testCreatePledgeWeeklySchedule() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'week',
'frequency_day' => 3,
'frequency_interval' => 2,
- );
+ ];
$params = array_merge($this->_params, $params);
$pledge = $this->callAPISuccess('Pledge', 'Create', $params);
//ensure that correct number of payments created & last payment has the right date
- $payments = $this->callAPISuccess('PledgePayment', 'Get', array(
+ $payments = $this->callAPISuccess('PledgePayment', 'Get', [
'pledge_id' => $pledge['id'],
'sequential' => 1,
- ));
+ ]);
$this->assertEquals($payments['count'], 5);
$this->assertEquals('2011-07-06 00:00:00', $payments['values'][4]['scheduled_date']);
- $this->callAPISuccess('pledge', 'delete', array('pledge_id' => $pledge['id']));
+ $this->callAPISuccess('pledge', 'delete', ['pledge_id' => $pledge['id']]);
}
/**
* Test that pledge with weekly schedule calculates dates correctly.
*/
public function testCreatePledgeMontlySchedule() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'Month',
'frequency_day' => 3,
'frequency_interval' => 2,
- );
+ ];
$params = array_merge($this->_params, $params);
$apiResult = $this->callAPISuccess('pledge', 'create', $params);
}
* http://issues.civicrm.org/jira/browse/CRM-8551
*/
public function testCreatePledgeSinglePayment() {
- $params = array(
+ $params = [
'scheduled_date' => '20110510',
'frequency_unit' => 'week',
'frequency_day' => 3,
'frequency_interval' => 2,
'installments' => 1,
- );
+ ];
$params = array_merge($this->_params, $params);
unset($params['pledge_status_id']);
$pledge = $this->callAPISuccess('Pledge', 'Create', $params);
//ensure that correct number of payments created & last payment has the right date
- $payments = $this->callAPISuccess('PledgePayment', 'Get', array(
+ $payments = $this->callAPISuccess('PledgePayment', 'Get', [
'pledge_id' => $pledge['id'],
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(1, $payments['count']);
$this->assertEquals(2, $payments['values'][0]['status_id']);
- $pledgeID = array('id' => $pledge['id']);
+ $pledgeID = ['id' => $pledge['id']];
$pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID);
}
unset($params['pledge_original_installment_amount']);
$result = $this->callAPISuccess('pledge', 'create', $params);
- $pledgeDetails = $this->callAPISuccess('Pledge', 'Get', array('id' => $result['id'], 'sequential' => 1));
+ $pledgeDetails = $this->callAPISuccess('Pledge', 'Get', ['id' => $result['id'], 'sequential' => 1]);
$pledge = $pledgeDetails['values'][0];
$this->assertEquals(100.00, $pledge['pledge_amount']);
$this->assertEquals('year', $pledge['pledge_frequency_unit']);
$this->assertEquals(5, $pledge['pledge_frequency_interval']);
$this->assertEquals(20, $pledge['pledge_next_pay_amount']);
- $pledgeID = array('id' => $result['id']);
+ $pledgeID = ['id' => $result['id']];
$pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID);
}
$result = $this->callAPISuccess('pledge', 'create', $this->_params);
$this->assertEquals(2, $result['values'][0]['status_id']);
- $cancelParams = array(
+ $cancelParams = [
'sequential' => 1,
'id' => $result['id'],
'pledge_status_id' => 3,
- );
+ ];
$result = $this->callAPISuccess('pledge', 'create', $cancelParams);
$this->assertEquals(3, $result['values'][0]['status_id']);
- $pledgeID = array('id' => $result['id']);
+ $pledgeID = ['id' => $result['id']];
$this->callAPISuccess('pledge', 'delete', $pledgeID);
}
$result = $this->callAPISuccess('pledge', 'create', $params);
$this->assertAPISuccess($result);
$this->assertEquals(2, $result['values'][0]['status_id']);
- $pledgeID = array('pledge_id' => $result['id']);
+ $pledgeID = ['pledge_id' => $result['id']];
$pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID);
}
*/
public function testCreateUpdatePledge() {
// we test 'sequential' param here too
- $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId));
- $old_params = array(
+ $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]);
+ $old_params = [
'id' => $pledgeID,
'sequential' => 1,
- );
+ ];
$original = $this->callAPISuccess('pledge', 'get', $old_params);
//Make sure it came back
$this->assertEquals($original['values'][0]['pledge_id'], $pledgeID);
$this->assertEquals($old_frequency_unit, 'year');
$this->assertEquals($old_frequency_interval, 5);
$this->assertEquals($old_status_id, 'Pending');
- $params = array(
+ $params = [
'id' => $pledgeID,
'contact_id' => $this->_individualId,
'pledge_status_id' => 3,
'financial_type_id' => 1,
'start_date' => date('Ymd'),
'installments' => 10,
- );
+ ];
$pledge = $this->callAPISuccess('pledge', 'create', $params);
- $new_params = array(
+ $new_params = [
'id' => $pledge['id'],
- );
+ ];
$pledge = $this->callAPISuccess('pledge', 'get', $new_params);
$this->assertEquals($pledge['values'][$pledgeID]['contact_id'], $this->_individualId);
$this->assertEquals($pledge['values'][$pledgeID]['pledge_status'], 'Cancelled');
* We test 'sequential' param here too.
*/
public function testCreateUpdatePledgeLegacy() {
- $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId));
- $old_params = array(
+ $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]);
+ $old_params = [
'id' => $pledgeID,
'sequential' => 1,
- );
+ ];
$original = $this->callAPISuccess('pledge', 'get', $old_params);
// Make sure it came back.
$this->assertEquals($original['values'][0]['pledge_id'], $pledgeID);
$this->assertEquals($old_frequency_unit, 'year');
$this->assertEquals($old_frequency_interval, 5);
$this->assertEquals($old_status_id, 'Pending');
- $params = array(
+ $params = [
'id' => $pledgeID,
'contact_id' => $this->_individualId,
'pledge_status_id' => 3,
'contribution_type_id' => 1,
'start_date' => date('Ymd'),
'installments' => 10,
- );
+ ];
$pledge = $this->callAPISuccess('pledge', 'create', $params);
- $new_params = array(
+ $new_params = [
'id' => $pledge['id'],
- );
+ ];
$pledge = $this->callAPISuccess('pledge', 'get', $new_params);
$this->assertEquals($pledge['values'][$pledgeID]['contact_id'], $this->_individualId);
$this->assertEquals($pledge['values'][$pledgeID]['pledge_status'], 'Cancelled');
* Failure test for delete without id.
*/
public function testDeleteEmptyParamsPledge() {
- $this->callAPIFailure('pledge', 'delete', array(), 'Mandatory key(s) missing from params array: id');
+ $this->callAPIFailure('pledge', 'delete', [], 'Mandatory key(s) missing from params array: id');
}
/**
* Failure test for invalid pledge id.
*/
public function testDeleteWrongParamPledge() {
- $params = array(
+ $params = [
'pledge_source' => 'SSF',
- );
+ ];
$this->callAPIFailure('pledge', 'delete', $params, 'Mandatory key(s) missing from params array: id');
}
*/
public function testDeletePledge() {
- $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId));
- $params = array(
+ $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]);
+ $params = [
'pledge_id' => $pledgeID,
- );
+ ];
$this->callAPIAndDocument('pledge', 'delete', $params, __FUNCTION__, __FILE__);
}
*/
public function testDeletePledgeUseID() {
- $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId));
- $params = array(
+ $pledgeID = $this->pledgeCreate(['contact_id' => $this->_individualId]);
+ $params = [
'id' => $pledgeID,
- );
+ ];
$this->callAPIAndDocument('pledge', 'delete', $params, __FUNCTION__, __FILE__);
}
*/
public function testGetEmpty() {
$this->callAPISuccess('pledge', 'create', $this->_params);
- $result = $this->callAPISuccess('pledge', 'get', array());
+ $result = $this->callAPISuccess('pledge', 'get', []);
$this->assertAPISuccess($result, "This test is failing because it's acting like a contact get when no params set. Not sure the fix");
$this->assertEquals(1, $result['count']);
- $pledgeID = array('id' => $result['id']);
+ $pledgeID = ['id' => $result['id']];
$this->callAPISuccess('pledge', 'delete', $pledgeID);
}
public function setUp() {
parent::setUp();
// put stuff here that should happen before all tests in this unit
- $priceSetparams = array(
+ $priceSetparams = [
# [domain_id] =>
'name' => 'default_goat_priceset',
'title' => 'Goat accomodation',
'financial_type_id' => 1,
'is_quick_config' => 1,
'is_reserved' => 1,
- );
+ ];
$price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams);
$this->priceSetID = $price_set['id'];
- $this->_params = array(
+ $this->_params = [
'price_set_id' => $this->priceSetID,
'name' => 'grassvariety',
'label' => 'Grass Variety',
'html_type' => 'Text',
'is_enter_qty' => 1,
'is_active' => 1,
- );
+ ];
}
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contact',
'civicrm_contribution',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
- $delete = $this->callAPISuccess('PriceSet', 'delete', array(
+ $delete = $this->callAPISuccess('PriceSet', 'delete', [
'id' => $this->priceSetID,
- ));
+ ]);
$this->assertAPISuccess($delete);
parent::tearDown();
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$this->id = $createResult['id'];
$this->assertAPISuccess($createResult);
- $getParams = array(
+ $getParams = [
'name' => 'contribution_amount',
- );
+ ];
$getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
$this->assertEquals(1, $getResult['count']);
- $this->callAPISuccess('price_field', 'delete', array('id' => $createResult['id']));
+ $this->callAPISuccess('price_field', 'delete', ['id' => $createResult['id']]);
}
public function testDeletePriceField() {
- $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
+ $startCount = $this->callAPISuccess($this->_entity, 'getcount', []);
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $deleteParams = array('id' => $createResult['id']);
+ $deleteParams = ['id' => $createResult['id']];
$deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
$this->assertAPISuccess($deleteResult);
- $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
+ $endCount = $this->callAPISuccess($this->_entity, 'getcount', []);
$this->assertEquals($startCount, $endCount);
}
public function testGetFieldsPriceField() {
- $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
+ $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
$this->assertEquals(1, $result['values']['options_per_line']['type']);
}
*/
public function testUpdatePriceFieldLabel() {
$field = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $this->callAPISuccess('price_field_value', 'create', array(
+ $this->callAPISuccess('price_field_value', 'create', [
'price_field_id' => $field['id'],
'name' => 'rye grass',
'label' => 'juicy and healthy',
'amount' => 1,
'financial_type_id' => 1,
- ));
- $priceField = $this->callAPISuccess($this->_entity, 'create', array('id' => $field['id'], 'label' => 'Rose Variety'));
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', array('price_field_id' => $field['id']));
+ ]);
+ $priceField = $this->callAPISuccess($this->_entity, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']);
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]);
$this->assertEquals($priceField['values'][$priceField['id']]['label'], $priceFieldValue['values'][$priceFieldValue['id']]['label']);
- $this->callAPISuccess('price_field_value', 'delete', array('id' => $priceFieldValue['id']));
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $field['id']));
+ $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]);
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $field['id']]);
}
/**
* Confirm value label only updates if fiedl type is html.
*/
public function testUpdatePriceFieldLabelNotUpdateField() {
- $field = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array('html_type' => 'Radio')));
- $this->callAPISuccess('price_field_value', 'create', array(
+ $field = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, ['html_type' => 'Radio']));
+ $this->callAPISuccess('price_field_value', 'create', [
'price_field_id' => $field['id'],
'name' => 'rye grass',
'label' => 'juicy and healthy',
'amount' => 1,
'financial_type_id' => 1,
- ));
- $priceField = $this->callAPISuccess($this->_entity, 'create', array('id' => $field['id'], 'label' => 'Rose Variety'));
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', array('price_field_id' => $field['id']));
+ ]);
+ $priceField = $this->callAPISuccess($this->_entity, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']);
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]);
$this->assertEquals('juicy and healthy', $priceFieldValue['values'][$priceFieldValue['id']]['label']);
- $this->callAPISuccess('price_field_value', 'delete', array('id' => $priceFieldValue['id']));
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $field['id']));
+ $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]);
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $field['id']]);
}
}
public function setUp() {
parent::setUp();
// Put stuff here that should happen before all tests in this unit.
- $priceSetParams = array(
+ $priceSetParams = [
'name' => 'default_goat_priceset',
'title' => 'Goat accommodation',
'is_active' => 1,
'financial_type_id' => 1,
'is_quick_config' => 1,
'is_reserved' => 1,
- );
+ ];
$price_set = $this->callAPISuccess('price_set', 'create', $priceSetParams);
$this->priceSetID = $price_set['id'];
- $priceFieldParams = array(
+ $priceFieldParams = [
'price_set_id' => $this->priceSetID,
'name' => 'grassvariety',
'label' => 'Grass Variety',
'html_type' => 'Text',
'is_enter_qty' => 1,
'is_active' => 1,
- );
+ ];
$priceField = $this->callAPISuccess('price_field', 'create', $priceFieldParams);
$this->priceFieldID = $priceField['id'];
- $this->_params = array(
+ $this->_params = [
'price_field_id' => $this->priceFieldID,
'name' => 'rye grass',
'label' => 'juicy and healthy',
'amount' => 1,
'financial_type_id' => 1,
- );
+ ];
$membershipOrgId = $this->organizationCreate(NULL);
- $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId));
- $priceSetParams1 = array(
+ $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $membershipOrgId]);
+ $priceSetParams1 = [
'name' => 'priceset',
'title' => 'Priceset with Multiple Terms',
'is_active' => 1,
'financial_type_id' => 2,
'is_quick_config' => 1,
'is_reserved' => 1,
- );
+ ];
$price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetParams1);
$this->priceSetID1 = $price_set1['id'];
- $priceFieldParams1 = array(
+ $priceFieldParams1 = [
'price_set_id' => $this->priceSetID1,
'name' => 'memtype',
'label' => 'memtype',
'html_type' => 'Radio',
'is_enter_qty' => 1,
'is_active' => 1,
- );
+ ];
$priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldParams1);
$this->priceFieldID1 = $priceField1['id'];
}
* @throws \Exception
*/
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contact',
'civicrm_contribution',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
- $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
- $this->callAPISuccess('PriceField', 'delete', array(
+ $this->membershipTypeDelete(['id' => $this->_membershipTypeID]);
+ $this->callAPISuccess('PriceField', 'delete', [
'id' => $this->priceFieldID1,
- ));
- $this->callAPISuccess('PriceSet', 'delete', array(
+ ]);
+ $this->callAPISuccess('PriceSet', 'delete', [
'id' => $this->priceSetID1,
- ));
- $this->callAPISuccess('PriceField', 'delete', array(
+ ]);
+ $this->callAPISuccess('PriceField', 'delete', [
'id' => $this->priceFieldID,
- ));
- $delete = $this->callAPISuccess('PriceSet', 'delete', array(
+ ]);
+ $delete = $this->callAPISuccess('PriceSet', 'delete', [
'id' => $this->priceSetID,
- ));
+ ]);
$this->assertAPISuccess($delete);
}
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$this->id = $createResult['id'];
$this->assertAPISuccess($createResult);
- $getParams = array(
+ $getParams = [
'name' => 'contribution_amount',
- );
+ ];
$getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
$this->assertEquals(1, $getResult['count']);
- $this->callAPISuccess('price_field_value', 'delete', array('id' => $createResult['id']));
+ $this->callAPISuccess('price_field_value', 'delete', ['id' => $createResult['id']]);
}
public function testDeletePriceFieldValue() {
- $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
+ $startCount = $this->callAPISuccess($this->_entity, 'getcount', []);
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $deleteParams = array('id' => $createResult['id']);
+ $deleteParams = ['id' => $createResult['id']];
$deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
+ $endCount = $this->callAPISuccess($this->_entity, 'getcount', []);
$this->assertEquals($startCount, $endCount);
}
public function testGetFieldsPriceFieldValue() {
- $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
+ $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
$this->assertEquals(1, $result['values']['max_value']['type']);
}
public function testCreatePriceFieldValuewithMultipleTerms() {
- $params = array(
+ $params = [
'price_field_id' => $this->priceFieldID1,
'membership_type_id' => $this->_membershipTypeID,
'name' => 'memType1',
'membership_num_terms' => 2,
'is_active' => 1,
'financial_type_id' => 2,
- );
+ ];
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
$this->assertEquals(1, $result['count']);
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
}
public function testGetPriceFieldValuewithMultipleTerms() {
- $params1 = array(
+ $params1 = [
'price_field_id' => $this->priceFieldID1,
'membership_type_id' => $this->_membershipTypeID,
'name' => 'memType1',
'membership_num_terms' => 2,
'is_active' => 1,
'financial_type_id' => 2,
- );
- $params2 = array(
+ ];
+ $params2 = [
'price_field_id' => $this->priceFieldID1,
'membership_type_id' => $this->_membershipTypeID,
'name' => 'memType2',
'membership_num_terms' => 3,
'is_active' => 1,
'financial_type_id' => 2,
- );
+ ];
$result1 = $this->callAPISuccess($this->_entity, 'create', $params1);
$result2 = $this->callAPISuccess($this->_entity, 'create', $params2);
- $result = $this->callAPISuccess($this->_entity, 'get', array('price_field_id' => $this->priceFieldID1));
+ $result = $this->callAPISuccess($this->_entity, 'get', ['price_field_id' => $this->priceFieldID1]);
$this->assertEquals(2, $result['count']);
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $result1['id']));
- $this->callAPISuccess($this->_entity, 'delete', array('id' => $result2['id']));
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result1['id']]);
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result2['id']]);
}
public function testCreatePriceFieldValueWithDisabledFinancialType() {
- $financialTypeParams = array(
+ $financialTypeParams = [
'is_active' => 0,
'name' => 'Disabled Donations',
- );
+ ];
$financialType = $this->callAPISuccess('financial_type', 'create', $financialTypeParams);
- $params = array(
+ $params = [
'price_field_id' => $this->priceFieldID,
'name' => 'DonType1',
'label' => 'DonType1',
'amount' => 90,
'is_active' => 1,
'financial_type_id' => $financialType['id'],
- );
+ ];
$this->callAPIFailure($this->_entity, 'create', $params);
}
protected $_apiversion = 3;
protected $_params;
protected $id = 0;
- protected $contactIds = array();
+ protected $contactIds = [];
protected $_entity = 'price_set';
public $DBResetRequired = TRUE;
*/
public function setUp() {
parent::setUp();
- $this->_params = array(
+ $this->_params = [
'name' => 'default_goat_priceset',
'title' => 'Goat accessories',
'is_active' => 1,
'financial_type_id' => 1,
'is_quick_config' => 1,
'is_reserved' => 1,
- );
+ ];
}
/**
*/
public function testCreatePriceSetForEventAndContribution() {
// Create the price set
- $createParams = array(
+ $createParams = [
'name' => 'some_price_set',
'title' => 'Some Price Set',
'is_active' => 1,
'financial_type_id' => 1,
- 'extends' => array(1, 2),
- );
+ 'extends' => [1, 2],
+ ];
$createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
// Get priceset we just created.
- $result = $this->callAPISuccess($this->_entity, 'getSingle', array(
+ $result = $this->callAPISuccess($this->_entity, 'getSingle', [
'id' => $createResult['id'],
- ));
+ ]);
// Count the number of items in 'extends'.
$this->assertEquals(2, count($result['extends']));
/**
*/
public function testGetBasicPriceSet() {
- $getParams = array(
+ $getParams = [
'name' => 'default_contribution_amount',
- );
+ ];
$getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
$this->assertEquals(1, $getResult['count']);
}
public function testEventPriceSet() {
- $event = $this->callAPISuccess('event', 'create', array(
+ $event = $this->callAPISuccess('event', 'create', [
'title' => 'Event with Price Set',
'event_type_id' => 1,
'is_public' => 1,
'start_date' => 20151021,
'end_date' => 20151023,
'is_active' => 1,
- ));
- $createParams = array(
+ ]);
+ $createParams = [
'entity_table' => 'civicrm_event',
'entity_id' => $event['id'],
'name' => 'event price',
'title' => 'event price',
'extends' => 1,
- );
+ ];
$createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
- $result = $this->callAPISuccess($this->_entity, 'get', array(
+ $result = $this->callAPISuccess($this->_entity, 'get', [
'id' => $createResult['id'],
- ));
- $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity']);
+ ]);
+ $this->assertEquals(['civicrm_event' => [$event['id']]], $result['values'][$createResult['id']]['entity']);
}
public function testDeletePriceSet() {
- $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
+ $startCount = $this->callAPISuccess($this->_entity, 'getcount', []);
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $deleteParams = array('id' => $createResult['id']);
+ $deleteParams = ['id' => $createResult['id']];
$this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
+ $endCount = $this->callAPISuccess($this->_entity, 'getcount', []);
$this->assertEquals($startCount, $endCount);
}
public function testGetFieldsPriceSet() {
- $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
+ $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
$this->assertEquals(16, $result['values']['is_quick_config']['type']);
}
}
public static function tearDownAfterClass() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contact',
'civicrm_contribution',
- );
+ ];
$unitTest = new CiviUnitTestCase();
$unitTest->quickCleanup($tablesToTruncate);
}
public function setUp() {
parent::setUp();
$this->useTransaction();
- $this->_params = array(
+ $this->_params = [
'name' => 'my product',
- );
+ ];
}
public function testGetFields() {
- $fields = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
+ $fields = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
$this->assertArrayHasKey('period_type', $fields['values']);
}
public function testGetOptions() {
- $options = $this->callAPISuccess($this->_entity, 'getoptions', array('field' => 'period_type'));
+ $options = $this->callAPISuccess($this->_entity, 'getoptions', ['field' => 'period_type']);
$this->assertArrayHasKey('rolling', $options['values']);
}
public function setUp() {
parent::setUp();
$this->_cId_a = $this->individualCreate();
- $this->_cId_a_2 = $this->individualCreate(array(
+ $this->_cId_a_2 = $this->individualCreate([
'last_name' => 'c2',
'email' => 'c@w.com',
'contact_type' => 'Individual',
- ));
+ ]);
$this->_cId_b = $this->organizationCreate();
- $this->_cId_b2 = $this->organizationCreate(array('organization_name' => ' Org 2'));
+ $this->_cId_b2 = $this->organizationCreate(['organization_name' => ' Org 2']);
$this->entity = 'Relationship';
//Create a relationship type.
- $relTypeParams = array(
+ $relTypeParams = [
'name_a_b' => 'Relation 1 for delete',
'name_b_a' => 'Relation 2 for delete',
'description' => 'Testing relationship type',
'contact_type_b' => 'Organization',
'is_reserved' => 1,
'is_active' => 1,
- );
+ ];
$this->_relTypeID = $this->relationshipTypeCreate($relTypeParams);
- $this->_params = array(
+ $this->_params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
- );
+ ];
}
$this->contactDelete($this->_cId_a_2);
$this->contactDelete($this->_cId_b);
$this->contactDelete($this->_cId_b2);
- $this->quickCleanup(array('civicrm_relationship'), TRUE);
+ $this->quickCleanup(['civicrm_relationship'], TRUE);
$this->relationshipTypeDelete($this->_relTypeID);
parent::tearDown();
}
*/
public function testRelationshipCreateEmpty($version) {
$this->_apiversion = $version;
- $this->callAPIFailure('relationship', 'create', array());
+ $this->callAPIFailure('relationship', 'create', []);
}
/**
* Test Current Employer is correctly set.
*/
public function testCurrentEmployerRelationship() {
- $employerRelationshipID = $this->callAPISuccessGetValue('RelationshipType', array(
+ $employerRelationshipID = $this->callAPISuccessGetValue('RelationshipType', [
'return' => "id",
'name_b_a' => "Employer Of",
- ));
- $employerRelationship = $this->callAPISuccess('Relationship', 'create', array(
+ ]);
+ $employerRelationship = $this->callAPISuccess('Relationship', 'create', [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $employerRelationshipID,
- ));
- $params = array($this->_cId_a => $this->_cId_b);
+ ]);
+ $params = [$this->_cId_a => $this->_cId_b];
CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($params);
//Check if current employer is correctly set.
- $employer = $this->callAPISuccessGetValue('Contact', array(
+ $employer = $this->callAPISuccessGetValue('Contact', [
'return' => "current_employer",
'id' => $this->_cId_a,
- ));
- $organisation = $this->callAPISuccessGetValue('Contact', array(
+ ]);
+ $organisation = $this->callAPISuccessGetValue('Contact', [
'return' => "sort_name",
'id' => $this->_cId_b,
- ));
+ ]);
$this->assertEquals($employer, $organisation);
//Update relationship type
- $update = $this->callAPISuccess('Relationship', 'create', array(
+ $update = $this->callAPISuccess('Relationship', 'create', [
'id' => $employerRelationship['id'],
'relationship_type_id' => $this->_relTypeID,
- ));
- $employeeContact = $this->callAPISuccessGetSingle('Contact', array(
- 'return' => array("current_employer"),
+ ]);
+ $employeeContact = $this->callAPISuccessGetSingle('Contact', [
+ 'return' => ["current_employer"],
'id' => $this->_cId_a,
- ));
+ ]);
//current employer should be removed.
$this->assertEmpty($employeeContact['current_employer']);
}
*/
public function testRelationshipCreateWithoutRequired($version) {
$this->_apiversion = $version;
- $params = array(
- 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'),
- 'end_date' => array('d' => '10', 'M' => '1', 'Y' => '2009'),
+ $params = [
+ 'start_date' => ['d' => '10', 'M' => '1', 'Y' => '2008'],
+ 'end_date' => ['d' => '10', 'M' => '1', 'Y' => '2009'],
'is_active' => 1,
- );
+ ];
$this->callAPIFailure('relationship', 'create', $params);
}
public function testRelationshipCreateWithIncorrectData($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => 'Breaking Relationship',
- );
+ ];
$this->callAPIFailure('relationship', 'create', $params);
//contact id is not an integer
- $params = array(
+ $params = [
'contact_id_a' => 'invalid',
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
- 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'),
+ 'start_date' => ['d' => '10', 'M' => '1', 'Y' => '2008'],
'is_active' => 1,
- );
+ ];
$this->callAPIFailure('relationship', 'create', $params);
// Contact id does not exist.
//invalid date
$params['contact_id_a'] = $this->_cId_a;
- $params['start_date'] = array('d' => '1', 'M' => '1');
+ $params['start_date'] = ['d' => '1', 'M' => '1'];
$this->callAPIFailure('relationship', 'create', $params);
}
public function testRelationshipCreateInvalidRelationship($version) {
$this->_apiversion = $version;
// Both have the contact type Individual.
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_a,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2008-01-10',
'is_active' => 1,
- );
+ ];
$this->callAPIFailure('relationship', 'create', $params);
// both the contact of type Organization
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_b,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2008-01-10',
'is_active' => 1,
- );
+ ];
$this->callAPIFailure('relationship', 'create', $params);
}
*/
public function testRelationshipCreateAlreadyExists($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2008-12-20',
'end_date' => NULL,
'is_active' => 1,
- );
+ ];
$relationship = $this->callAPISuccess('relationship', 'create', $params);
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
- );
+ ];
$this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship');
$params['id'] = $relationship['id'];
*/
public function testRelationshipCreateUpdateAlreadyExists($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'end_date' => NULL,
'is_active' => 1,
- );
+ ];
$relationship = $this->callAPISuccess('relationship', 'create', $params);
- $params = array(
+ $params = [
'id' => $relationship['id'],
'is_active' => 0,
'debug' => 1,
- );
+ ];
$this->callAPISuccess('relationship', 'create', $params);
$this->callAPISuccess('relationship', 'get', $params);
$params['id'] = $relationship['id'];
*/
public function testRelationshipCreateUpdateDoesNotMangle($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'is_active' => 1,
'is_permission_a_b' => 1,
'description' => 'my desc',
- );
+ ];
$relationship = $this->callAPISuccess('relationship', 'create', $params);
- $updateParams = array(
+ $updateParams = [
'id' => $relationship['id'],
'relationship_type_id' => $this->_relTypeID,
- );
+ ];
$this->callAPISuccess('relationship', 'create', $updateParams);
//make sure the orig params didn't get changed
*/
public function testRelationshipCreate($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'end_date' => '2010-12-30',
'is_active' => 1,
'note' => 'note',
- );
+ ];
$result = $this->callAPIAndDocument('relationship', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($result['id']);
- $relationParams = array(
+ $relationParams = [
'id' => $result['id'],
- );
+ ];
// assertDBState compares expected values in $result to actual values in the DB
$this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
- $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
+ $result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]);
$values = $result['values'][$result['id']];
foreach ($params as $key => $value) {
if ($key == 'note') {
$this->_apiversion = $version;
$result = $this->callAPISuccess('relationship', 'create', $this->_params);
$relID = $result['id'];
- $result = $this->callAPISuccess('relationship', 'create', array('id' => $relID, 'description' => 'blah'));
+ $result = $this->callAPISuccess('relationship', 'create', ['id' => $relID, 'description' => 'blah']);
$this->assertEquals($relID, $result['id']);
$this->assertEquals('blah', $result['values'][$result['id']]['description']);
- $result = $this->callAPISuccess('relationship', 'create', array('id' => $relID, 'is_permission_b_a' => 1));
+ $result = $this->callAPISuccess('relationship', 'create', ['id' => $relID, 'is_permission_b_a' => 1]);
$this->assertEquals(1, $result['values'][$result['id']]['is_permission_b_a']);
- $result = $this->callAPISuccess('relationship', 'create', array('id' => $result['id'], 'is_active' => 0));
- $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
+ $result = $this->callAPISuccess('relationship', 'create', ['id' => $result['id'], 'is_active' => 0]);
+ $result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]);
$this->assertEquals(0, $result['values'][$result['id']]['is_active']);
$this->assertEquals('blah', $result['values'][$result['id']]['description']);
$this->assertEquals(1, $result['values'][$result['id']]['is_permission_b_a']);
*/
public function testRelationshipCreateEmptyEndDate($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'end_date' => '',
'is_active' => 1,
'note' => 'note',
- );
+ ];
$result = $this->callAPISuccess('relationship', 'create', $params);
$this->assertNotNull($result['id']);
- $relationParams = array(
+ $relationParams = [
'id' => $result['id'],
- );
+ ];
// assertDBState compares expected values in $result to actual values in the DB
$this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
- $result = $this->callAPISuccess('relationship', 'get', array('id' => $result['id']));
+ $result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]);
$values = $result['values'][$result['id']];
foreach ($params as $key => $value) {
if ($key == 'note') {
$this->assertDBState('CRM_Contact_DAO_Relationship', $result['id'], $relationParams);
//Test Edit of custom field from the form.
- $getParams = array('id' => $result['id']);
- $updateParams = array_merge($getParams, array(
+ $getParams = ['id' => $result['id']];
+ $updateParams = array_merge($getParams, [
$this->getCustomFieldName('text') => 'Edited Text Value',
'relationship_type_id' => $this->_relTypeID . '_b_a',
'related_contact_id' => $this->_cId_a,
- ));
+ ]);
$reln = new CRM_Contact_Form_Relationship();
$reln->_action = CRM_Core_Action::UPDATE;
$reln->_relationshipId = $result['id'];
$result = $this->callAPISuccess($this->entity, 'create', $params);
$this->assertEquals($result['id'], $result['values'][$result['id']]['id']);
- $getParams = array('id' => $result['id']);
+ $getParams = ['id' => $result['id']];
$check = $this->callAPIAndDocument($this->entity, 'get', $getParams, __FUNCTION__, __FILE__);
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
*/
public function testRelationshipDeleteWithoutRequired($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'start_date' => '2008-12-20',
'end_date' => '2009-12-20',
'is_active' => 1,
- );
+ ];
$this->callAPIFailure('relationship', 'delete', $params);
}
* Check with incorrect required fields.
*/
public function testRelationshipDeleteWithIncorrectData() {
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => 'Breaking Relationship',
- );
+ ];
$this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id');
*/
public function testRelationshipDelete($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
- );
+ ];
$result = $this->callAPISuccess('relationship', 'create', $params);
- $params = array('id' => $result['id']);
+ $params = ['id' => $result['id']];
$this->callAPIAndDocument('relationship', 'delete', $params, __FUNCTION__, __FILE__);
$this->relationshipTypeDelete($this->_relTypeID);
}
*/
public function testRelationshipUpdateEmpty($version) {
$this->_apiversion = $version;
- $this->callAPIFailure('relationship', 'create', array(),
+ $this->callAPIFailure('relationship', 'create', [],
'contact_id_a, contact_id_b, relationship_type_id');
}
*/
public function testRelationshipCreateDuplicate($version) {
$this->_apiversion = $version;
- $relParams = array(
+ $relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '20081214',
'end_date' => '20091214',
'is_active' => 1,
- );
+ ];
$result = $this->callAPISuccess('relationship', 'create', $relParams);
$this->assertNotNull($result['id']);
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '20081214',
'end_date' => '20091214',
'is_active' => 0,
- );
+ ];
$this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship');
- $this->callAPISuccess('relationship', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('relationship', 'delete', ['id' => $result['id']]);
$this->relationshipTypeDelete($this->_relTypeID);
}
public function testRelationshipCreateDuplicateWithCustomFields() {
$this->createCustomGroupWithFieldsOfAllTypes();
- $custom_params_1 = array(
+ $custom_params_1 = [
$this->getCustomFieldName('text') => 'Hello! this is custom data for relationship',
$this->getCustomFieldName('select_string') => 'Y',
$this->getCustomFieldName('select_date') => '2009-07-11 00:00:00',
$this->getCustomFieldName('link') => 'http://example.com',
- );
+ ];
- $custom_params_2 = array(
+ $custom_params_2 = [
$this->getCustomFieldName('text') => 'Hello! this is other custom data',
$this->getCustomFieldName('select_string') => 'Y',
$this->getCustomFieldName('select_date') => '2009-07-11 00:00:00',
$this->getCustomFieldName('link') => 'http://example.org',
- );
+ ];
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
- );
+ ];
$params_1 = array_merge($params, $custom_params_1);
$params_2 = array_merge($params, $custom_params_2);
public function testRelationshipCreateDuplicateWithCustomFields2() {
$this->createCustomGroupWithFieldsOfAllTypes();
- $custom_params_2 = array(
+ $custom_params_2 = [
$this->getCustomFieldName('text') => 'Hello! this is other custom data',
$this->getCustomFieldName('select_string') => 'Y',
$this->getCustomFieldName('select_date') => '2009-07-11 00:00:00',
$this->getCustomFieldName('link') => 'http://example.org',
- );
+ ];
$params_1 = [
'contact_id_a' => $this->_cId_a,
$this->getCustomFieldName('link') => 'http://example.org',
];
- $params_2 = array(
+ $params_2 = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
- );
+ ];
$params_1 = array_merge($params_2, $custom_params_1);
* Check with valid params array.
*/
public function testRelationshipsGet() {
- $relParams = array(
+ $relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2011-01-01',
'end_date' => '2013-01-01',
'is_active' => 1,
- );
+ ];
$this->callAPISuccess('relationship', 'create', $relParams);
//get relationship
- $params = array(
+ $params = [
'contact_id' => $this->_cId_b,
- );
+ ];
$result = $this->callAPISuccess('relationship', 'get', $params);
$this->assertEquals($result['count'], 1);
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_a,
- );
+ ];
$result = $this->callAPISuccess('relationship', 'get', $params);
$this->assertEquals($result['count'], 1);
// contact_id_a is wrong so should be no matches
- $params = array(
+ $params = [
'contact_id_a' => $this->_cId_b,
- );
+ ];
$result = $this->callAPISuccess('relationship', 'get', $params);
$this->assertEquals($result['count'], 0);
}
$id = $createResult['id'];
// Try to retrieve it using chaining.
- $params = array(
+ $params = [
'relationship_type_id' => $this->_relTypeID,
'id' => $id,
- 'api.Contact.get' => array(
+ 'api.Contact.get' => [
'id' => '$value.contact_id_b',
- ),
- );
+ ],
+ ];
$result = $this->callAPISuccess('relationship', 'get', $params);
$this->callAPISuccess('relationship', 'create', $this->_params);
// Try to retrieve it using chaining.
- $params = array(
+ $params = [
'id' => $this->_cId_a,
- 'api.Relationship.get' => array(
+ 'api.Relationship.get' => [
'relationship_type_id' => $this->_relTypeID,
'contact_id_a' => '$value.id',
- 'api.Contact.get' => array(
+ 'api.Contact.get' => [
'id' => '$value.contact_id_b',
- ),
- ),
- );
+ ],
+ ],
+ ];
$result = $this->callAPISuccess('contact', 'get', $params);
$this->assertEquals(1, $result['count']);
*/
public function testRelationshipsGetGeneric($version) {
$this->_apiversion = $version;
- $relParams = array(
+ $relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2011-01-01',
'end_date' => '2013-01-01',
'is_active' => 1,
- );
+ ];
$this->callAPISuccess('relationship', 'create', $relParams);
//get relationship
- $params = array(
+ $params = [
'contact_id_b' => $this->_cId_b,
- );
+ ];
$this->callAPISuccess('relationship', 'get', $params);
}
*/
public function testGetIsCurrent($version) {
$this->_apiversion = $version;
- $rel2Params = array(
+ $rel2Params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b2,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2008-12-20',
'is_active' => 0,
- );
+ ];
$rel0 = $this->callAPISuccess('relationship', 'create', $rel2Params);
$rel1 = $this->callAPISuccess('relationship', 'create', $this->_params);
*/
public function testGetTypeOperators($version) {
$this->_apiversion = $version;
- $relTypeParams = array(
+ $relTypeParams = [
'name_a_b' => 'Relation 3 for delete',
'name_b_a' => 'Relation 6 for delete',
'description' => 'Testing relationship type 2',
'contact_type_b' => 'Organization',
'is_reserved' => 1,
'is_active' => 1,
- );
+ ];
$relationType2 = $this->relationshipTypeCreate($relTypeParams);
- $relTypeParams = array(
+ $relTypeParams = [
'name_a_b' => 'Relation 8 for delete',
'name_b_a' => 'Relation 9 for delete',
'description' => 'Testing relationship type 7',
'contact_type_b' => 'Organization',
'is_reserved' => 1,
'is_active' => 1,
- );
+ ];
$relationType3 = $this->relationshipTypeCreate($relTypeParams);
- $relTypeParams = array(
+ $relTypeParams = [
'name_a_b' => 'Relation 6 for delete',
'name_b_a' => 'Relation 88for delete',
'description' => 'Testing relationship type 00',
'contact_type_b' => 'Organization',
'is_reserved' => 1,
'is_active' => 1,
- );
+ ];
$relationType4 = $this->relationshipTypeCreate($relTypeParams);
$rel1 = $this->callAPISuccess('relationship', 'create', $this->_params);
$rel2 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params,
- array('relationship_type_id' => $relationType2)));
+ ['relationship_type_id' => $relationType2]));
$rel3 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params,
- array('relationship_type_id' => $relationType3)));
+ ['relationship_type_id' => $relationType3]));
$rel4 = $this->callAPISuccess('relationship', 'create', array_merge($this->_params,
- array('relationship_type_id' => $relationType4)));
+ ['relationship_type_id' => $relationType4]));
- $getParams = array(
- 'relationship_type_id' => array('IN' => array($relationType2, $relationType3)),
- );
+ $getParams = [
+ 'relationship_type_id' => ['IN' => [$relationType2, $relationType3]],
+ ];
$description = "Demonstrates use of IN filter.";
$subfile = 'INRelationshipType';
$result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($result['count'], 2);
- $this->AssertEquals(array($rel2['id'], $rel3['id']), array_keys($result['values']));
+ $this->AssertEquals([$rel2['id'], $rel3['id']], array_keys($result['values']));
$description = "Demonstrates use of NOT IN filter.";
$subfile = 'NotInRelationshipType';
- $getParams = array(
- 'relationship_type_id' => array('NOT IN' => array($relationType2, $relationType3)),
- );
+ $getParams = [
+ 'relationship_type_id' => ['NOT IN' => [$relationType2, $relationType3]],
+ ];
$result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($result['count'], 2);
- $this->AssertEquals(array($rel1['id'], $rel4['id']), array_keys($result['values']));
+ $this->AssertEquals([$rel1['id'], $rel4['id']], array_keys($result['values']));
$description = "Demonstrates use of BETWEEN filter.";
$subfile = 'BetweenRelationshipType';
- $getParams = array(
- 'relationship_type_id' => array('BETWEEN' => array($relationType2, $relationType4)),
- );
+ $getParams = [
+ 'relationship_type_id' => ['BETWEEN' => [$relationType2, $relationType4]],
+ ];
$result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($result['count'], 3);
- $this->AssertEquals(array($rel2['id'], $rel3['id'], $rel4['id']), array_keys($result['values']));
+ $this->AssertEquals([$rel2['id'], $rel3['id'], $rel4['id']], array_keys($result['values']));
$description = "Demonstrates use of Not BETWEEN filter.";
$subfile = 'NotBetweenRelationshipType';
- $getParams = array(
- 'relationship_type_id' => array('NOT BETWEEN' => array($relationType2, $relationType4)),
- );
+ $getParams = [
+ 'relationship_type_id' => ['NOT BETWEEN' => [$relationType2, $relationType4]],
+ ];
$result = $this->callAPIAndDocument('relationship', 'get', $getParams, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals($result['count'], 1);
- $this->AssertEquals(array($rel1['id']), array_keys($result['values']));
+ $this->AssertEquals([$rel1['id']], array_keys($result['values']));
foreach ([$relationType2, $relationType3, $relationType4] as $id) {
$this->callAPISuccess('RelationshipType', 'delete', ['id' => $id]);
* Check with invalid relationshipType Id.
*/
public function testRelationshipTypeAddInvalidId() {
- $relTypeParams = array(
+ $relTypeParams = [
'id' => 'invalid',
'name_a_b' => 'Relation 1 for delete',
'name_b_a' => 'Relation 2 for delete',
'contact_type_a' => 'Individual',
'contact_type_b' => 'Organization',
- );
+ ];
$this->callAPIFailure('relationship_type', 'create', $relTypeParams,
'id is not a valid integer');
}
* Check with valid data with contact_b.
*/
public function testGetRelationshipWithContactB() {
- $relParams = array(
+ $relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2011-01-01',
'end_date' => '2013-01-01',
'is_active' => 1,
- );
+ ];
$relationship = $this->callAPISuccess('relationship', 'create', $relParams);
- $contacts = array(
+ $contacts = [
'contact_id' => $this->_cId_a,
- );
+ ];
$result = $this->callAPISuccess('relationship', 'get', $contacts);
$this->assertGreaterThan(0, $result['count']);
- $params = array(
+ $params = [
'id' => $relationship['id'],
- );
+ ];
$this->callAPISuccess('relationship', 'delete', $params);
$this->relationshipTypeDelete($this->_relTypeID);
}
* Check with valid data with relationshipTypes.
*/
public function testGetRelationshipWithRelTypes() {
- $relParams = array(
+ $relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
'relationship_type_id' => $this->_relTypeID,
'start_date' => '2011-01-01',
'end_date' => '2013-01-01',
'is_active' => 1,
- );
+ ];
$relationship = $this->callAPISuccess('relationship', 'create', $relParams);
- $contact_a = array(
+ $contact_a = [
'contact_id' => $this->_cId_a,
- );
+ ];
$this->callAPISuccess('relationship', 'get', $contact_a);
- $params = array(
+ $params = [
'id' => $relationship['id'],
- );
+ ];
$this->callAPISuccess('relationship', 'delete', $params);
$this->relationshipTypeDelete($this->_relTypeID);
}
*/
public function testGetRelationshipByTypeReciprocal() {
$created = $this->callAPISuccess($this->entity, 'create', $this->_params);
- $result = $this->callAPISuccess($this->entity, 'get', array(
+ $result = $this->callAPISuccess($this->entity, 'get', [
'contact_id' => $this->_cId_a,
'relationship_type_id' => $this->_relTypeID,
- ));
+ ]);
$this->assertEquals(1, $result['count']);
- $result = $this->callAPISuccess($this->entity, 'get', array(
+ $result = $this->callAPISuccess($this->entity, 'get', [
'contact_id' => $this->_cId_a,
'relationship_type_id' => $this->_relTypeID + 1,
- ));
+ ]);
$this->assertEquals(0, $result['count']);
- $this->callAPISuccess($this->entity, 'delete', array('id' => $created['id']));
+ $this->callAPISuccess($this->entity, 'delete', ['id' => $created['id']]);
}
/**
*/
public function testGetRelationshipByTypeDAO($version) {
$this->_apiversion = $version;
- $this->_ids['relationship'] = $this->callAPISuccess($this->entity, 'create', array('format.only_id' => TRUE) +
+ $this->_ids['relationship'] = $this->callAPISuccess($this->entity, 'create', ['format.only_id' => TRUE] +
$this->_params);
- $this->callAPISuccess($this->entity, 'getcount', array(
+ $this->callAPISuccess($this->entity, 'getcount', [
'contact_id_a' => $this->_cId_a,
- ), 1);
- $result = $this->callAPISuccess($this->entity, 'get', array(
+ ], 1);
+ $result = $this->callAPISuccess($this->entity, 'get', [
'contact_id_a' => $this->_cId_a,
'relationship_type_id' => $this->_relTypeID,
- ));
+ ]);
$this->assertEquals(1, $result['count']);
- $result = $this->callAPISuccess($this->entity, 'get', array(
+ $result = $this->callAPISuccess($this->entity, 'get', [
'contact_id_a' => $this->_cId_a,
'relationship_type_id' => $this->_relTypeID + 1,
- ));
+ ]);
$this->assertEquals(0, $result['count']);
}
// Relationship 2.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType2,
'contact_id_b' => $this->_cId_b2,
- ))
+ ])
);
// Relationship 3.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType3,
'contact_id_b' => $org3,
- ))
+ ])
);
- $result = $this->callAPISuccess($this->entity, 'get', array(
+ $result = $this->callAPISuccess($this->entity, 'get', [
'contact_id_a' => $this->_cId_a,
- 'relationship_type_id' => array('IN' => array($this->_relTypeID, $relType3)),
- ));
+ 'relationship_type_id' => ['IN' => [$this->_relTypeID, $relType3]],
+ ]);
$this->assertEquals(2, $result['count']);
foreach ($result['values'] as $key => $value) {
- $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID, $relType3)));
+ $this->assertTrue(in_array($value['relationship_type_id'], [$this->_relTypeID, $relType3]));
}
}
// Relationship 2.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType2,
'contact_id_b' => $this->_cId_b2,
- ))
+ ])
);
// Relationship 3.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType3,
'contact_id_b' => $org3,
- ))
+ ])
);
- $result = $this->callAPISuccess($this->entity, 'get', array(
+ $result = $this->callAPISuccess($this->entity, 'get', [
'contact_id' => $this->_cId_a,
- 'relationship_type_id' => array('IN' => array($this->_relTypeID, $relType3)),
- ));
+ 'relationship_type_id' => ['IN' => [$this->_relTypeID, $relType3]],
+ ]);
$this->assertEquals(2, $result['count']);
foreach ($result['values'] as $key => $value) {
- $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID, $relType3)));
+ $this->assertTrue(in_array($value['relationship_type_id'], [$this->_relTypeID, $relType3]));
}
}
// lets just assume built in ones aren't being messed with!
$relType3 = 6;
$relType1 = 1;
- $memberType = $this->membershipTypeCreate(array(
+ $memberType = $this->membershipTypeCreate([
'relationship_type_id' => CRM_Core_DAO::VALUE_SEPARATOR . $relType1 . CRM_Core_DAO::VALUE_SEPARATOR . $relType3 . CRM_Core_DAO::VALUE_SEPARATOR,
'relationship_direction' => CRM_Core_DAO::VALUE_SEPARATOR . 'a_b' . CRM_Core_DAO::VALUE_SEPARATOR . 'b_a' . CRM_Core_DAO::VALUE_SEPARATOR,
- ));
+ ]);
// Relationship 2.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType2,
'contact_id_b' => $this->_cId_b2,
- ))
+ ])
);
// Relationship 3.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType3,
'contact_id_b' => $org3,
- ))
+ ])
);
// Relationship 4 with reversal.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType1,
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_a_2,
- ))
+ ])
);
- $result = $this->callAPISuccess($this->entity, 'get', array(
+ $result = $this->callAPISuccess($this->entity, 'get', [
'contact_id_a' => $this->_cId_a,
'membership_type_id' => $memberType,
- ));
+ ]);
// although our contact has more than one relationship we have passed them in as contact_id_a & can't get reciprocal
$this->assertEquals(1, $result['count']);
foreach ($result['values'] as $key => $value) {
- $this->assertTrue(in_array($value['relationship_type_id'], array($relType1)));
+ $this->assertTrue(in_array($value['relationship_type_id'], [$relType1]));
}
}
$relType2 = 5;
$relType3 = 6;
$relType1 = 1;
- $memberType = $this->membershipTypeCreate(array(
+ $memberType = $this->membershipTypeCreate([
'relationship_type_id' => CRM_Core_DAO::VALUE_SEPARATOR . $relType1 . CRM_Core_DAO::VALUE_SEPARATOR . $relType3 . CRM_Core_DAO::VALUE_SEPARATOR,
'relationship_direction' => CRM_Core_DAO::VALUE_SEPARATOR . 'a_b' . CRM_Core_DAO::VALUE_SEPARATOR . 'b_a' . CRM_Core_DAO::VALUE_SEPARATOR,
- ));
+ ]);
// Relationship 2.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType2,
'contact_id_b' => $this->_cId_b2,
- ))
+ ])
);
// Relationship 4.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType3,
'contact_id_b' => $org3,
- ))
+ ])
);
// Relationship 4 with reversal.
$this->callAPISuccess($this->entity, 'create',
- array_merge($this->_params, array(
+ array_merge($this->_params, [
'relationship_type_id' => $relType1,
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_a_2,
- ))
+ ])
);
- $result = $this->callAPISuccess($this->entity, 'get', array(
+ $result = $this->callAPISuccess($this->entity, 'get', [
'contact_id' => $this->_cId_a,
'membership_type_id' => $memberType,
- ));
+ ]);
// Although our contact has more than one relationship we have passed them in as contact_id_a & can't get reciprocal
$this->assertEquals(2, $result['count']);
foreach ($result['values'] as $key => $value) {
- $this->assertTrue(in_array($value['relationship_type_id'], array($relType1, $relType3)));
+ $this->assertTrue(in_array($value['relationship_type_id'], [$relType1, $relType3]));
}
}
public function testSetActive($version) {
$this->_apiversion = $version;
$relationship = $this->callAPISuccess($this->entity, 'create', $this->_params);
- $this->callAPISuccess($this->entity, 'create', array('id' => $relationship['id'], 'is_active' => 0));
- $this->callAPISuccess($this->entity, 'create', array('id' => $relationship['id'], 'is_active' => 1));
+ $this->callAPISuccess($this->entity, 'create', ['id' => $relationship['id'], 'is_active' => 0]);
+ $this->callAPISuccess($this->entity, 'create', ['id' => $relationship['id'], 'is_active' => 1]);
}
/**
*/
public function testCreateRelatedMembership($version) {
$this->_apiversion = $version;
- $relatedMembershipType = $this->callAPISuccess('MembershipType', 'create', array(
+ $relatedMembershipType = $this->callAPISuccess('MembershipType', 'create', [
'name' => 'Membership with Related',
'member_of_contact_id' => 1,
'financial_type_id' => 1,
'auto_renew' => 0,
'is_active' => 1,
'domain_id' => CRM_Core_Config::domainID(),
- ));
- $originalMembership = $this->callAPISuccess('Membership', 'create', array(
+ ]);
+ $originalMembership = $this->callAPISuccess('Membership', 'create', [
'membership_type_id' => $relatedMembershipType['id'],
'contact_id' => $this->_cId_b,
- ));
- $this->callAPISuccess('Relationship', 'create', array(
+ ]);
+ $this->callAPISuccess('Relationship', 'create', [
'relationship_type_id' => $this->_relTypeID,
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- ));
- $contactAMembership = $this->callAPISuccessGetSingle('membership', array('contact_id' => $this->_cId_a));
+ ]);
+ $contactAMembership = $this->callAPISuccessGetSingle('membership', ['contact_id' => $this->_cId_a]);
$this->assertEquals($originalMembership['id'], $contactAMembership['owner_membership_id']);
// Adding a relationship with a future start date should NOT create a membership
- $this->callAPISuccess('Relationship', 'create', array(
+ $this->callAPISuccess('Relationship', 'create', [
'relationship_type_id' => $this->_relTypeID,
'contact_id_a' => $this->_cId_a_2,
'contact_id_b' => $this->_cId_b,
'start_date' => 'now + 1 week',
- ));
- $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_cId_a_2), 0);
+ ]);
+ $this->callAPISuccessGetCount('membership', ['contact_id' => $this->_cId_a_2], 0);
// Deleting the organization should cause the related membership to be deleted.
- $this->callAPISuccess('contact', 'delete', array('id' => $this->_cId_b));
- $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_cId_a), 0);
+ $this->callAPISuccess('contact', 'delete', ['id' => $this->_cId_b]);
+ $this->callAPISuccessGetCount('membership', ['contact_id' => $this->_cId_a], 0);
}
}
public function tearDown() {
- $tablesToTruncate = array(
+ $tablesToTruncate = [
'civicrm_contact',
'civicrm_relationship_type',
- );
+ ];
$this->quickCleanup($tablesToTruncate);
}
*/
public function testRelationshipTypeCreateWithoutName($version) {
$this->_apiversion = $version;
- $relTypeParams = array(
+ $relTypeParams = [
'contact_type_a' => 'Individual',
'contact_type_b' => 'Organization',
- );
+ ];
$result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams);
}
*/
public function testRelationshipTypeCreate($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'name_a_b' => 'Relation 1 for relationship type create',
'name_b_a' => 'Relation 2 for relationship type create',
'contact_type_a' => 'Individual',
'is_reserved' => 1,
'is_active' => 1,
'sequential' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('relationship_type', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($result['values'][0]['id']);
unset($params['sequential']);
*/
public function testRelationshipTypeDeleteWithoutRequired($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'name_b_a' => 'Relation 2 delete without required',
'contact_type_b' => 'Individual',
'is_reserved' => 0,
'is_active' => 0,
- );
+ ];
$result = $this->callAPIFailure('relationship_type', 'delete', $params);
if ($version == 3) {
* Check with incorrect required fields.
*/
public function testRelationshipTypeDeleteWithIncorrectData() {
- $params = array(
+ $params = [
'id' => 'abcd',
'name_b_a' => 'Relation 2 delete with incorrect',
'description' => 'Testing relationship type',
'contact_type_b' => 'Individual',
'is_reserved' => 0,
'is_active' => 0,
- );
+ ];
$result = $this->callAPIFailure('relationship_type', 'delete', $params,
'id is not a valid integer'
);
$this->_apiversion = $version;
$id = $this->_relationshipTypeCreate();
// create sample relationship type.
- $params = array(
+ $params = [
'id' => $id,
- );
+ ];
$result = $this->callAPIAndDocument('relationship_type', 'delete', $params, __FUNCTION__, __FILE__);
$this->assertAPIDeleted('relationship_type', $id);
}
*/
public function testRelationshipTypeUpdateEmpty($version) {
$this->_apiversion = $version;
- $params = array();
+ $params = [];
$result = $this->callAPIFailure('relationship_type', 'create', $params);
$this->assertContains('name_a_b', $result['error_message']);
$this->assertContains('name_b_a', $result['error_message']);
// create sample relationship type.
$this->_relTypeID = $this->_relationshipTypeCreate();
- $relTypeParams = array(
+ $relTypeParams = [
'id' => $this->_relTypeID,
'name_a_b' => 'Test 1',
'name_b_a' => 'Test 2',
'description' => 'Testing relationship type',
'is_reserved' => 1,
'is_active' => 0,
- );
+ ];
$result = $this->callAPISuccess('relationship_type', 'create', $relTypeParams);
$this->assertNotNull($result['id']);
// create sample relationship type.
$this->_relTypeID = $this->_relationshipTypeCreate();
- $params = array(
+ $params = [
'id' => $this->_relTypeID,
'name_a_b' => 'Test 1 for update',
'name_b_a' => 'Test 2 for update',
'contact_type_b' => 'Individual',
'is_reserved' => 0,
'is_active' => 0,
- );
+ ];
$result = $this->callAPISuccess('relationship_type', 'create', $params);
$this->assertNotNull($result['id']);
*/
public function testRelationshipTypesGetEmptyParams($version) {
$this->_apiversion = $version;
- $firstRelTypeParams = array(
+ $firstRelTypeParams = [
'name_a_b' => 'Relation 27 for create',
'name_b_a' => 'Relation 28 for create',
'description' => 'Testing relationship type',
'contact_type_b' => 'Organization',
'is_reserved' => 1,
'is_active' => 1,
- );
+ ];
$first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
- $secondRelTypeParams = array(
+ $secondRelTypeParams = [
'name_a_b' => 'Relation 25 for create',
'name_b_a' => 'Relation 26 for create',
'description' => 'Testing relationship type second',
'contact_type_b' => 'Organization',
'is_reserved' => 0,
'is_active' => 1,
- );
+ ];
$second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
- $results = $this->callAPISuccess('relationship_type', 'get', array());
+ $results = $this->callAPISuccess('relationship_type', 'get', []);
$this->assertEquals(2, $results['count']);
}
*/
public function testRelationshipTypesGet($version) {
$this->_apiversion = $version;
- $firstRelTypeParams = array(
+ $firstRelTypeParams = [
'name_a_b' => 'Relation 30 for create',
'name_b_a' => 'Relation 31 for create',
'description' => 'Testing relationship type',
'contact_type_b' => 'Organization',
'is_reserved' => 1,
'is_active' => 1,
- );
+ ];
$first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams);
- $secondRelTypeParams = array(
+ $secondRelTypeParams = [
'name_a_b' => 'Relation 32 for create',
'name_b_a' => 'Relation 33 for create',
'description' => 'Testing relationship type second',
'contact_type_b' => 'Organization',
'is_reserved' => 0,
'is_active' => 1,
- );
+ ];
$second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams);
- $params = array(
+ $params = [
'name_a_b' => 'Relation 32 for create',
'name_b_a' => 'Relation 33 for create',
'description' => 'Testing relationship type second',
- );
+ ];
$results = $this->callAPISuccess('relationship_type', 'get', $params);
$this->assertEquals(1, $results['count'], ' in line ' . __LINE__);
*/
public function _relationshipTypeCreate($params = NULL) {
if (!is_array($params) || empty($params)) {
- $params = array(
+ $params = [
'name_a_b' => 'Relation 1 for create',
'name_b_a' => 'Relation 2 for create',
'description' => 'Testing relationship type',
'contact_type_b' => 'Organization',
'is_reserved' => 1,
'is_active' => 1,
- );
+ ];
}
return $this->relationshipTypeCreate($params);
}
public function testReportTemplate() {
- $result = $this->callAPISuccess('ReportTemplate', 'create', array(
+ $result = $this->callAPISuccess('ReportTemplate', 'create', [
'label' => 'Example Form',
'description' => 'Longish description of the example form',
'class_name' => 'CRM_Report_Form_Examplez',
'report_url' => 'example/path',
'component' => 'CiviCase',
- ));
+ ]);
$this->assertAPISuccess($result);
$this->assertEquals(1, $result['count']);
$entityId = $result['id'];
WHERE name = "CRM_Report_Form_Examplez"');
// change component to null
- $result = $this->callAPISuccess('ReportTemplate', 'create', array(
+ $result = $this->callAPISuccess('ReportTemplate', 'create', [
'id' => $entityId,
'component' => '',
- ));
+ ]);
$this->assertAPISuccess($result);
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
AND component_id IS NULL');
// deactivate
- $result = $this->callAPISuccess('ReportTemplate', 'create', array(
+ $result = $this->callAPISuccess('ReportTemplate', 'create', [
'id' => $entityId,
'is_active' => 0,
- ));
+ ]);
$this->assertAPISuccess($result);
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
WHERE name = "CRM_Report_Form_Examplez"');
// activate
- $result = $this->callAPISuccess('ReportTemplate', 'create', array(
+ $result = $this->callAPISuccess('ReportTemplate', 'create', [
'id' => $entityId,
'is_active' => 1,
- ));
+ ]);
$this->assertAPISuccess($result);
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
$this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
WHERE name = "CRM_Report_Form_Examplez"');
- $result = $this->callAPISuccess('ReportTemplate', 'delete', array(
+ $result = $this->callAPISuccess('ReportTemplate', 'delete', [
'id' => $entityId,
- ));
+ ]);
$this->assertAPISuccess($result);
$this->assertEquals(1, $result['count']);
$this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
* @throws \PHPUnit\Framework\IncompleteTestError
*/
public function testReportTemplateSelectWhere($reportID) {
- $this->hookClass->setHook('civicrm_selectWhereClause', array($this, 'hookSelectWhere'));
+ $this->hookClass->setHook('civicrm_selectWhereClause', [$this, 'hookSelectWhere']);
$result = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $reportID,
'options' => ['metadata' => ['sql']],
*/
public function testReportTemplateGetRowsContactSummary() {
$description = "Retrieve rows from a report template (optionally providing the instance_id).";
- $result = $this->callAPISuccess('report_template', 'getrows', array(
+ $result = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contact/summary',
- 'options' => array('metadata' => array('labels', 'title')),
- ), __FUNCTION__, __FILE__, $description, 'Getrows');
+ 'options' => ['metadata' => ['labels', 'title']],
+ ], __FUNCTION__, __FILE__, $description, 'Getrows');
$this->assertEquals('Contact Name', $result['metadata']['labels']['civicrm_contact_sort_name']);
//the second part of this test has been commented out because it relied on the db being reset to
// Check total rows without distinct
global $_REQUEST;
$_REQUEST['distinct'] = 0;
- $result = $this->callAPIAndDocument('report_template', 'getrows', array(
+ $result = $this->callAPIAndDocument('report_template', 'getrows', [
'report_id' => 'Mailing/opened',
- 'options' => array('metadata' => array('labels', 'title')),
- ), __FUNCTION__, __FILE__, $description, 'Getrows');
+ 'options' => ['metadata' => ['labels', 'title']],
+ ], __FUNCTION__, __FILE__, $description, 'Getrows');
$this->assertEquals(14, $result['count']);
// Check total rows with distinct
$_REQUEST['distinct'] = 1;
- $result = $this->callAPIAndDocument('report_template', 'getrows', array(
+ $result = $this->callAPIAndDocument('report_template', 'getrows', [
'report_id' => 'Mailing/opened',
- 'options' => array('metadata' => array('labels', 'title')),
- ), __FUNCTION__, __FILE__, $description, 'Getrows');
+ 'options' => ['metadata' => ['labels', 'title']],
+ ], __FUNCTION__, __FILE__, $description, 'Getrows');
$this->assertEquals(5, $result['count']);
// Check total rows with distinct by passing NULL value to distinct parameter
$_REQUEST['distinct'] = NULL;
- $result = $this->callAPIAndDocument('report_template', 'getrows', array(
+ $result = $this->callAPIAndDocument('report_template', 'getrows', [
'report_id' => 'Mailing/opened',
- 'options' => array('metadata' => array('labels', 'title')),
- ), __FUNCTION__, __FILE__, $description, 'Getrows');
+ 'options' => ['metadata' => ['labels', 'title']],
+ ], __FUNCTION__, __FILE__, $description, 'Getrows');
$this->assertEquals(5, $result['count']);
}
Civi::settings()->set('logging', 1);
}
- $this->callAPISuccess('report_template', 'getrows', array(
+ $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $reportID,
- ));
+ ]);
if (substr($reportID, 0, '7') === 'logging') {
Civi::settings()->set('logging', 0);
}
Civi::settings()->set('logging', 1);
$group1 = $this->customGroupCreate();
$group2 = $this->customGroupCreate(['name' => 'second_one', 'title' => 'second one', 'table_name' => 'civicrm_value_second_one']);
- $this->customFieldCreate(array('custom_group_id' => $group1['id'], 'label' => 'field one'));
- $this->customFieldCreate(array('custom_group_id' => $group2['id'], 'label' => 'field two'));
- $this->hookClass->setHook('civicrm_alterLogTables', array($this, 'alterLogTablesRemoveCustom'));
+ $this->customFieldCreate(['custom_group_id' => $group1['id'], 'label' => 'field one']);
+ $this->customFieldCreate(['custom_group_id' => $group2['id'], 'label' => 'field two']);
+ $this->hookClass->setHook('civicrm_alterLogTables', [$this, 'alterLogTablesRemoveCustom']);
- $this->callAPISuccess('report_template', 'getrows', array(
+ $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'logging/contact/summary',
- ));
+ ]);
Civi::settings()->set('logging', 0);
$this->customGroupDelete($group1['id']);
$this->customGroupDelete($group2['id']);
if (stristr($reportID, 'has existing issues')) {
$this->markTestIncomplete($reportID);
}
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults'));
- $this->callAPISuccess('report_template', 'getrows', array(
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookNoResults']);
+ $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $reportID,
- ));
+ ]);
}
/**
if (stristr($reportID, 'has existing issues')) {
$this->markTestIncomplete($reportID);
}
- if (in_array($reportID, array('contribute/softcredit', 'contribute/bookkeeping'))) {
+ if (in_array($reportID, ['contribute/softcredit', 'contribute/bookkeeping'])) {
$this->markTestIncomplete($reportID . " has non enotices when calling statistics fn");
}
$description = "Get Statistics from a report (note there isn't much data to get in the test DB).";
- $result = $this->callAPIAndDocument('report_template', 'getstatistics', array(
+ $result = $this->callAPIAndDocument('report_template', 'getstatistics', [
'report_id' => $reportID,
- ), __FUNCTION__, __FILE__, $description, 'Getstatistics', 'getstatistics');
+ ], __FUNCTION__, __FILE__, $description, 'Getstatistics', 'getstatistics');
}
/**
* be static so cannot use $this->callAPISuccess
*/
public static function getReportTemplates() {
- $reportsToSkip = array(
+ $reportsToSkip = [
'event/income' => 'I do no understand why but error is Call to undefined method CRM_Report_Form_Event_Income::from() in CRM/Report/Form.php on line 2120',
'contribute/history' => 'Declaration of CRM_Report_Form_Contribute_History::buildRows() should be compatible with CRM_Report_Form::buildRows($sql, &$rows)',
- );
+ ];
- $reports = civicrm_api3('report_template', 'get', array('return' => 'value', 'options' => array('limit' => 500)));
+ $reports = civicrm_api3('report_template', 'get', ['return' => 'value', 'options' => ['limit' => 500]]);
foreach ($reports['values'] as $report) {
if (empty($reportsToSkip[$report['value']])) {
- $reportTemplates[] = array($report['value']);
+ $reportTemplates[] = [$report['value']];
}
else {
- $reportTemplates[] = array($report['value'] . " has existing issues : " . $reportsToSkip[$report['value']]);
+ $reportTemplates[] = [$report['value'] . " has existing issues : " . $reportsToSkip[$report['value']]];
}
}
* These templates require minimal data config.
*/
public static function getContributionReportTemplates() {
- return array(array('contribute/summary'), array('contribute/detail'), array('contribute/repeat'), array('topDonor' => 'contribute/topDonor'));
+ return [['contribute/summary'], ['contribute/detail'], ['contribute/repeat'], ['topDonor' => 'contribute/topDonor']];
}
/**
* These templates require minimal data config.
*/
public static function getMembershipReportTemplates() {
- return array(array('member/detail'));
+ return [['member/detail']];
}
/**
public function testLybuntReportWithData() {
$inInd = $this->individualCreate();
$outInd = $this->individualCreate();
- $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-03-01'));
- $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL));
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $this->contributionCreate(['contact_id' => $inInd, 'receive_date' => '2014-03-01']);
+ $this->contributionCreate(['contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL]);
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contribute/lybunt',
'yid_value' => 2015,
'yid_op' => 'calendar',
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
$this->assertEquals(1, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE));
}
* Test Lybunt report applies ACLs.
*/
public function testLybuntReportWithDataAndACLFilter() {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('administer CiviCRM');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['administer CiviCRM'];
$inInd = $this->individualCreate();
$outInd = $this->individualCreate();
- $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-03-01'));
- $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL));
- $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults'));
- $params = array(
+ $this->contributionCreate(['contact_id' => $inInd, 'receive_date' => '2014-03-01']);
+ $this->contributionCreate(['contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL]);
+ $this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookNoResults']);
+ $params = [
'report_id' => 'contribute/lybunt',
'yid_value' => 2015,
'yid_op' => 'calendar',
- 'options' => array('metadata' => array('sql')),
+ 'options' => ['metadata' => ['sql']],
'check_permissions' => 1,
- );
+ ];
$rows = $this->callAPISuccess('report_template', 'getrows', $params);
$this->assertEquals(0, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE));
public function testLybuntReportWithFYData() {
$inInd = $this->individualCreate();
$outInd = $this->individualCreate();
- $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-10-01'));
- $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL));
- $this->callAPISuccess('Setting', 'create', array('fiscalYearStart' => array('M' => 7, 'd' => 1)));
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $this->contributionCreate(['contact_id' => $inInd, 'receive_date' => '2014-10-01']);
+ $this->contributionCreate(['contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL]);
+ $this->callAPISuccess('Setting', 'create', ['fiscalYearStart' => ['M' => 7, 'd' => 1]]);
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contribute/lybunt',
'yid_value' => 2015,
'yid_op' => 'fiscal',
- 'options' => array('metadata' => array('sql')),
- 'order_bys' => array(
- array(
+ 'options' => ['metadata' => ['sql']],
+ 'order_bys' => [
+ [
'column' => 'first_name',
'order' => 'ASC',
- ),
- ),
- ));
+ ],
+ ],
+ ]);
$this->assertEquals(2, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE));
public function testLybuntReportWithFYDataOrderByLastYearAmount() {
$inInd = $this->individualCreate();
$outInd = $this->individualCreate();
- $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-10-01'));
- $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL));
- $this->callAPISuccess('Setting', 'create', array('fiscalYearStart' => array('M' => 7, 'd' => 1)));
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $this->contributionCreate(['contact_id' => $inInd, 'receive_date' => '2014-10-01']);
+ $this->contributionCreate(['contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL]);
+ $this->callAPISuccess('Setting', 'create', ['fiscalYearStart' => ['M' => 7, 'd' => 1]]);
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contribute/lybunt',
'yid_value' => 2015,
'yid_op' => 'fiscal',
- 'options' => array('metadata' => array('sql')),
- 'fields' => array('first_name'),
- 'order_bys' => array(
- array(
+ 'options' => ['metadata' => ['sql']],
+ 'fields' => ['first_name'],
+ 'order_bys' => [
+ [
'column' => 'last_year_total_amount',
'order' => 'ASC',
- ),
- ),
- ));
+ ],
+ ],
+ ]);
$this->assertEquals(2, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE));
}
*/
public function testContributionSummaryWithSmartGroupFilter($template) {
$groupID = $this->setUpPopulatedSmartGroup();
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $template,
'gid_value' => $groupID,
'gid_op' => 'in',
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
$this->assertNumberOfContactsInResult(3, $rows, $template);
if ($template === 'contribute/summary') {
$this->assertEquals(3, $rows['values'][0]['civicrm_contribution_total_amount_count']);
*/
public function testContributionSummaryWithNotINSmartGroupFilter($template) {
$groupID = $this->setUpPopulatedSmartGroup();
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contribute/summary',
'gid_value' => $groupID,
'gid_op' => 'notin',
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
$this->assertEquals(2, $rows['values'][0]['civicrm_contribution_total_amount_count']);
}
$contactID2 = $this->individualCreate();
$this->contributionCreate(['contact_id' => $contactID, 'api.ContributionSoft.create' => ['amount' => 5, 'contact_id' => $contactID2]]);
$template = 'contribute/detail';
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $template,
'contribution_or_soft_value' => 'contributions_only',
'fields' => ['soft_credits' => 1, 'contribution_or_soft' => 1, 'sort_name' => 1],
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
$this->assertEquals(
"<a href='/index.php?q=civicrm/contact/view&reset=1&cid=" . $contactID2 . "'>Anderson, Anthony</a> $ 5.00",
$rows['values'][0]['civicrm_contribution_soft_credits']
$contactID2 = $this->individualCreate();
$this->contributionCreate(['contact_id' => $contactID, 'api.ContributionSoft.create' => ['amount' => 5, 'contact_id' => $contactID2]]);
$template = 'contribute/detail';
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $template,
'contribution_or_soft_value' => 'soft_credits_only',
'fields' => [
'receive_date' => '1',
'total_amount' => '1',
],
- 'options' => array('metadata' => ['sql', 'labels']),
- ));
+ 'options' => ['metadata' => ['sql', 'labels']],
+ ]);
foreach (array_keys($rows['metadata']['labels']) as $header) {
$this->assertTrue(!empty($rows['values'][0][$header]));
}
*/
public function testReportsWithNonSmartGroupFilter($template) {
$groupID = $this->setUpPopulatedGroup();
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $template,
- 'gid_value' => array($groupID),
+ 'gid_value' => [$groupID],
'gid_op' => 'in',
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
$this->assertNumberOfContactsInResult(1, $rows, $template);
}
public function testContributionSummaryWithTwoGroups() {
$groupID = $this->setUpPopulatedGroup();
$groupID2 = $this->setUpPopulatedSmartGroup();
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contribute/summary',
- 'gid_value' => array($groupID, $groupID2),
+ 'gid_value' => [$groupID, $groupID2],
'gid_op' => 'in',
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
$this->assertEquals(4, $rows['values'][0]['civicrm_contribution_total_amount_count']);
}
public function testContributionSummaryWithSingleContactsInTwoGroups() {
list($groupID1, $individualID) = $this->setUpPopulatedGroup(TRUE);
// create second group and add the individual to it.
- $groupID2 = $this->groupCreate(array('name' => uniqid(), 'title' => uniqid()));
- $this->callAPISuccess('GroupContact', 'create', array(
+ $groupID2 = $this->groupCreate(['name' => uniqid(), 'title' => uniqid()]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID2,
'contact_id' => $individualID,
'status' => 'Added',
- ));
+ ]);
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contribute/summary',
- 'gid_value' => array($groupID1, $groupID2),
+ 'gid_value' => [$groupID1, $groupID2],
'gid_op' => 'in',
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
$this->assertEquals(1, $rows['count']);
}
public function testContributionSummaryWithTwoGroupsWithIntersection() {
$groups = $this->setUpIntersectingGroups();
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contribute/summary',
'gid_value' => $groups,
'gid_op' => 'in',
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
$this->assertEquals(7, $rows['values'][0]['civicrm_contribution_total_amount_count']);
}
$householdID = $this->householdCreate();
$individualID = $this->individualCreate();
$individualIDRemoved = $this->individualCreate();
- $groupID = $this->smartGroupCreate(array(), array('name' => uniqid(), 'title' => uniqid()));
- $this->callAPISuccess('GroupContact', 'create', array(
+ $groupID = $this->smartGroupCreate([], ['name' => uniqid(), 'title' => uniqid()]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID,
'contact_id' => $individualIDRemoved,
'status' => 'Removed',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID,
'contact_id' => $individualID,
'status' => 'Added',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID,
'contact_id' => $householdID,
'status' => 'Added',
- ));
- foreach (array($household1ID, $individual1ID, $householdID, $individualID, $individualIDRemoved) as $contactID) {
- $this->contributionCreate(array('contact_id' => $contactID, 'invoice_id' => '', 'trxn_id' => ''));
- $this->contactMembershipCreate(array('contact_id' => $contactID));
+ ]);
+ foreach ([$household1ID, $individual1ID, $householdID, $individualID, $individualIDRemoved] as $contactID) {
+ $this->contributionCreate(['contact_id' => $contactID, 'invoice_id' => '', 'trxn_id' => '']);
+ $this->contactMembershipCreate(['contact_id' => $contactID]);
}
// Refresh the cache for test purposes. It would be better to alter to alter the GroupContact add function to add contacts to the cache.
$individual1ID = $this->individualCreate();
$individualID = $this->individualCreate();
$individualIDRemoved = $this->individualCreate();
- $groupID = $this->groupCreate(array('name' => uniqid(), 'title' => uniqid()));
- $this->callAPISuccess('GroupContact', 'create', array(
+ $groupID = $this->groupCreate(['name' => uniqid(), 'title' => uniqid()]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID,
'contact_id' => $individualIDRemoved,
'status' => 'Removed',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID,
'contact_id' => $individualID,
'status' => 'Added',
- ));
+ ]);
- foreach (array($individual1ID, $individualID, $individualIDRemoved) as $contactID) {
- $this->contributionCreate(array('contact_id' => $contactID, 'invoice_id' => '', 'trxn_id' => ''));
- $this->contactMembershipCreate(array('contact_id' => $contactID));
+ foreach ([$individual1ID, $individualID, $individualIDRemoved] as $contactID) {
+ $this->contributionCreate(['contact_id' => $contactID, 'invoice_id' => '', 'trxn_id' => '']);
+ $this->contactMembershipCreate(['contact_id' => $contactID]);
}
// Refresh the cache for test purposes. It would be better to alter to alter the GroupContact add function to add contacts to the cache.
CRM_Contact_BAO_GroupContactCache::clearGroupContactCache($groupID);
if ($returnAddedContact) {
- return array($groupID, $individualID);
+ return [$groupID, $individualID];
}
return $groupID;
$removedFromBothIndividualID = $this->individualCreate();
$addedToSmartGroupRemovedFromOtherIndividualID = $this->individualCreate();
$removedFromSmartGroupAddedToOtherIndividualID = $this->individualCreate();
- $this->callAPISuccess('GroupContact', 'create', array(
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID,
'contact_id' => $addedToBothIndividualID,
'status' => 'Added',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID2,
'contact_id' => $addedToBothIndividualID,
'status' => 'Added',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID,
'contact_id' => $removedFromBothIndividualID,
'status' => 'Removed',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID2,
'contact_id' => $removedFromBothIndividualID,
'status' => 'Removed',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID2,
'contact_id' => $addedToSmartGroupRemovedFromOtherIndividualID,
'status' => 'Added',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID,
'contact_id' => $addedToSmartGroupRemovedFromOtherIndividualID,
'status' => 'Removed',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID,
'contact_id' => $removedFromSmartGroupAddedToOtherIndividualID,
'status' => 'Added',
- ));
- $this->callAPISuccess('GroupContact', 'create', array(
+ ]);
+ $this->callAPISuccess('GroupContact', 'create', [
'group_id' => $groupID2,
'contact_id' => $removedFromSmartGroupAddedToOtherIndividualID,
'status' => 'Removed',
- ));
+ ]);
- foreach (array(
+ foreach ([
$addedToBothIndividualID,
$removedFromBothIndividualID,
$addedToSmartGroupRemovedFromOtherIndividualID,
$removedFromSmartGroupAddedToOtherIndividualID,
- ) as $contactID) {
- $this->contributionCreate(array(
+ ] as $contactID) {
+ $this->contributionCreate([
'contact_id' => $contactID,
'invoice_id' => '',
'trxn_id' => '',
- ));
+ ]);
}
- return array($groupID, $groupID2);
+ return [$groupID, $groupID2];
}
/**
public function testDeferredRevenueReport() {
$indv1 = $this->individualCreate();
$indv2 = $this->individualCreate();
- $params = array(
- 'contribution_invoice_settings' => array(
+ $params = [
+ 'contribution_invoice_settings' => [
'deferred_revenue_enabled' => '1',
- ),
- );
+ ],
+ ];
$this->callAPISuccess('Setting', 'create', $params);
$this->contributionCreate(
- array(
+ [
'contact_id' => $indv1,
'receive_date' => '2016-10-01',
'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+3 month')),
'financial_type_id' => 2,
- )
+ ]
);
$this->contributionCreate(
- array(
+ [
'contact_id' => $indv1,
'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+22 month')),
'financial_type_id' => 4,
'trxn_id' => NULL,
'invoice_id' => NULL,
- )
+ ]
);
$this->contributionCreate(
- array(
+ [
'contact_id' => $indv2,
'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+1 month')),
'financial_type_id' => 4,
'trxn_id' => NULL,
'invoice_id' => NULL,
- )
+ ]
);
$this->contributionCreate(
- array(
+ [
'contact_id' => $indv2,
'receive_date' => '2016-03-01',
'revenue_recognition_date' => date('Y-m-t', strtotime(date('ymd') . '+4 month')),
'financial_type_id' => 2,
'trxn_id' => NULL,
'invoice_id' => NULL,
- )
+ ]
);
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => 'contribute/deferredrevenue',
- ));
+ ]);
$this->assertEquals(2, $rows['count'], "Report failed to get row count");
- $count = array(2, 1);
+ $count = [2, 1];
foreach ($rows['values'] as $row) {
$this->assertEquals(array_pop($count), count($row['rows']), "Report failed to get row count");
}
*/
public function testReportsWithNoTInSmartGroupFilter($template) {
$groupID = $this->setUpPopulatedGroup();
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $template,
- 'gid_value' => array($groupID),
+ 'gid_value' => [$groupID],
'gid_op' => 'notin',
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
$this->assertNumberOfContactsInResult(2, $rows, $template);
}
'status_id' => 1,
'activity_type_id' => 'Meeting',
'source_contact_id' => $this->contactIDs[2],
- 'target_contact_id' => array($this->contactIDs[0], $this->contactIDs[1]),
+ 'target_contact_id' => [$this->contactIDs[0], $this->contactIDs[1]],
'assignee_contact_id' => $this->contactIDs[1],
]);
}
$contactID2 = $this->individualCreate();
$this->contributionCreate(['contact_id' => $contactID, 'api.ContributionSoft.create' => ['amount' => 5, 'contact_id' => $contactID2]]);
$template = 'contribute/detail';
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $template,
'contribution_or_soft_value' => 'contributions_only',
'fields' => [
'total_amount' => '1',
],
'order_bys' => [['column' => 'sort_name', 'order' => 'ASC', 'section' => '1']],
- 'options' => array('metadata' => array('sql')),
- ));
+ 'options' => ['metadata' => ['sql']],
+ ]);
}
/**
$pcp2 = CRM_PCP_BAO_PCP::create($pcpParams);
// Get soft credit types, with the name column as the key.
- $soft_credit_types = CRM_Contribute_BAO_ContributionSoft::buildOptions("soft_credit_type_id", NULL, array("flip" => TRUE, 'labelColumn' => 'name'));
+ $soft_credit_types = CRM_Contribute_BAO_ContributionSoft::buildOptions("soft_credit_type_id", NULL, ["flip" => TRUE, 'labelColumn' => 'name']);
$pcp_soft_credit_type_id = $soft_credit_types['pcp'];
// Create two contributions assigned to this contribution page and
// assign soft credits appropriately.
// FIRST...
- $contribution1params = array(
+ $contribution1params = [
'contact_id' => $donor1ContactId,
'contribution_page_id' => $contribution_page_id,
'total_amount' => '75.00',
- );
+ ];
$c1 = $this->contributionCreate($contribution1params);
// Now the soft contribution.
- $p = array(
+ $p = [
'contribution_id' => $c1,
'pcp_id' => $pcp1->id,
'contact_id' => $pcpOwnerContact1Id,
'amount' => 75.00,
'currency' => 'USD',
'soft_credit_type_id' => $pcp_soft_credit_type_id,
- );
+ ];
$this->callAPISuccess('contribution_soft', 'create', $p);
// SECOND...
- $contribution2params = array(
+ $contribution2params = [
'contact_id' => $donor2ContactId,
'contribution_page_id' => $contribution_page_id,
'total_amount' => '25.00',
- );
+ ];
$c2 = $this->contributionCreate($contribution2params);
// Now the soft contribution.
- $p = array(
+ $p = [
'contribution_id' => $c2,
'pcp_id' => $pcp1->id,
'contact_id' => $pcpOwnerContact1Id,
'amount' => 25.00,
'currency' => 'USD',
'soft_credit_type_id' => $pcp_soft_credit_type_id,
- );
+ ];
$this->callAPISuccess('contribution_soft', 'create', $p);
// Create one contributions assigned to the second PCP page
- $contribution3params = array(
+ $contribution3params = [
'contact_id' => $donor3ContactId,
'contribution_page_id' => $contribution_page_id,
'total_amount' => '200.00',
- );
+ ];
$c3 = $this->contributionCreate($contribution3params);
// Now the soft contribution.
$p = [
$this->callAPISuccess('contribution_soft', 'create', $p);
$template = 'contribute/pcp';
- $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ $rows = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $template,
'title' => 'My PCP',
'fields' => [
'amount_1' => '1',
'soft_id' => '1',
],
- ));
+ ]);
$values = $rows['values'][0];
$this->assertEquals(100.00, $values['civicrm_contribution_soft_amount_1_sum'], "Total commited should be $100");
$this->assertEquals(2, $values['civicrm_contribution_soft_soft_id_count'], "Total donors should be 2");
// params for saved search that returns all volunteers for the
// default organization.
- $this->params = array(
- 'form_values' => array(
+ $this->params = [
+ 'form_values' => [
// Is volunteer for
'relation_type_id' => '6_a_b',
'relation_target_name' => 'Default Organization',
- ),
- );
+ ],
+ ];
}
/**
// Act:
$get_result = $this->callAPIAndDocument(
- $this->_entity, 'get', array('id' => $create_result['id']), __FUNCTION__, __FILE__);
+ $this->_entity, 'get', ['id' => $create_result['id']], __FUNCTION__, __FILE__);
// Assert:
$this->assertEquals(1, $get_result['count']);
public function testCreateSavedSearchWithSmartGroup() {
// First create a volunteer for the default organization
- $result = $this->callAPISuccess('Contact', 'create', array(
+ $result = $this->callAPISuccess('Contact', 'create', [
'first_name' => 'Joe',
'last_name' => 'Schmoe',
'contact_type' => 'Individual',
- 'api.Relationship.create' => array(
+ 'api.Relationship.create' => [
'contact_id_a' => '$value.id',
// default organization:
'contact_id_b' => 1,
// volunteer relationship:
'relationship_type_id' => 6,
'is_active' => 1,
- ),
- ));
+ ],
+ ]);
$contact_id = $result['id'];
// Now create our saved search, and chain the creation of a smart group.
$params = $this->params;
- $params['api.Group.create'] = array(
+ $params['api.Group.create'] = [
'name' => 'my_smartgroup',
'title' => 'my smartgroup',
'description' => 'Volunteers for the default organization',
'visibility' => 'User and User Admin Only',
'is_hidden' => 0,
'is_reserved' => 0,
- );
+ ];
$create_result = $this->callAPIAndDocument(
$this->_entity, 'create', $params, __FUNCTION__, __FILE__);
// Search for contacts in our new smart group
$get_result = $this->callAPISuccess(
- 'Contact', 'get', array('group' => $group_id), __FUNCTION__, __FILE__);
+ 'Contact', 'get', ['group' => $group_id], __FUNCTION__, __FILE__);
// Expect our contact to be there.
$this->assertEquals(1, $get_result['count']);
public function testDeleteSavedSearch() {
// Create saved search, delete it again, and try to get it
$create_result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $delete_params = array('id' => $create_result['id']);
+ $delete_params = ['id' => $create_result['id']];
$this->callAPIAndDocument(
$this->_entity, 'delete', $delete_params, __FUNCTION__, __FILE__);
- $get_result = $this->callAPISuccess($this->_entity, 'get', array());
+ $get_result = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $get_result['count']);
}
class api_v3_SelectQueryTest extends CiviUnitTestCase {
private $hookEntity;
- private $hookCondition = array();
+ private $hookCondition = [];
public function setUp() {
parent::setUp();
$this->useTransaction(TRUE);
- CRM_Utils_Hook::singleton()->setHook('civicrm_selectWhereClause', array($this, 'hook_civicrm_selectWhereClause'));
+ CRM_Utils_Hook::singleton()->setHook('civicrm_selectWhereClause', [$this, 'hook_civicrm_selectWhereClause']);
}
public function testHookPhoneClause() {
- $person1 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'Bob', 'last_name' => 'Tester'));
+ $person1 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'Bob', 'last_name' => 'Tester']);
$cid = $person1['id'];
for ($number = 1; $number < 6; ++$number) {
- $this->callAPISuccess('Phone', 'create', array(
+ $this->callAPISuccess('Phone', 'create', [
'contact_id' => $cid,
'phone' => $number,
- ));
+ ]);
}
$this->hookEntity = 'Phone';
- $this->hookCondition = array(
- 'phone' => array('= 3'),
- );
- $phone = $this->callAPISuccessGetSingle('Phone', array('contact_id' => $cid, 'check_permissions' => 1));
+ $this->hookCondition = [
+ 'phone' => ['= 3'],
+ ];
+ $phone = $this->callAPISuccessGetSingle('Phone', ['contact_id' => $cid, 'check_permissions' => 1]);
$this->assertEquals(3, $phone['phone']);
}
public function testHookContactClause() {
- $person1 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'Bob', 'last_name' => 'Tester', 'email' => 'bob@test.er'));
- $person2 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'Tom', 'last_name' => 'Tester', 'email' => 'tom@test.er'));
- $person3 = $this->callAPISuccess('Contact', 'create', array('contact_type' => 'Individual', 'first_name' => 'Tim', 'last_name' => 'Tester', 'email' => 'tim@test.er'));
+ $person1 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'Bob', 'last_name' => 'Tester', 'email' => 'bob@test.er']);
+ $person2 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'Tom', 'last_name' => 'Tester', 'email' => 'tom@test.er']);
+ $person3 = $this->callAPISuccess('Contact', 'create', ['contact_type' => 'Individual', 'first_name' => 'Tim', 'last_name' => 'Tester', 'email' => 'tim@test.er']);
$this->hookEntity = 'Contact';
- $this->hookCondition = array('id' => array('= ' . $person2['id']));
- $email = $this->callAPISuccessGetSingle('Email', array('check_permissions' => 1));
+ $this->hookCondition = ['id' => ['= ' . $person2['id']]];
+ $email = $this->callAPISuccessGetSingle('Email', ['check_permissions' => 1]);
$this->assertEquals($person2['id'], $email['contact_id']);
}
public function hook_civicrm_selectWhereClause($entity, &$clauses) {
if ($entity == $this->hookEntity) {
foreach ($this->hookCondition as $field => $clause) {
- $clauses[$field] = array_merge(CRM_Utils_Array::value($field, $clauses, array()), $clause);
+ $clauses[$field] = array_merge(CRM_Utils_Array::value($field, $clauses, []), $clause);
}
}
}
public function setUp() {
parent::setUp();
- $params = array(
+ $params = [
'name' => 'Default Domain Name',
'domain_version' => '4.7',
- );
+ ];
$result = $this->callAPISuccess('domain', 'get', $params);
if (empty($result['id'])) {
$result = $this->callAPISuccess('domain', 'create', $params);
public function tearDown() {
CRM_Utils_Hook::singleton()->reset();
parent::tearDown();
- $this->callAPISuccess('system', 'flush', array());
- $this->quickCleanup(array('civicrm_domain'));
+ $this->callAPISuccess('system', 'flush', []);
+ $this->quickCleanup(['civicrm_domain']);
}
/**
public function testGetFields($version) {
$this->_apiversion = $version;
$description = 'Demonstrate return from getfields - see subfolder for variants';
- $result = $this->callAPIAndDocument('setting', 'getfields', array(), __FUNCTION__, __FILE__, $description);
+ $result = $this->callAPIAndDocument('setting', 'getfields', [], __FUNCTION__, __FILE__, $description);
$this->assertArrayHasKey('customCSSURL', $result['values']);
$description = 'Demonstrate return from getfields';
- $result = $this->callAPISuccess('setting', 'getfields', array());
+ $result = $this->callAPISuccess('setting', 'getfields', []);
$this->assertArrayHasKey('customCSSURL', $result['values']);
- $this->callAPISuccess('system', 'flush', array());
+ $this->callAPISuccess('system', 'flush', []);
}
/**
*/
public function testGetFieldsCaching($version) {
$this->_apiversion = $version;
- $settingsMetadata = array();
+ $settingsMetadata = [];
Civi::cache('settings')->set('settingsMetadata_' . \CRM_Core_Config::domainID() . '_', $settingsMetadata);
- $result = $this->callAPISuccess('setting', 'getfields', array());
+ $result = $this->callAPISuccess('setting', 'getfields', []);
$this->assertArrayNotHasKey('customCSSURL', $result['values']);
- $this->quickCleanup(array('civicrm_cache'));
+ $this->quickCleanup(['civicrm_cache']);
Civi::cache('settings')->flush();
}
*/
public function testGetFieldsFilters($version) {
$this->_apiversion = $version;
- $params = array('name' => 'advanced_search_options');
+ $params = ['name' => 'advanced_search_options'];
$result = $this->callAPISuccess('setting', 'getfields', $params);
$this->assertArrayNotHasKey('customCSSURL', $result['values']);
$this->assertArrayHasKey('advanced_search_options', $result['values']);
*/
public function testGetFieldsGroupFilters($version) {
$this->_apiversion = $version;
- $params = array('filters' => array('group' => 'multisite'));
+ $params = ['filters' => ['group' => 'multisite']];
$result = $this->callAPISuccess('setting', 'getfields', $params);
$this->assertArrayNotHasKey('customCSSURL', $result['values']);
$this->assertArrayHasKey('domain_group_id', $result['values']);
public function testOnChange($version) {
$this->_apiversion = $version;
global $_testOnChange_hookCalls;
- $this->setMockSettingsMetaData(array(
- 'onChangeExample' => array(
+ $this->setMockSettingsMetaData([
+ 'onChangeExample' => [
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'onChangeExample',
'type' => 'Array',
'quick_form_type' => 'Element',
'html_type' => 'advmultiselect',
- 'default' => array('CiviEvent', 'CiviContribute'),
+ 'default' => ['CiviEvent', 'CiviContribute'],
'add' => '4.4',
'title' => 'List of Components',
'is_domain' => '1',
'description' => NULL,
'help_text' => NULL,
// list of callbacks
- 'on_change' => array(
- array(__CLASS__, '_testOnChange_onChangeExample'),
- ),
- ),
- ));
+ 'on_change' => [
+ [__CLASS__, '_testOnChange_onChangeExample'],
+ ],
+ ],
+ ]);
// set initial value
- $_testOnChange_hookCalls = array('count' => 0);
- $this->callAPISuccess('setting', 'create', array(
- 'onChangeExample' => array('First', 'Value'),
- ));
+ $_testOnChange_hookCalls = ['count' => 0];
+ $this->callAPISuccess('setting', 'create', [
+ 'onChangeExample' => ['First', 'Value'],
+ ]);
$this->assertEquals(1, $_testOnChange_hookCalls['count']);
- $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['newValue']);
+ $this->assertEquals(['First', 'Value'], $_testOnChange_hookCalls['newValue']);
$this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']);
// change value
- $_testOnChange_hookCalls = array('count' => 0);
- $this->callAPISuccess('setting', 'create', array(
- 'onChangeExample' => array('Second', 'Value'),
- ));
+ $_testOnChange_hookCalls = ['count' => 0];
+ $this->callAPISuccess('setting', 'create', [
+ 'onChangeExample' => ['Second', 'Value'],
+ ]);
$this->assertEquals(1, $_testOnChange_hookCalls['count']);
- $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['oldValue']);
- $this->assertEquals(array('Second', 'Value'), $_testOnChange_hookCalls['newValue']);
+ $this->assertEquals(['First', 'Value'], $_testOnChange_hookCalls['oldValue']);
+ $this->assertEquals(['Second', 'Value'], $_testOnChange_hookCalls['newValue']);
$this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']);
}
$this->_apiversion = $version;
$description = "Shows setting a variable for a given domain - if no domain is set current is assumed.";
- $params = array(
+ $params = [
'domain_id' => $this->_domainID2,
'uniq_email_per_site' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__);
- $params = array('uniq_email_per_site' => 1);
+ $params = ['uniq_email_per_site' => 1];
$description = "Shows setting a variable for a current domain.";
$result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateSettingCurrentDomain');
$this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']);
*/
public function testCreateInvalidSettings($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'domain_id' => $this->_domainID2,
'invalid_key' => 1,
- );
+ ];
$result = $this->callAPIFailure('setting', 'create', $params);
}
*/
public function testCreateInvalidURLSettings($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'domain_id' => $this->_domainID2,
'userFrameworkResourceURL' => 'dfhkd hfd',
- );
+ ];
$result = $this->callAPIFailure('setting', 'create', $params);
- $params = array(
+ $params = [
'domain_id' => $this->_domainID2,
'userFrameworkResourceURL' => 'http://blah.com',
- );
+ ];
$result = $this->callAPISuccess('setting', 'create', $params);
}
*/
public function testCreateInvalidBooleanSettings($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'domain_id' => $this->_domainID2,
'track_civimail_replies' => 'dfhkdhfd',
- );
+ ];
$result = $this->callAPIFailure('setting', 'create', $params);
- $params = array('track_civimail_replies' => '0');
+ $params = ['track_civimail_replies' => '0'];
$result = $this->callAPISuccess('setting', 'create', $params);
$getResult = $this->callAPISuccess('setting', 'get');
$this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']);
$getResult = $this->callAPISuccess('setting', 'get');
$this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']);
- $params = array(
+ $params = [
'domain_id' => $this->_domainID2,
'track_civimail_replies' => '1',
- );
+ ];
$result = $this->callAPISuccess('setting', 'create', $params);
$getResult = $this->callAPISuccess('setting', 'get', ['domain_id' => $this->_domainID2]);
$this->assertEquals(1, $getResult['values'][$this->_domainID2]['track_civimail_replies']);
- $params = array(
+ $params = [
'domain_id' => $this->_domainID2,
'track_civimail_replies' => 'TRUE',
- );
+ ];
$result = $this->callAPISuccess('setting', 'create', $params);
$getResult = $this->callAPISuccess('setting', 'get', ['domain_id' => $this->_domainID2]);
$this->_apiversion = $version;
$description = "Shows setting a variable for all domains.";
- $params = array(
+ $params = [
'domain_id' => 'all',
'uniq_email_per_site' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateAllDomains');
$this->assertEquals(1, $result['values'][2]['uniq_email_per_site']);
$this->assertArrayHasKey(3, $result['values'], 'Domain create probably failed Debug this IF domain test is passing');
$this->assertEquals(1, $result['values'][3]['uniq_email_per_site'], 'failed to set setting for domain 3.');
- $params = array(
+ $params = [
'domain_id' => 'all',
'return' => 'uniq_email_per_site',
- );
+ ];
// we'll check it with a 'get'
$description = "Shows getting a variable for all domains.";
$result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetAllDomains');
$this->assertEquals(1, $result['values'][1]['uniq_email_per_site']);
$this->assertEquals(1, $result['values'][3]['uniq_email_per_site']);
- $params = array(
- 'domain_id' => array(1, 3),
+ $params = [
+ 'domain_id' => [1, 3],
'uniq_email_per_site' => 0,
- );
+ ];
$description = "Shows setting a variable for specified domains.";
$result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateSpecifiedDomains');
$this->assertEquals(0, $result['values'][3]['uniq_email_per_site']);
$this->assertEquals(0, $result['values'][1]['uniq_email_per_site']);
- $params = array(
- 'domain_id' => array(1, 2),
- 'return' => array('uniq_email_per_site'),
- );
+ $params = [
+ 'domain_id' => [1, 2],
+ 'return' => ['uniq_email_per_site'],
+ ];
$description = "Shows getting a variable for specified domains.";
$result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetSpecifiedDomains');
$this->assertEquals(1, $result['values'][2]['uniq_email_per_site']);
*/
public function testGetSetting($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'domain_id' => $this->_domainID2,
'return' => 'uniq_email_per_site',
- );
+ ];
$description = "Shows get setting a variable for a given domain - if no domain is set current is assumed.";
$result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__);
- $params = array(
+ $params = [
'return' => 'uniq_email_per_site',
- );
+ ];
$description = "Shows getting a variable for a current domain.";
$result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetSettingCurrentDomain');
$this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']);
*/
public function testGetExtensionSetting($version) {
$this->_apiversion = $version;
- $this->hookClass->setHook('civicrm_alterSettingsFolders', array($this, 'setExtensionMetadata'));
+ $this->hookClass->setHook('civicrm_alterSettingsFolders', [$this, 'setExtensionMetadata']);
$data = NULL;
Civi::cache('settings')->flush();
- $fields = $this->callAPISuccess('setting', 'getfields', array('filters' => array('group_name' => 'Test Settings')));
+ $fields = $this->callAPISuccess('setting', 'getfields', ['filters' => ['group_name' => 'Test Settings']]);
$this->assertArrayHasKey('test_key', $fields['values']);
- $this->callAPISuccess('setting', 'create', array('test_key' => 'keyset'));
+ $this->callAPISuccess('setting', 'create', ['test_key' => 'keyset']);
$this->assertEquals('keyset', Civi::settings()->get('test_key'));
- $result = $this->callAPISuccess('setting', 'getvalue', array('name' => 'test_key', 'group' => 'Test Settings'));
+ $result = $this->callAPISuccess('setting', 'getvalue', ['name' => 'test_key', 'group' => 'Test Settings']);
$this->assertEquals('keyset', $result);
}
*/
public function testGetConfigSetting($version) {
$this->_apiversion = $version;
- $settings = $this->callAPISuccess('setting', 'get', array(
+ $settings = $this->callAPISuccess('setting', 'get', [
'name' => 'defaultCurrency',
'sequential' => 1,
- ));
+ ]);
$this->assertEquals('USD', $settings['values'][0]['defaultCurrency']);
}
*/
public function testGetSetConfigSettingMultipleDomains($version) {
$this->_apiversion = $version;
- $settings = $this->callAPISuccess('setting', 'create', array(
+ $settings = $this->callAPISuccess('setting', 'create', [
'defaultCurrency' => 'USD',
'domain_id' => $this->_currentDomain,
- ));
- $settings = $this->callAPISuccess('setting', 'create', array(
+ ]);
+ $settings = $this->callAPISuccess('setting', 'create', [
'defaultCurrency' => 'CAD',
'domain_id' => $this->_domainID2,
- ));
- $settings = $this->callAPISuccess('setting', 'get', array(
+ ]);
+ $settings = $this->callAPISuccess('setting', 'get', [
'return' => 'defaultCurrency',
'domain_id' => 'all',
- ));
+ ]);
$this->assertEquals('USD', $settings['values'][$this->_currentDomain]['defaultCurrency']);
$this->assertEquals('CAD', $settings['values'][$this->_domainID2]['defaultCurrency'],
"second domain (id {$this->_domainID2} ) should be set to CAD. First dom was {$this->_currentDomain} & was USD");
*/
public function testGetValueConfigSetting($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'name' => 'monetaryThousandSeparator',
'group' => 'Localization Setting',
- );
+ ];
$result = $this->callAPISuccess('setting', 'getvalue', $params);
$this->assertEquals(',', $result);
}
*/
public function testGetValue($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'name' => 'petition_contacts',
'group' => 'Campaign Preferences',
- );
+ ];
$description = "Demonstrates getvalue action - intended for runtime use as better caching than get.";
$result = $this->callAPIAndDocument('setting', 'getvalue', $params, __FUNCTION__, __FILE__, $description);
public function testGetDefaults() {
$description = "Gets defaults setting a variable for a given domain - if no domain is set current is assumed.";
- $params = array(
+ $params = [
'name' => 'address_format',
- );
+ ];
$result = $this->callAPIAndDocument('setting', 'getdefaults', $params, __FUNCTION__, __FILE__, $description, 'GetDefaults');
$this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']);
- $params = array('name' => 'mailing_format');
+ $params = ['name' => 'mailing_format'];
$result = $this->callAPISuccess('setting', 'getdefaults', $params);
$this->assertEquals("{contact.addressee}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['mailing_format']);
$this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']);
*/
public function testRevert($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'address_format' => 'xyz',
'mailing_format' => 'bcs',
- );
+ ];
$result = $this->callAPISuccess('setting', 'create', $params);
$this->assertAPISuccess($result, "in line " . __LINE__);
- $revertParams = array(
+ $revertParams = [
'name' => 'address_format',
- );
+ ];
$result = $this->callAPISuccess('setting', 'get');
//make sure it's set
$this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']);
//make sure it's reverted
$result = $this->callAPISuccess('setting', 'get');
$this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']);
- $params = array(
- 'return' => array('mailing_format'),
- );
+ $params = [
+ 'return' => ['mailing_format'],
+ ];
$result = $this->callAPISuccess('setting', 'get', $params);
//make sure it's unchanged
$this->assertEquals('bcs', $result['values'][CRM_Core_Config::domainID()]['mailing_format']);
* Api3 only.
*/
public function testRevertAll() {
- $params = array(
+ $params = [
'address_format' => 'xyz',
'mailing_format' => 'bcs',
- );
+ ];
$result = $this->callAPISuccess('setting', 'create', $params);
- $revertParams = array();
+ $revertParams = [];
$result = $this->callAPISuccess('setting', 'get', $params);
//make sure it's set
$this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']);
$this->callAPISuccess('setting', 'revert', $revertParams);
//make sure it's reverted
- $result = $this->callAPISuccess('setting', 'get', array('group' => 'core'));
+ $result = $this->callAPISuccess('setting', 'get', ['group' => 'core']);
$this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']);
$this->assertEquals("{contact.addressee}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['mailing_format']);
}
* V3 only - no fill action in v4
*/
public function testDefaults() {
- $domparams = array(
+ $domparams = [
'name' => 'B Team Domain',
'domain_version' => '4.7',
- );
+ ];
$dom = $this->callAPISuccess('domain', 'create', $domparams);
- $params = array(
+ $params = [
'domain_id' => 'all',
- );
+ ];
$result = $this->callAPISuccess('setting', 'get', $params);
- $params = array(
+ $params = [
'address_format' => 'xyz',
'mailing_format' => 'bcs',
'domain_id' => $this->_domainID2,
- );
+ ];
$result = $this->callAPISuccess('setting', 'create', $params);
- $params = array(
+ $params = [
'domain_id' => $dom['id'],
- );
+ ];
$result = $this->callAPISuccess('setting', 'get', $params);
$this->assertAPISuccess($result, "in line " . __LINE__);
$this->assertEquals('Unconfirmed', $result['values'][$dom['id']]['tag_unconfirmed']);
global $civicrm_setting;
unset($civicrm_setting[CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME]['environment']);
Civi::service('settings_manager')->useMandatory();
- $params = array(
+ $params = [
'environment' => 'Staging',
- );
+ ];
$result = $this->callAPISuccess('Setting', 'create', $params);
- $params = array(
+ $params = [
'name' => 'environment',
'group' => 'Developer Preferences',
- );
+ ];
$result = $this->callAPISuccess('Setting', 'getvalue', $params);
$this->assertEquals('Staging', $result);
$this->_apiversion = 3;
parent::setUp();
$this->useTransaction(TRUE);
- $this->_params = array(
+ $this->_params = [
'name' => 'Wessex',
'abbreviation' => 'WEX',
'country_id' => 1226,
- );
+ ];
}
public function testCreateStateProvince() {
$result = $this->callAPIAndDocument('StateProvince', 'create', $this->_params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->callAPISuccess('StateProvince', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('StateProvince', 'delete', ['id' => $result['id']]);
}
public function testDeleteStateProvince() {
$create = $this->callAPISuccess('StateProvince', 'create', $this->_params);
// Delete
- $result = $this->callAPIAndDocument('StateProvince', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('StateProvince', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
- $get = $this->callAPISuccess('StateProvince', 'get', array(
+ $get = $this->callAPISuccess('StateProvince', 'get', [
'id' => $create['id'],
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'State/province not successfully deleted');
}
* Test with empty params
*/
public function testGetEmptyParams() {
- $result = $this->callAPISuccess('StateProvince', 'Get', array());
+ $result = $this->callAPISuccess('StateProvince', 'Get', []);
}
/**
* Test with wrong params
*/
public function testGetWrongParams() {
- $this->callAPIFailure('StateProvince', 'Get', array('id' => 'abc'));
+ $this->callAPIFailure('StateProvince', 'Get', ['id' => 'abc']);
}
/**
*/
public function testGet() {
$province = $this->callAPISuccess('StateProvince', 'create', $this->_params);
- $params = array(
+ $params = [
'name' => $this->_params['name'],
- );
+ ];
$result = $this->callAPIAndDocument('StateProvince', 'Get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($province['values'][$province['id']]['name'], $result['values'][$province['id']]['name']);
$this->assertEquals($province['values'][$province['id']]['abbreviation'], $result['values'][$province['id']]['abbreviation']);
unset($params['id']);
$this->callAPISuccess('StateProvince', 'create', $params);
$this->callAPIFailure('StateProvince', 'create', $params);
- $check = $this->callAPISuccess('StateProvince', 'getcount', array(
+ $check = $this->callAPISuccess('StateProvince', 'getcount', [
'name' => $params['name'],
- ));
+ ]);
$this->assertEquals(1, $check);
}
$this->_apiversion = 3;
parent::setUp();
$this->useTransaction(TRUE);
- $this->_params = array(
+ $this->_params = [
'name' => 'test_check',
'domain_id' => 1,
'hush_until' => '20151212',
'ignore_severity' => 4,
'check_info' => NULL,
- );
+ ];
}
public function testCreateStatusPreference() {
$this->assertEquals('test_check', $result['values'][$id]['name'], 'In line ' . __LINE__);
$this->assertEquals(4, $result['values'][$id]['ignore_severity'], 'In line ' . __LINE__);
- $this->callAPISuccess('StatusPreference', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('StatusPreference', 'delete', ['id' => $result['id']]);
}
public function testDeleteStatusPreference() {
// create one
$create = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
- $result = $this->callAPIAndDocument('StatusPreference', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('StatusPreference', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
- $get = $this->callAPISuccess('StatusPreference', 'get', array(
+ $get = $this->callAPISuccess('StatusPreference', 'get', [
'id' => $create['id'],
- ));
+ ]);
$this->assertEquals(0, $get['count'], 'Status Preference not successfully deleted In line ' . __LINE__);
}
* Test a get with empty params.
*/
public function testStatusPreferenceGetEmptyParams() {
- $result = $this->callAPISuccess('StatusPreference', 'Get', array());
+ $result = $this->callAPISuccess('StatusPreference', 'Get', []);
}
/**
public function testStatusPreferenceGet() {
$statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
$id = $statusPreference['id'];
- $params = array(
+ $params = [
'id' => $id,
- );
+ ];
$result = $this->callAPIAndDocument('StatusPreference', 'Get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($statusPreference['values'][$id]['name'], $result['values'][$id]['name'], 'In line ' . __LINE__);
$this->assertEquals($statusPreference['values'][$id]['domain_id'], $result['values'][$id]['domain_id'], 'In line ' . __LINE__);
public function setUp() {
parent::setUp();
$this->useTransaction(TRUE);
- $phoneBankActivity = $this->callAPISuccess('Option_value', 'Get', array('label' => 'PhoneBank', 'sequential' => 1));
+ $phoneBankActivity = $this->callAPISuccess('Option_value', 'Get', ['label' => 'PhoneBank', 'sequential' => 1]);
$phoneBankActivityTypeID = $phoneBankActivity['values'][0]['value'];
- $surveyParams = array(
+ $surveyParams = [
'title' => "survey respondent",
'activity_type_id' => $phoneBankActivityTypeID,
'instructions' => "Call people, ask for money",
- );
+ ];
$survey = $this->callAPISuccess('survey', 'create', $surveyParams);
$surveyID = $survey['id'];
- $this->params = array(
+ $this->params = [
'sequential' => '1',
'survey_id' => $surveyID,
- );
+ ];
}
/**
public $DBResetRequired = FALSE;
public function setUp() {
- $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', array(
+ $phoneBankActivityTypeID = $this->callAPISuccessGetValue('Option_value', [
'label' => 'PhoneBank',
'return' => 'value',
- ), 'integer');
+ ], 'integer');
$this->useTransaction();
$this->enableCiviCampaign();
- $this->params = array(
+ $this->params = [
'title' => "survey title",
'activity_type_id' => $phoneBankActivityTypeID,
'max_number_of_contacts' => 12,
'instructions' => "Call people, ask for money",
- );
+ ];
parent::setUp();
}
*/
public function testDeleteSurvey() {
$entity = $this->createTestEntity();
- $result = $this->callAPIAndDocument('survey', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->entity, 'get', array());
+ $result = $this->callAPIAndDocument('survey', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__);
+ $checkDeleted = $this->callAPISuccess($this->entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testGetSurveyChainDelete() {
$description = "Demonstrates get + delete in the same call.";
$subfile = 'ChainedGetDelete';
- $params = array(
+ $params = [
'title' => "survey title",
'api.survey.delete' => 1,
- );
+ ];
$result = $this->callAPISuccess('survey', 'create', $this->params);
$result = $this->callAPIAndDocument('survey', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', array()));
+ $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', []));
}
}
* Map custom group entities to civicrm components.
* @var array
*/
- protected static $componentMap = array(
+ protected static $componentMap = [
'Contribution' => 'CiviContribute',
'Membership' => 'CiviMember',
'Participant' => 'CiviEvent',
'Grant' => 'CiviGrant',
'Campaign' => 'CiviCampaign',
'Survey' => 'CiviCampaign',
- );
+ ];
/**
* Set up function.
public function setUp() {
parent::setUp();
$this->enableCiviCampaign();
- $this->toBeImplemented['get'] = array(
+ $this->toBeImplemented['get'] = [
// CxnApp.get exists but relies on remote data outside our control; QA w/UtilsTest::testBasicArrayGet
'CxnApp',
'Profile',
'Setting',
'Payment',
'Logging',
- );
- $this->toBeImplemented['create'] = array(
+ ];
+ $this->toBeImplemented['create'] = [
'Cxn',
'CxnApp',
'SurveyRespondant',
//work fine in local
'SavedSearch',
'Logging',
- );
- $this->toBeImplemented['delete'] = array(
+ ];
+ $this->toBeImplemented['delete'] = [
'Cxn',
'CxnApp',
'MembershipPayment',
'System',
'Payment',
'Order',
- );
- $this->onlyIDNonZeroCount['get'] = array(
+ ];
+ $this->onlyIDNonZeroCount['get'] = [
'ActivityType',
'Entity',
'Domain',
'Setting',
'User',
- );
- $this->deprecatedAPI = array('Location', 'ActivityType', 'SurveyRespondant');
- $this->deletableTestObjects = array();
+ ];
+ $this->deprecatedAPI = ['Location', 'ActivityType', 'SurveyRespondant'];
+ $this->deletableTestObjects = [];
}
public function tearDown() {
foreach ($this->deletableTestObjects as $entityName => $entities) {
foreach ($entities as $entityID) {
- CRM_Core_DAO::deleteTestObjects($entityName, array('id' => $entityID));
+ CRM_Core_DAO::deleteTestObjects($entityName, ['id' => $entityID]);
}
}
}
*
* @return array
*/
- public static function entities($skip = array()) {
+ public static function entities($skip = []) {
// The order of operations in here is screwy. In the case where SYNTAX_CONFORMANCE_ENTITIES is
// defined, we should be able to parse+return it immediately. However, some weird dependency
// crept into the system where civicrm_api('Entity','get') must be called as part of entities()
// (even if its return value is ignored).
- $tmp = civicrm_api('Entity', 'Get', array('version' => 3));
+ $tmp = civicrm_api('Entity', 'Get', ['version' => 3]);
if (getenv('SYNTAX_CONFORMANCE_ENTITIES')) {
- $tmp = array(
+ $tmp = [
'values' => explode(' ', getenv('SYNTAX_CONFORMANCE_ENTITIES')),
- );
+ ];
}
if (!is_array($skip)) {
- $skip = array();
+ $skip = [];
}
$tmp = array_diff($tmp['values'], $skip);
- $entities = array();
+ $entities = [];
foreach ($tmp as $e) {
- $entities[] = array($e);
+ $entities[] = [$e];
}
return $entities;
}
public static function custom_data_entities() {
$entities = CRM_Core_BAO_CustomQuery::$extendsMap;
$enabledComponents = Civi::settings()->get('enable_components');
- $customDataEntities = array();
- $invalidEntities = array('Individual', 'Organization', 'Household');
- $entitiesToFix = array('Case', 'Relationship');
+ $customDataEntities = [];
+ $invalidEntities = ['Individual', 'Organization', 'Household'];
+ $entitiesToFix = ['Case', 'Relationship'];
foreach ($entities as $entityName => $entity) {
if (!in_array($entityName, $invalidEntities)
&& !in_array($entityName, $entitiesToFix)
if (!empty(self::$componentMap[$entityName]) && empty($enabledComponents[self::$componentMap[$entityName]])) {
CRM_Core_BAO_ConfigSetting::enableComponent(self::$componentMap[$entityName]);
}
- $customDataEntities[] = array($entityName);
+ $customDataEntities[] = [$entityName];
}
}
return $customDataEntities;
* @return array
*/
public static function toBeSkipped_get($sequential = FALSE) {
- $entitiesWithoutGet = array(
+ $entitiesWithoutGet = [
'MailingEventSubscribe',
'MailingEventConfirm',
'MailingEventResubscribe',
'MailingEventUnsubscribe',
'Location',
- );
+ ];
if ($sequential === TRUE) {
return $entitiesWithoutGet;
}
- $entities = array();
+ $entities = [];
foreach ($entitiesWithoutGet as $e) {
- $entities[] = array($e);
+ $entities[] = [$e];
}
return $entities;
}
* Entities that cannot be retrieved by ID
*/
public static function toBeSkipped_getByID($sequential = FALSE) {
- return array('MailingContact', 'User', 'Attachment', 'Entity');
+ return ['MailingContact', 'User', 'Attachment', 'Entity'];
}
/**
* @return array
*/
public static function toBeSkipped_create($sequential = FALSE) {
- $entitiesWithoutCreate = array('Constant', 'Entity', 'Location', 'Profile', 'MailingRecipients');
+ $entitiesWithoutCreate = ['Constant', 'Entity', 'Location', 'Profile', 'MailingRecipients'];
if ($sequential === TRUE) {
return $entitiesWithoutCreate;
}
- $entities = array();
+ $entities = [];
foreach ($entitiesWithoutCreate as $e) {
- $entities[] = array($e);
+ $entities[] = [$e];
}
return $entities;
}
* @return array
*/
public static function toBeSkipped_delete($sequential = FALSE) {
- $entitiesWithout = array(
+ $entitiesWithout = [
'MailingContact',
'MailingEventConfirm',
'MailingEventResubscribe',
'Setting',
'User',
'Logging',
- );
+ ];
if ($sequential === TRUE) {
return $entitiesWithout;
}
- $entities = array();
+ $entities = [];
foreach ($entitiesWithout as $e) {
- $entities[] = array($e);
+ $entities[] = [$e];
}
return $entities;
}
* @return array
*/
public static function toBeSkipped_custom_data_creatable($sequential = FALSE) {
- $entitiesWithout = array(
+ $entitiesWithout = [
// Ones to fix.
'CaseContact',
'CustomField',
'Order',
'MailingGroup',
'Logging',
- );
+ ];
if ($sequential === TRUE) {
return $entitiesWithout;
}
- $entities = array();
+ $entities = [];
foreach ($entitiesWithout as $e) {
- $entities[] = array($e);
+ $entities[] = [$e];
}
return $entities;
}
* @todo add metadata for ALL these entities
*/
public static function toBeSkipped_getfields($sequential = FALSE) {
- $entitiesWithMetadataNotYetFixed = array('ReportTemplate', 'CustomSearch');
+ $entitiesWithMetadataNotYetFixed = ['ReportTemplate', 'CustomSearch'];
if ($sequential === TRUE) {
return $entitiesWithMetadataNotYetFixed;
}
- $entities = array();
+ $entities = [];
foreach ($entitiesWithMetadataNotYetFixed as $e) {
- $entities[] = array($e);
+ $entities[] = [$e];
}
return $entities;
}
* Entities to be skipped
*/
public static function toBeSkipped_automock($sequential = FALSE) {
- $entitiesWithoutGet = array(
+ $entitiesWithoutGet = [
'MailingContact',
'EntityTag',
'Participant',
'ReportTemplate',
'System',
'Logging',
- );
+ ];
if ($sequential === TRUE) {
return $entitiesWithoutGet;
}
- $entities = array();
+ $entities = [];
foreach ($entitiesWithoutGet as $e) {
- $entities[] = array($e);
+ $entities[] = [$e];
}
return $entities;
}
* @return array
*/
public static function toBeSkipped_updatesingle($sequential = FALSE) {
- $entitiesWithout = array(
+ $entitiesWithout = [
'Attachment',
// pseudo-entity; testUpdateSingleValueAlter doesn't introspect properly on it. Multiple magic fields
'Mailing',
'SystemLog',
//skip this because it doesn't make sense to update logs,
'Logging',
- );
+ ];
if ($sequential === TRUE) {
return $entitiesWithout;
}
- $entities = array();
+ $entities = [];
foreach ($entitiesWithout as $e) {
- $entities[] = array(
+ $entities[] = [
$e,
- );
+ ];
}
- return array('pledge');
+ return ['pledge'];
return $entities;
}
* At this stage exclude the ones that don't pass & add them as we can troubleshoot them
*/
public static function toBeSkipped_getlimit() {
- $entitiesWithout = array(
+ $entitiesWithout = [
'Case',
//case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
'EntityTag',
// fails on 5 limit - probably a set up problem
'Setting',
//a bit of a pseudoapi - keys by domain
- );
+ ];
return $entitiesWithout;
}
* At this stage exclude the ones that don't pass & add them as we can troubleshoot them
*/
public static function toBeSkipped_getSqlOperators() {
- $entitiesWithout = array(
+ $entitiesWithout = [
//case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
'Case',
// on the todo list!
'Note',
//a bit of a pseudoapi - keys by domain
'Setting',
- );
+ ];
return $entitiesWithout;
}
*/
public function getKnownUnworkablesUpdateSingle($entity, $key) {
// can't update values are values for which updates don't result in the value being changed
- $knownFailures = array(
- 'ActionSchedule' => array(
- 'cant_update' => array(
+ $knownFailures = [
+ 'ActionSchedule' => [
+ 'cant_update' => [
'group_id',
- ),
- ),
- 'ActivityContact' => array(
- 'cant_update' => array(
+ ],
+ ],
+ 'ActivityContact' => [
+ 'cant_update' => [
'activity_id',
//we have an FK on activity_id + contact_id + record id so if we don't leave this one distinct we get an FK constraint error
- ),
- ),
- 'Address' => array(
- 'cant_update' => array(
+ ],
+ ],
+ 'Address' => [
+ 'cant_update' => [
//issues with country id - need to ensure same country
'state_province_id',
'world_region',
//creates relationship
'master_id',
- ),
+ ],
'cant_return' => ['street_parsing', 'skip_geocode', 'fix_address'],
- ),
- 'Batch' => array(
- 'cant_update' => array(
+ ],
+ 'Batch' => [
+ 'cant_update' => [
// believe this field is defined in error
'entity_table',
- ),
- 'cant_return' => array(
+ ],
+ 'cant_return' => [
'entity_table',
- ),
- ),
- 'CaseType' => array(
- 'cant_update' => array(
+ ],
+ ],
+ 'CaseType' => [
+ 'cant_update' => [
'definition',
- ),
- ),
+ ],
+ ],
'Domain' => ['cant_update' => ['domain_version']],
- 'MembershipBlock' => array(
- 'cant_update' => array(
+ 'MembershipBlock' => [
+ 'cant_update' => [
// The fake/auto-generated values leave us unable to properly cleanup fake data
'entity_type',
'entity_id',
- ),
- ),
+ ],
+ ],
'MailingJob' => ['cant_update' => ['parent_id']],
- 'ContributionSoft' => array(
- 'cant_update' => array(
+ 'ContributionSoft' => [
+ 'cant_update' => [
// can't be changed through api
'pcp_id',
- ),
- ),
- 'Email' => array(
- 'cant_update' => array(
+ ],
+ ],
+ 'Email' => [
+ 'cant_update' => [
// This is being legitimately manipulated to always have a valid primary - skip.
'is_primary',
- ),
- ),
- 'Navigation' => array(
- 'cant_update' => array(
+ ],
+ ],
+ 'Navigation' => [
+ 'cant_update' => [
// Weight is deliberately altered when this is changed - skip.
'parent_id',
- ),
- ),
- 'LocationType' => array(
- 'cant_update' => array(
+ ],
+ ],
+ 'LocationType' => [
+ 'cant_update' => [
// I'm on the fence about whether the test should skip or the behaviour is wrong.
// display_name is set to match name if display_name is not provided. It would be more 'normal'
// to only calculate a default IF id is not set - but perhaps the current behaviour is kind
// of what someone updating the name expects..
'name',
- ),
- ),
- 'Pledge' => array(
- 'cant_update' => array(
+ ],
+ ],
+ 'Pledge' => [
+ 'cant_update' => [
'pledge_original_installment_amount',
'installments',
'original_installment_amount',
'next_pay_date',
// can't be changed through API,
'amount',
- ),
+ ],
// if these are passed in they are retrieved from the wrong table
- 'break_return' => array(
+ 'break_return' => [
'honor_contact_id',
'cancel_date',
'contribution_page_id',
'financial_account_id',
'financial_type_id',
'currency',
- ),
+ ],
// can't be retrieved from api
- 'cant_return' => array(
+ 'cant_return' => [
//due to uniquename missing
'honor_type_id',
'end_date',
'pledge_status_id',
'pledge_campaign_id',
'pledge_financial_type_id',
- ),
- ),
- 'PaymentProcessorType' => array(
- 'cant_update' => array(
+ ],
+ ],
+ 'PaymentProcessorType' => [
+ 'cant_update' => [
'billing_mode',
- ),
- 'break_return' => array(),
- 'cant_return' => array(),
- ),
- 'PriceFieldValue' => array(
- 'cant_update' => array(
+ ],
+ 'break_return' => [],
+ 'cant_return' => [],
+ ],
+ 'PriceFieldValue' => [
+ 'cant_update' => [
//won't update as there is no 1 in the same price set
'weight',
- ),
- ),
- 'ReportInstance' => array(
+ ],
+ ],
+ 'ReportInstance' => [
// View mode is part of the navigation which is not retrieved by the api.
- 'cant_return' => array('view_mode'),
- ),
- 'SavedSearch' => array(
+ 'cant_return' => ['view_mode'],
+ ],
+ 'SavedSearch' => [
// I think the fields below are generated based on form_values.
- 'cant_update' => array(
+ 'cant_update' => [
'search_custom_id',
'where_clause',
'select_tables',
'where_tables',
- ),
- ),
- 'StatusPreference' => array(
- 'break_return' => array(
+ ],
+ ],
+ 'StatusPreference' => [
+ 'break_return' => [
'ignore_severity',
- ),
- ),
- 'UFField' => array(
- 'cant_update' => array(
+ ],
+ ],
+ 'UFField' => [
+ 'cant_update' => [
// These fields get auto-adjusted by the BAO prior to saving
'weight',
'location_type_id',
'website_type_id',
// Not a real field
'option.autoweight',
- ),
- 'break_return' => array(
+ ],
+ 'break_return' => [
// These fields get auto-adjusted by the BAO prior to saving
'weight',
'field_type',
'website_type_id',
// Not a real field
'option.autoweight',
- ),
- ),
- 'JobLog' => array(
+ ],
+ ],
+ 'JobLog' => [
// For better or worse triggers override.
'break_return' => ['run_time'],
'cant_update' => ['run_time'],
- ),
- );
+ ],
+ ];
if (empty($knownFailures[$entity]) || empty($knownFailures[$entity][$key])) {
- return array();
+ return [];
}
return $knownFailures[$entity][$key];
}
* @param $Entity
*/
public function testNotImplemented_get($Entity) {
- $result = civicrm_api($Entity, 'Get', array('version' => 3));
+ $result = civicrm_api($Entity, 'Get', ['version' => 3]);
$this->assertEquals(1, $result['is_error']);
// $this->assertContains("API ($Entity, Get) does not exist", $result['error_message']);
$this->assertRegExp('/API (.*) does not exist/', $result['error_message']);
return;
}
- $result = civicrm_api($Entity, 'getfields', array('version' => 3));
+ $result = civicrm_api($Entity, 'getfields', ['version' => 3]);
$this->assertTrue(is_array($result['values']), "$Entity ::get fields doesn't return values array in line " . __LINE__);
foreach ($result['values'] as $key => $value) {
$this->assertTrue(is_array($value), $Entity . "::" . $key . " is not an array in line " . __LINE__);
// $this->markTestIncomplete("civicrm_api3_{$Entity}_get to be implemented");
return;
}
- $result = civicrm_api($Entity, 'Get', array());
+ $result = civicrm_api($Entity, 'Get', []);
$this->assertEquals(1, $result['is_error']);
$this->assertContains("Unknown api version", $result['error_message']);
}
if (in_array($Entity, $this->toBeImplemented['get'])) {
return;
}
- $result = civicrm_api($Entity, 'Get', array('version' => 3));
+ $result = civicrm_api($Entity, 'Get', ['version' => 3]);
// @TODO: list the get that have mandatory params
if ($result['is_error']) {
$this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
if ($entityName === 'Note') {
$this->markTestIncomplete('Note can not be processed here because of a vagary in the note api, it adds entity_table=contact to the get params when id is not present - which makes sense almost always but kills this test');
}
- $this->quickCleanup(array('civicrm_uf_match'));
+ $this->quickCleanup(['civicrm_uf_match']);
// so subsidiary activities are created
$this->createLoggedInUser();
}
// We are not passing 'check_permissions' so the the more limited permissions *should* be
// ignored but per CRM-17700 there is a history of custom data applying permissions when it shouldn't.
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'view my contact');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'view my contact'];
$objects = $this->getMockableBAOObjects($entityName, 1);
// simple custom field
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, $usableName . 'Test.php');
$customFieldName = 'custom_' . $ids['custom_field_id'];
- $params = array('id' => $objects[0]->id, 'custom_' . $ids['custom_field_id'] => "custom string");
+ $params = ['id' => $objects[0]->id, 'custom_' . $ids['custom_field_id'] => "custom string"];
$result = $this->callAPISuccess($entityName, 'create', $params);
$this->assertTrue(isset($result['id']), 'no id on ' . $entityName);
- $getParams = array('id' => $result['id'], 'return' => array($customFieldName));
+ $getParams = ['id' => $result['id'], 'return' => [$customFieldName]];
$check = $this->callAPISuccess($entityName, 'get', $getParams);
$this->assertTrue(!empty($check['values'][$check['id']][$customFieldName]), 'Custom data not present for ' . $entityName);
$this->assertEquals("custom string", $check['values'][$check['id']][$customFieldName], 'Custom data not present for ' . $entityName);
$this->customFieldDelete($ids2['custom_field_id']);
$this->customGroupDelete($ids2['custom_group_id']);
- $this->callAPISuccess($entityName, 'delete', array('id' => $result['id']));
- $this->quickCleanup(array('civicrm_uf_match'));
+ $this->callAPISuccess($entityName, 'delete', ['id' => $result['id']]);
+ $this->quickCleanup(['civicrm_uf_match']);
if (!empty($createdValue)) {
$this->callAPISuccess('OptionValue', 'delete', ['id' => $createdValue['id']]);
}
// we'll fix this once beta1 is released
// return;
- $result = civicrm_api($Entity, 'Get', array('version' => 3, 'id' => $nonExistantID));
+ $result = civicrm_api($Entity, 'Get', ['version' => 3, 'id' => $nonExistantID]);
if ($result['is_error']) {
// just to get a clearer message in the log
list($baoObj1, $baoObj2) = $baos;
// fetch first by ID
- $result = $this->callAPISuccess($entityName, 'get', array(
+ $result = $this->callAPISuccess($entityName, 'get', [
'id' => $baoObj1->id,
- ));
+ ]);
$this->assertTrue(!empty($result['values'][$baoObj1->id]), 'Should find first object by id');
$this->assertEquals($baoObj1->id, $result['values'][$baoObj1->id]['id'], 'Should find id on first object');
$this->assertEquals(1, count($result['values']));
// fetch second by ID
- $result = $this->callAPISuccess($entityName, 'get', array(
+ $result = $this->callAPISuccess($entityName, 'get', [
'id' => $baoObj2->id,
- ));
+ ]);
$this->assertTrue(!empty($result['values'][$baoObj2->id]), 'Should find second object by id');
$this->assertEquals($baoObj2->id, $result['values'][$baoObj2->id]['id'], 'Should find id on second object');
$this->assertEquals(1, count($result['values']));
*/
public function testLimit($entityName) {
// each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount)
- $cases = array();
- $cases[] = array(
- array('options' => array('limit' => NULL)),
+ $cases = [];
+ $cases[] = [
+ ['options' => ['limit' => NULL]],
30,
'check that a NULL limit returns unlimited',
- );
- $cases[] = array(
- array('options' => array('limit' => FALSE)),
+ ];
+ $cases[] = [
+ ['options' => ['limit' => FALSE]],
30,
'check that a FALSE limit returns unlimited',
- );
- $cases[] = array(
- array('options' => array('limit' => 0)),
+ ];
+ $cases[] = [
+ ['options' => ['limit' => 0]],
30,
'check that a 0 limit returns unlimited',
- );
- $cases[] = array(
- array('options' => array('limit' => 5)),
+ ];
+ $cases[] = [
+ ['options' => ['limit' => 5]],
5,
'check that a 5 limit returns 5',
- );
- $cases[] = array(
- array(),
+ ];
+ $cases[] = [
+ [],
25,
'check that no limit returns 25',
- );
+ ];
$baoString = _civicrm_api3_get_BAO($entityName);
if (empty($baoString)) {
}
// make 30 test items -- 30 > 25 (the default limit)
- $ids = array();
+ $ids = [];
for ($i = 0; $i < 30; $i++) {
- $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
+ $baoObj = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']);
$ids[] = $baoObj->id;
}
//non preferred / legacy syntax
if (isset($case[0]['options']['limit'])) {
- $this->checkLimitAgainstExpected($entityName, array('rowCount' => $case[0]['options']['limit']), $case[1], $case[2]);
- $this->checkLimitAgainstExpected($entityName, array('option_limit' => $case[0]['options']['limit']), $case[1], $case[2]);
- $this->checkLimitAgainstExpected($entityName, array('option.limit' => $case[0]['options']['limit']), $case[1], $case[2]);
+ $this->checkLimitAgainstExpected($entityName, ['rowCount' => $case[0]['options']['limit']], $case[1], $case[2]);
+ $this->checkLimitAgainstExpected($entityName, ['option_limit' => $case[0]['options']['limit']], $case[1], $case[2]);
+ $this->checkLimitAgainstExpected($entityName, ['option.limit' => $case[0]['options']['limit']], $case[1], $case[2]);
}
}
foreach ($ids as $id) {
- CRM_Core_DAO::deleteTestObjects($baoString, array('id' => $id));
+ CRM_Core_DAO::deleteTestObjects($baoString, ['id' => $id]);
}
}
$baoString = _civicrm_api3_get_BAO($entityName);
- $entities = $this->callAPISuccess($entityName, 'get', array('options' => array('limit' => 0), 'return' => 'id'));
+ $entities = $this->callAPISuccess($entityName, 'get', ['options' => ['limit' => 0], 'return' => 'id']);
$entities = array_keys($entities['values']);
$totalEntities = count($entities);
if ($totalEntities < 3) {
- $ids = array();
+ $ids = [];
for ($i = 0; $i < 3 - $totalEntities; $i++) {
- $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
+ $baoObj = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']);
$ids[] = $baoObj->id;
}
$totalEntities = 3;
}
- $entities = $this->callAPISuccess($entityName, 'get', array('options' => array('limit' => 0)));
+ $entities = $this->callAPISuccess($entityName, 'get', ['options' => ['limit' => 0]]);
$entities = array_keys($entities['values']);
$this->assertGreaterThan(2, $totalEntities);
- $this->callAPISuccess($entityName, 'getsingle', array('id' => array('IN' => array($entities[0]))));
- $this->callAPISuccessGetCount($entityName, array('id' => array('NOT IN' => array($entities[0]))), $totalEntities - 1);
- $this->callAPISuccessGetCount($entityName, array('id' => array('>' => $entities[0])), $totalEntities - 1);
+ $this->callAPISuccess($entityName, 'getsingle', ['id' => ['IN' => [$entities[0]]]]);
+ $this->callAPISuccessGetCount($entityName, ['id' => ['NOT IN' => [$entities[0]]]], $totalEntities - 1);
+ $this->callAPISuccessGetCount($entityName, ['id' => ['>' => $entities[0]]], $totalEntities - 1);
}
/**
$idFieldName = _civicrm_api_get_entity_name_from_camel($entityName) . '_id';
// create entities
- $baoObj1 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
+ $baoObj1 = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']);
$this->assertTrue(is_int($baoObj1->id), 'check first id');
$this->deletableTestObjects[$baoString][] = $baoObj1->id;
- $baoObj2 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
+ $baoObj2 = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']);
$this->assertTrue(is_int($baoObj2->id), 'check second id');
$this->deletableTestObjects[$baoString][] = $baoObj2->id;
// fetch first by ID
- $result = civicrm_api($entityName, 'get', array(
+ $result = civicrm_api($entityName, 'get', [
'version' => 3,
$idFieldName => $baoObj1->id,
- ));
+ ]);
$this->assertAPISuccess($result);
$this->assertTrue(!empty($result['values'][$baoObj1->id]), 'Should find first object by id');
$this->assertEquals($baoObj1->id, $result['values'][$baoObj1->id]['id'], 'Should find id on first object');
$this->assertEquals(1, count($result['values']));
// fetch second by ID
- $result = civicrm_api($entityName, 'get', array(
+ $result = civicrm_api($entityName, 'get', [
'version' => 3,
$idFieldName => $baoObj2->id,
- ));
+ ]);
$this->assertAPISuccess($result);
$this->assertTrue(!empty($result['values'][$baoObj2->id]), 'Should find second object by id');
$this->assertEquals($baoObj2->id, $result['values'][$baoObj2->id]['id'], 'Should find id on second object');
return;
}
- $result = civicrm_api($Entity, 'Get', array('version' => 3, 'id' => $nonExistantID));
+ $result = civicrm_api($Entity, 'Get', ['version' => 3, 'id' => $nonExistantID]);
// redundant with testAcceptsOnlyID_get
if ($result['is_error']) {
* @param $Entity
*/
public function testNotImplemented_create($Entity) {
- $result = civicrm_api($Entity, 'Create', array('version' => 3));
+ $result = civicrm_api($Entity, 'Create', ['version' => 3]);
$this->assertEquals(1, $result['is_error']);
$this->assertContains(strtolower("API ($Entity, Create) does not exist"), strtolower($result['error_message']));
}
* @throws \PHPUnit\Framework\IncompleteTestError
*/
public function testInvalidSort_get($Entity) {
- $invalidEntitys = array('ActivityType', 'Setting', 'System');
+ $invalidEntitys = ['ActivityType', 'Setting', 'System'];
if (in_array($Entity, $invalidEntitys)) {
$this->markTestSkipped('It seems OK for ' . $Entity . ' to skip here as it silently sips invalid params');
}
- $result = $this->callAPIFailure($Entity, 'get', array('options' => array('sort' => 'sleep(1)')));
+ $result = $this->callAPIFailure($Entity, 'get', ['options' => ['sort' => 'sleep(1)']]);
}
/**
* @throws \PHPUnit\Framework\IncompleteTestError
*/
public function testValidSortSingleArrayById_get($Entity) {
- $invalidEntitys = array('ActivityType', 'Setting', 'System');
- $tests = array(
+ $invalidEntitys = ['ActivityType', 'Setting', 'System'];
+ $tests = [
'id' => '_id',
'id desc' => '_id desc',
'id DESC' => '_id DESC',
'id ASC' => '_id ASC',
'id asc' => '_id asc',
- );
+ ];
foreach ($tests as $test => $expected) {
if (in_array($Entity, $invalidEntitys)) {
$this->markTestSkipped('It seems OK for ' . $Entity . ' to skip here as it silently ignores passed in params');
}
- $params = array('sort' => array($test));
+ $params = ['sort' => [$test]];
$result = _civicrm_api3_get_options_from_params($params, FALSE, $Entity, 'get');
$lowercase_entity = _civicrm_api_get_entity_name_from_camel($Entity);
$this->assertEquals($lowercase_entity . $expected, $result['sort']);
// $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
return;
}
- $result = $this->callAPIFailure($Entity, 'Create', array('id' => 999));
+ $result = $this->callAPIFailure($Entity, 'Create', ['id' => 999]);
}
/**
$baoString = _civicrm_api3_get_BAO($entityName);
$this->assertNotEmpty($baoString, $entityName);
$this->assertNotEmpty($entityName, $entityName);
- $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get', 'options' => array('get_options' => 'all')));
+ $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', ['action' => 'get', 'options' => ['get_options' => 'all']]);
if ($entityName != 'Pledge') {
- $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create', 'options' => array('get_options' => 'all')));
+ $fields = $this->callAPISuccess($entityName, 'getfields', ['action' => 'create', 'options' => ['get_options' => 'all']]);
}
$fields = $fields['values'];
$return = array_keys($fieldsGet['values']);
$return = array_diff($return, $valuesNotToReturn);
$baoObj = new CRM_Core_DAO();
- $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0);
+ $baoObj->createTestObject($baoString, ['currency' => 'USD'], 2, 0);
- $getEntities = $this->callAPISuccess($entityName, 'get', array(
+ $getEntities = $this->callAPISuccess($entityName, 'get', [
'sequential' => 1,
'return' => $return,
- 'options' => array(
+ 'options' => [
'sort' => 'id DESC',
'limit' => 2,
- ),
- ));
+ ],
+ ]);
// lets use first rather than assume only one exists
$entity = $getEntities['values'][0];
// http://forum.civicrm.org/index.php/topic,33990.0.html
// See also my question on the CiviCRM Stack Exchange:
// https://civicrm.stackexchange.com/questions/3437
- $entity[$fieldName] = array('sort_name' => "SortName2");
+ $entity[$fieldName] = ['sort_name' => "SortName2"];
}
else {
$entity[$fieldName] = substr('New String', 0, CRM_Utils_Array::Value('maxlength', $specs, 100));
$entity[$fieldName] = strtolower($entity[$fieldName]);
}
// typecast with array to satisfy changes made in CRM-13160
- if ($entityName == 'MembershipType' && in_array($fieldName, array(
+ if ($entityName == 'MembershipType' && in_array($fieldName, [
'relationship_type_id',
'relationship_direction',
- ))) {
+ ])) {
$entity[$fieldName] = (array) $entity[$fieldName];
}
}
}
else {
if (!empty($entity[$fieldName])) {
- $resetFKTo = array($fieldName => $entity[$fieldName]);
+ $resetFKTo = [$fieldName => $entity[$fieldName]];
}
$entity[$fieldName] = (string) empty($entity2[$field]) ? '' : $entity2[$field];
//todo - there isn't always something set here - & our checking on unset values is limited
$entity[$field] = 'warm.beer.com';
}
if (empty($specs['FKClassName']) && (!empty($specs['pseudoconstant']) || !empty($specs['options']))) {
- $options = CRM_Utils_Array::value('options', $specs, array());
+ $options = CRM_Utils_Array::value('options', $specs, []);
if (!$options) {
//eg. pdf_format id doesn't ship with any
if (isset($specs['pseudoconstant']['optionGroupName'])) {
- $optionValue = $this->callAPISuccess('option_value', 'create', array(
+ $optionValue = $this->callAPISuccess('option_value', 'create', [
'option_group_id' => $specs['pseudoconstant']['optionGroupName'],
'label' => 'new option value',
'sequential' => 1,
- ));
+ ]);
$optionValue = $optionValue['values'];
$keyColumn = CRM_Utils_Array::value('keyColumn', $specs['pseudoconstant'], 'value');
$options[$optionValue[0][$keyColumn]] = 'new option value';
// in the weird situation where a field has both an fk and pseudoconstant defined,
// e.g. campaign_id field, need to flush caches.
// FIXME: Why doesn't creating a campaign clear caches?
- civicrm_api3($entityName, 'getfields', array('cache_clear' => 1));
+ civicrm_api3($entityName, 'getfields', ['cache_clear' => 1]);
}
- $updateParams = array(
+ $updateParams = [
'id' => $entity['id'],
$field => isset($entity[$field]) ? $entity[$field] : NULL,
- );
- if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
+ ];
+ if (isset($updateParams['financial_type_id']) && in_array($entityName, ['Grant'])) {
//api has special handling on these 2 fields for backward compatibility reasons
$entity['contribution_type_id'] = $updateParams['financial_type_id'];
}
- if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, array('ContributionRecur'))) {
+ if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, ['ContributionRecur'])) {
//api has special handling on these 2 fields for backward compatibility reasons
$entity['next_sched_contribution'] = $updateParams['next_sched_contribution_date'];
}
}
$update = $this->callAPISuccess($entityName, 'create', $updateParams);
- $checkParams = array(
+ $checkParams = [
'id' => $entity['id'],
'sequential' => 1,
'return' => $return,
- 'options' => array(
+ 'options' => [
'sort' => 'id DESC',
'limit' => 2,
- ),
- );
+ ],
+ ];
$checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
if (!empty($specs['serialize']) && !is_array($checkEntity[$field])) {
$entity[$field] = CRM_Core_DAO::serializeField($checkEntity[$field], $specs['serialize']);
}
- $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if $fieldName was correctly updated\n" . print_r(array(
+ $this->assertAPIArrayComparison($entity, $checkEntity, [], "checking if $fieldName was correctly updated\n" . print_r([
'update-params' => $updateParams,
'update-result' => $update,
'getsingle-params' => $checkParams,
'getsingle-result' => $checkEntity,
'expected entity' => $entity,
- ), TRUE));
+ ], TRUE));
if ($resetFKTo) {
//reset the foreign key fields because otherwise our cleanup routine fails & some other unexpected stuff can kick in
$entity = array_merge($entity, $resetFKTo);
$updateParams = array_merge($updateParams, $resetFKTo);
$this->callAPISuccess($entityName, 'create', $updateParams);
- if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
+ if (isset($updateParams['financial_type_id']) && in_array($entityName, ['Grant'])) {
//api has special handling on these 2 fields for backward compatibility reasons
$entity['contribution_type_id'] = $updateParams['financial_type_id'];
}
- if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, array('ContributionRecur'))) {
+ if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, ['ContributionRecur'])) {
//api has special handling on these 2 fields for backward compatibility reasons
$entity['next_sched_contribution'] = $updateParams['next_sched_contribution_date'];
}
*/
public function testNotImplemented_delete($Entity) {
$nonExistantID = 151416349;
- $result = civicrm_api($Entity, 'Delete', array('version' => 3, 'id' => $nonExistantID));
+ $result = civicrm_api($Entity, 'Delete', ['version' => 3, 'id' => $nonExistantID]);
$this->assertEquals(1, $result['is_error']);
$this->assertContains(strtolower("API ($Entity, Delete) does not exist"), strtolower($result['error_message']));
}
// $this->markTestIncomplete("civicrm_api3_{$Entity}_delete to be implemented");
return;
}
- $result = civicrm_api($Entity, 'Delete', array());
+ $result = civicrm_api($Entity, 'Delete', []);
$this->assertEquals(1, $result['is_error']);
$this->assertContains("Unknown api version", $result['error_message']);
}
* @throws \PHPUnit\Framework\IncompleteTestError
*/
public function testInvalidID_delete($Entity) {
- $result = $this->callAPIFailure($Entity, 'Delete', array('id' => 999999));
+ $result = $this->callAPIFailure($Entity, 'Delete', ['id' => 999999]);
}
/**
// $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
return;
}
- $startCount = $this->callAPISuccess($entityName, 'getcount', array());
+ $startCount = $this->callAPISuccess($entityName, 'getcount', []);
$createcount = 2;
$baos = $this->getMockableBAOObjects($entityName, $createcount);
list($baoObj1, $baoObj2) = $baos;
// make sure exactly 2 exist
- $result = $this->callAPISuccess($entityName, 'getcount', array(),
+ $result = $this->callAPISuccess($entityName, 'getcount', [],
$createcount + $startCount
);
- $this->callAPISuccess($entityName, 'delete', array('id' => $baoObj2->id));
+ $this->callAPISuccess($entityName, 'delete', ['id' => $baoObj2->id]);
//make sure 1 less exists now
- $result = $this->callAPISuccess($entityName, 'getcount', array(),
+ $result = $this->callAPISuccess($entityName, 'getcount', [],
($createcount + $startCount) - 1
);
//make sure id #1 exists
- $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj1->id),
+ $result = $this->callAPISuccess($entityName, 'getcount', ['id' => $baoObj1->id],
1
);
//make sure id #2 desn't exist
- $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj2->id),
+ $result = $this->callAPISuccess($entityName, 'getcount', ['id' => $baoObj2->id],
0
);
}
if (in_array($entity, $entities)) {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, $entity . 'Test.php');
}
- $actions = $this->callAPISuccess($entity, 'getactions', array());
+ $actions = $this->callAPISuccess($entity, 'getactions', []);
foreach ($actions['values'] as $action) {
if (substr($action, -7) == '_create' || substr($action, -4) == '_get' || substr($action, -7) == '_delete') {
//getactions can't distinguish between contribution_page.create & contribution_page.create
continue;
}
- $fields = $this->callAPISuccess($entity, 'getfields', array('action' => $action));
- if (!empty($ids) && in_array($action, array('create', 'get'))) {
+ $fields = $this->callAPISuccess($entity, 'getfields', ['action' => $action]);
+ if (!empty($ids) && in_array($action, ['create', 'get'])) {
$this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $fields['values']);
}
*/
public function getEntitiesSupportingCustomFields() {
$entities = self::custom_data_entities_get();
- $returnEntities = array();
+ $returnEntities = [];
foreach ($entities as $entityArray) {
$returnEntities[] = $entityArray[0];
}
$baoString = _civicrm_api3_get_BAO($entityName);
if (empty($baoString)) {
$this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
- return array();
+ return [];
}
- $baos = array();
+ $baos = [];
$i = 0;
while ($i < $count) {
// create entities
- $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
+ $baoObj = CRM_Core_DAO::createTestObject($baoString, ['currency' => 'USD']);
$this->assertTrue(is_int($baoObj->id), 'check first id');
$this->deletableTestObjects[$baoString][] = $baoObj->id;
$baos[] = $baoObj;
*/
public function testEncodeDecodeConsistency() {
// Create example
- $createResult = civicrm_api('Event', 'Create', array(
+ $createResult = civicrm_api('Event', 'Create', [
'version' => 3,
'title' => 'CiviCRM <> TheRest',
'description' => 'TheRest <> CiviCRM',
'event_type_id' => 1,
'is_public' => 1,
'start_date' => 20081021,
- ));
+ ]);
$this->assertAPISuccess($createResult);
$eventId = $createResult['id'];
$this->assertEquals('CiviCRM <> TheRest', $createResult['values'][$eventId]['title']);
$this->assertEquals('TheRest <> CiviCRM', $createResult['values'][$eventId]['description']);
// Verify "get" handles decoding in result value
- $getByIdResult = civicrm_api('Event', 'Get', array(
+ $getByIdResult = civicrm_api('Event', 'Get', [
'version' => 3,
'id' => $eventId,
- ));
+ ]);
$this->assertAPISuccess($getByIdResult);
$this->assertEquals('CiviCRM <> TheRest', $getByIdResult['values'][$eventId]['title']);
$this->assertEquals('TheRest <> CiviCRM', $getByIdResult['values'][$eventId]['description']);
// Verify "get" handles encoding in search value
- $getByTitleResult = civicrm_api('Event', 'Get', array(
+ $getByTitleResult = civicrm_api('Event', 'Get', [
'version' => 3,
'title' => 'CiviCRM <> TheRest',
- ));
+ ]);
$this->assertAPISuccess($getByTitleResult);
$this->assertEquals('CiviCRM <> TheRest', $getByTitleResult['values'][$eventId]['title']);
$this->assertEquals('TheRest <> CiviCRM', $getByTitleResult['values'][$eventId]['description']);
// Verify that "getSingle" handles decoding
- $getSingleResult = $this->callAPISuccess('Event', 'GetSingle', array(
+ $getSingleResult = $this->callAPISuccess('Event', 'GetSingle', [
'id' => $eventId,
- ));
+ ]);
$this->assertEquals('CiviCRM <> TheRest', $getSingleResult['title']);
$this->assertEquals('TheRest <> CiviCRM', $getSingleResult['description']);
// Verify that chaining handles decoding
- $chainResult = $this->callAPISuccess('Event', 'Get', array(
+ $chainResult = $this->callAPISuccess('Event', 'Get', [
'id' => $eventId,
- 'api.event.get' => array(),
- ));
+ 'api.event.get' => [],
+ ]);
$this->assertEquals('CiviCRM <> TheRest', $chainResult['values'][$eventId]['title']);
$this->assertEquals('TheRest <> CiviCRM', $chainResult['values'][$eventId]['description']);
$this->assertEquals('CiviCRM <> TheRest', $chainResult['values'][$eventId]['api.event.get']['values'][0]['title']);
$this->assertEquals('TheRest <> CiviCRM', $chainResult['values'][$eventId]['api.event.get']['values'][0]['description']);
// Verify that "setvalue" handles encoding for updates
- $setValueTitleResult = civicrm_api('Event', 'setvalue', array(
+ $setValueTitleResult = civicrm_api('Event', 'setvalue', [
'version' => 3,
'id' => $eventId,
'field' => 'title',
'value' => 'setValueTitle: CiviCRM <> TheRest',
- ));
+ ]);
$this->assertAPISuccess($setValueTitleResult);
$this->assertEquals('setValueTitle: CiviCRM <> TheRest', $setValueTitleResult['values']['title']);
- $setValueDescriptionResult = civicrm_api('Event', 'setvalue', array(
+ $setValueDescriptionResult = civicrm_api('Event', 'setvalue', [
'version' => 3,
'id' => $eventId,
'field' => 'description',
'value' => 'setValueDescription: TheRest <> CiviCRM',
- ));
+ ]);
//$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue
$this->assertEquals('setValueDescription: TheRest <> CiviCRM', $setValueDescriptionResult['values']['description']);
}
*/
public function testEncodeWrite() {
// Create example
- $createResult = civicrm_api('Event', 'Create', array(
+ $createResult = civicrm_api('Event', 'Create', [
'version' => 3,
'title' => 'createNew: CiviCRM <> TheRest',
'description' => 'createNew: TheRest <> CiviCRM',
'event_type_id' => 1,
'is_public' => 1,
'start_date' => 20081021,
- ));
+ ]);
$this->assertAPISuccess($createResult);
$eventId = $createResult['id'];
- $this->assertDBQuery('createNew: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
- 1 => array($eventId, 'Integer'),
- ));
- $this->assertDBQuery('createNew: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
- 1 => array($eventId, 'Integer'),
- ));
+ $this->assertDBQuery('createNew: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', [
+ 1 => [$eventId, 'Integer'],
+ ]);
+ $this->assertDBQuery('createNew: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', [
+ 1 => [$eventId, 'Integer'],
+ ]);
// Verify that "create" handles encoding for updates
- $createWithIdResult = civicrm_api('Event', 'Create', array(
+ $createWithIdResult = civicrm_api('Event', 'Create', [
'version' => 3,
'id' => $eventId,
'title' => 'createWithId: CiviCRM <> TheRest',
'description' => 'createWithId: TheRest <> CiviCRM',
- ));
+ ]);
$this->assertAPISuccess($createWithIdResult);
- $this->assertDBQuery('createWithId: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
- 1 => array($eventId, 'Integer'),
- ));
- $this->assertDBQuery('createWithId: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
- 1 => array($eventId, 'Integer'),
- ));
+ $this->assertDBQuery('createWithId: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', [
+ 1 => [$eventId, 'Integer'],
+ ]);
+ $this->assertDBQuery('createWithId: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', [
+ 1 => [$eventId, 'Integer'],
+ ]);
// Verify that "setvalue" handles encoding for updates
- $setValueTitleResult = civicrm_api('Event', 'setvalue', array(
+ $setValueTitleResult = civicrm_api('Event', 'setvalue', [
'version' => 3,
'id' => $eventId,
'field' => 'title',
'value' => 'setValueTitle: CiviCRM <> TheRest',
- ));
+ ]);
$this->assertAPISuccess($setValueTitleResult);
- $this->assertDBQuery('setValueTitle: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
- 1 => array($eventId, 'Integer'),
- ));
- $setValueDescriptionResult = civicrm_api('Event', 'setvalue', array(
+ $this->assertDBQuery('setValueTitle: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', [
+ 1 => [$eventId, 'Integer'],
+ ]);
+ $setValueDescriptionResult = civicrm_api('Event', 'setvalue', [
'version' => 3,
'id' => $eventId,
'field' => 'description',
'value' => 'setValueDescription: TheRest <> CiviCRM',
- ));
+ ]);
//$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue
$this->assertAPISuccess($setValueDescriptionResult);
- $this->assertDBQuery('setValueDescription: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
- 1 => array($eventId, 'Integer'),
- ));
+ $this->assertDBQuery('setValueDescription: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', [
+ 1 => [$eventId, 'Integer'],
+ ]);
}
}
*/
public function testSystemCheckBasic($version) {
$this->_apiversion = $version;
- $result = $this->callAPISuccess('System', 'check', array());
+ $result = $this->callAPISuccess('System', 'check', []);
foreach ($result['values'] as $check) {
if ($check['name'] == 'checkDefaultMailbox') {
$testedCheck = $check;
*/
public function testSystemCheckHushForever($version) {
$this->_apiversion = $version;
- $this->_params = array(
+ $this->_params = [
'name' => 'checkDefaultMailbox',
'ignore_severity' => 7,
- );
+ ];
$statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
- $result = $this->callAPISuccess('System', 'check', array());
+ $result = $this->callAPISuccess('System', 'check', []);
foreach ($result['values'] as $check) {
if ($check['name'] == 'checkDefaultMailbox') {
$testedCheck = $check;
break;
}
else {
- $testedCheck = array();
+ $testedCheck = [];
}
}
$this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
public function testSystemCheckHushFuture($version) {
$this->_apiversion = $version;
$tomorrow = new DateTime('tomorrow');
- $this->_params = array(
+ $this->_params = [
'name' => 'checkDefaultMailbox',
'ignore_severity' => 7,
'hush_until' => $tomorrow->format('Y-m-d'),
- );
+ ];
$statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
- $result = $this->callAPISuccess('System', 'check', array());
+ $result = $this->callAPISuccess('System', 'check', []);
foreach ($result['values'] as $check) {
if ($check['name'] == 'checkDefaultMailbox') {
$testedCheck = $check;
break;
}
else {
- $testedCheck = array();
+ $testedCheck = [];
}
}
$this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);;
public function testSystemCheckHushToday($version) {
$this->_apiversion = $version;
$today = new DateTime('today');
- $this->_params = array(
+ $this->_params = [
'name' => 'checkDefaultMailbox',
'ignore_severity' => 7,
'hush_until' => $today->format('Y-m-d'),
- );
+ ];
$statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
- $result = $this->callAPISuccess('System', 'check', array());
+ $result = $this->callAPISuccess('System', 'check', []);
foreach ($result['values'] as $check) {
if ($check['name'] == 'checkDefaultMailbox') {
$testedCheck = $check;
break;
}
else {
- $testedCheck = array();
+ $testedCheck = [];
}
}
$this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
public function testSystemCheckHushYesterday($version) {
$this->_apiversion = $version;
$yesterday = new DateTime('yesterday');
- $this->_params = array(
+ $this->_params = [
'name' => 'checkDefaultMailbox',
'ignore_severity' => 7,
'hush_until' => $yesterday->format('Y-m-d'),
- );
+ ];
$statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
- $result = $this->callAPISuccess('System', 'check', array());
+ $result = $this->callAPISuccess('System', 'check', []);
foreach ($result['values'] as $check) {
if ($check['name'] == 'checkDefaultMailbox') {
$testedCheck = $check;
break;
}
else {
- $testedCheck = array();
+ $testedCheck = [];
}
}
$this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
*/
public function testSystemCheckHushAboveSeverity($version) {
$this->_apiversion = $version;
- $this->_params = array(
+ $this->_params = [
'name' => 'checkDefaultMailbox',
'ignore_severity' => 4,
- );
+ ];
$statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
- $result = $this->callAPISuccess('System', 'check', array());
+ $result = $this->callAPISuccess('System', 'check', []);
foreach ($result['values'] as $check) {
if ($check['name'] == 'checkDefaultMailbox') {
$testedCheck = $check;
break;
}
else {
- $testedCheck = array();
+ $testedCheck = [];
}
}
$this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
*/
public function testSystemCheckHushAtSeverity($version) {
$this->_apiversion = $version;
- $this->_params = array(
+ $this->_params = [
'name' => 'checkDefaultMailbox',
'ignore_severity' => 3,
- );
+ ];
$this->callAPISuccess('StatusPreference', 'create', $this->_params);
$result = $this->callAPISuccess('System', 'check');
foreach ($result['values'] as $check) {
break;
}
else {
- $testedCheck = array();
+ $testedCheck = [];
}
}
$this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
*/
public function testSystemCheckHushBelowSeverity($version) {
$this->_apiversion = $version;
- $this->_params = array(
+ $this->_params = [
'name' => 'checkDefaultMailbox',
'ignore_severity' => 2,
- );
+ ];
$statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
- $result = $this->callAPISuccess('System', 'check', array());
+ $result = $this->callAPISuccess('System', 'check', []);
foreach ($result['values'] as $check) {
if ($check['name'] == 'checkDefaultMailbox') {
$testedCheck = $check;
break;
}
else {
- $testedCheck = array();
+ $testedCheck = [];
}
}
$this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
$this->assertEquals('abc', Civi::cache()->get(CRM_Utils_Cache::cleanKey(self::TEST_CACHE_PATH)));
- $params = array();
+ $params = [];
$result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush');
$this->assertTrue(NULL === Civi::cache()->get(CRM_Utils_Cache::cleanKey(self::TEST_CACHE_PATH)));
* Test system log function.
*/
public function testSystemLog() {
- $this->callAPISuccess('system', 'log', array('level' => 'info', 'message' => 'We wish you a merry Christmas'));
- $result = $this->callAPISuccess('SystemLog', 'getsingle', array(
+ $this->callAPISuccess('system', 'log', ['level' => 'info', 'message' => 'We wish you a merry Christmas']);
+ $result = $this->callAPISuccess('SystemLog', 'getsingle', [
'sequential' => 1,
- 'message' => array('LIKE' => '%Chris%'),
- ));
+ 'message' => ['LIKE' => '%Chris%'],
+ ]);
$this->assertEquals($result['message'], 'We wish you a merry Christmas');
$this->assertEquals($result['level'], 'info');
}
* Test system log function.
*/
public function testSystemLogNoLevel() {
- $this->callAPISuccess('system', 'log', array('message' => 'We wish you a merry Christmas', 'level' => 'alert'));
- $result = $this->callAPISuccess('SystemLog', 'getsingle', array(
+ $this->callAPISuccess('system', 'log', ['message' => 'We wish you a merry Christmas', 'level' => 'alert']);
+ $result = $this->callAPISuccess('SystemLog', 'getsingle', [
'sequential' => 1,
- 'message' => array('LIKE' => '%Chris%'),
- ));
+ 'message' => ['LIKE' => '%Chris%'],
+ ]);
$this->assertEquals($result['message'], 'We wish you a merry Christmas');
$this->assertEquals($result['level'], 'alert');
}
public function testSystemGet() {
- $result = $this->callAPISuccess('system', 'get', array());
+ $result = $this->callAPISuccess('system', 'get', []);
$this->assertRegExp('/^[0-9]+\.[0-9]+\.[0-9a-z\-]+$/', $result['values'][0]['version']);
$this->assertEquals('UnitTests', $result['values'][0]['uf']);
}
* @var array
* @ids array of values to be cleaned up in the tear down
*/
- protected $ids = array();
+ protected $ids = [];
/**
* Tag id.
*
* @var int
*/
- protected $tag = array();
+ protected $tag = [];
protected $tagID;
*/
public function testGetWrongParams($version) {
$this->_apiversion = $version;
- $params = array('name' => 'Wrong Tag Name');
+ $params = ['name' => 'Wrong Tag Name'];
$result = $this->callAPISuccess('tag', 'get', $params);
$this->assertEquals(0, $result['count']);
}
*/
public function testGet($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'id' => $this->tagID,
'name' => $this->tag['name'],
- );
+ ];
$result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($this->tag['description'], $result['values'][$this->tagID]['description']);
$this->assertEquals($this->tag['name'], $result['values'][$this->tagID]['name']);
$description = "Demonstrates use of Return as an array.";
$subfile = "GetReturnArray";
- $params = array(
+ $params = [
'id' => $this->tagID,
'name' => $this->tag['name'],
- 'return' => array('name'),
- );
+ 'return' => ['name'],
+ ];
$result = $this->callAPIAndDocument('tag', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertTrue(empty($result['values'][$this->tagID]['description']));
$this->assertEquals($this->tag['name'], $result['values'][$this->tagID]['name']);
*/
public function testCreateEmptyParams($version) {
$this->_apiversion = $version;
- $result = $this->callAPIFailure('tag', 'create', array(), 'name');
+ $result = $this->callAPIFailure('tag', 'create', [], 'name');
}
/**
*/
public function testCreatePasstagInParams($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'tag' => 10,
'name' => 'New Tag23',
'description' => 'This is description for New Tag 02',
- );
+ ];
$result = $this->callAPISuccess('tag', 'create', $params);
$this->assertEquals(10, $result['id']);
}
* Skipping v4 because used_for is an array
*/
public function testCreate() {
- $params = array(
+ $params = [
'name' => 'Super Heros',
'description' => 'Outside undie-wearers',
- );
+ ];
$result = $this->callAPIAndDocument('tag', 'create', $params, __FUNCTION__, __FILE__);
$this->assertNotNull($result['id']);
$params['used_for'] = 'civicrm_contact';
* Skipping v4 because used_for is an array
*/
public function testCreateEntitySpecificTag() {
- $params = array(
+ $params = [
'name' => 'New Tag4',
'description' => 'This is description for New Activity tag',
'used_for' => 'civicrm_activity',
- );
+ ];
$result = $this->callAPISuccess('tag', 'create', $params);
- $this->callAPISuccess('tag', 'get', array());
+ $this->callAPISuccess('tag', 'get', []);
$this->getAndCheck($params, $result['id'], 'tag', 0, __FUNCTION__ . ' tag first created');
unset($params['used_for']);
$params['id'] = $result['id'];
*/
public function testDeleteWithoutTagId($version) {
$this->_apiversion = $version;
- $result = $this->callAPIFailure('tag', 'delete', array());
+ $result = $this->callAPIFailure('tag', 'delete', []);
}
/**
*/
public function testTagDeleteOldSyntax($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'tag_id' => $this->tagID,
- );
+ ];
$result = $this->callAPISuccess('tag', 'delete', $params);
unset($this->ids['tag']);
}
*/
public function testTagDeleteCorrectSyntax($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'id' => $this->tagID,
- );
+ ];
$result = $this->callAPIAndDocument('tag', 'delete', $params, __FUNCTION__, __FILE__);
unset($this->ids['tag']);
}
public function testTagGetfields() {
$description = "Demonstrate use of getfields to interrogate api.";
- $params = array('action' => 'create');
+ $params = ['action' => 'create'];
$result = $this->callAPIAndDocument('tag', 'getfields', $params, __FUNCTION__, __FILE__, $description, NULL);
$this->assertEquals('civicrm_contact', $result['values']['used_for']['api.default']);
}
public function testTagGetList() {
$description = "Demonstrates use of api.getlist for autocomplete and quicksearch applications.";
- $params = array(
+ $params = [
'input' => $this->tag['name'],
- 'extra' => array('used_for'),
- );
+ 'extra' => ['used_for'],
+ ];
$result = $this->callAPIAndDocument('tag', 'getlist', $params, __FUNCTION__, __FILE__, $description);
$this->assertEquals($this->tag['id'], $result['values'][0]['id']);
$this->assertEquals($this->tag['description'], $result['values'][0]['description'][0]);
protected $financialtypeID;
protected $financialAccountId;
protected $_entity = 'contribution_page';
- protected $_priceSetParams = array();
+ protected $_priceSetParams = [];
protected $_paymentProcessorType;
- protected $payParams = array();
- protected $paymentProceParams = array();
- protected $settingValue = array();
+ protected $payParams = [];
+ protected $paymentProceParams = [];
+ protected $settingValue = [];
protected $setInvoiceSettings;
- protected $_ids = array();
+ protected $_ids = [];
protected $_individualId;
protected $financialAccHalftax;
protected $financialtypeHalftax;
$this->_individualId = $this->individualCreate();
$this->_orgId = $this->organizationCreate(NULL);
- $this->params = array(
+ $this->params = [
'title' => "Test Contribution Page" . substr(sha1(rand()), 0, 7),
'financial_type_id' => 1,
'payment_processor' => 1,
'pay_later_receipt' => "I will pay later",
'is_monetary' => TRUE,
'is_billing_required' => TRUE,
- );
+ ];
- $this->_priceSetParams = array(
+ $this->_priceSetParams = [
'name' => 'tax_contribution' . substr(sha1(rand()), 0, 7),
'title' => 'contributiontax' . substr(sha1(rand()), 0, 7),
'is_active' => 1,
'financial_type_id' => 3,
'is_quick_config' => 0,
'is_reserved' => 0,
- );
+ ];
// Financial Account with 20% tax rate
- $financialAccountSetparams = array(
+ $financialAccountSetparams = [
#[domain_id] =>
'name' => 'vat full taxrate account' . substr(sha1(rand()), 0, 7),
'contact_id' => $this->_orgId,
'is_reserved' => 0,
'is_active' => 1,
'is_default' => 0,
- );
+ ];
$financialAccount = $this->callAPISuccess('financial_account', 'create', $financialAccountSetparams);
$this->financialAccountId = $financialAccount['id'];
// Financial type having 'Sales Tax Account is' with liability financail account
- $financialType = array(
+ $financialType = [
'name' => 'grassvariety1' . substr(sha1(rand()), 0, 7),
'is_reserved' => 0,
'is_active' => 1,
- );
+ ];
$priceField = $this->callAPISuccess('financial_type', 'create', $financialType);
$this->financialtypeID = $priceField['id'];
- $financialRelationParams = array(
+ $financialRelationParams = [
'entity_table' => 'civicrm_financial_type',
'entity_id' => $this->financialtypeID,
'account_relationship' => 10,
'financial_account_id' => $this->financialAccountId,
- );
+ ];
$financialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationParams);
// Financial type with 5% tax rate
- $financialAccHalftax = array(
+ $financialAccHalftax = [
'name' => 'vat half taxrate account' . substr(sha1(rand()), 0, 7),
'contact_id' => $this->_orgId,
'financial_account_type_id' => 2,
'is_reserved' => 0,
'is_active' => 1,
'is_default' => 0,
- );
+ ];
$halfFinancialAccount = CRM_Financial_BAO_FinancialAccount::add($financialAccHalftax);
$this->halfFinancialAccId = $halfFinancialAccount->id;
- $halfFinancialtypeHalftax = array(
+ $halfFinancialtypeHalftax = [
'name' => 'grassvariety2' . substr(sha1(rand()), 0, 7),
'is_reserved' => 0,
'is_active' => 1,
- );
+ ];
$halfFinancialType = CRM_Financial_BAO_FinancialType::add($halfFinancialtypeHalftax);
$this->halfFinancialTypeId = $halfFinancialType->id;
- $financialRelationHalftax = array(
+ $financialRelationHalftax = [
'entity_table' => 'civicrm_financial_type',
'entity_id' => $this->halfFinancialTypeId,
'account_relationship' => 10,
'financial_account_id' => $this->halfFinancialAccId,
- );
+ ];
$halfFinancialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationHalftax);
$setInvoiceSettings = $this->enableTaxAndInvoicing();
// Payment Processor
- $paymentProceParams = array(
+ $paymentProceParams = [
'domain_id' => 1,
'name' => 'dummy' . substr(sha1(rand()), 0, 7),
'payment_processor_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Financial_BAO_PaymentProcessor', 'payment_processor_type_id', 'Dummy'),
'billing_mode' => 1,
'is_recur' => 1,
'payment_type' => 1,
- );
+ ];
$result = $this->callAPISuccess('payment_processor', 'create', $paymentProceParams);
$this->_ids['paymentProcessID'] = $result['id'];
require_once 'api/v3/examples/PaymentProcessor/Create.php';
CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
if (empty($this->_ids['price_field'])) {
- $priceField = $this->callAPISuccess('price_field', 'create', array(
+ $priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => $priceSetID,
'label' => 'Goat Breed',
'html_type' => 'Radio',
- ));
- $this->_ids['price_field'] = array($priceField['id']);
+ ]);
+ $this->_ids['price_field'] = [$priceField['id']];
}
if (empty($this->_ids['price_field_value'])) {
- $this->callAPISuccess('price_field_value', 'create', array(
+ $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Long Haired Goat',
'amount' => 100,
'financial_type_id' => $this->financialtypeID,
- ));
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array(
+ ]);
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Shoe-eating Goat',
'amount' => 300,
'financial_type_id' => $this->halfFinancialTypeId,
- ));
- $this->_ids['price_field_value'] = array($priceFieldValue['id']);
+ ]);
+ $this->_ids['price_field_value'] = [$priceFieldValue['id']];
}
$this->_ids['contribution_page'] = $contributionPageResult['id'];
}
public function testCreateContributionOnline($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$this->setUpContributionPage();
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => $this->formatMoneyInput(100.00),
'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$this->_ids['contributionId'] = $contribution['id'];
public function testCreateContributionChainedLineItems($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$this->setUpContributionPage();
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 400.00,
'source' => 'SSF',
'contribution_status_id' => 1,
'skipLineItem' => 1,
- 'api.line_item.create' => array(
- array(
+ 'api.line_item.create' => [
+ [
'price_field_id' => $this->_ids['price_field'],
'qty' => 1,
'line_total' => '100',
'unit_price' => '100',
'financial_type_id' => $this->financialtypeID,
- ),
- array(
+ ],
+ [
'price_field_id' => $this->_ids['price_field'],
'qty' => 1,
'line_total' => '300',
'unit_price' => '300',
'financial_type_id' => $this->halfFinancialTypeId,
- ),
- ),
- );
+ ],
+ ],
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params);
- $lineItems = $this->callAPISuccess('line_item', 'get', array(
+ $lineItems = $this->callAPISuccess('line_item', 'get', [
'entity_id' => $contribution['id'],
'contribution_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
- ));
+ ]);
$this->assertEquals(2, $lineItems['count']);
}
public function testCreateContributionPayLaterOnline() {
$this->setUpContributionPage();
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 2,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
$this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00);
public function testCreateContributionPendingOnline($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$this->setUpContributionPage();
- $params = array(
+ $params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => $this->formatMoneyInput(100.00),
'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 2,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId);
*/
public function testCreateUpdateContributionChangeTotal() {
$this->setUpContributionPage();
- $this->contributionParams = array(
+ $this->contributionParams = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'financial_type_id' => $this->financialtypeID,
'source' => 'SSF',
'contribution_status_id' => 1,
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $this->contributionParams);
- $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
+ $lineItems = $this->callAPISuccess('line_item', 'getvalue', [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
'return' => 'line_total',
- ));
+ ]);
$this->assertEquals('100.00', $lineItems);
$trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
$this->assertEquals('120.00', $trxnAmount);
- $newParams = array(
+ $newParams = [
'id' => $contribution['id'],
// without tax rate i.e Donation
'financial_type_id' => 1,
'total_amount' => '300',
- );
+ ];
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
- $lineItems = $this->callAPISuccess('line_item', 'getvalue', array(
+ $lineItems = $this->callAPISuccess('line_item', 'getvalue', [
'entity_id' => $contribution['id'],
'entity_table' => 'civicrm_contribution',
'sequential' => 1,
'return' => 'line_total',
- ));
+ ]);
$this->assertEquals('300.00', $lineItems);
$trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
* @param $context
*/
public function _checkFinancialRecords($params, $context) {
- $entityParams = array(
+ $entityParams = [
'entity_id' => $params['id'],
'entity_table' => 'civicrm_contribution',
- );
+ ];
if ($context == 'pending') {
$trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
$this->assertNull($trxn, 'No Trxn to be created until IPN callback');
return;
}
$trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
- $trxnParams = array(
+ $trxnParams = [
'id' => $trxn['financial_trxn_id'],
- );
+ ];
if ($context != 'online' && $context != 'payLater') {
- $compareParams = array(
+ $compareParams = [
'to_financial_account_id' => 6,
'total_amount' => 120,
'status_id' => 1,
- );
+ ];
}
if ($context == 'online') {
- $compareParams = array(
+ $compareParams = [
'to_financial_account_id' => 12,
'total_amount' => 120,
'status_id' => 1,
- );
+ ];
}
elseif ($context == 'payLater') {
- $compareParams = array(
+ $compareParams = [
'to_financial_account_id' => 7,
'total_amount' => 120,
'status_id' => 2,
- );
+ ];
}
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
- $entityParams = array(
+ $entityParams = [
'financial_trxn_id' => $trxn['financial_trxn_id'],
'entity_table' => 'civicrm_financial_item',
- );
+ ];
$entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
- $fitemParams = array(
+ $fitemParams = [
'id' => $entityTrxn['entity_id'],
- );
- $compareParams = array(
+ ];
+ $compareParams = [
'amount' => 100,
'status_id' => 1,
'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID),
- );
+ ];
if ($context == 'payLater') {
- $compareParams = array(
+ $compareParams = [
'amount' => 100,
'status_id' => 3,
'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID),
- );
+ ];
}
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
}
public function _getFinancialAccountId($financialTypeId) {
$accountRel = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
- $searchParams = array(
+ $searchParams = [
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialTypeId,
'account_relationship' => $accountRel,
- );
+ ];
- $result = array();
+ $result = [];
CRM_Financial_BAO_FinancialTypeAccount::retrieve($searchParams, $result);
return CRM_Utils_Array::value('financial_account_id', $result);
}
* on the contribution test class & might be copy and paste....).
*/
public function testDeleteContribution() {
- $contributionID = $this->contributionCreate(array(
+ $contributionID = $this->contributionCreate([
'contact_id' => $this->_individualId,
'trxn_id' => 12389,
'financial_type_id' => $this->financialtypeID,
'invoice_id' => 'dfsdf',
- ));
- $this->callAPISuccess('contribution', 'delete', array('id' => $contributionID));
+ ]);
+ $this->callAPISuccess('contribution', 'delete', ['id' => $contributionID]);
}
}
$this->_groupId = $this->groupCreate();
$this->_contactId = $this->individualCreate();
$this->createLoggedInUser();
- $ufGroup = $this->callAPISuccess('uf_group', 'create', array(
+ $ufGroup = $this->callAPISuccess('uf_group', 'create', [
'group_type' => 'Contact',
'help_pre' => 'Profile to Test API',
'title' => 'Test Profile',
- ));
+ ]);
$this->_ufGroupId = $ufGroup['id'];
- $ufMatch = $this->callAPISuccess('uf_match', 'create', array(
+ $ufMatch = $this->callAPISuccess('uf_match', 'create', [
'contact_id' => $this->_contactId,
'uf_id' => 42,
'uf_name' => 'email@mail.com',
- ));
+ ]);
$this->_ufMatchId = $ufMatch['id'];
- $this->params = array(
+ $this->params = [
'add_captcha' => 1,
'add_contact_to_group' => $this->_groupId,
'group' => $this->_groupId,
'notify' => 'admin@example.org',
'post_URL' => 'http://example.org/post',
'title' => 'Test Group',
- );
+ ];
}
public function tearDown() {
// Truncate the tables
$this->quickCleanup(
- array(
+ [
'civicrm_group',
'civicrm_contact',
'civicrm_uf_group',
'civicrm_uf_join',
'civicrm_uf_match',
- )
+ ]
);
}
*/
public function testUpdateUFGroup($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'title' => 'Edited Test Profile',
'help_post' => 'Profile Pro help text.',
'is_active' => 1,
'id' => $this->_ufGroupId,
- );
+ ];
$result = $this->callAPISuccess('uf_group', 'create', $params);
foreach ($params as $key => $value) {
*/
public function testUFGroupCreateWithWrongParams($version) {
$this->_apiversion = $version;
- $result = $this->callAPIFailure('uf_group', 'create', array('name' => 'A title-less group'));
+ $result = $this->callAPIFailure('uf_group', 'create', ['name' => 'A title-less group']);
}
/**
*/
public function testUFGroupUpdate($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'id' => $this->_ufGroupId,
'add_captcha' => 1,
'add_contact_to_group' => $this->_groupId,
'notify' => 'admin@example.org',
'post_URL' => 'http://example.org/post',
'title' => 'Test Group',
- );
+ ];
$result = $this->callAPISuccess('uf_group', 'create', $params);
$params['created_date'] = date('YmdHis', strtotime($params['created_date']));
foreach ($params as $key => $value) {
public function testUFGroupGet($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess('uf_group', 'create', $this->params);
- $params = array('id' => $result['id']);
+ $params = ['id' => $result['id']];
$result = $this->callAPIAndDocument('uf_group', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params['add_contact_to_group']);
$this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params['group']);
public function testUFGroupDelete($version) {
$this->_apiversion = $version;
$ufGroup = $this->callAPISuccess('uf_group', 'create', $this->params);
- $params = array('id' => $ufGroup['id']);
+ $params = ['id' => $ufGroup['id']];
$this->assertEquals(1, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__);
$result = $this->callAPIAndDocument('uf_group', 'delete', $params, __FUNCTION__, __FILE__);
$this->assertEquals(0, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__);
parent::setUp();
// Truncate the tables
$this->quickCleanup(
- array(
+ [
'civicrm_group',
'civicrm_contact',
'civicrm_uf_group',
'civicrm_uf_join',
'civicrm_uf_match',
- )
+ ]
);
$this->loadXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml');
}
public function tearDown() {
// Truncate the tables
$this->quickCleanup(
- array(
+ [
'civicrm_group',
'civicrm_contact',
'civicrm_uf_group',
'civicrm_uf_join',
'civicrm_uf_match',
- )
+ ]
);
}
*/
public function testFindUFGroupId($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'module' => 'CiviContribute',
'entity_table' => 'civicrm_contribution_page',
'entity_id' => 1,
'weight' => 1,
'uf_group_id' => $this->_ufGroupId,
'is_active' => 1,
- );
+ ];
$ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
- $searchParams = array(
+ $searchParams = [
'entity_table' => 'civicrm_contribution_page',
'entity_id' => 1,
- );
+ ];
$result = $this->callAPISuccess('uf_join', 'get', $searchParams);
foreach ($result['values'] as $key => $value) {
*/
public function testUFJoinEditWithoutUFGroupId($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'module' => 'CiviContribute',
'entity_table' => 'civicrm_contribution_page',
'entity_id' => 1,
'weight' => 1,
'is_active' => 1,
- );
+ ];
$result = $this->callAPIFailure('uf_join', 'create', $params);
$this->assertContains('Mandatory', $result['error_message']);
$this->assertContains('missing', $result['error_message']);
*/
public function testCreateUFJoin($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'module' => 'CiviContribute',
'entity_table' => 'civicrm_contribution_page',
'entity_id' => 1,
'uf_group_id' => $this->_ufGroupId,
'is_active' => 1,
'sequential' => 1,
- );
+ ];
$ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
$this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
$this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']);
- $params = array(
+ $params = [
'id' => $ufJoin['id'],
'module' => 'CiviContribute',
'entity_table' => 'civicrm_contribution_page',
'uf_group_id' => $this->_ufGroupId,
'is_active' => 0,
'sequential' => 1,
- );
+ ];
$ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
$this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module']);
$this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id']);
*/
public function testCreateSurveyUFJoin($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'module' => 'CiviCampaign',
'entity_table' => 'civicrm_survey',
'entity_id' => 1,
'uf_group_id' => $this->_ufGroupId,
'is_active' => 1,
'sequential' => 1,
- );
+ ];
$ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
$this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
*/
public function testFindUFJoinEmptyParams($version) {
$this->_apiversion = $version;
- $result = $this->callAPIFailure('uf_join', 'create', array());
+ $result = $this->callAPIFailure('uf_join', 'create', []);
$this->assertContains('Mandatory', $result['error_message']);
$this->assertContains('missing', $result['error_message']);
$this->assertContains('module', $result['error_message']);
*/
public function testCreateUFJoinWithoutUFGroupId($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'module' => 'CiviContribute',
'entity_table' => 'civicrm_contribution_page',
'entity_id' => 1,
'weight' => 1,
'is_active' => 1,
- );
+ ];
$result = $this->callAPIFailure('uf_join', 'create', $params);
$this->assertContains('Mandatory', $result['error_message']);
$this->assertContains('missing', $result['error_message']);
*/
public function testGetUFJoinId($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'module' => 'CiviContribute',
'entity_table' => 'civicrm_contribution_page',
'entity_id' => 1,
'weight' => 1,
'uf_group_id' => $this->_ufGroupId,
'is_active' => 1,
- );
+ ];
$ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
- $searchParams = array(
+ $searchParams = [
'entity_table' => 'civicrm_contribution_page',
'entity_id' => 1,
'sequential' => 1,
- );
+ ];
$result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][0]['module'], $params['module']);
protected $_ufGroupId = 11;
protected $_ufFieldId;
protected $_contactId;
- protected $_params = array();
+ protected $_params = [];
protected function setUp() {
parent::setUp();
$this->quickCleanup(
- array(
+ [
'civicrm_group',
'civicrm_contact',
'civicrm_uf_group',
'civicrm_uf_join',
'civicrm_uf_match',
- )
+ ]
);
$this->_contactId = $this->individualCreate();
$this->loadXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml');
- $this->_params = array(
+ $this->_params = [
'contact_id' => $this->_contactId,
'uf_id' => '2',
'uf_name' => 'blahdyblah@gmail.com',
'domain_id' => 1,
- );
+ ];
}
public function tearDown() {
// Truncate the tables
$this->quickCleanup(
- array(
+ [
'civicrm_group',
'civicrm_contact',
'civicrm_uf_group',
'civicrm_uf_join',
'civicrm_uf_match',
- )
+ ]
);
}
*/
public function testGetUFMatchID($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'uf_id' => 42,
- );
+ ];
$result = $this->callAPISuccess('uf_match', 'get', $params);
$this->assertEquals($result['values'][$result['id']]['contact_id'], 69);
}
*/
public function testGetUFID($version) {
$this->_apiversion = $version;
- $params = array(
+ $params = [
'contact_id' => 69,
- );
+ ];
$result = $this->callAPIAndDocument('uf_match', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals($result['values'][$result['id']]['uf_id'], 42);
}
// Case A: Enable CMS integration
Civi::settings()->set('syncCMSEmail', TRUE);
- $this->callAPISuccess('email', 'create', array(
+ $this->callAPISuccess('email', 'create', [
'contact_id' => $this->_contactId,
'email' => $email1,
'is_primary' => 1,
- ));
- $ufName = $this->callAPISuccess('uf_match', 'getvalue', array(
+ ]);
+ $ufName = $this->callAPISuccess('uf_match', 'getvalue', [
'contact_id' => $this->_contactId,
'return' => 'uf_name',
- ));
+ ]);
$this->assertEquals($email1, $ufName);
// Case B: Disable CMS integration
Civi::settings()->set('syncCMSEmail', FALSE);
- $this->callAPISuccess('email', 'create', array(
+ $this->callAPISuccess('email', 'create', [
'contact_id' => $this->_contactId,
'email' => $email2,
'is_primary' => 1,
- ));
- $ufName = $this->callAPISuccess('uf_match', 'getvalue', array(
+ ]);
+ $ufName = $this->callAPISuccess('uf_match', 'getvalue', [
'contact_id' => $this->_contactId,
'return' => 'uf_name',
- ));
+ ]);
$this->assertNotEquals($email2, $ufName, 'primary email will not match if changed on disabled CMS integration setting');
$this->assertEquals($email1, $ufName);
}
public function testDelete($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess('uf_match', 'create', $this->_params);
- $this->assertEquals(1, $this->callAPISuccess('uf_match', 'getcount', array(
+ $this->assertEquals(1, $this->callAPISuccess('uf_match', 'getcount', [
'id' => $result['id'],
- )));
- $this->callAPISuccess('uf_match', 'delete', array(
+ ]));
+ $this->callAPISuccess('uf_match', 'delete', [
'id' => $result['id'],
- ));
- $this->assertEquals(0, $this->callAPISuccess('uf_match', 'getcount', array(
+ ]);
+ $this->assertEquals(0, $this->callAPISuccess('uf_match', 'getcount', [
'id' => $result['id'],
- )));
+ ]));
}
}
public function setUp() {
parent::setUp();
$this->contactID = $this->createLoggedInUser();
- $this->params = array(
+ $this->params = [
'contact_id' => $this->contactID,
'sequential' => 1,
- );
+ ];
}
public function testUserGet() {
* Test retrieval of label metadata.
*/
public function testGetFields() {
- $result = $this->callAPIAndDocument($this->_entity, 'getfields', array('action' => 'get'), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument($this->_entity, 'getfields', ['action' => 'get'], __FUNCTION__, __FILE__);
$this->assertArrayKeyExists('name', $result['values']);
}
}
public function testAddFormattedParam() {
- $values = array('contact_type' => 'Individual');
- $params = array('something' => 1);
+ $values = ['contact_type' => 'Individual'];
+ $params = ['something' => 1];
$result = _civicrm_api3_deprecated_add_formatted_param($values, $params);
$this->assertTrue($result);
}
public function testCheckPermissionReturn() {
- $check = array('check_permissions' => TRUE);
+ $check = ['check_permissions' => TRUE];
$config = CRM_Core_Config::singleton();
- $config->userPermissionClass->permissions = array();
+ $config->userPermissionClass->permissions = [];
$this->assertFalse($this->runPermissionCheck('contact', 'create', $check), 'empty permissions should not be enough');
- $config->userPermissionClass->permissions = array('access CiviCRM');
+ $config->userPermissionClass->permissions = ['access CiviCRM'];
$this->assertFalse($this->runPermissionCheck('contact', 'create', $check), 'lacking permissions should not be enough');
- $config->userPermissionClass->permissions = array('add contacts');
+ $config->userPermissionClass->permissions = ['add contacts'];
$this->assertFalse($this->runPermissionCheck('contact', 'create', $check), 'lacking permissions should not be enough');
- $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts');
+ $config->userPermissionClass->permissions = ['access CiviCRM', 'add contacts'];
$this->assertTrue($this->runPermissionCheck('contact', 'create', $check), 'exact permissions should be enough');
- $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts');
+ $config->userPermissionClass->permissions = ['access CiviCRM', 'add contacts', 'import contacts'];
$this->assertTrue($this->runPermissionCheck('contact', 'create', $check), 'overfluous permissions should be enough');
}
public function testCheckPermissionThrow() {
- $check = array('check_permissions' => TRUE);
+ $check = ['check_permissions' => TRUE];
$config = CRM_Core_Config::singleton();
try {
- $config->userPermissionClass->permissions = array('access CiviCRM');
+ $config->userPermissionClass->permissions = ['access CiviCRM'];
$this->runPermissionCheck('contact', 'create', $check, TRUE);
}
catch (Exception $e) {
}
$this->assertEquals($message, 'API permission check failed for Contact/create call; insufficient permission: require access CiviCRM and add contacts', 'lacking permissions should throw an exception');
- $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts');
+ $config->userPermissionClass->permissions = ['access CiviCRM', 'add contacts', 'import contacts'];
$this->assertTrue($this->runPermissionCheck('contact', 'create', $check), 'overfluous permissions should return true');
}
public function testCheckPermissionSkip() {
$config = CRM_Core_Config::singleton();
- $config->userPermissionClass->permissions = array('access CiviCRM');
- $params = array('check_permissions' => TRUE);
+ $config->userPermissionClass->permissions = ['access CiviCRM'];
+ $params = ['check_permissions' => TRUE];
$this->assertFalse($this->runPermissionCheck('contact', 'create', $params), 'lacking permissions should not be enough');
- $params = array('check_permissions' => FALSE);
+ $params = ['check_permissions' => FALSE];
$this->assertTrue($this->runPermissionCheck('contact', 'create', $params), 'permission check should be skippable');
}
*/
public function testVerifyMandatory() {
_civicrm_api3_initialize(TRUE);
- $params = array(
+ $params = [
'entity_table' => 'civicrm_contact',
'note' => '',
'contact_id' => $this->_contactID,
'modified_date' => '2011-01-31',
'subject' => NULL,
'version' => $this->_apiversion,
- );
+ ];
try {
- civicrm_api3_verify_mandatory($params, 'CRM_Core_BAO_Note', array('note', 'subject'));
+ civicrm_api3_verify_mandatory($params, 'CRM_Core_BAO_Note', ['note', 'subject']);
}
catch (Exception $expected) {
$this->assertEquals('Mandatory key(s) missing from params array: note, subject', $expected->getMessage());
*/
public function testVerifyOneMandatory() {
_civicrm_api3_initialize(TRUE);
- $params = array(
+ $params = [
'entity_table' => 'civicrm_contact',
'note' => '',
'contact_id' => $this->_contactID,
'modified_date' => '2011-01-31',
'subject' => NULL,
'version' => $this->_apiversion,
- );
+ ];
try {
- civicrm_api3_verify_one_mandatory($params, 'CRM_Core_BAO_Note', array('note', 'subject'));
+ civicrm_api3_verify_one_mandatory($params, 'CRM_Core_BAO_Note', ['note', 'subject']);
}
catch (Exception $expected) {
$this->assertEquals('Mandatory key(s) missing from params array: one of (note, subject)', $expected->getMessage());
*/
public function testVerifyOneMandatoryOneSet() {
_civicrm_api3_initialize(TRUE);
- $params = array(
+ $params = [
'version' => 3,
'entity_table' => 'civicrm_contact',
'note' => 'note',
'contact_id' => $this->_contactID,
'modified_date' => '2011-01-31',
'subject' => NULL,
- );
+ ];
try {
- civicrm_api3_verify_one_mandatory($params, NULL, array('note', 'subject'));
+ civicrm_api3_verify_one_mandatory($params, NULL, ['note', 'subject']);
}
catch (Exception$expected) {
$this->fail('Exception raised when it shouldn\'t have been in line ' . __LINE__);
* Test GET DAO function returns DAO.
*/
public function testGetDAO() {
- $params = array(
+ $params = [
'civicrm_api3_custom_group_get' => 'CRM_Core_DAO_CustomGroup',
'custom_group' => 'CRM_Core_DAO_CustomGroup',
'CustomGroup' => 'CRM_Core_DAO_CustomGroup',
'civicrm_api3_pledge_payment_get' => 'CRM_Pledge_DAO_PledgePayment',
'civicrm_api3_website_get' => 'CRM_Core_DAO_Website',
'Membership' => 'CRM_Member_DAO_Membership',
- );
+ ];
foreach ($params as $input => $expected) {
$result = _civicrm_api3_get_DAO($input);
$this->assertEquals($expected, $result);
* Test GET BAO function returns BAO when it exists.
*/
public function testGetBAO() {
- $params = array(
+ $params = [
'civicrm_api3_website_get' => 'CRM_Core_BAO_Website',
'civicrm_api3_survey_get' => 'CRM_Campaign_BAO_Survey',
'civicrm_api3_pledge_payment_get' => 'CRM_Pledge_BAO_PledgePayment',
'mailing_group' => 'CRM_Mailing_DAO_MailingGroup',
// Make sure we get null back with nonexistant entities
'civicrm_this_does_not_exist' => NULL,
- );
+ ];
foreach ($params as $input => $expected) {
$result = _civicrm_api3_get_BAO($input);
$this->assertEquals($expected, $result);
}
public function test_civicrm_api3_validate_fields() {
- $params = array('start_date' => '2010-12-20', 'end_date' => '');
- $fields = civicrm_api3('relationship', 'getfields', array('action' => 'get'));
+ $params = ['start_date' => '2010-12-20', 'end_date' => ''];
+ $fields = civicrm_api3('relationship', 'getfields', ['action' => 'get']);
_civicrm_api3_validate_fields('relationship', 'get', $params, $fields['values']);
$this->assertEquals('20101220000000', $params['start_date']);
$this->assertEquals('', $params['end_date']);
}
public function test_civicrm_api3_validate_fields_membership() {
- $params = array(
+ $params = [
'start_date' => '2010-12-20',
'end_date' => '',
'membership_end_date' => '0',
'join_date' => '2010-12-20',
'membership_start_date' => '2010-12-20',
- );
- $fields = civicrm_api3('Membership', 'getfields', array('action' => 'get'));
+ ];
+ $fields = civicrm_api3('Membership', 'getfields', ['action' => 'get']);
_civicrm_api3_validate_fields('Membership', 'get', $params, $fields['values']);
$this->assertEquals('2010-12-20', $params['start_date']);
$this->assertEquals('20101220000000', $params['membership_start_date']);
public function test_civicrm_api3_validate_fields_event() {
- $params = array(
+ $params = [
'registration_start_date' => 20080601,
'registration_end_date' => '2008-10-15',
'start_date' => '2010-12-20',
'end_date' => '',
- );
- $fields = civicrm_api3('Event', 'getfields', array('action' => 'create'));
+ ];
+ $fields = civicrm_api3('Event', 'getfields', ['action' => 'create']);
_civicrm_api3_validate_fields('event', 'create', $params, $fields['values']);
$this->assertEquals('20101220000000', $params['start_date']);
$this->assertEquals('20081015000000', $params['registration_end_date']);
}
public function test_civicrm_api3_validate_fields_exception() {
- $params = array(
+ $params = [
'join_date' => 'abc',
- );
+ ];
try {
- $fields = civicrm_api3('Membership', 'getfields', array('action' => 'get'));
+ $fields = civicrm_api3('Membership', 'getfields', ['action' => 'get']);
_civicrm_api3_validate_fields('Membership', 'get', $params, $fields['values']);
}
catch (Exception$expected) {
}
public function testGetFields() {
- $result = $this->callAPISuccess('membership', 'getfields', array());
+ $result = $this->callAPISuccess('membership', 'getfields', []);
$this->assertArrayHasKey('values', $result);
- $result = $this->callAPISuccess('relationship', 'getfields', array());
+ $result = $this->callAPISuccess('relationship', 'getfields', []);
$this->assertArrayHasKey('values', $result);
- $result = $this->callAPISuccess('event', 'getfields', array());
+ $result = $this->callAPISuccess('event', 'getfields', []);
$this->assertArrayHasKey('values', $result);
}
public function testGetFields_AllOptions() {
- $result = $this->callAPISuccess('contact', 'getfields', array(
- 'options' => array(
+ $result = $this->callAPISuccess('contact', 'getfields', [
+ 'options' => [
'get_options' => 'all',
- ),
- ));
+ ],
+ ]);
$this->assertEquals('Household', $result['values']['contact_type']['options']['Household']);
$this->assertEquals('HTML', $result['values']['preferred_mail_format']['options']['HTML']);
}
public function basicArrayCases() {
- $records = array(
- array('snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'),
- array('snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'),
- array('snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'),
- array('snack_id' => 'd', 'fruit' => 'apple', 'cheese' => 'gouda'),
- array('snack_id' => 'e', 'fruit' => 'apple', 'cheese' => 'provolone'),
- );
-
- $cases[] = array(
+ $records = [
+ ['snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'],
+ ['snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'],
+ ['snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'],
+ ['snack_id' => 'd', 'fruit' => 'apple', 'cheese' => 'gouda'],
+ ['snack_id' => 'e', 'fruit' => 'apple', 'cheese' => 'provolone'],
+ ];
+
+ $cases[] = [
$records,
// params
- array('version' => 3),
+ ['version' => 3],
// expected results
- array('a', 'b', 'c', 'd', 'e'),
- );
+ ['a', 'b', 'c', 'd', 'e'],
+ ];
- $cases[] = array(
+ $cases[] = [
$records,
// params
- array('version' => 3, 'fruit' => 'apple'),
+ ['version' => 3, 'fruit' => 'apple'],
// expected results
- array('a', 'c', 'd', 'e'),
- );
+ ['a', 'c', 'd', 'e'],
+ ];
- $cases[] = array(
+ $cases[] = [
$records,
- array('version' => 3, 'cheese' => 'cheddar'),
- array('b', 'c'),
- );
+ ['version' => 3, 'cheese' => 'cheddar'],
+ ['b', 'c'],
+ ];
- $cases[] = array(
+ $cases[] = [
$records,
- array('version' => 3, 'id' => 'd'),
- array('d'),
- );
+ ['version' => 3, 'id' => 'd'],
+ ['d'],
+ ];
return $cases;
}
$provider = new \Civi\API\Provider\AdhocProvider($params['version'], 'Widget');
$provider->addAction('get', 'access CiviCRM', function ($apiRequest) use ($records) {
- return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', array('snack_id', 'fruit', 'cheese'));
+ return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', ['snack_id', 'fruit', 'cheese']);
});
$kernel->registerApiProvider($provider);
$this->assertEquals($resultIds, array_values(CRM_Utils_Array::collect('snack_id', $r1['values'])));
$this->assertEquals($resultIds, array_values(CRM_Utils_Array::collect('id', $r1['values'])));
- $r2 = $kernel->run('Widget', 'get', $params + array('sequential' => 1));
+ $r2 = $kernel->run('Widget', 'get', $params + ['sequential' => 1]);
$this->assertEquals(count($resultIds), $r2['count']);
$this->assertEquals($resultIds, array_values(CRM_Utils_Array::collect('snack_id', $r2['values'])));
$this->assertEquals($resultIds, array_values(CRM_Utils_Array::collect('id', $r2['values'])));
- $r3 = $kernel->run('Widget', 'get', $params + array('options' => array('offset' => 1, 'limit' => 2)));
+ $r3 = $kernel->run('Widget', 'get', $params + ['options' => ['offset' => 1, 'limit' => 2]]);
$slice = array_slice($resultIds, 1, 2);
$this->assertEquals(count($slice), $r3['count']);
$this->assertEquals($slice, array_values(CRM_Utils_Array::collect('snack_id', $r3['values'])));
}
public function testBasicArrayGetReturn() {
- $records = array(
- array('snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'),
- array('snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'),
- array('snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'),
- );
+ $records = [
+ ['snack_id' => 'a', 'fruit' => 'apple', 'cheese' => 'swiss'],
+ ['snack_id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar'],
+ ['snack_id' => 'c', 'fruit' => 'apple', 'cheese' => 'cheddar'],
+ ];
$kernel = new \Civi\API\Kernel(new \Symfony\Component\EventDispatcher\EventDispatcher());
$provider = new \Civi\API\Provider\AdhocProvider(3, 'Widget');
$provider->addAction('get', 'access CiviCRM', function ($apiRequest) use ($records) {
- return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', array('snack_id', 'fruit', 'cheese'));
+ return _civicrm_api3_basic_array_get('Widget', $apiRequest['params'], $records, 'snack_id', ['snack_id', 'fruit', 'cheese']);
});
$kernel->registerApiProvider($provider);
- $r1 = $kernel->run('Widget', 'get', array(
+ $r1 = $kernel->run('Widget', 'get', [
'version' => 3,
'snack_id' => 'b',
'return' => 'fruit',
- ));
+ ]);
$this->assertAPISuccess($r1);
- $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape')), $r1['values']);
+ $this->assertEquals(['b' => ['id' => 'b', 'fruit' => 'grape']], $r1['values']);
- $r2 = $kernel->run('Widget', 'get', array(
+ $r2 = $kernel->run('Widget', 'get', [
'version' => 3,
'snack_id' => 'b',
- 'return' => array('fruit', 'cheese'),
- ));
+ 'return' => ['fruit', 'cheese'],
+ ]);
$this->assertAPISuccess($r2);
- $this->assertEquals(array('b' => array('id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar')), $r2['values']);
+ $this->assertEquals(['b' => ['id' => 'b', 'fruit' => 'grape', 'cheese' => 'cheddar']], $r2['values']);
- $r3 = $kernel->run('Widget', 'get', array(
+ $r3 = $kernel->run('Widget', 'get', [
'version' => 3,
'cheese' => 'cheddar',
- 'return' => array('fruit'),
- ));
+ 'return' => ['fruit'],
+ ]);
$this->assertAPISuccess($r3);
- $this->assertEquals(array(
- 'b' => array('id' => 'b', 'fruit' => 'grape'),
- 'c' => array('id' => 'c', 'fruit' => 'apple'),
- ), $r3['values']);
+ $this->assertEquals([
+ 'b' => ['id' => 'b', 'fruit' => 'grape'],
+ 'c' => ['id' => 'c', 'fruit' => 'apple'],
+ ], $r3['values']);
}
/**
public function testTimeStampChecking() {
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_mailing (id, modified_date) VALUES (25, '2016-06-30 12:52:52')");
$this->assertTrue(_civicrm_api3_compare_timestamps('2017-02-15 16:00:00', 25, 'Mailing'));
- $this->callAPISuccess('Mailing', 'create', array('id' => 25, 'subject' => 'Test Subject'));
+ $this->callAPISuccess('Mailing', 'create', ['id' => 25, 'subject' => 'Test Subject']);
$this->assertFalse(_civicrm_api3_compare_timestamps('2017-02-15 16:00:00', 25, 'Mailing'));
- $this->callAPISuccess('Mailing', 'delete', array('id' => 25));
+ $this->callAPISuccess('Mailing', 'delete', ['id' => 25]);
}
}
}
public function testEmptyContactValidate() {
- $validation = $this->callAPISuccess('Contact', 'validate', array('action' => "create"));
- $expectedOut = array(
- 'contact_type' => array(
+ $validation = $this->callAPISuccess('Contact', 'validate', ['action' => "create"]);
+ $expectedOut = [
+ 'contact_type' => [
'message' => "Mandatory key(s) missing from params array: contact_type",
'code' => "mandatory_missing",
- ),
- );
+ ],
+ ];
$this->assertEquals($validation['values'][0], $expectedOut);
}
public function testContributionValidate() {
- $validation = $this->callAPISuccess('Contribution', 'validate', array('action' => "create", 'total_amount' => "100w"));
- $totalAmountErrors = array(
+ $validation = $this->callAPISuccess('Contribution', 'validate', ['action' => "create", 'total_amount' => "100w"]);
+ $totalAmountErrors = [
'message' => "total_amount is not a valid amount: 100w",
'code' => "incorrect_value",
- );
+ ];
- $contactIdErrors = array(
+ $contactIdErrors = [
'message' => "Mandatory key(s) missing from params array: contact_id",
'code' => "mandatory_missing",
- );
+ ];
$this->assertEquals($validation['values'][0]['total_amount'], $totalAmountErrors);
$this->assertEquals($validation['values'][0]['contact_id'], $contactIdErrors);
}
public function testContributionDateValidate() {
- $params = array(
+ $params = [
'action' => "create",
'financial_type_id' => "1",
'total_amount' => "100",
'contact_id' => "1",
'receive_date' => 'abc',
- );
+ ];
$validation = $this->callAPISuccess('Contribution', 'validate', $params);
- $expectedOut = array(
- 'receive_date' => array(
+ $expectedOut = [
+ 'receive_date' => [
'message' => "receive_date is not a valid date: abc",
'code' => "incorrect_value",
- ),
- );
+ ],
+ ];
$this->assertEquals($validation['values'][0], $expectedOut);
}
$this->_entity = 'website';
$this->_contactID = $this->organizationCreate();
- $this->params = array(
+ $this->params = [
'contact_id' => $this->_contactID,
'url' => 'website.com',
'website_type_id' => 1,
- );
+ ];
}
/**
$result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
- $this->callAPISuccess('website', 'delete', array('id' => $result['id']));
+ $this->callAPISuccess('website', 'delete', ['id' => $result['id']]);
}
/**
public function testDeleteWebsite($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => $result['id']);
+ $deleteParams = ['id' => $result['id']];
$result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
}
public function testDeleteWebsiteInvalid($version) {
$this->_apiversion = $version;
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = array('id' => 600);
+ $deleteParams = ['id' => 600];
$result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
+ $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
$this->assertEquals(1, $checkDeleted['count']);
}
* Test retrieval of metadata.
*/
public function testGetMetadata() {
- $result = $this->callAPIAndDocument($this->_entity, 'get', array(
- 'options' => array(
- 'metadata' => array('fields'),
- ),
- ), __FUNCTION__, __FILE__, 'Demonostrates returning field metadata', 'GetWithMetadata');
+ $result = $this->callAPIAndDocument($this->_entity, 'get', [
+ 'options' => [
+ 'metadata' => ['fields'],
+ ],
+ ], __FUNCTION__, __FILE__, 'Demonostrates returning field metadata', 'GetWithMetadata');
$this->assertEquals('Website', $result['metadata']['fields']['url']['title']);
}
*/
public function testGetFields($version) {
$this->_apiversion = $version;
- $result = $this->callAPIAndDocument($this->_entity, 'getfields', array('action' => 'get'), __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument($this->_entity, 'getfields', ['action' => 'get'], __FUNCTION__, __FILE__);
$this->assertArrayKeyExists('url', $result['values']);
}
*/
public static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
- Civi::$statics[__CLASS__]['fields'] = array(
- 'contact_identifier' => array(
+ Civi::$statics[__CLASS__]['fields'] = [
+ 'contact_identifier' => [
'name' => 'contact_identifier',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Contact Identifier') ,
'entity' => 'MailingProviderData',
'bao' => 'CRM_Omnimail_DAO_MailingProviderData',
'localizable' => 0,
- ) ,
- 'mailing_identifier' => array(
+ ] ,
+ 'mailing_identifier' => [
'name' => 'mailing_identifier',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Mailing Identifier') ,
'entity' => 'MailingProviderData',
'bao' => 'CRM_Omnimail_DAO_MailingProviderData',
'localizable' => 0,
- ) ,
- 'email' => array(
+ ] ,
+ 'email' => [
'name' => 'email',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Email') ,
'entity' => 'MailingProviderData',
'bao' => 'CRM_Omnimail_DAO_MailingProviderData',
'localizable' => 0,
- ) ,
- 'event_type' => array(
+ ] ,
+ 'event_type' => [
'name' => 'event_type',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Recipient Action Type') ,
'entity' => 'MailingProviderData',
'bao' => 'CRM_Omnimail_DAO_MailingProviderData',
'localizable' => 0,
- ) ,
- 'recipient_action_datetime' => array(
+ ] ,
+ 'recipient_action_datetime' => [
'name' => 'recipient_action_datetime',
'type' => CRM_Utils_Type::T_TIMESTAMP,
'title' => ts('Recipient Action Datetime') ,
'entity' => 'MailingProviderData',
'bao' => 'CRM_Omnimail_DAO_MailingProviderData',
'localizable' => 0,
- ),
- 'contact_id' => array(
+ ],
+ 'contact_id' => [
'name' => 'contact_id',
'type' => CRM_Utils_Type::T_INT,
'description' => 'Contact in CiviCRM',
'entity' => 'MailingProviderData',
'bao' => 'CRM_Omnimail_DAO_MailingProviderData',
'localizable' => 0,
- ) ,
- 'is_civicrm_updated' => array(
+ ] ,
+ 'is_civicrm_updated' => [
'name' => 'is_civicrm_updated',
'type' => CRM_Utils_Type::T_BOOLEAN,
'description' => 'Has the action been synchronised through to CiviCRM',
'entity' => 'MailingProviderData',
'bao' => 'CRM_Omnimail_DAO_MailingProviderData',
'localizable' => 0,
- ) ,
- );
+ ] ,
+ ];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
* @return array
*/
public static function &import($prefix = FALSE) {
- $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'mailing_provider_data', $prefix, array());
+ $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'mailing_provider_data', $prefix, []);
return $r;
}
* @return array
*/
public static function &export($prefix = FALSE) {
- $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'mailing_provider_data', $prefix, array());
+ $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'mailing_provider_data', $prefix, []);
return $r;
}
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
- $indices = array();
+ $indices = [];
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
*/
function civicrm_api3_contact_example_action2($params) {
return civicrm_api3_create_success(
- array('0' => 'civicrm_api3_contact_example_action2 is ok'),
+ ['0' => 'civicrm_api3_contact_example_action2 is ok'],
$params,
'contact',
'example_action2'
*/
function civicrm_api3_generic_example_action1($apiRequest) {
return civicrm_api3_create_success(
- array('0' => 'civicrm_api3_generic_example_action1 is ok'),
+ ['0' => 'civicrm_api3_generic_example_action1 is ok'],
$apiRequest['params'],
$apiRequest['entity'],
$apiRequest['action']
*/
function civicrm_api3_generic_example_action2($apiRequest) {
return civicrm_api3_create_success(
- array('0' => 'civicrm_api3_generic_example_action2 should not be called'),
+ ['0' => 'civicrm_api3_generic_example_action2 should not be called'],
$apiRequest['params'],
$apiRequest['entity'],
$apiRequest['action']
*/
function civicrm_api3_test_entity_example_action3($params) {
return civicrm_api3_create_success(
- array('0' => 'civicrm_api3_test_entity_example_action3 is ok'),
+ ['0' => 'civicrm_api3_test_entity_example_action3 is ok'],
$params,
'test_entity',
'example_action3'
<?php
-return array(
- 'test_key' => array(
+return [
+ 'test_key' => [
'group_name' => 'Test Settings',
'group' => 'test',
'name' => 'test_key',
'help_text' => '',
'html_type' => 'Text',
'quick_form_type' => 'Element',
- ),
- 'test_secret' => array(
+ ],
+ 'test_secret' => [
'group_name' => 'Test Settings',
'group' => 'test',
'name' => 'test_secret',
'help_text' => '',
'html_type' => 'Text',
'quick_form_type' => 'Element',
- ),
- 'test_public_certificate' => array(
+ ],
+ 'test_public_certificate' => [
'group_name' => 'Test Settings',
'group' => 'test',
'name' => 'test_public_certificate',
'description' => 'Enter the full path to your public Certificate',
'help_text' => '',
'html_type' => 'Text',
- 'html_attributes' => array(
+ 'html_attributes' => [
'size' => 50,
- ),
+ ],
'quick_form_type' => 'Element',
- ),
- 'test_private_key' => array(
+ ],
+ 'test_private_key' => [
'group_name' => 'Test Settings',
'group' => 'test',
'name' => 'test_private_key',
'help_text' => '',
'html_type' => 'Text',
'quick_form_type' => 'Element',
- ),
-);
+ ],
+];