fix membershiptypetest
[civicrm-core.git] / tests / phpunit / api / v3 / EmailTest.php
index ce6a5a93b2605ee483610cb87a20caf2ba522872..735be1bb43f9f2b72a05a87fc0a1b5873572c629 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.                                    |
 |                                                                    |
@@ -23,7 +23,7 @@
 | 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';
 
@@ -37,18 +37,20 @@ class api_v3_EmailTest extends CiviUnitTestCase {
   protected $_entity;
   protected $_params;
 
-  function setUp() {
+  public function setUp() {
     $this->_apiversion = 3;
     $this->_entity = 'Email';
     parent::setUp();
+    $this->useTransaction(TRUE);
+
     $this->_contactID = $this->organizationCreate(NULL);
     $this->_locationType = $this->locationTypeCreate(NULL);
     $this->_locationType2 = $this->locationTypeCreate(array(
-        'name' => 'New Location Type 2',
-        'vcard_name' => 'New Location Type 2',
-        'description' => 'Another Location Type',
-        'is_active' => 1,
-      ));
+      'name' => 'New Location Type 2',
+      'vcard_name' => 'New Location Type 2',
+      'description' => 'Another Location Type',
+      'is_active' => 1,
+    ));
     $this->_params = array(
       'contact_id' => $this->_contactID,
       'location_type_id' => $this->_locationType->id,
@@ -59,11 +61,6 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     );
   }
 
-  function tearDown() {
-    $this->contactDelete($this->_contactID);
-    $this->locationTypeDelete($this->_locationType->id);
-    $this->locationTypeDelete($this->_locationType2->id);
-  }
   public function testCreateEmail() {
     $params = $this->_params;
     //check there are no emails to start with
@@ -73,19 +70,17 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__);
 
     $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__);
-    $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
-    $this->assertNotNull($result['id'], 'In line ' . __LINE__);
-    $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
+    $this->assertEquals(1, $result['count']);
+    $this->assertNotNull($result['id']);
+    $this->assertNotNull($result['values'][$result['id']]['id']);
     $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
   }
-  /*
-   * If a new email is set to is_primary the prev should no longer be
+
+  /**
+   * If a new email is set to is_primary the prev should no longer be.
    *
    * If is_primary is not set then it should become is_primary is no others exist
    */
-
-
-
   public function testCreateEmailPrimaryHandlingChangeToPrimary() {
     $params = $this->_params;
     unset($params['is_primary']);
@@ -93,27 +88,27 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     //now we check & make sure it has been set to primary
     $expected = 1;
     $check = $this->callAPISuccess('email', 'getcount', array(
-      'is_primary' => 1,
-      'id' => $email1['id'],
+        'is_primary' => 1,
+        'id' => $email1['id'],
       ),
       $expected
-     );
+    );
   }
 
   public function testCreateEmailPrimaryHandlingChangeExisting() {
     $email1 = $this->callAPISuccess('email', 'create', $this->_params);
     $email2 = $this->callAPISuccess('email', 'create', $this->_params);
     $check = $this->callAPISuccess('email', 'getcount', array(
-        'is_primary' => 1,
-        'contact_id' => $this->_contactID,
-      ));
+      'is_primary' => 1,
+      'contact_id' => $this->_contactID,
+    ));
     $this->assertEquals(1, $check);
   }
 
   public function testCreateEmailWithoutEmail() {
     $result = $this->callAPIFailure('Email', 'Create', array('contact_id' => 4));
-    $this->assertContains('missing', $result['error_message'], 'In line ' . __LINE__);
-    $this->assertContains('email', $result['error_message'], 'In line ' . __LINE__);
+    $this->assertContains('missing', $result['error_message']);
+    $this->assertContains('email', $result['error_message']);
   }
 
   public function testGetEmail() {
@@ -126,6 +121,7 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     $this->assertEquals($get['count'], 1);
     $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
   }
+
   public function testDeleteEmail() {
     $params = array(
       'contact_id' => $this->_contactID,
@@ -137,15 +133,15 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     );
     //check there are no emails to start with
     $get = $this->callAPISuccess('email', 'get', array(
-     'location_type_id' => $this->_locationType->id,
+      'location_type_id' => $this->_locationType->id,
     ));
     $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
 
     //create one
     $create = $this->callAPISuccess('email', 'create', $params);
 
-    $result = $this->callAPIAndDocument('email', 'delete', array('id' => $create['id'],), __FUNCTION__, __FILE__);
-    $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
+    $result = $this->callAPIAndDocument('email', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__);
+    $this->assertEquals(1, $result['count']);
     $get = $this->callAPISuccess('email', 'get', array(
       'location_type_id' => $this->_locationType->id,
     ));
@@ -155,8 +151,8 @@ class api_v3_EmailTest extends CiviUnitTestCase {
   public function testReplaceEmail() {
     // check there are no emails to start with
     $get = $this->callAPISuccess('email', 'get', array(
-        'contact_id' => $this->_contactID,
-      ));
+      'contact_id' => $this->_contactID,
+    ));
     $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
 
     // initialize email list with three emails at loc #1 and two emails at loc #2
@@ -191,12 +187,12 @@ class api_v3_EmailTest extends CiviUnitTestCase {
       ),
     );
     $replace1 = $this->callAPIAndDocument('email', 'replace', $replace1Params, __FUNCTION__, __FILE__);
-    $this->assertEquals(5, $replace1['count'], 'In line ' . __LINE__);
+    $this->assertEquals(5, $replace1['count']);
 
     // check emails at location #1 or #2
     $get = $this->callAPISuccess('email', 'get', array(
-        'contact_id' => $this->_contactID,
-      ));
+      'contact_id' => $this->_contactID,
+    ));
     $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__);
 
     // replace the subset of emails in location #1, but preserve location #2
