* @group headless
*/
class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
+ use CRMTraits_PCP_PCPTestTrait;
protected $_individualId;
protected $_contribution;
parent::setUp();
$this->_userId = $this->createLoggedInUser();
- $this->_individualId = $this->individualCreate();
+ $this->_individualId = $this->ids['contact'][0] = $this->individualCreate();
$this->_params = [
'contact_id' => $this->_individualId,
'receive_date' => '20120511',
$mut->stop();
}
+ /**
+ * Test submitting the back office contribution form with pcp data.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ * @throws \Civi\Payment\Exception\PaymentProcessorException
+ */
+ public function testSubmitWithPCP() {
+ $params = $this->pcpParams();
+ $pcpID = $this->createPCPBlock($params);
+ $form = new CRM_Contribute_Form_Contribution();
+ $form->testSubmit([
+ 'financial_type_id' => 3,
+ 'contact_id' => $this->_individualId,
+ 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'),
+ 'contribution_status_id' => 1,
+ 'total_amount' => 5,
+ 'pcp_made_through_id' => $pcpID,
+ 'pcp_display_in_roll' => '1',
+ 'pcp_roll_nickname' => 'Dobby',
+ 'pcp_personal_note' => 'I wuz here',
+ ], CRM_Core_Action::ADD);
+ $softCredit = $this->callAPISuccessGetSingle('ContributionSoft', []);
+ $this->assertEquals('Dobby', $softCredit['pcp_roll_nickname']);
+ }
+
/**
* Test the submit function on the contribution page.
*/
$this->assertEquals($params['is_active'], $pcpBlock->is_active, 'Check for is_active.');
}
- public function testAddPCP() {
- $blockParams = $this->pcpBlockParams();
- $pcpBlock = CRM_PCP_BAO_PCPBlock::create($blockParams);
-
+ /**
+ * Basic create test.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testCreatePCP() {
$params = $this->pcpParams();
- $params['pcp_block_id'] = $pcpBlock->id;
-
- $pcp = CRM_PCP_BAO_PCP::create($params);
-
- $this->assertInstanceOf('CRM_PCP_DAO_PCP', $pcp, 'Check for created object');
- $this->assertEquals($params['contact_id'], $pcp->contact_id, 'Check for entity table.');
- $this->assertEquals($params['status_id'], $pcp->status_id, 'Check for status.');
- $this->assertEquals($params['title'], $pcp->title, 'Check for title.');
- $this->assertEquals($params['intro_text'], $pcp->intro_text, 'Check for intro_text.');
- $this->assertEquals($params['page_text'], $pcp->page_text, 'Check for page_text.');
- $this->assertEquals($params['donate_link_text'], $pcp->donate_link_text, 'Check for donate_link_text.');
- $this->assertEquals($params['is_thermometer'], $pcp->is_thermometer, 'Check for is_thermometer.');
- $this->assertEquals($params['is_honor_roll'], $pcp->is_honor_roll, 'Check for is_honor_roll.');
- $this->assertEquals($params['goal_amount'], $pcp->goal_amount, 'Check for goal_amount.');
- $this->assertEquals($params['is_active'], $pcp->is_active, 'Check for is_active.');
+ $pcpID = $this->createPCPBlock($params);
+ $this->getAndCheck($params, $pcpID, 'Pcp');
}
public function testAddPCPNoStatus() {
return $params;
}
+ /**
+ * Create a pcp block for testing.
+ *
+ * @param array $params
+ *
+ * @return int
+ */
+ 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;
+
+ $pcp = CRM_PCP_BAO_PCP::create($params);
+ return (int) $pcp->id;
+ }
+
}