Merge pull request #5536 from totten/4.5-httpclient
[civicrm-core.git] / tests / phpunit / api / v3 / APITest.php
index dc29ed34c73175b5edd133555f65415b2b2334b8..a259e677e5975dd75b4a588ebe148ff985ed1142 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | 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 class for API functions
+ * Test class for API functions.
  *
  * @package CiviCRM_APIv3
  */
@@ -58,7 +58,7 @@ class api_v3_APITest extends CiviUnitTestCase {
       'big_rock' => '$value.api.tag.create.api.tag.create.values.0.display',
       'villain' => '$value.api.tag.create.values.0.api_tag_get.display',
     );
-    _civicrm_api_replace_variables('Activity', 'Get', $params, $result);
+    _civicrm_api_replace_variables($params, $result);
     $this->assertEquals(999, $params['number']);
     $this->assertEquals(8, $params['tag_id']);
     $this->assertEquals(6, $params['activity_type_id']);
@@ -68,25 +68,32 @@ class api_v3_APITest extends CiviUnitTestCase {
     $this->assertEquals('krypton', $params['big_rock']);
   }
 
-  /*
-    * test that error doesn't occur for non-existant file
-    */
+  /**
+   * Test that error doesn't occur for non-existent file.
+   */
   public function testAPIWrapperIncludeNoFile() {
-
-    $result = $this->callAPIFailure('RandomFile', 'get', array(), 'API (RandomFile,get) does not exist (join the API team and implement it!)');
+    $this->callAPIFailure(
+      'RandomFile',
+      'get',
+      array(),
+      'API (RandomFile,get) does not exist (join the API team and  implement it!)'
+    );
   }
 
   public function testAPIWrapperCamelCaseFunction() {
-    $result = $this->callAPISuccess('OptionGroup', 'Get', array());
+    $this->callAPISuccess('OptionGroup', 'Get', array());
   }
 
   public function testAPIWrapperLcaseFunction() {
-    $result = $this->callAPISuccess('OptionGroup', 'get', array());
+    $this->callAPISuccess('OptionGroup', 'get', array());
   }
 
+  /**
+   * Test resolver.
+   */
   public function testAPIResolver() {
-    $oldpath = get_include_path();
-    set_include_path($oldpath . PATH_SEPARATOR . dirname(__FILE__) . '/dataset/resolver');
+    $oldPath = get_include_path();
+    set_include_path($oldPath . PATH_SEPARATOR . dirname(__FILE__) . '/dataset/resolver');
 
     $result = $this->callAPISuccess('contact', 'example_action1', array());
     $this->assertEquals($result['values'][0], 'civicrm_api3_generic_example_action1 is ok');
@@ -95,7 +102,7 @@ class api_v3_APITest extends CiviUnitTestCase {
     $result = $this->callAPISuccess('test_entity', 'example_action3', array());
     $this->assertEquals($result['values'][0], 'civicrm_api3_test_entity_example_action3 is ok');
 
-    set_include_path($oldpath);
+    set_include_path($oldPath);
   }
 
   public function testFromCamel() {
@@ -123,7 +130,6 @@ class api_v3_APITest extends CiviUnitTestCase {
       'optionValue' => 'OptionValue',
       'option_value' => 'OptionValue',
       'UFJoin' => 'UFJoin',
-      // dommage 'ufJoin' => 'UFJoin',
       'uf_join' => 'UFJoin',
     );
     foreach ($cases as $input => $expected) {
@@ -131,14 +137,15 @@ class api_v3_APITest extends CiviUnitTestCase {
       $this->assertEquals($expected, $actual, sprintf('input=%s expected=%s actual=%s', $input, $expected, $actual));
     }
   }
+
   /**
-   * Test that calling via wrapper works
+   * Test that calling via wrapper works.
    */
   public function testv3Wrapper() {
-    try{
+    try {
       $result = civicrm_api3('contact', 'get', array());
     }
-    catch (CRM_Exception $e){
+    catch (CRM_Exception $e) {
       $this->fail("This should have been a success test");
     }
     $this->assertTrue(is_array($result));
@@ -146,13 +153,13 @@ class api_v3_APITest extends CiviUnitTestCase {
   }
 
   /**
-   * Test exception is thrown
+   * Test exception is thrown.
    */
-  public function testv3WrapperException(){
-    try{
-      $result = civicrm_api3('contact', 'create', array('debug' => 1));
+  public function testV3WrapperException() {
+    try {
+      civicrm_api3('contact', 'create', array('debug' => 1));
     }
-    catch (CiviCRM_API3_Exception $e){
+    catch (CiviCRM_API3_Exception $e) {
       $this->assertEquals('mandatory_missing', $e->getErrorCode());
       $this->assertEquals('Mandatory key(s) missing from params array: contact_type', $e->getMessage());
       $extra = $e->getExtraParams();
@@ -162,7 +169,10 @@ class api_v3_APITest extends CiviUnitTestCase {
     $this->fail('Exception was expected');
   }
 
-  public function testCreate_NoStringNullResult() {
+  /**
+   * Test result parsing for null.
+   */
+  public function testCreateNoStringNullResult() {
     // create an example contact
     // $contact = CRM_Core_DAO::createTestObject('CRM_Contribute_DAO_ContributionPage')->toArray();
     $result = $this->callAPISuccess('ContributionPage', 'create', array(
@@ -186,11 +196,12 @@ class api_v3_APITest extends CiviUnitTestCase {
       'currency' => '',
     ));
 
-    // check return format
+    // Check return format.
     $this->assertEquals(1, $result['count']);
     foreach ($result['values'] as $resultValue) {
       $this->assertEquals('New title', $resultValue['title']);
-      $this->assertEquals('', $resultValue['currency']); // BUG: $resultValue['location'] === 'null'
+      // BUG: $resultValue['location'] === 'null'.
+      $this->assertEquals('', $resultValue['currency']);
     }
   }