From 5fc991dddef5e97088636aafdfc55592cc0537ab Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 1 Jul 2015 09:49:15 +1200 Subject: [PATCH] CRM-16473 add user api test --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 9 +++ tests/phpunit/api/v3/UserTest.php | 70 +++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 tests/phpunit/api/v3/UserTest.php 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']); + } + +} -- 2.25.1