+--------------------------------------------------------------------+
*/
+use Civi\Api4\RelationshipType;
+
/**
* Class contains api test cases for "civicrm_relationship"
* @group headless
* @var int
*/
protected $_cId_b2;
- protected $_relTypeID;
+ protected $relationshipTypeID;
protected $_ids = [];
- protected $_customFieldId = NULL;
+ protected $_customFieldId;
protected $_params;
protected $entity;
'is_active' => 1,
];
- $this->_relTypeID = $this->relationshipTypeCreate($relTypeParams);
+ $this->relationshipTypeID = $this->relationshipTypeCreate($relTypeParams);
$this->_params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
];
*/
public function tearDown(): void {
$this->quickCleanup(['civicrm_relationship', 'civicrm_membership'], TRUE);
- $this->relationshipTypeDelete($this->_relTypeID);
+ RelationshipType::delete(FALSE)->addWhere('id', '>', ($this->relationshipTypeID - 1))->execute();
parent::tearDown();
}
/**
* Check with empty array.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipCreateEmpty($version): void {
+ public function testRelationshipCreateEmpty(int $version): void {
$this->_apiversion = $version;
$this->callAPIFailure('relationship', 'create', []);
}
/**
* Test Current Employer is correctly set.
- *
- * @throws \CRM_Core_Exception
*/
- public function testCurrentEmployerRelationship() {
+ public function testCurrentEmployerRelationship(): void {
$employerRelationshipID = $this->callAPISuccessGetValue('RelationshipType', [
'return' => 'id',
'name_b_a' => 'Employer Of',
'id' => $this->_cId_a,
]);
$organisation = $this->callAPISuccessGetValue('Contact', [
- 'return' => "sort_name",
+ 'return' => 'sort_name',
'id' => $this->_cId_b,
]);
$this->assertEquals($employer, $organisation);
//Update relationship type
$this->callAPISuccess('Relationship', 'create', [
'id' => $employerRelationship['id'],
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
]);
$employeeContact = $this->callAPISuccessGetSingle('Contact', [
'return' => ['current_employer'],
/**
* Check if required fields are not passed.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipCreateWithoutRequired($version) {
+ public function testRelationshipCreateWithoutRequired(int $version): void {
$this->_apiversion = $version;
$params = [
'start_date' => ['d' => '10', 'M' => '1', 'Y' => '2008'],
/**
* Check with incorrect required fields.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipCreateWithIncorrectData($version) {
+ public function testRelationshipCreateWithIncorrectData(int $version): void {
$this->_apiversion = $version;
$params = [
$params = [
'contact_id_a' => 'invalid',
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => ['d' => '10', 'M' => '1', 'Y' => '2008'],
'is_active' => 1,
];
/**
* Check relationship creation with invalid Relationship.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipCreateInvalidRelationship($version) {
+ public function testRelationshipCreateInvalidRelationship(int $version): void {
$this->_apiversion = $version;
// Both have the contact type Individual.
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_a,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-01-10',
'is_active' => 1,
];
$params = [
'contact_id_a' => $this->_cId_b,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-01-10',
'is_active' => 1,
];
/**
* Check relationship already exists.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipCreateAlreadyExists($version) {
+ public function testRelationshipCreateAlreadyExists(int $version): void {
$this->_apiversion = $version;
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'end_date' => NULL,
'is_active' => 1,
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
];
- $this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship');
-
- $params['id'] = $relationship['id'];
- $this->callAPISuccess('relationship', 'delete', $params);
+ $this->callAPIFailure('Relationship', 'create', $params, 'Duplicate Relationship');
}
/**
* Check relationship already exists.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipCreateUpdateAlreadyExists($version) {
+ public function testRelationshipCreateUpdateAlreadyExists(int $version): void {
$this->_apiversion = $version;
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'end_date' => NULL,
'is_active' => 1,
];
- $relationship = $this->callAPISuccess('relationship', 'create', $params);
+ $relationship = $this->callAPISuccess('Relationship', 'create', $params);
$params = [
'id' => $relationship['id'],
'is_active' => 0,
'debug' => 1,
];
- $this->callAPISuccess('relationship', 'create', $params);
- $this->callAPISuccess('relationship', 'get', $params);
- $params['id'] = $relationship['id'];
- $this->callAPISuccess('relationship', 'delete', $params);
+ $this->callAPISuccess('Relationship', 'create', $params);
+ $this->callAPISuccess('Relationship', 'get', $params);
}
/**
* Check update doesn't reset stuff badly - CRM-11789.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipCreateUpdateDoesNotMangle($version) {
+ public function testRelationshipCreateUpdateDoesNotMangle(int $version): void {
$this->_apiversion = $version;
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
'is_permission_a_b' => 1,
$updateParams = [
'id' => $relationship['id'],
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
];
$this->callAPISuccess('relationship', 'create', $updateParams);
//make sure the orig params didn't get changed
$this->getAndCheck($params, $relationship['id'], 'relationship');
-
}
/**
* Check relationship creation.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipCreate($version) {
+ public function testRelationshipCreate(int $version): void {
$this->_apiversion = $version;
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2010-10-30',
'end_date' => '2010-12-30',
'is_active' => 1,
'note' => 'note',
];
- $result = $this->callAPIAndDocument('relationship', 'create', $params, __FUNCTION__, __FILE__);
- $this->assertNotNull($result['id']);
+ $result = $this->callAPIAndDocument('Relationship', 'create', $params, __FUNCTION__, __FILE__);
$relationParams = [
'id' => $result['id'],
];
$result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]);
$values = $result['values'][$result['id']];
foreach ($params as $key => $value) {
- if ($key == 'note') {
+ if ($key === 'note') {
continue;
}
$this->assertEquals($value, $values[$key], $key . " doesn't match " . print_r($values, TRUE));
}
- $params['id'] = $result['id'];
- $this->callAPISuccess('relationship', 'delete', $params);
}
/**
* Ensure disabling works.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipUpdate($version) {
+ public function testRelationshipUpdate(int $version): void {
$this->_apiversion = $version;
$result = $this->callAPISuccess('relationship', 'create', $this->_params);
$relID = $result['id'];
/**
* Check relationship creation.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipCreateEmptyEndDate($version) {
+ public function testRelationshipCreateEmptyEndDate(int $version): void {
$this->_apiversion = $version;
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2010-10-30',
'end_date' => '',
'is_active' => 1,
$result = $this->callAPISuccess('relationship', 'get', ['id' => $result['id']]);
$values = $result['values'][$result['id']];
foreach ($params as $key => $value) {
- if ($key == 'note') {
+ if ($key === 'note') {
continue;
}
- if ($key == 'end_date') {
+ if ($key === 'end_date') {
$this->assertTrue(empty($values[$key]));
continue;
}
* Check relationship creation with custom data.
* FIXME: Api4
*/
- public function testRelationshipCreateEditWithCustomData() {
+ public function testRelationshipCreateEditWithCustomData(): void {
$this->createCustomGroupWithFieldsOfAllTypes();
//few custom Values for comparing
$custom_params = [
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
];
$getParams = ['id' => $result['id']];
$updateParams = array_merge($getParams, [
$this->getCustomFieldName('text') => 'Edited Text Value',
- 'relationship_type_id' => $this->_relTypeID . '_b_a',
+ 'relationship_type_id' => $this->relationshipTypeID . '_b_a',
'related_contact_id' => $this->_cId_a,
]);
$reln = new CRM_Contact_Form_Relationship();
$reln->submit($updateParams);
$check = $this->callAPISuccess('relationship', 'get', $getParams);
- $this->assertEquals("Edited Text Value", $check['values'][$check['id']][$this->getCustomFieldName('text')]);
-
- $params['id'] = $result['id'];
- $this->callAPISuccess('relationship', 'delete', $params);
- $this->relationshipTypeDelete($this->_relTypeID);
+ $this->assertEquals('Edited Text Value', $check['values'][$check['id']][$this->getCustomFieldName('text')]);
}
/**
* and / or moved to the automated test suite
* FIXME: Api4
*/
- public function testGetWithCustom() {
+ public function testGetWithCustom(): void {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
* @param int $version
* @dataProvider versionThreeAndFour
*/
- public function testRelationshipDeleteWithoutRequired($version) {
+ public function testRelationshipDeleteWithoutRequired($version): void {
$this->_apiversion = $version;
$params = [
'start_date' => '2008-12-20',
/**
* Check with incorrect required fields.
*/
- public function testRelationshipDeleteWithIncorrectData() {
+ public function testRelationshipDeleteWithIncorrectData(): void {
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
$this->callAPIFailure('relationship', 'delete', $params, 'Mandatory key(s) missing from params array: id');
- $params['id'] = "Invalid";
+ $params['id'] = 'Invalid';
$this->callAPIFailure('relationship', 'delete', $params, 'id is not a valid integer');
}
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
];
$result = $this->callAPISuccess('relationship', 'create', $params);
$params = ['id' => $result['id']];
$this->callAPIAndDocument('relationship', 'delete', $params, __FUNCTION__, __FILE__);
- $this->relationshipTypeDelete($this->_relTypeID);
}
///////////////// civicrm_relationship_update methods
$relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '20081214',
'end_date' => '20091214',
'is_active' => 1,
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '20081214',
'end_date' => '20091214',
'is_active' => 0,
];
$this->callAPIFailure('relationship', 'create', $params, 'Duplicate Relationship');
-
- $this->callAPISuccess('relationship', 'delete', ['id' => $result['id']]);
- $this->relationshipTypeDelete($this->_relTypeID);
}
/**
* should be OK if the custom field values differ.
* FIXME: Api4
*/
- public function testRelationshipCreateDuplicateWithCustomFields() {
+ public function testRelationshipCreateDuplicateWithCustomFields(): void {
$this->createCustomGroupWithFieldsOfAllTypes();
$custom_params_1 = [
$params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
];
$this->assertNotNull($result_2['id']);
$this->assertEquals(0, $result_2['is_error']);
-
- $this->relationshipTypeDelete($this->_relTypeID);
}
/**
* does.
* FIXME: Api4
*/
- public function testRelationshipCreateDuplicateWithCustomFields2() {
+ public function testRelationshipCreateDuplicateWithCustomFields2(): void {
$this->createCustomGroupWithFieldsOfAllTypes();
$custom_params_2 = [
$params_1 = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
];
$this->assertNotNull($result_2['id']);
$this->assertEquals(0, $result_2['is_error']);
-
- $this->relationshipTypeDelete($this->_relTypeID);
}
/**
$params_2 = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'is_active' => 1,
];
$this->assertNotNull($result_2['id']);
$this->assertEquals(0, $result_2['is_error']);
-
- $this->relationshipTypeDelete($this->_relTypeID);
}
/**
$relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2011-01-01',
'end_date' => '2013-01-01',
'is_active' => 1,
// Try to retrieve it using chaining.
$params = [
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'id' => $id,
'api.Contact.get' => [
'id' => '$value.contact_id_b',
$params = [
'id' => $this->_cId_a,
'api.Relationship.get' => [
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'contact_id_a' => '$value.id',
'api.Contact.get' => [
'id' => '$value.contact_id_b',
$relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2011-01-01',
'end_date' => '2013-01-01',
'is_active' => 1,
$rel2Params = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b2,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2008-12-20',
'is_active' => 0,
];
$relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2011-01-01',
'end_date' => '2013-01-01',
'is_active' => 1,
];
- $relationship = $this->callAPISuccess('relationship', 'create', $relParams);
-
- $contacts = [
- 'contact_id' => $this->_cId_a,
- ];
-
- $result = $this->callAPISuccess('relationship', 'get', $contacts);
+ $this->callAPISuccess('relationship', 'create', $relParams);
+ $result = $this->callAPISuccess('Relationship', 'get', ['contact_id' => $this->_cId_a]);
$this->assertGreaterThan(0, $result['count']);
- $params = [
- 'id' => $relationship['id'],
- ];
- $this->callAPISuccess('relationship', 'delete', $params);
- $this->relationshipTypeDelete($this->_relTypeID);
}
/**
* Check with valid data with relationshipTypes.
*/
- public function testGetRelationshipWithRelTypes() {
+ public function testGetRelationshipWithRelTypes(): void {
$relParams = [
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $this->_cId_b,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'start_date' => '2011-01-01',
'end_date' => '2013-01-01',
'is_active' => 1,
];
- $relationship = $this->callAPISuccess('relationship', 'create', $relParams);
+ $this->callAPISuccess('relationship', 'create', $relParams);
$contact_a = [
'contact_id' => $this->_cId_a,
];
$this->callAPISuccess('relationship', 'get', $contact_a);
-
- $params = [
- 'id' => $relationship['id'],
- ];
- $this->callAPISuccess('relationship', 'delete', $params);
- $this->relationshipTypeDelete($this->_relTypeID);
}
/**
* We should get 1 result without or with correct relationship type id & 0 with
* an incorrect one
*/
- public function testGetRelationshipByTypeReciprocal() {
+ public function testGetRelationshipByTypeReciprocal(): void {
$created = $this->callAPISuccess($this->entity, 'create', $this->_params);
$result = $this->callAPISuccess($this->entity, 'get', [
'contact_id' => $this->_cId_a,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
]);
$this->assertEquals(1, $result['count']);
$result = $this->callAPISuccess($this->entity, 'get', [
* @param int $version
* @dataProvider versionThreeAndFour
*/
- public function testGetRelationshipByTypeDAO($version) {
+ public function testGetRelationshipByTypeDAO($version): void {
$this->_apiversion = $version;
$this->_ids['relationship'] = $this->callAPISuccess($this->entity, 'create', ['format.only_id' => TRUE] +
$this->_params);
], 1);
$result = $this->callAPISuccess($this->entity, 'get', [
'contact_id_a' => $this->_cId_a,
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
]);
$this->assertEquals(1, $result['count']);
$result = $this->callAPISuccess($this->entity, 'get', [
*
* We should get 1 result without or with correct relationship type id & 0 with
* an incorrect one
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
*/
- public function testGetRelationshipByTypeArrayDAO($version) {
+ public function testGetRelationshipByTypeArrayDAO(int $version): void {
$this->_apiversion = $version;
$this->callAPISuccess($this->entity, 'create', $this->_params);
$org3 = $this->organizationCreate();
$result = $this->callAPISuccess($this->entity, 'get', [
'contact_id_a' => $this->_cId_a,
- 'relationship_type_id' => ['IN' => [$this->_relTypeID, $relType3]],
+ 'relationship_type_id' => ['IN' => [$this->relationshipTypeID, $relType3]],
]);
$this->assertEquals(2, $result['count']);
- foreach ($result['values'] as $key => $value) {
- $this->assertTrue(in_array($value['relationship_type_id'], [$this->_relTypeID, $relType3]));
+ foreach ($result['values'] as $value) {
+ $this->assertContains($value['relationship_type_id'], [$this->relationshipTypeID, $relType3]);
}
}
$result = $this->callAPISuccess($this->entity, 'get', [
'contact_id' => $this->_cId_a,
- 'relationship_type_id' => ['IN' => [$this->_relTypeID, $relType3]],
+ 'relationship_type_id' => ['IN' => [$this->relationshipTypeID, $relType3]],
]);
$this->assertEquals(2, $result['count']);
foreach ($result['values'] as $key => $value) {
- $this->assertTrue(in_array($value['relationship_type_id'], [$this->_relTypeID, $relType3]));
+ $this->assertTrue(in_array($value['relationship_type_id'], [$this->relationshipTypeID, $relType3]));
}
}
// 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'], [$relType1]));
+ $this->assertContains($value['relationship_type_id'], [$relType1]);
}
}
'duration_unit' => 'year',
'duration_interval' => 1,
'period_type' => 'rolling',
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'relationship_direction' => 'b_a',
'visibility' => 'Public',
'auto_renew' => 0,
'contact_id' => $mainContactID,
]);
$this->callAPISuccess('Relationship', 'create', [
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'contact_id_a' => $this->_cId_a,
'contact_id_b' => $mainContactID,
]);
// Adding a relationship with a future start date should NOT create a membership
$this->callAPISuccess('Relationship', 'create', [
- 'relationship_type_id' => $this->_relTypeID,
+ 'relationship_type_id' => $this->relationshipTypeID,
'contact_id_a' => $this->_cId_a_2,
'contact_id_b' => $mainContactID,
'start_date' => 'now + 1 week',