X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fapi%2Fv3%2FRelationshipTest.php;h=2ee40f064bc70c4ec9a16e32a1a20d4a3e0fe36e;hb=832f3e1f078d2ae5fcd1ea70276f16716080af6d;hp=6b9501bf90025808ab55bf4c8494dd4e96a31497;hpb=05328349418e23e4ac7dc2353b89a8864818ca63;p=civicrm-core.git diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index 6b9501bf90..2ee40f064b 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -1,9 +1,9 @@ callAPIFailure('relationship', 'create', array()); } + /** + * Test Current Employer is correctly set. + */ + public function testCurrentEmployerRelationship() { + $employerRelationshipID = $this->callAPISuccessGetValue('RelationshipType', array( + 'return' => "id", + 'name_b_a' => "Employer Of", + )); + $employerRelationship = $this->callAPISuccess('Relationship', 'create', array( + 'contact_id_a' => $this->_cId_a, + 'contact_id_b' => $this->_cId_b, + 'relationship_type_id' => $employerRelationshipID, + )); + $params = array($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( + 'return' => "current_employer", + 'id' => $this->_cId_a, + )); + $organisation = $this->callAPISuccessGetValue('Contact', array( + 'return' => "sort_name", + 'id' => $this->_cId_b, + )); + $this->assertEquals($employer, $organisation); + + //Update relationship type + $update = $this->callAPISuccess('Relationship', 'create', array( + 'id' => $employerRelationship['id'], + 'relationship_type_id' => $this->_relTypeID, + )); + $employeeContact = $this->callAPISuccessGetSingle('Contact', array( + 'return' => array("current_employer"), + 'id' => $this->_cId_a, + )); + //current employer should be removed. + $this->assertEmpty($employeeContact['current_employer']); + } + /** * Check if required fields are not passed. */