From 265de86067e7576199dd52594d48d5b2b0e659ba Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 4 Dec 2020 23:38:42 +1300 Subject: [PATCH] Add test to check pcp notification is sent I wound up adding PcpBlock v4 api to write the test In support of https://github.com/civicrm/civicrm-core/pull/19096 --- CRM/Contribute/BAO/ContributionSoft.php | 1 - Civi/Api4/PcpBlock.php | 28 +++++++++++++++++++ api/v3/utils.php | 3 ++ .../CRM/Contribute/Form/ContributionTest.php | 5 +++- tests/phpunit/CRMTraits/PCP/PCPTestTrait.php | 19 +++++++------ tests/phpunit/CiviTest/CiviMailUtils.php | 4 +-- 6 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 Civi/Api4/PcpBlock.php diff --git a/CRM/Contribute/BAO/ContributionSoft.php b/CRM/Contribute/BAO/ContributionSoft.php index 588d04f7e707..670e30adfae7 100644 --- a/CRM/Contribute/BAO/ContributionSoft.php +++ b/CRM/Contribute/BAO/ContributionSoft.php @@ -609,7 +609,6 @@ protected static function processPCP($pcp, $contribution) { $contributionSoft = self::add($softParams); //Send notification to owner for PCP if ($contributionSoft->pcp_id && empty($pcpId)) { - throw new CRM_Core_Exception('is this line reached in tests?'); CRM_Contribute_Form_Contribution_Confirm::pcpNotifyOwner($contribution, $contributionSoft); } } diff --git a/Civi/Api4/PcpBlock.php b/Civi/Api4/PcpBlock.php new file mode 100644 index 000000000000..206a425bedf0 --- /dev/null +++ b/Civi/Api4/PcpBlock.php @@ -0,0 +1,28 @@ +clearMessages(); $params = $this->pcpParams(); $pcpID = $this->createPCPBlock($params); $form = new CRM_Contribute_Form_Contribution(); @@ -834,6 +836,7 @@ public function testSubmitWithPCP() { ], CRM_Core_Action::ADD); $softCredit = $this->callAPISuccessGetSingle('ContributionSoft', []); $this->assertEquals('Dobby', $softCredit['pcp_roll_nickname']); + $mut->checkMailLog(['email_greeting_display_1']); } /** diff --git a/tests/phpunit/CRMTraits/PCP/PCPTestTrait.php b/tests/phpunit/CRMTraits/PCP/PCPTestTrait.php index 04db4f2a3b5c..71d12ed7ee6c 100644 --- a/tests/phpunit/CRMTraits/PCP/PCPTestTrait.php +++ b/tests/phpunit/CRMTraits/PCP/PCPTestTrait.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\Email; + /** * Trait CRMTraits_PCP_PCPTestTrait * @@ -29,7 +31,7 @@ public function pcpBlockParams() { $supporterProfile = CRM_Core_DAO::createTestObject('CRM_Core_DAO_UFGroup'); $supporterProfileId = $supporterProfile->id; - $params = [ + return [ 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $contribPageId, 'supporter_profile_id' => $supporterProfileId, @@ -39,9 +41,8 @@ public function pcpBlockParams() { 'tellfriend_limit' => 1, 'link_text' => 'Create your own PCP', 'is_active' => 1, + 'owner_notify_id:name' => 'owner_chooses', ]; - - return $params; } /** @@ -49,14 +50,17 @@ public function pcpBlockParams() { * * Create the necessary initial objects for a pcp page, then return the * params needed to create the pcp page. + * + * @throw API_Exception */ public function pcpParams() { $contact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact'); $contactId = $contact->id; + Email::create()->setValues(['email' => 'dobby@example.org', 'contact_id' => $contactId])->execute(); $contribPage = CRM_Core_DAO::createTestObject('CRM_Contribute_DAO_ContributionPage'); $contribPageId = $contribPage->id; - $params = [ + return [ 'contact_id' => $contactId, 'status_id' => '1', 'title' => 'My PCP', @@ -64,13 +68,12 @@ public function pcpParams() { 'page_text' => 'You better give more.', 'donate_link_text' => 'Donate Now', 'page_id' => $contribPageId, + 'is_notify' => TRUE, 'is_thermometer' => 1, 'is_honor_roll' => 1, 'goal_amount' => 10000.00, 'is_active' => 1, ]; - - return $params; } /** @@ -82,10 +85,8 @@ public function pcpParams() { */ protected function createPCPBlock(array $params):int { $blockParams = $this->pcpBlockParams(); - $pcpBlock = CRM_PCP_BAO_PCPBlock::create($blockParams); - $params = array_merge($this->pcpParams(), $params); - $params['pcp_block_id'] = $pcpBlock->id; + $params['pcp_block_id'] = \Civi\Api4\PcpBlock::create()->setValues($blockParams)->execute()->first()['id']; $pcp = CRM_PCP_BAO_PCP::create($params); return (int) $pcp->id; diff --git a/tests/phpunit/CiviTest/CiviMailUtils.php b/tests/phpunit/CiviTest/CiviMailUtils.php index b502273e8373..b0a98b13e4db 100644 --- a/tests/phpunit/CiviTest/CiviMailUtils.php +++ b/tests/phpunit/CiviTest/CiviMailUtils.php @@ -356,13 +356,13 @@ private function convertToEzc($msg) { } /** - * @param $strings + * @param array $strings * @param $absentStrings * @param $prefix * @param $mail * @return mixed */ - public function checkMailForStrings($strings, $absentStrings, $prefix, $mail) { + public function checkMailForStrings(array $strings, $absentStrings = [], $prefix = '', $mail) { foreach ($strings as $string) { $this->_ut->assertContains($string, $mail, "$string . not found in $mail $prefix"); }