X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fphpunit%2Fapi%2Fv3%2FRelationshipTest.php;h=2ee40f064bc70c4ec9a16e32a1a20d4a3e0fe36e;hb=41cb88cef12d65bb470c0bc458736547db9b7952;hp=bd75c42112fce7fd725262a19f094fccefb96637;hpb=57143973f6f5e9b0914f5840811131217e5d9dbf;p=civicrm-core.git diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index bd75c42112..2ee40f064b 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -3,7 +3,7 @@ * +--------------------------------------------------------------------+ * | CiviCRM version 5 | * +--------------------------------------------------------------------+ - * | Copyright CiviCRM LLC (c) 2004-2018 | + * | Copyright CiviCRM LLC (c) 2004-2019 | * +--------------------------------------------------------------------+ * | This file is a part of CiviCRM. | * | | @@ -109,6 +109,46 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { $this->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. */