If a template contribution is updated we need to update the amount on the recurring...
[civicrm-core.git] / tests / phpunit / CRM / Contribute / BAO / ContributionPageTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class CRM_Contribute_BAO_ContributionPageTest
14 * @group headless
15 */
16 class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
17
18 public function setUp(): void {
19 parent::setUp();
20 $this->_financialTypeID = 1;
21 }
22
23 /**
24 * Create() method (create Contribution Page)
25 */
26 public function testCreate() {
27
28 $params = [
29 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
30 'title' => 'Test Contribution Page',
31 'financial_type_id' => $this->_financialTypeID,
32 'intro_text' => '',
33 'footer_text' => 'Thanks',
34 'is_for_organization' => 0,
35 'for_organization' => ' I am contributing on behalf of an organization',
36 'goal_amount' => '400',
37 'is_active' => 1,
38 'honor_block_title' => '',
39 'honor_block_text' => '',
40 'start_date' => '20091022105900',
41 'start_date_time' => '10:59AM',
42 'end_date' => '19700101000000',
43 'end_date_time' => '',
44 'is_credit_card_only' => '',
45 ];
46
47 $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
48
49 $this->assertNotNull($contributionpage->id);
50 $this->assertIsInt($contributionpage->id);
51 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
52 }
53
54 /**
55 * test setIsActive() method
56 */
57 public function testsetIsActive() {
58
59 $params = [
60 'title' => 'Test Contribution Page',
61 'financial_type_id' => $this->_financialTypeID,
62 'is_active' => 1,
63 ];
64
65 $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
66 $id = $contributionpage->id;
67 $is_active = 1;
68 $pageActive = CRM_Contribute_BAO_ContributionPage::setIsActive($id, $is_active);
69 $this->assertEquals($pageActive, TRUE, 'Verify financial types record deletion.');
70 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
71 }
72
73 /**
74 * Test setValues() method
75 */
76 public function testSetValues() {
77
78 $params = [
79 'title' => 'Test Contribution Page',
80 'financial_type_id' => $this->_financialTypeID,
81 'is_active' => 1,
82 ];
83
84 $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
85
86 $id = $contributionPage->id;
87 $values = [];
88 CRM_Contribute_BAO_ContributionPage::setValues($id, $values);
89
90 $this->assertEquals($params['title'], $values['title'], 'Verify contribution title.');
91 $this->assertEquals($this->_financialTypeID, $values['financial_type_id'], 'Verify financial types id.');
92 $this->assertEquals(1, $values['is_active'], 'Verify contribution is_active value.');
93 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
94 }
95
96 /**
97 * Test copy() method
98 */
99 public function testcopy() {
100 $params = [
101 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
102 'title' => 'Test Contribution Page',
103 'financial_type_id' => $this->_financialTypeID,
104 'intro_text' => '',
105 'footer_text' => 'Thanks',
106 'is_for_organization' => 0,
107 'for_organization' => ' I am contributing on behalf of an organization',
108 'goal_amount' => '400',
109 'is_active' => 1,
110 'honor_block_title' => '',
111 'honor_block_text' => '',
112 'start_date' => '20091022105900',
113 'start_date_time' => '10:59AM',
114 'end_date' => '19700101000000',
115 'end_date_time' => '',
116 'is_credit_card_only' => '',
117 ];
118
119 $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
120 $copyContributionPage = CRM_Contribute_BAO_ContributionPage::copy($contributionPage->id);
121 $this->assertEquals($copyContributionPage->financial_type_id, $this->_financialTypeID, 'Check for Financial type id.');
122 $this->assertEquals($copyContributionPage->goal_amount, 400, 'Check for goal amount.');
123 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
124 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $copyContributionPage->id]);
125 }
126
127 }