3 * File for the TestMailing class
9 * This file is part of CiviCRM
11 * CiviCRM is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Affero General Public License
13 * as published by the Free Software Foundation; either version 3 of
14 * the License, or (at your option) any later version.
16 * CiviCRM is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Affero General Public License for more details.
21 * You should have received a copy of the GNU Affero General Public
22 * License along with this program. If not, see
23 * <http://www.gnu.org/licenses/>.
26 require_once 'CiviTest/CiviUnitTestCase.php';
30 * Test APIv3 civicrm_mailingab_* functions
34 class api_v3_MailingABTest
extends CiviUnitTestCase
{
35 protected $_mailingID_A;
36 protected $_mailingID_B;
37 protected $_mailingID_C;
39 protected $_apiversion = 3;
40 protected $_entity = 'MailingAB';
49 'description' => 'Test all Mailer methods.',
50 'group' => 'CiviCRM API Tests',
56 $this->_mailingID_A
= $this->createMailing();
57 $this->_mailingID_B
= $this->createMailing();
58 $this->_mailingID_C
= $this->createMailing();
60 $this->_params
= array(
61 'mailing_id_a' => $this->_mailingID_A
,
62 'mailing_id_b' => $this->_mailingID_B
,
63 'mailing_id_c' => $this->_mailingID_C
,
64 'testing_criteria_id' => 1,
65 'winner_criteria_id' => 1,
66 'declare_winning_time' => '+2 days',
67 'group_percentage' => 10,
72 $this->deleteMailing($this->_mailingID_A
);
73 $this->deleteMailing($this->_mailingID_B
);
74 $this->deleteMailing($this->_mailingID_C
);
78 * Test civicrm_mailing_create
80 public function testMailingABCreateSuccess() {
81 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
82 $this->assertTrue(is_numeric($result['id']), "In line " . __LINE__
);
83 $this->assertEquals($this->_params
['group_percentage'], $result['values'][$result['id']]['group_percentage']);
87 * Test civicrm_mailing_delete
89 public function testMailerDeleteSuccess() {
90 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
91 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result['id']));
95 public function testMailingABRecipientsUpdate() {
96 //create 100 contacts for group $this->_groupID
97 $totalGroupContacts = 100;
98 $result = $this->groupContactCreate($this->_groupID
, $totalGroupContacts);
99 //check if 100 group contacts are included on desired group
100 $this->assertEquals($totalGroupContacts, $result['added'], "in line " . __LINE__
);
101 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
102 $totalSelectedContacts = round(($totalGroupContacts * $result['values'][$result['id']]['group_percentage'])/100);
103 $params = array('id' => $result['id'], 'groups' => array('include' => array($this->_groupID
)));
104 $this->callAPISuccess('Mailing', 'a_b_recipients_update', $params);
105 //check total number of A/B mail recipients is what selected percentage of Mail C
106 $countA = $this->callAPISuccess('MailingRecipients', 'getcount', array('mailing_id' => $this->_mailingID_A
));
107 $this->assertEquals($countA, $totalSelectedContacts, "in line " . __LINE__
);
108 $countB = $this->callAPISuccess('MailingRecipients', 'getcount', array('mailing_id' => $this->_mailingID_B
));
109 $this->assertEquals($countB, $totalSelectedContacts, "in line " . __LINE__
);