CRM-13072 upgrade MailingTest to pass
authoreileen <eileen@fuzion.co.nz>
Thu, 25 Jul 2013 12:09:54 +0000 (00:09 +1200)
committereileen <eileen@fuzion.co.nz>
Thu, 25 Jul 2013 12:09:54 +0000 (00:09 +1200)
api/v3/Mailing.php
tests/phpunit/api/v3/MailingTest.php

index 5f8ec91cc88bb3976ff119be51e8967c0ae52e94..937056cc51995f0799fc6560d03932a97d690784 100644 (file)
@@ -66,13 +66,24 @@ function _civicrm_api3_mailing_create_spec(&$params) {
   $params['api.mailing_job.create']['api.default'] = 1;
 }
 
+/**
+ * Handle a create event.
+ *
+ * @param array $params
+ * @return array API Success Array
+ */
+function civicrm_api3_mailing_delete($params, $ids = array()) {
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+
 /**
  * Handle a get event.
  *
  * @param array $params
  * @return array
  */
-function civicrm_api3_mailing_get($params, $ids = array()) {
+function civicrm_api3_mailing_get($params) {
   return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
index 9214443bac3b577aa797fba2b84f14e05828326a..d08fa72ec7cf52985293cc9a9f160f9953673b81 100644 (file)
@@ -36,6 +36,7 @@ class api_v3_MailingTest extends CiviUnitTestCase {
   protected $_email;
   protected $_apiversion = 3;
   protected $_params = array();
+  protected $_entity = 'Mailing';
 
   function get_info() {
     return array(
@@ -69,16 +70,16 @@ class api_v3_MailingTest extends CiviUnitTestCase {
     $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
     $this->assertEquals(1, $jobs['count']);
     unset($params['created_id']);// return isn't working on this in getAndCheck so lets not check it for now
-    $this->getAndCheck($params, $result['id'], 'mailing');
+    $this->getAndCheck($this->_params, $result['id'], 'mailing');
   }
 
   /**
    * Test civicrm_mailing_create
    */
   public function testMailerDeleteSuccess() {
-    $result = $this->callAPISuccess('mailing', 'create', $params, __FUNCTION__, __FILE__);
-    $jobs = $this->callAPISuccess('mailing_job', 'delete', array('id' => $result['id']));
-    $this->assertAPIDeleted($entity, $result['id']);
+    $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+    $jobs = $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
+    $this->assertAPIDeleted($this->_entity, $result['id']);
   }
 
   //@ todo tests below here are all failure tests which are not hugely useful - need success tests
@@ -87,6 +88,9 @@ class api_v3_MailingTest extends CiviUnitTestCase {
 
   /**
    * Test civicrm_mailing_event_bounce with wrong params.
+   * Note that tests like this are slightly better than no test but an
+   * api function cannot be considered supported  / 'part of the api' without a
+   * success test
    */
   public function testMailerBounceWrongParams() {
     $params = array(
@@ -96,15 +100,17 @@ class api_v3_MailingTest extends CiviUnitTestCase {
       'body' => 'Body...',
       'time_stamp' => '20111109212100',
     );
-    $result = $this->callAPISuccess('mailing_event', 'bounce', $params);
-    $this->assertAPIFailure($result, 'In line ' . __LINE__);
-    $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
+    $result = $this->callAPIFailure('mailing_event', 'bounce', $params,
+      'Queue event could not be found');
   }
 
   //----------- civicrm_mailing_event_confirm methods -----------
 
   /**
    * Test civicrm_mailing_event_confirm with wrong params.
+   * Note that tests like this are slightly better than no test but an
+   * api function cannot be considered supported  / 'part of the api' without a
+   * success test
    */
   public function testMailerConfirmWrongParams() {
     $params = array(
@@ -114,15 +120,19 @@ class api_v3_MailingTest extends CiviUnitTestCase {
       'event_subscribe_id' => '123',
       'time_stamp' => '20111111010101',
          );
-    $result = $this->callAPISuccess('mailing_event', 'confirm', $params);
-    $this->assertAPIFailure($result, 'In line ' . __LINE__);
-    $this->assertEquals($result['error_message'], 'Confirmation failed', 'In line ' . __LINE__);
+    $result = $this->callAPIFailure('mailing_event', 'confirm', $params,
+      'Confirmation failed'
+    );
   }
 
   //---------- civicrm_mailing_event_reply methods -----------
 
   /**
    * Test civicrm_mailing_event_reply with wrong params.
+   *
+   * Note that tests like this are slightly better than no test but an
+   * api function cannot be considered supported  / 'part of the api' without a
+   * success test
    */
   public function testMailerReplyWrongParams() {
     $params = array(
@@ -133,9 +143,9 @@ class api_v3_MailingTest extends CiviUnitTestCase {
       'replyTo' => $this->_email,
       'time_stamp' => '20111111010101',
          );
-    $result = $this->callAPISuccess('mailing_event', 'reply', $params);
-    $this->assertAPIFailure($result, 'In line ' . __LINE__);
-    $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
+    $result = $this->callAPIFailure('mailing_event', 'reply', $params,
+      'Queue event could not be found'
+     );
   }
 
 
@@ -143,6 +153,9 @@ class api_v3_MailingTest extends CiviUnitTestCase {
 
   /**
    * Test civicrm_mailing_event_forward with wrong params.
+   * Note that tests like this are slightly better than no test but an
+   * api function cannot be considered supported  / 'part of the api' without a
+   * success test
    */
   public function testMailerForwardWrongParams() {
     $params = array(
@@ -152,9 +165,9 @@ class api_v3_MailingTest extends CiviUnitTestCase {
       'email' => $this->_email,
       'time_stamp' => '20111111010101',
          );
-    $result = $this->callAPISuccess('mailing_event', 'forward', $params);
-    $this->assertAPIFailure($result, 'In line ' . __LINE__);
-    $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
+    $result = $this->callAPIFailure('mailing_event', 'forward', $params,
+      'Queue event could not be found'
+    );
   }