Add test to check pcp notification is sent
authoreileen <emcnaughton@wikimedia.org>
Fri, 4 Dec 2020 05:32:16 +0000 (18:32 +1300)
committereileen <emcnaughton@wikimedia.org>
Sat, 5 Dec 2020 22:35:00 +0000 (11:35 +1300)
I wound up adding PcpBlock v4 api to write the test

In support of
https://github.com/civicrm/civicrm-core/pull/19096

Civi/Api4/PcpBlock.php [new file with mode: 0644]
api/v3/utils.php
tests/phpunit/CRM/Contribute/Form/ContributionTest.php
tests/phpunit/CRMTraits/PCP/PCPTestTrait.php
tests/phpunit/CiviTest/CiviMailUtils.php

diff --git a/Civi/Api4/PcpBlock.php b/Civi/Api4/PcpBlock.php
new file mode 100644 (file)
index 0000000..206a425
--- /dev/null
@@ -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 {
+
+}
index 86b374b4e6c09660f080273981271bcf1b9a7e15..b1858f77dc370d6c54cffe78ea1a39a5e16c94f8 100644 (file)
@@ -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;
index 42094065cbb474db7d950151b4742251c0de9775..cc10a426e825a9aabe82de7b017bfdc3e8c26e8b 100644 (file)
@@ -817,7 +817,9 @@ Price Field - Price Field 1        1   $ 100.00      $ 100.00
    * @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();
@@ -834,6 +836,7 @@ Price Field - Price Field 1        1   $ 100.00      $ 100.00
     ], CRM_Core_Action::ADD);
     $softCredit = $this->callAPISuccessGetSingle('ContributionSoft', []);
     $this->assertEquals('Dobby', $softCredit['pcp_roll_nickname']);
+    $mut->checkMailLog(['Personal Campaign Page Owner Notification']);
   }
 
   /**
index 04db4f2a3b5c4675677403b3db1e7eb9d41c5163..71d12ed7ee6c13cfc6948904b919b2ecc15fe718 100644 (file)
@@ -9,6 +9,8 @@
  +--------------------------------------------------------------------+
  */
 
+use Civi\Api4\Email;
+
 /**
  * Trait CRMTraits_PCP_PCPTestTrait
  *
@@ -29,7 +31,7 @@ trait CRMTraits_PCP_PCPTestTrait {
     $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 @@ trait CRMTraits_PCP_PCPTestTrait {
       'tellfriend_limit' => 1,
       'link_text' => 'Create your own PCP',
       'is_active' => 1,
+      'owner_notify_id:name' => 'owner_chooses',
     ];
-
-    return $params;
   }
 
   /**
@@ -49,14 +50,17 @@ trait CRMTraits_PCP_PCPTestTrait {
    *
    * 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 @@ trait CRMTraits_PCP_PCPTestTrait {
       '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 @@ trait CRMTraits_PCP_PCPTestTrait {
    */
   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;
index b502273e837372ef8ecd35a6b63b7cef1bb84acb..b0a98b13e4dbfb6cfecddd609ec09123e5e2612b 100644 (file)
@@ -356,13 +356,13 @@ class CiviMailUtils extends PHPUnit\Framework\TestCase {
   }
 
   /**
-   * @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");
     }