From: Eileen McNaughton Date: Tue, 30 Jun 2015 21:49:15 +0000 (+1200) Subject: CRM-16473 add user api test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5fc991dddef5e97088636aafdfc55592cc0537ab;p=civicrm-core.git CRM-16473 add user api test --- diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index b896aac5bb..eadb9f2436 100755 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -473,6 +473,9 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * Emulate a logged in user since certain functions use that. * value to store a record in the DB (like activity) * CRM-8180 + * + * @return int + * Contact ID of the created user. */ public function createLoggedInUser() { $params = array( @@ -481,9 +484,15 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { 'contact_type' => 'Individual', ); $contactID = $this->individualCreate($params); + $this->callAPISuccess('UFMatch', 'create', array( + 'contact_id' => $contactID, + 'uf_name' => 'superman', + 'uf_id' => 6, + )); $session = CRM_Core_Session::singleton(); $session->set('userID', $contactID); + return $contactID; } public function cleanDB() { diff --git a/tests/phpunit/api/v3/UserTest.php b/tests/phpunit/api/v3/UserTest.php new file mode 100644 index 0000000000..b507f30dbf --- /dev/null +++ b/tests/phpunit/api/v3/UserTest.php @@ -0,0 +1,70 @@ +contactID = $this->createLoggedInUser(); + $this->params = array( + 'contact_id' => $this->contactID, + 'sequential' => 1, + ); + } + + public function testUserGet() { + $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__); + $this->assertEquals(1, $result['count']); + $this->assertEquals($this->contactID, $result['values'][0]['contact_id']); + $this->assertEquals(6, $result['values'][0]['id']); + $this->assertEquals('superman', $result['values'][0]['name']); + } + + /** + * Test retrieval of label metadata. + */ + public function testGetFields() { + $result = $this->callAPIAndDocument($this->_entity, 'getfields', array('action' => 'get'), __FUNCTION__, __FILE__); + $this->assertArrayKeyExists('name', $result['values']); + } + +}