Merge pull request #5536 from totten/4.5-httpclient
[civicrm-core.git] / tests / phpunit / api / v3 / MailingContactTest.php
index b1863f860100c4223c7996b289e3fc5aeb7d02b5..0c5ac77938c91bad3bd0c47c9ced456d02afb413 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -31,9 +31,8 @@
  * @package CiviCRM_APIv3
  * @subpackage API_MailingContact
  *
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $
- *
  */
 require_once 'CiviTest/CiviUnitTestCase.php';
 
@@ -44,7 +43,7 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
   protected $_apiversion = 3;
   protected $_entity = 'mailing';
 
-  function setUp() {
+  public function setUp() {
     parent::setUp();
     $params = array(
       'first_name' => 'abc1',
@@ -54,20 +53,23 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
     $this->_contact = $this->callAPISuccess("contact", "create", $params);
   }
 
-  function tearDown() {
+  public function tearDown() {
     $this->callAPISuccess("contact", "delete", array('id' => $this->_contact['id']));
     parent::tearDown();
   }
 
   /**
-   * Test that the api responds correctly to null params
-   * Note to copy & pasters - tests like this that test the wrapper belong in the SyntaxConformance class
+   * Test that the api responds correctly to null params.
+   *
+   * Do not copy and paste.
+   *
+   * Tests like this that test the wrapper belong in the SyntaxConformance class
    * (which already has a 'not array test)
    * I have left this here in case 'null' isn't covered in that class
    * but don't copy it only any other classes
    */
   public function testMailingNullParams() {
-    $result = $this->callAPIFailure('MailingContact', 'get', null);
+    $this->callAPIFailure('MailingContact', 'get', NULL);
   }
 
   public function testMailingContactGetFields() {
@@ -79,54 +81,58 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test that the api will return the proper error when you do not
-   * supply the contact_id
-   * Note to copy & pasters - test is of marginal if any value & testing of wrapper level functionaliy
+   * Test for proper error when you do not supply the contact_id.
+   *
+   * Do not copy and paste.
+   *
+   * Test is of marginal if any value & testing of wrapper level functionality
    * belongs in the SyntaxConformance class
    */
   public function testMailingNoContactID() {
     $params = array(
       'something' => 'This is not a real field',
     );
-    $result = $this->callAPIFailure('MailingContact', 'get', $params);
+    $this->callAPIFailure('MailingContact', 'get', $params);
   }
 
   /**
-   * Test that invalid contact_id return with proper error messages
-   * Note to copy & pasters - test is of marginal if any value & testing of wrapper level functionaliy
+   * Test that invalid contact_id return with proper error messages.
+   *
+   * Do not copy & paste.
+   *
+   * Test is of marginal if any value & testing of wrapper level functionality
    * belongs in the SyntaxConformance class
    */
   public function testMailingContactInvalidContactID() {
-    $params = array('contact_id' => 'This is not a number',);
-    $result = $this->callAPIFailure('MailingContact', 'get', $params);
+    $params = array('contact_id' => 'This is not a number');
+    $this->callAPIFailure('MailingContact', 'get', $params);
   }
 
   /**
-   * Test that invalid types are returned with appropriate errors
+   * Test that invalid types are returned with appropriate errors.
    */
   public function testMailingContactInvalidType() {
     $params = array(
       'contact_id' => 23,
       'type' => 'invalid',
     );
-    $result = $this->callAPIFailure('MailingContact', 'get', $params);
+    $this->callAPIFailure('MailingContact', 'get', $params);
   }
 
   /**
-   * Test that the API returns properly when there are no mailings
-   * for a the given contact
+   * Test for success result when there are no mailings for a the given contact.
    */
   public function testMailingContactNoMailings() {
     $params = array(
       'contact_id' => $this->_contact['id'],
     );
     $result = $this->callAPISuccess('MailingContact', 'get', $params);
-    $this->assertEquals($result['count'], 0, "In line " . __LINE__);
-    $this->assertTrue(empty($result['values']), "In line " . __LINE__);
+    $this->assertEquals($result['count'], 0);
+    $this->assertTrue(empty($result['values']));
   }
 
   /**
-   * Test that the API returns a mailing properly when there is only one
+   * Test that the API returns a mailing properly when there is only one.
    */
   public function testMailingContactDelivered() {
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
@@ -136,7 +142,7 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
         dirname(__FILE__) . '/dataset/mailing_contact.xml'
       )
     );
-    //~ Create the Mailing and connections to the user
+    // Create the Mailing and connections to the user.
     $op->execute($this->_dbconn,
       $this->createXMLDataSet(
         dirname(__FILE__) . '/dataset/mailing_delivered.xml'
@@ -150,28 +156,28 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
 
     $result = $this->callAPISuccess('MailingContact', 'get', $params);
     $count = $this->callAPISuccess('MailingContact', 'getcount', $params);
-    $this->assertEquals($result['count'], 1, "In line " . __LINE__);
-    $this->assertEquals($count, 1, "In line " . __LINE__);
-    $this->assertFalse(empty($result['values']), "In line " . __LINE__);
-    $this->assertEquals($result['values'][1]['mailing_id'], 1, "In line " . __LINE__);
-    $this->assertEquals($result['values'][1]['subject'], "Some Subject", "In line " . __LINE__);
-    $this->assertEquals($result['values'][1]['creator_id'], 3, "In line " . __LINE__);
-    $this->assertEquals($result['values'][1]['creator_name'], "xyz1, abc1", "In line " . __LINE__);
+    $this->assertEquals($result['count'], 1);
+    $this->assertEquals($count, 1);
+    $this->assertFalse(empty($result['values']));
+    $this->assertEquals($result['values'][1]['mailing_id'], 1);
+    $this->assertEquals($result['values'][1]['subject'], "Some Subject");
+    $this->assertEquals($result['values'][1]['creator_id'], 3);
+    $this->assertEquals($result['values'][1]['creator_name'], "xyz1, abc1");
   }
 
 
   /**
-   * Test that the API returns only the "Bounced" mailings when instructed to do so
+   * Test that the API returns only the "Bounced" mailings when instructed to do so.
    */
-  function testMailingContactBounced( ) {
+  public function testMailingContactBounced() {
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
-    //Create the User
+    // Create the User.
     $op->execute($this->_dbconn,
       $this->createXMLDataSet(
         dirname(__FILE__) . '/dataset/mailing_contact.xml'
       )
     );
-    //~ Create the Mailing and connections to the user
+    // Create the Mailing and connections to the user.
     $op->execute($this->_dbconn,
       $this->createXMLDataSet(
         dirname(__FILE__) . '/dataset/mailing_bounced.xml'
@@ -184,11 +190,12 @@ class api_v3_MailingContactTest extends CiviUnitTestCase {
     );
 
     $result = $this->callAPISuccess('MailingContact', 'get', $params);
-    $this->assertEquals($result['count'], 1, "In line " . __LINE__);
-    $this->assertFalse(empty($result['values']), "In line " . __LINE__);
-    $this->assertEquals($result['values'][2]['mailing_id'], 2, "In line " . __LINE__);
-    $this->assertEquals($result['values'][2]['subject'], "Some Subject", "In line " . __LINE__);
-    $this->assertEquals($result['values'][2]['creator_id'], 3, "In line " . __LINE__);
-    $this->assertEquals($result['values'][2]['creator_name'], "xyz1, abc1", "In line " . __LINE__);
+    $this->assertEquals($result['count'], 1);
+    $this->assertFalse(empty($result['values']));
+    $this->assertEquals($result['values'][2]['mailing_id'], 2);
+    $this->assertEquals($result['values'][2]['subject'], "Some Subject");
+    $this->assertEquals($result['values'][2]['creator_id'], 3);
+    $this->assertEquals($result['values'][2]['creator_name'], "xyz1, abc1");
   }
+
 }