Merge pull request #14840 from MegaphoneJon/core-1130
[civicrm-core.git] / tests / phpunit / CRM / Contribute / BAO / ContributionPageTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info'AT'civicrm'DOT'org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Class CRM_Contribute_BAO_ContributionPageTest
30 * @group headless
31 */
32 class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
33
34 public function setUp() {
35 parent::setUp();
36 $this->_financialTypeID = 1;
37 }
38
39 public function tearDown() {
40 }
41
42 /**
43 * Create() method (create Contribution Page)
44 */
45 public function testCreate() {
46
47 $params = [
48 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
49 'title' => 'Test Contribution Page',
50 'financial_type_id' => $this->_financialTypeID,
51 'intro_text' => '',
52 'footer_text' => 'Thanks',
53 'is_for_organization' => 0,
54 'for_organization' => ' I am contributing on behalf of an organization',
55 'goal_amount' => '400',
56 'is_active' => 1,
57 'honor_block_title' => '',
58 'honor_block_text' => '',
59 'start_date' => '20091022105900',
60 'start_date_time' => '10:59AM',
61 'end_date' => '19700101000000',
62 'end_date_time' => '',
63 'is_credit_card_only' => '',
64 ];
65
66 $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
67
68 $this->assertNotNull($contributionpage->id);
69 $this->assertType('int', $contributionpage->id);
70 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
71 }
72
73 /**
74 * test setIsActive() method
75 */
76 public function testsetIsActive() {
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 $id = $contributionpage->id;
86 $is_active = 1;
87 $pageActive = CRM_Contribute_BAO_ContributionPage::setIsActive($id, $is_active);
88 $this->assertEquals($pageActive, TRUE, 'Verify financial types record deletion.');
89 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
90 }
91
92 /**
93 * Test setValues() method
94 */
95 public function testSetValues() {
96
97 $params = [
98 'title' => 'Test Contribution Page',
99 'financial_type_id' => $this->_financialTypeID,
100 'is_active' => 1,
101 ];
102
103 $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
104
105 $id = $contributionPage->id;
106 $values = [];
107 CRM_Contribute_BAO_ContributionPage::setValues($id, $values);
108
109 $this->assertEquals($params['title'], $values['title'], 'Verify contribution title.');
110 $this->assertEquals($this->_financialTypeID, $values['financial_type_id'], 'Verify financial types id.');
111 $this->assertEquals(1, $values['is_active'], 'Verify contribution is_active value.');
112 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
113 }
114
115 /**
116 * Test copy() method
117 */
118 public function testcopy() {
119 $params = [
120 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
121 'title' => 'Test Contribution Page',
122 'financial_type_id' => $this->_financialTypeID,
123 'intro_text' => '',
124 'footer_text' => 'Thanks',
125 'is_for_organization' => 0,
126 'for_organization' => ' I am contributing on behalf of an organization',
127 'goal_amount' => '400',
128 'is_active' => 1,
129 'honor_block_title' => '',
130 'honor_block_text' => '',
131 'start_date' => '20091022105900',
132 'start_date_time' => '10:59AM',
133 'end_date' => '19700101000000',
134 'end_date_time' => '',
135 'is_credit_card_only' => '',
136 ];
137
138 $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
139 $copyContributionPage = CRM_Contribute_BAO_ContributionPage::copy($contributionPage->id);
140 $this->assertEquals($copyContributionPage->financial_type_id, $this->_financialTypeID, 'Check for Financial type id.');
141 $this->assertEquals($copyContributionPage->goal_amount, 400, 'Check for goal amount.');
142 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
143 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $copyContributionPage->id]);
144 }
145
146 }