Merge pull request #15595 from eileenmcnaughton/dedupe3
[civicrm-core.git] / tests / phpunit / CRM / Mailing / Form / Task / AdhocMailingTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 | |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
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_Mailing_Form_Task_AdhocMailingTest extends CiviUnitTestCase {
32
33 /**
34 * @throws \Exception
35 */
36 protected function setUp() {
37 parent::setUp();
38 $this->_contactIds = [
39 $this->individualCreate(['first_name' => 'Antonia', 'last_name' => 'D`souza']),
40 $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']),
41 ];
42 $this->_optionValue = $this->callAPISuccess('optionValue', 'create', [
43 'label' => '"Seamus Lee" <seamus@example.com>',
44 'option_group_id' => 'from_email_address',
45 ]);
46 }
47
48 /**
49 * Test creating a hidden smart group from a search builder search.
50 *
51 * A hidden smart group is a group used for sending emails.
52 *
53 * @throws \CRM_Core_Exception
54 * @throws \Exception
55 */
56 public function testCreateHiddenGroupFromSearchBuilder() {
57 $this->createLoggedInUser();
58 $formValues = [
59 'qfKey' => 'dde96a85ddebb90fb66de44859404aeb_2077',
60 'entryURL' => 'http://dmaster.local/civicrm/contact/search/builder?reset=1',
61 'mapper' => [1 => [['Individual']]],
62 'operator' => [1 => ['=']],
63 'value' => [1 => [0 => 'erwr']],
64 '_qf_default' => 'Builder:refresh',
65 '_qf_Builder_refresh' => 'Search',
66 'radio_ts' => '',
67 ];
68 $form = $this->getFormObject('CRM_Mailing_Form_Task_AdhocMailing', $formValues, 'Builder');
69 $form->setAction(CRM_Core_Action::PROFILE);
70 $form->set('formValues', $formValues);
71 $form->set('isSearchBuilder', 1);
72 $form->set('context', 'builder');
73 try {
74 $form->preProcess();
75 }
76 catch (CRM_Core_Exception_PrematureExitException $e) {
77 // Nothing to see here.
78 }
79 $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []);
80 $this->assertEquals($formValues, $savedSearch['form_values']);
81 }
82
83 }