From 4715d2676bb5764cc695385c4a94a4b2b13bd20d Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 13 Jun 2019 13:01:40 -0400 Subject: [PATCH] Add Unit test for testing smart group flow --- .../Mailing/Form/Task/AdhocMailingTest.php | 77 +++++++++++++++++++ tests/phpunit/CiviTest/CiviUnitTestCase.php | 9 ++- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/CRM/Mailing/Form/Task/AdhocMailingTest.php diff --git a/tests/phpunit/CRM/Mailing/Form/Task/AdhocMailingTest.php b/tests/phpunit/CRM/Mailing/Form/Task/AdhocMailingTest.php new file mode 100644 index 0000000000..8c86b4ed2e --- /dev/null +++ b/tests/phpunit/CRM/Mailing/Form/Task/AdhocMailingTest.php @@ -0,0 +1,77 @@ +_contactIds = [ + $this->individualCreate(['first_name' => 'Antonia', 'last_name' => 'D`souza']), + $this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']), + ]; + $this->_optionValue = $this->callApiSuccess('optionValue', 'create', [ + 'label' => '"Seamus Lee" ', + 'option_group_id' => 'from_email_address', + ]); + } + + /** + * Test creating a hidden smart group from a search builder search. + * + * A hidden smart group is a group used for sending emails. + * + * @throws \CRM_Core_Exception + * @throws \Exception + */ + public function testCreateHiddenGroupFromSearchBuilder() { + $this->createLoggedInUser(); + $formValues = [ + 'qfKey' => 'dde96a85ddebb90fb66de44859404aeb_2077', + 'entryURL' => 'http://dmaster.local/civicrm/contact/search/builder?reset=1', + 'mapper' => [1 => [['Individual']]], + 'operator' => [1 => ['=']], + 'value' => [1 => [0 => 'erwr']], + '_qf_default' => 'Builder:refresh', + '_qf_Builder_refresh' => 'Search', + 'radio_ts' => '', + ]; + $form = $this->getFormObject('CRM_Mailing_Form_Task_AdhocMailing', $formValues, 'Builder'); + $form->setAction(CRM_Core_Action::PROFILE); + try { + $form->preProcess(); + } + catch (CRM_Core_Exception_PrematureExitException $e) { + // Nothing to see here. + } + $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); + $this->assertEquals(['bla'], $savedSearch); + } + +} diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 5ecff3a9f5..817bff2356 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3160,12 +3160,19 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) * @param string $class * Name of form class. * + * @param array $formValues + * + * @param string $pageName + * * @return \CRM_Core_Form + * @throws \CRM_Core_Exception */ - public function getFormObject($class) { + public function getFormObject($class, $formValues = [], $pageName = '') { $form = new $class(); $_SERVER['REQUEST_METHOD'] = 'GET'; $form->controller = new CRM_Core_Controller(); + $form->controller->setStateMachine(new CRM_Core_StateMachine($form->controller)); + $_SESSION['_' . $form->controller->_name . '_container']['values'][$pageName] = $formValues; return $form; } -- 2.25.1