Skip to content

Commit

Permalink
Add test to check pcp notification is sent
Browse files Browse the repository at this point in the history
I wound up adding PcpBlock v4 api to write the test

In support of
civicrm#19096
  • Loading branch information
eileenmcnaughton committed Dec 4, 2020
1 parent 53bc1b8 commit 03983c2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
28 changes: 28 additions & 0 deletions Civi/Api4/PcpBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

namespace Civi\Api4;

/**
* PCP Block entity.
*
* @package Civi\Api4
*/
class PcpBlock extends Generic\DAOEntity {

}
3 changes: 3 additions & 0 deletions api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ function _civicrm_api3_get_DAO($name) {
if ($name === 'Im' || $name === 'Acl' || $name === 'Pcp') {
$name = strtoupper($name);
}
if ($name === 'PcpBlock') {
$name = 'PCPBlock';
}
$dao = CRM_Core_DAO_AllCoreTables::getFullName($name);
if ($dao || !$name) {
return $dao;
Expand Down
5 changes: 4 additions & 1 deletion tests/phpunit/CRM/Contribute/Form/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,9 @@ public function testPremiumUpdateCreditCard() {
* @throws \CiviCRM_API3_Exception
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function testSubmitWithPCP() {
public function testSubmitWithPCP(): void {
$mut = new CiviMailUtils($this, TRUE);
$mut->clearMessages();
$params = $this->pcpParams();
$pcpID = $this->createPCPBlock($params);
$form = new CRM_Contribute_Form_Contribution();
Expand All @@ -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']);
}

/**
Expand Down
19 changes: 10 additions & 9 deletions tests/phpunit/CRMTraits/PCP/PCPTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/

use Civi\Api4\Email;

/**
* Trait CRMTraits_PCP_PCPTestTrait
*
Expand All @@ -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,
Expand All @@ -39,38 +41,39 @@ public function pcpBlockParams() {
'tellfriend_limit' => 1,
'link_text' => 'Create your own PCP',
'is_active' => 1,
'owner_notify_id:name' => 'owner_chooses',
];

return $params;
}

/**
* Build and return pcp params.
*
* 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',
'intro_text' => 'Hey you, contribute now!',
'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;
}

/**
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CiviTest/CiviMailUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 03983c2

Please sign in to comment.