Action schedule API modifications
[civicrm-core.git] / tests / phpunit / api / v3 / PhoneTest.php
index 8260cf5be2cb9db8ef9af277432ce735008296d5..877452eb92f433792dcd4ee822c570f7271b2639 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -56,7 +56,6 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
       'location_type_id' => $this->_locationType,
       'phone' => '(123) 456-7890',
       'is_primary' => 1,
-      'version' => $this->_apiversion,
       'phone_type_id' => 1,
     );
   }
@@ -68,88 +67,52 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
 
   public function testCreatePhone() {
 
-    $result = civicrm_api('phone', 'create', $this->_params);
-
-    $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('phone', 'create', $this->_params, __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
 
-    // $this->assertEquals( 1, $result['id'], 'In line ' . __LINE__ );
-
-    $delresult = civicrm_api('phone', 'delete', array('id' => $result['id'], 'version' => $this->_apiversion));
-    $this->assertEquals(0, $delresult['is_error'], 'In line ' . __LINE__);
+    $this->callAPISuccess('phone', 'delete', array('id' => $result['id']));
   }
 
   public function testDeletePhone() {
     //create one
-    $create = civicrm_api('phone', 'create', $this->_params);
-
-    $this->assertAPISuccess($create, 'In line ' . __LINE__);
+    $create = $this->callAPISuccess('phone', 'create', $this->_params);
 
-    $result = civicrm_api('phone', 'delete', array('id' => $create['id'], 'version' => $this->_apiversion));
-    $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('phone', 'delete', array('id' => $create['id'],), __FUNCTION__, __FILE__);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
-    $get = civicrm_api('phone', 'get', array(
-      'version' => $this->_apiversion, 'id' => $create['id'],
-        'location_type_id' => $this->_locationType,
-      ));
-    $this->assertEquals(0, $get['is_error'], 'In line ' . __LINE__);
+    $get = $this->callAPISuccess('phone', 'get', array(
+      'id' => $create['id'],
+      'location_type_id' => $this->_locationType,
+    ));
     $this->assertEquals(0, $get['count'], 'Phone not successfully deleted In line ' . __LINE__);
   }
 
-  /**
-   * Test civicrm_phone_get with wrong params type.
-   */
-  public function testGetWrongParamsType() {
-    $params = 'is_string';
-    $result = civicrm_api('Phone', 'Get', ($params));
-    $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__);
-  }
-
   /**
    * Test civicrm_phone_get with empty params.
    */
   public function testGetEmptyParams() {
-    $params = array('version' => $this->_apiversion);
-    $result = civicrm_api('Phone', 'Get', ($params));
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPISuccess('Phone', 'Get', array());
   }
 
   /**
    * Test civicrm_phone_get with wrong params.
    */
   public function testGetWrongParams() {
-    $params = array('contact_id' => 'abc', 'version' => $this->_apiversion, 'debug'=>1 );
-    $result = civicrm_api('Phone', 'Get', $params);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
-    $this->assertEquals(0, $result['count'], 'In line ' . __LINE__);
-
-    $params = array('location_type_id' => 'abc', 'version' => $this->_apiversion);
-    $result = civicrm_api('Phone', 'Get', ($params));
-    $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__);
-
-    $params = array('phone_type_id' => 'abc', 'version' => $this->_apiversion);
-    $result = civicrm_api('Phone', 'Get', ($params));
-    $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__);
-    $this->assertTrue(empty($result['count']), 'In line ' . __LINE__);
+    $this->callAPIFailure('Phone', 'Get', array('contact_id' => 'abc'));
+    $this->callAPIFailure('Phone', 'Get', array('location_type_id' => 'abc'));
+    $this->callAPIFailure('Phone', 'Get', array('phone_type_id' => 'abc'));
   }
 
   /**
    * Test civicrm_phone_get - success expected.
    */
   public function testGet() {
-    $phone = civicrm_api('phone', 'create', $this->_params);
-    $this->assertAPISuccess($phone, 'In line ' . __LINE__);
+    $phone = $this->callAPISuccess('phone', 'create', $this->_params);
     $params = array(
       'contact_id' =>  $this->_params['contact_id'],
       'phone' => $phone['values'][$phone['id']]['phone'],
-      'version' => $this->_apiversion,
     );
-    $result = civicrm_api('Phone', 'Get', ($params));
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('Phone', 'Get', $params, __FUNCTION__, __FILE__);
     $this->assertEquals($phone['values'][$phone['id']]['location_type_id'], $result['values'][$phone['id']]['location_type_id'], 'In line ' . __LINE__);
     $this->assertEquals($phone['values'][$phone['id']]['phone_type_id'], $result['values'][$phone['id']]['phone_type_id'], 'In line ' . __LINE__);
     $this->assertEquals($phone['values'][$phone['id']]['is_primary'], $result['values'][$phone['id']]['is_primary'], 'In line ' . __LINE__);
@@ -158,24 +121,14 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
 
   ///////////////// civicrm_phone_create methods
 
-  /**
-   * Test civicrm_phone_create with wrong params type.
-   */
-  public function testCreateWrongParamsType() {
-    $params = 'a string';
-    $result = civicrm_api('Phone', 'Create', $params);
-    $this->assertEquals(1, $result['is_error'], "In line " . __LINE__);
-  }
-
   /**
    * Ensure numeric_phone field is correctly populated (this happens via sql trigger)
    */
   public function testNumericPhone() {
-    $result = civicrm_api('phone', 'create', $this->_params);
-    $this->assertAPISuccess($result, 'In line ' . __LINE__);
+    $result = $this->callAPISuccess('phone', 'create', $this->_params);
     $id = $result['id'];
-    $params = array('id' => $id, 'version' => $this->_apiversion, 'return.phone_numeric' => 1);
-    $result = civicrm_api('phone', 'get', $params);
+    $params = array('id' => $id, 'return.phone_numeric' => 1);
+    $result = $this->callAPISuccess('phone', 'get', $params);
     $this->assertEquals('1234567890', $result['values'][$id]['phone_numeric']);
   }
 
@@ -187,26 +140,21 @@ class api_v3_PhoneTest extends CiviUnitTestCase {
   public function testCreatePhonePrimaryHandlingChangeToPrimary() {
     $params = $this->_params;
     unset($params['is_primary']);
-    $phone1 = civicrm_api('phone', 'create', $params);
-    $this->assertApiSuccess($phone1, 'In line ' . __LINE__);
+    $phone1 = $this->callAPISuccess('phone', 'create', $params);
     //now we check & make sure it has been set to primary
-    $check = civicrm_api('phone', 'getcount', array(
-        'version' => 3,
+    $check = $this->callAPISuccess('phone', 'getcount', array(
         'is_primary' => 1,
         'id' => $phone1['id'],
       ));
     $this->assertEquals(1, $check);
   }
   public function testCreatePhonePrimaryHandlingChangeExisting() {
-    $phone1 = civicrm_api('phone', 'create', $this->_params);
-    $this->assertApiSuccess($phone1, 'In line ' . __LINE__);
-    $phone2 = civicrm_api('phone', 'create', $this->_params);
-    $this->assertApiSuccess($phone2, 'In line ' . __LINE__);
-    $check = civicrm_api('phone', 'getcount', array(
-        'version' => 3,
-        'is_primary' => 1,
-        'contact_id' => $this->_contactID,
-      ));
+    $phone1 = $this->callAPISuccess('phone', 'create', $this->_params);
+    $phone2 = $this->callAPISuccess('phone', 'create', $this->_params);
+    $check = $this->callAPISuccess('phone', 'getcount', array(
+      'is_primary' => 1,
+      'contact_id' => $this->_contactID,
+    ));
     $this->assertEquals(1, $check);
   }
 }