From 9e23eadbd210fb3310e4f16114844ffef1f35ef1 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 4 Aug 2013 11:23:39 +1200 Subject: [PATCH] CRM-13152 - api mailing_event_subscribe.create returns array in wrong format --- api/v3/MailingEventSubscribe.php | 9 ++++----- tests/phpunit/api/v3/MailingGroupTest.php | 16 ++++++---------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/api/v3/MailingEventSubscribe.php b/api/v3/MailingEventSubscribe.php index 9ec4744c39..d109dd64b3 100644 --- a/api/v3/MailingEventSubscribe.php +++ b/api/v3/MailingEventSubscribe.php @@ -56,7 +56,7 @@ function civicrm_api3_mailing_event_subscribe_create($params) { $group->is_active = 1; $group->id = (int)$group_id; if (!$group->find(TRUE)) { - return civicrm_api3_create_error('Invalid Group id'); + throw new API_Exception('Invalid Group id'); } $subscribe = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id, $email, $contact_id); @@ -68,10 +68,9 @@ function civicrm_api3_mailing_event_subscribe_create($params) { $subscribe->send_confirm_request($email); $values = array(); - $values['contact_id'] = $subscribe->contact_id; - $values['subscribe_id'] = $subscribe->id; - $values['hash'] = $subscribe->hash; - $values['is_error'] = 0; + $values[$subscribe->id]['contact_id'] = $subscribe->contact_id; + $values[$subscribe->id]['subscribe_id'] = $subscribe->id; + $values[$subscribe->id]['hash'] = $subscribe->hash; return civicrm_api3_create_success($values); } diff --git a/tests/phpunit/api/v3/MailingGroupTest.php b/tests/phpunit/api/v3/MailingGroupTest.php index 6c84dece11..c971a32070 100644 --- a/tests/phpunit/api/v3/MailingGroupTest.php +++ b/tests/phpunit/api/v3/MailingGroupTest.php @@ -96,7 +96,7 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { 'time_stamp' => '20101212121212', ); $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__); - $this->assertEquals($result['values']['contact_id'], $contactID); + $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); $this->contactDelete($contactID); } @@ -176,20 +176,16 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { ); $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params); - $this->assertAPISuccess($result, 'in line ' . __LINE__); - $this->assertEquals($result['values']['contact_id'], $contactID); + $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); $params = array( - 'contact_id' => $result['values']['contact_id'], - 'subscribe_id' => $result['values']['subscribe_id'], - 'hash' => $result['values']['hash'], 'time_stamp' => '20101212121212', - 'event_subscribe_id' => $result['values']['subscribe_id'], + 'contact_id' => $result['values'][$result['id']]['contact_id'], + 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'], + 'hash' => $result['values'][$result['id']]['hash'], 'time_stamp' => '20101212121212', + 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'], ); - $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params); - - $this->assertAPISuccess($result, 'in line ' . __LINE__); $this->contactDelete($contactID); } } -- 2.25.1