*
* @throws CRM_Core_Exception
*/
- public function getAndCheck($params, $id, $entity, $delete = 1, $errorText = '') {
+ public function getAndCheck(array $params, int $id, $entity, int $delete = 1, string $errorText = ''): void {
$result = $this->callAPISuccessGetSingle($entity, [
'id' => $id,
+ 'return' => array_keys($params),
]);
if ($delete) {
$keys[CRM_Utils_Array::value('name', $settings, $field)] = CRM_Utils_Array::value('name', $settings, $field);
}
$type = $settings['type'] ?? NULL;
- if ($type == CRM_Utils_Type::T_DATE) {
+ if ($type === CRM_Utils_Type::T_DATE) {
$dateFields[] = $settings['name'];
// we should identify both real names & unique names as dates
- if ($field != $settings['name']) {
+ if ($field !== $settings['name']) {
$dateFields[] = $field;
}
}
- if ($type == CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME) {
+ if ($type === CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME) {
$dateTimeFields[] = $settings['name'];
// we should identify both real names & unique names as dates
- if ($field != $settings['name']) {
+ if ($field !== $settings['name']) {
$dateTimeFields[] = $field;
}
}
}
- if (strtolower($entity) == 'contribution') {
+ if (strtolower($entity) === 'contribution') {
$params['receive_date'] = date('Y-m-d', strtotime($params['receive_date']));
// this is not returned in id format
unset($params['payment_instrument_id']);
}
foreach ($params as $key => $value) {
- if ($key == 'version' || substr($key, 0, 3) == 'api' || (!array_key_exists($key, $keys) || !array_key_exists($keys[$key], $result))) {
+ if ($key === 'version' || strpos($key, 'api') === 0 || (!array_key_exists($key, $keys) || !array_key_exists($keys[$key], $result))) {
continue;
}
- if (in_array($key, $dateFields)) {
+ if (in_array($key, $dateFields, TRUE)) {
$value = date('Y-m-d', strtotime($value));
$result[$key] = date('Y-m-d', strtotime($result[$key]));
}
- if (in_array($key, $dateTimeFields)) {
+ if (in_array($key, $dateTimeFields, TRUE)) {
$value = date('Y-m-d H:i:s', strtotime($value));
$result[$keys[$key]] = date('Y-m-d H:i:s', strtotime(CRM_Utils_Array::value($keys[$key], $result, CRM_Utils_Array::value($key, $result))));
}
}
/**
- * Test api updates an existing activity, including removing activity contacts in apiv3 style.
+ * Test api updates an existing activity, including removing activity
+ * contacts in apiv3 style.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testActivityUpdate() {
+ public function testActivityUpdate(): void {
$result = $this->callAPISuccess('activity', 'create', $this->_params);
$params = [
'record_type_id' => ['IN' => ['Activity Assignees', 'Activity Targets']],
], 0);
- unset($params['source_contact_id']);
+ unset($params['source_contact_id'], $params['assignee_contact_id'], $params['target_contact_id']);
$this->getAndCheck($params, $result['id'], 'activity');
}
/**
* Test civicrm_activity_update() with valid parameters
* and some custom data
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testActivityUpdateCustom() {
+ public function testActivityUpdateCustom(): void {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
* Is_primary should be set as a default.
*
* ie. create the address, unset the params & recreate.
- * is_primary should be 0 before & after the update. ie - having no other address
- * is_primary is invalid.
+ * is_primary should be 0 before & after the update. ie - having no other
+ * address is_primary is invalid.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
- public function testCreateAddressTestDefaultWithID($version) {
+ public function testCreateAddressTestDefaultWithID(int $version): void {
$this->_apiversion = $version;
$params = $this->_params;
$params['is_primary'] = 0;
- $result = $this->callAPISuccess('address', 'create', $params);
+ $result = $this->callAPISuccess('Address', 'create', $params);
unset($params['is_primary']);
$params['id'] = $result['id'];
- $this->callAPISuccess('address', 'create', $params);
- $result = $this->callAPISuccess('address', 'get', ['contact_id' => $params['contact_id']]);
+ $this->callAPISuccess('Address', 'create', $params);
+ $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__);
+ $this->getAndCheck($params, $result['id'], 'address');
}
/**
* test address deletion.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
- public function testDeleteAddress($version) {
+ public function testDeleteAddress($version): void {
$this->_apiversion = $version;
//check there are no address to start with
$get = $this->callAPISuccess('address', 'get', [
* @package CiviCRM_APIv3
*/
+use Civi\Api4\Participant;
+
/**
* Class api_v3_ParticipantTest
* @group headless
/**
* Test the line items for participant fee with multiple price field values.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testCreateParticipantLineItems() {
// Create a price set for this event.
/**
* Check with complete array.
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
- public function testUpdate() {
+ public function testUpdate(): void {
$participantId = $this->participantCreate([
'contactID' => $this->_individualId,
'eventID' => $this->_eventID,
'contact_id' => $this->_individualId,
'event_id' => $this->_eventID,
'status_id' => 3,
- 'role_id' => 3,
- 'register_date' => '2006-01-21',
+ 'role_id' => [3],
+ 'register_date' => '2006-01-21 00:00:00',
'source' => 'US Open',
];
- $participant = $this->callAPISuccess('participant', 'create', $params);
- $this->getAndCheck($params, $participant['id'], 'participant');
- $result = $this->participantDelete($params['id']);
+ $participantID = $this->callAPISuccess('Participant', 'create', $params)['id'];
+ $participant = Participant::get()
+ ->setSelect(array_keys($params))
+ ->addWhere('id', '=', $participantID)
+ ->execute()->first();
+
+ foreach ($params as $key => $value) {
+ $this->assertEquals($value, $participant[$key], $key . ' mismatch');
+ }
}
/**
* @throws \CRM_Core_Exception
*/
public function testCreatePaymentToken(): void {
- $description = "Create a payment token - Note use of relative dates here:
- @link http://www.php.net/manual/en/datetime.formats.relative.php.";
+ $description = 'Create a payment token - Note use of relative dates here:
+ @link http://www.php.net/manual/en/datetime.formats.relative.php.';
$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, [$this->params]), $result['id'], 'payment_token', TRUE);
+ $this->getAndCheck($this->params, $result['id'], 'payment_token', TRUE);
}
/**