(NFC) Update version headers in `tests/`
[civicrm-core.git] / tests / phpunit / CRM / Contact / Form / Task / EmailCommonTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 | |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 * Test class for CRM_Contact_Form_Task_EmailCommon.
29 * @group headless
30 */
31 class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase {
32
33 protected function setUp() {
34 parent::setUp();
35 $this->_contactIds = array(
36 $this->individualCreate(array('first_name' => 'Antonia', 'last_name' => 'D`souza')),
37 $this->individualCreate(array('first_name' => 'Anthony', 'last_name' => 'Collins')),
38 );
39 $this->_optionValue = $this->callApiSuccess('optionValue', 'create', array(
40 'label' => '"Seamus Lee" <seamus@example.com>',
41 'option_group_id' => 'from_email_address',
42 ));
43 }
44
45 /**
46 * Test generating domain emails
47 */
48 public function testDomainEmailGeneration() {
49 $emails = CRM_Core_BAO_Email::domainEmails();
50 $this->assertNotEmpty($emails);
51 $optionValue = $this->callAPISuccess('OptionValue', 'Get', array(
52 'id' => $this->_optionValue['id'],
53 ));
54 $this->assertTrue(array_key_exists('"Seamus Lee" <seamus@example.com>', $emails));
55 $this->assertEquals('"Seamus Lee" <seamus@example.com>', $optionValue['values'][$this->_optionValue['id']]['label']);
56 }
57
58 public function testPostProcess() {
59 $this->createLoggedInUser();
60 $form = new CRM_Contact_Form_Task_Email();
61 $_SERVER['REQUEST_METHOD'] = 'GET';
62 $form->controller = new CRM_Core_Controller();
63
64 for ($i = 0; $i < 27; $i++) {
65 $email = 'spy' . $i . '@secretsquirrels.com';
66 $contactID = $this->individualCreate(array('email' => $email));
67 $form->_contactIds[$contactID] = $contactID;
68 $form->_toContactEmails[$this->callAPISuccessGetValue('Email', array('return' => 'id', 'email' => $email))] = $email;
69 }
70 $form->_allContactIds = $form->_toContactIds = $form->_contactIds;
71 $form->_emails = array(1 => 'mickey@mouse.com');
72 $form->_fromEmails = array(1 => 'mickey@mouse.com');
73
74 CRM_Contact_Form_Task_EmailCommon::buildQuickForm($form);
75
76 CRM_Contact_Form_Task_EmailCommon::submit($form, array(
77 'fromEmailAddress' => 1,
78 'subject' => 'Really interesting stuff',
79 ));
80 }
81
82 }