From 71f1227b5a1ba834c7ff7e4acf6370781a91158b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 12 Apr 2019 17:41:12 -0700 Subject: [PATCH] Move helpers from CiviUnitTestCase to MailingTestTrait * `createMailing(...)` * `deleteMailing(...)` --- Civi/Test/MailingTestTrait.php | 45 +++++++++++++++++++++ tests/phpunit/CiviTest/CiviUnitTestCase.php | 32 +-------------- 2 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 Civi/Test/MailingTestTrait.php diff --git a/Civi/Test/MailingTestTrait.php b/Civi/Test/MailingTestTrait.php new file mode 100644 index 0000000000..6609750fbe --- /dev/null +++ b/Civi/Test/MailingTestTrait.php @@ -0,0 +1,45 @@ + 'maild' . rand(), + 'body_text' => 'bdkfhdskfhduew{domain.address}{action.optOutUrl}', + 'name' => 'mailing name' . rand(), + 'created_id' => 1, + ), $params); + + $result = $this->callAPISuccess('Mailing', 'create', $params); + return $result['id']; + } + + /** + * Helper function to delete mailing. + * @param $id + */ + public function deleteMailing($id) { + $params = array( + 'id' => $id, + ); + + $this->callAPISuccess('Mailing', 'delete', $params); + } + +} diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index c5e8ff08ce..db21ca346a 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -57,6 +57,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { use \Civi\Test\GenericAssertionsTrait; use \Civi\Test\DbTestTrait; use \Civi\Test\ContactTestTrait; + use \Civi\Test\MailingTestTrait; /** * Database has been initialized. @@ -2415,37 +2416,6 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) throw new Exception("{$message['message']}: {$message['code']}"); } - /** - * Helper function to create new mailing. - * - * @param array $params - * - * @return int - */ - public function createMailing($params = array()) { - $params = array_merge(array( - 'subject' => 'maild' . rand(), - 'body_text' => 'bdkfhdskfhduew{domain.address}{action.optOutUrl}', - 'name' => 'mailing name' . rand(), - 'created_id' => 1, - ), $params); - - $result = $this->callAPISuccess('Mailing', 'create', $params); - return $result['id']; - } - - /** - * Helper function to delete mailing. - * @param $id - */ - public function deleteMailing($id) { - $params = array( - 'id' => $id, - ); - - $this->callAPISuccess('Mailing', 'delete', $params); - } - /** * Wrap the entire test case in a transaction. * -- 2.25.1