CRM-16473 add user api test
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 30 Jun 2015 21:49:15 +0000 (09:49 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Tue, 30 Jun 2015 21:49:15 +0000 (09:49 +1200)
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/UserTest.php [new file with mode: 0644]

index b896aac5bb0a92c58fce0cb9797ee2ceb90e5197..eadb9f2436d08478319483e59cc7f1975d56f5b1 100755 (executable)
@@ -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 (file)
index 0000000..b507f30
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+
+/**
+ *  Test APIv3 civicrm_website_* functions
+ *
+ * @package CiviCRM_APIv3
+ * @subpackage API_Contact
+ */
+class api_v3_UserWebsiteTest extends CiviUnitTestCase {
+  protected $_apiversion = 3;
+  protected $params;
+  protected $_entity = 'User';
+  protected $contactID;
+
+  public $DBResetRequired = FALSE;
+
+  public function setUp() {
+    parent::setUp();
+    $this->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']);
+  }
+
+}