| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | /** |
| 12 | * Test class for CRM_Contact_Form_Task_EmailCommon. |
| 13 | * @group headless |
| 14 | */ |
| 15 | class CRM_Mailing_Form_Task_AdhocMailingTest extends CiviUnitTestCase { |
| 16 | |
| 17 | /** |
| 18 | * @throws \Exception |
| 19 | */ |
| 20 | protected function setUp() { |
| 21 | parent::setUp(); |
| 22 | $this->_contactIds = [ |
| 23 | $this->individualCreate(['first_name' => 'Antonia', 'last_name' => 'D`souza']), |
| 24 | $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']), |
| 25 | ]; |
| 26 | $this->_optionValue = $this->callAPISuccess('optionValue', 'create', [ |
| 27 | 'label' => '"Seamus Lee" <seamus@example.com>', |
| 28 | 'option_group_id' => 'from_email_address', |
| 29 | ]); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Test creating a hidden smart group from a search builder search. |
| 34 | * |
| 35 | * A hidden smart group is a group used for sending emails. |
| 36 | * |
| 37 | * @throws \CRM_Core_Exception |
| 38 | * @throws \Exception |
| 39 | */ |
| 40 | public function testCreateHiddenGroupFromSearchBuilder() { |
| 41 | $this->createLoggedInUser(); |
| 42 | $formValues = [ |
| 43 | 'qfKey' => 'dde96a85ddebb90fb66de44859404aeb_2077', |
| 44 | 'entryURL' => 'http://dmaster.local/civicrm/contact/search/builder?reset=1', |
| 45 | 'mapper' => [1 => [['Individual']]], |
| 46 | 'operator' => [1 => ['=']], |
| 47 | 'value' => [1 => [0 => 'erwr']], |
| 48 | '_qf_default' => 'Builder:refresh', |
| 49 | '_qf_Builder_refresh' => 'Search', |
| 50 | 'radio_ts' => '', |
| 51 | ]; |
| 52 | $form = $this->getFormObject('CRM_Mailing_Form_Task_AdhocMailing', $formValues, 'Builder'); |
| 53 | $form->setAction(CRM_Core_Action::PROFILE); |
| 54 | $form->set('formValues', $formValues); |
| 55 | $form->set('isSearchBuilder', 1); |
| 56 | $form->set('context', 'builder'); |
| 57 | try { |
| 58 | $form->preProcess(); |
| 59 | } |
| 60 | catch (CRM_Core_Exception_PrematureExitException $e) { |
| 61 | // Nothing to see here. |
| 62 | } |
| 63 | $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); |
| 64 | $this->assertEquals($formValues, $savedSearch['form_values']); |
| 65 | } |
| 66 | |
| 67 | } |