@@ -211,7 +207,7 @@ class api_v3_EmailTest extends CiviUnitTestCase {
       ),
     );
     $replace2 = $this->callAPISuccess('email', 'replace', $replace2Params);
-    $this->assertEquals(1, $replace2['count'], 'In line ' . __LINE__);
+    $this->assertEquals(1, $replace2['count']);
 
     // check emails at location #1 -- all three replaced by one
     $get = $this->callAPISuccess('email', 'get', array(
@@ -234,13 +230,13 @@ class api_v3_EmailTest extends CiviUnitTestCase {
       'values' => array(),
     );
     $replace3 = $this->callAPISuccess('email', 'replace', $replace3Params);
-    $this->assertEquals(0, $replace3['count'], 'In line ' . __LINE__);
+    $this->assertEquals(0, $replace3['count']);
 
     // check emails
     $get = $this->callAPISuccess('email', 'get', array(
 
-        'contact_id' => $this->_contactID,
-      ));
+      'contact_id' => $this->_contactID,
+    ));
     $this->assertAPISuccess($get, 'In line ' . __LINE__);
     $this->assertEquals(0, $get['count'], 'Incorrect email count at ' . __LINE__);
   }
@@ -249,11 +245,11 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     // check there are no emails to start with
     $get = $this->callAPISuccess('email', 'get', array(
 
-        'contact_id' => $this->_contactID,
-      ));
+      'contact_id' => $this->_contactID,
+    ));
     $this->assertAPISuccess($get, 'In line ' . __LINE__);
     $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
-    $description = "example demonstrates use of Replace in a nested API call";
+    $description = "Demonstrates use of Replace in a nested API call.";
     $subfile = "NestedReplaceEmail";
     // initialize email list with three emails at loc #1 and two emails at loc #2
     $getReplace1Params = array(
@@ -290,12 +286,12 @@ class api_v3_EmailTest extends CiviUnitTestCase {
       ),
     );
     $getReplace1 = $this->callAPIAndDocument('contact', 'get', $getReplace1Params, __FUNCTION__, __FILE__, $description, $subfile);
-    $this->assertEquals(5, $getReplace1['values'][$this->_contactID]['api.email.replace']['count'], 'In line ' . __LINE__);
+    $this->assertEquals(5, $getReplace1['values'][$this->_contactID]['api.email.replace']['count']);
 
     // check emails at location #1 or #2
     $get = $this->callAPISuccess('email', 'get', array(
-        'contact_id' => $this->_contactID,
-      ));
+      'contact_id' => $this->_contactID,
+    ));
     $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__);
 
     // replace the subset of emails in location #1, but preserve location #2
@@ -312,8 +308,8 @@ class api_v3_EmailTest extends CiviUnitTestCase {
       ),
     );
     $getReplace2 = $this->callAPISuccess('contact', 'get', $getReplace2Params);
-    $this->assertEquals(0, $getReplace2['values'][$this->_contactID]['api.email.replace']['is_error'], 'In line ' . __LINE__);
-    $this->assertEquals(1, $getReplace2['values'][$this->_contactID]['api.email.replace']['count'], 'In line ' . __LINE__);
+    $this->assertEquals(0, $getReplace2['values'][$this->_contactID]['api.email.replace']['is_error']);
+    $this->assertEquals(1, $getReplace2['values'][$this->_contactID]['api.email.replace']['count']);
 
     // check emails at location #1 -- all three replaced by one
     $get = $this->callAPISuccess('email', 'get', array(
@@ -334,8 +330,8 @@ class api_v3_EmailTest extends CiviUnitTestCase {
   public function testReplaceEmailWithId() {
     // check there are no emails to start with
     $get = $this->callAPISuccess('email', 'get', array(
-        'contact_id' => $this->_contactID,
-      ));
+      'contact_id' => $this->_contactID,
+    ));
     $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__);
 
     // initialize email address
@@ -351,7 +347,7 @@ class api_v3_EmailTest extends CiviUnitTestCase {
       ),
     );
     $replace1 = $this->callAPISuccess('email', 'replace', $replace1Params);
-    $this->assertEquals(1, $replace1['count'], 'In line ' . __LINE__);
+    $this->assertEquals(1, $replace1['count']);
 
     $keys = array_keys($replace1['values']);
     $emailID = array_shift($keys);
@@ -367,7 +363,7 @@ class api_v3_EmailTest extends CiviUnitTestCase {
       ),
     );
     $replace2 = $this->callAPISuccess('email', 'replace', $replace2Params);
-    $this->assertEquals(1, $replace2['count'], 'In line ' . __LINE__);
+    $this->assertEquals(1, $replace2['count']);
 
     // ensure the 'email' was updated while other fields were preserved
     $get = $this->callAPISuccess('email', 'get', array(
@@ -376,9 +372,9 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     ));
 
     $this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__);
-    $this->assertEquals(1, $get['values'][$emailID]['is_primary'], 'In line ' . __LINE__);
-    $this->assertEquals(1, $get['values'][$emailID]['on_hold'], 'In line ' . __LINE__);
-    $this->assertEquals('1-2@example.com', $get['values'][$emailID]['email'], 'In line ' . __LINE__);
+    $this->assertEquals(1, $get['values'][$emailID]['is_primary']);
+    $this->assertEquals(1, $get['values'][$emailID]['on_hold']);
+    $this->assertEquals('1-2@example.com', $get['values'][$emailID]['email']);
   }
-}
 
+}