Commit | Line | Data |
---|---|---|
07c09ae4 EM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.5 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2014 | | |
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 | * | |
34 | * @copyright CiviCRM LLC (c) 2004-2014 | |
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'; | |
41 | /** | |
42 | * Class api_v3_JobTest | |
43 | */ | |
44 | class api_v3_JobProcessMailingTest extends CiviUnitTestCase { | |
45 | protected $_apiversion = 3; | |
46 | ||
47 | public $DBResetRequired = FALSE; | |
48 | public $_entity = 'Job'; | |
49 | public $_params = array(); | |
50 | private $_groupID; | |
51 | private $_email; | |
52 | ||
53 | /** | |
54 | * @var CiviMailUtils | |
55 | */ | |
56 | private $_mut; | |
57 | ||
58 | function setUp() { | |
59 | parent::setUp(); | |
60 | $this->_groupID = $this->groupCreate(); | |
61 | $this->_email = 'test@test.test'; | |
62 | $this->_params = array( | |
63 | 'subject' => 'Accidents in cars cause children', | |
64 | 'body_text' => 'BEWARE children need regular infusions of toys', | |
65 | 'name' => 'mailing name', | |
66 | 'created_id' => 1, | |
67 | 'groups' => array('include' => array($this->_groupID)), | |
68 | ); | |
69 | $this->_mut = new CiviMailUtils( $this, true ); | |
70 | $this->callAPISuccess('mail_settings', 'get', array('api.mail_settings.create' => array('domain' => 'chaos.org'))); | |
71 | } | |
72 | ||
73 | /** | |
74 | * | |
75 | */ | |
76 | function tearDown() { | |
77 | $this->_mut->stop(); | |
78 | $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact')); | |
79 | CRM_Utils_Hook::singleton()->reset(); | |
80 | parent::tearDown(); | |
81 | ||
82 | } | |
83 | ||
84 | /** | |
85 | * Check mailing is sent | |
86 | */ | |
87 | function testProcessMailing() { | |
88 | $this->createContactsInGroup(10, $this->_groupID); | |
89 | CRM_Core_Config::singleton()->mailerBatchLimit = 2; | |
90 | $this->callAPISuccess('mailing', 'create', $this->_params); | |
91 | $this->callAPISuccess('job', 'process_mailing', array()); | |
92 | $this->_mut->assertRecipients($this->getRecipients(1, 2)); | |
93 | } | |
94 | ||
95 | /** | |
96 | * @param integer $count | |
97 | * @param integer $groupID | |
98 | */ | |
99 | function createContactsInGroup($count, $groupID) { | |
100 | for($i = 1; $i <= $count; $i++ ) { | |
101 | $contactID = $this->individualCreate(array('first_name' => $count, 'email' => 'mail' . $i . '@nul.com')); | |
102 | $this->callAPISuccess('group_contact', 'create', array('contact_id' => $contactID, 'group_id' => $groupID, 'status' => 'Added')); | |
103 | } | |
104 | } | |
105 | ||
106 | /** | |
107 | * @param integer $start | |
108 | * @param integer $count | |
109 | * | |
110 | * @return array | |
111 | */ | |
112 | function getRecipients($start, $count) { | |
113 | $recipients = array(); | |
114 | for($i = $start; $i < ($start + $count); $i++ ) { | |
115 | $recipients[][0] = 'mail' . $i . '@nul.com'; | |
116 | } | |
117 | return $recipients; | |
118 | } | |
119 | } |