Commit | Line | Data |
---|---|---|
07c09ae4 EM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
07c09ae4 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
07c09ae4 EM |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * File for the CiviCRM APIv3 job functions | |
30 | * | |
31 | * @package CiviCRM_APIv3 | |
32 | * @subpackage API_Job | |
33 | * | |
e7112fa7 | 34 | * @copyright CiviCRM LLC (c) 2004-2015 |
07c09ae4 EM |
35 | * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $ |
36 | * | |
37 | */ | |
38 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
39 | //@todo - why doesn't class loader find these (I tried renaming) | |
40 | require_once 'CiviTest/CiviMailUtils.php'; | |
92915c55 | 41 | |
07c09ae4 EM |
42 | /** |
43 | * Class api_v3_JobTest | |
44 | */ | |
45 | class api_v3_JobProcessMailingTest extends CiviUnitTestCase { | |
46 | protected $_apiversion = 3; | |
47 | ||
48 | public $DBResetRequired = FALSE; | |
49 | public $_entity = 'Job'; | |
50 | public $_params = array(); | |
51 | private $_groupID; | |
52 | private $_email; | |
53 | ||
54 | /** | |
55 | * @var CiviMailUtils | |
56 | */ | |
57 | private $_mut; | |
58 | ||
00be9182 | 59 | public function setUp() { |
07c09ae4 | 60 | parent::setUp(); |
e24a5794 | 61 | $this->useTransaction(); |
97b7d4a0 | 62 | CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; // DGW |
07c09ae4 EM |
63 | $this->_groupID = $this->groupCreate(); |
64 | $this->_email = 'test@test.test'; | |
65 | $this->_params = array( | |
66 | 'subject' => 'Accidents in cars cause children', | |
21b09c13 | 67 | 'body_text' => 'BEWARE children need regular infusions of toys. Santa knows your {domain.address}. There is no {action.optOutUrl}.', |
07c09ae4 EM |
68 | 'name' => 'mailing name', |
69 | 'created_id' => 1, | |
70 | 'groups' => array('include' => array($this->_groupID)), | |
5f445749 | 71 | 'scheduled_date' => 'now', |
07c09ae4 | 72 | ); |
481a74f4 | 73 | $this->_mut = new CiviMailUtils($this, TRUE); |
07c09ae4 EM |
74 | $this->callAPISuccess('mail_settings', 'get', array('api.mail_settings.create' => array('domain' => 'chaos.org'))); |
75 | } | |
76 | ||
77 | /** | |
07c09ae4 | 78 | */ |
00be9182 | 79 | public function tearDown() { |
07c09ae4 | 80 | $this->_mut->stop(); |
6c6e6187 | 81 | // $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact')); |
07c09ae4 | 82 | CRM_Utils_Hook::singleton()->reset(); |
97b7d4a0 | 83 | CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; // DGW |
07c09ae4 EM |
84 | parent::tearDown(); |
85 | ||
86 | } | |
87 | ||
88 | /** | |
eceb18cc | 89 | * Check mailing is sent. |
07c09ae4 | 90 | */ |
00be9182 | 91 | public function testProcessMailing() { |
07c09ae4 EM |
92 | $this->createContactsInGroup(10, $this->_groupID); |
93 | CRM_Core_Config::singleton()->mailerBatchLimit = 2; | |
94 | $this->callAPISuccess('mailing', 'create', $this->_params); | |
95 | $this->callAPISuccess('job', 'process_mailing', array()); | |
96 | $this->_mut->assertRecipients($this->getRecipients(1, 2)); | |
97 | } | |
98 | ||
99 | /** | |
e16033b4 TO |
100 | * @param int $count |
101 | * @param int $groupID | |
07c09ae4 | 102 | */ |
00be9182 | 103 | public function createContactsInGroup($count, $groupID) { |
481a74f4 | 104 | for ($i = 1; $i <= $count; $i++) { |
07c09ae4 | 105 | $contactID = $this->individualCreate(array('first_name' => $count, 'email' => 'mail' . $i . '@nul.com')); |
92915c55 TO |
106 | $this->callAPISuccess('group_contact', 'create', array( |
107 | 'contact_id' => $contactID, | |
108 | 'group_id' => $groupID, | |
af9b09df | 109 | 'status' => 'Added', |
92915c55 | 110 | )); |
07c09ae4 EM |
111 | } |
112 | } | |
113 | ||
114 | /** | |
e16033b4 TO |
115 | * @param int $start |
116 | * @param int $count | |
07c09ae4 EM |
117 | * |
118 | * @return array | |
119 | */ | |
00be9182 | 120 | public function getRecipients($start, $count) { |
07c09ae4 | 121 | $recipients = array(); |
481a74f4 | 122 | for ($i = $start; $i < ($start + $count); $i++) { |
07c09ae4 EM |
123 | $recipients[][0] = 'mail' . $i . '@nul.com'; |
124 | } | |
125 | return $recipients; | |
126 | } | |
96025800 | 127 | |
07c09ae4 | 128 | } |