Merge pull request #14922 from civicrm/5.16
[civicrm-core.git] / tests / phpunit / CRM / Contribute / BAO / ContributionPageTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035 27
4cbe18b8
EM
28/**
29 * Class CRM_Contribute_BAO_ContributionPageTest
acb109b7 30 * @group headless
4cbe18b8 31 */
6a488035 32class CRM_Contribute_BAO_ContributionPageTest extends CiviUnitTestCase {
6a488035 33
00be9182 34 public function setUp() {
6a488035 35 parent::setUp();
e6ff1593 36 $this->_financialTypeID = 1;
6a488035
TO
37 }
38
00be9182 39 public function tearDown() {
6a488035
TO
40 }
41
42 /**
100fef9d 43 * Create() method (create Contribution Page)
6a488035 44 */
00be9182 45 public function testCreate() {
6a488035 46
9099cab3 47 $params = [
6a488035
TO
48 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
49 'title' => 'Test Contribution Page',
e6ff1593 50 'financial_type_id' => $this->_financialTypeID,
6a488035
TO
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' => '',
9099cab3 64 ];
6a488035 65
6a488035
TO
66 $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
67
68 $this->assertNotNull($contributionpage->id);
69 $this->assertType('int', $contributionpage->id);
9099cab3 70 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
6a488035
TO
71 }
72
73 /**
74 * test setIsActive() method
75 */
00be9182 76 public function testsetIsActive() {
6a488035 77
9099cab3 78 $params = [
6a488035 79 'title' => 'Test Contribution Page',
e6ff1593 80 'financial_type_id' => $this->_financialTypeID,
6a488035 81 'is_active' => 1,
9099cab3 82 ];
6a488035
TO
83
84 $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
92915c55
TO
85 $id = $contributionpage->id;
86 $is_active = 1;
87 $pageActive = CRM_Contribute_BAO_ContributionPage::setIsActive($id, $is_active);
6c6e6187 88 $this->assertEquals($pageActive, TRUE, 'Verify financial types record deletion.');
9099cab3 89 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
6a488035
TO
90 }
91
92 /**
100fef9d 93 * Test setValues() method
6a488035 94 */
00be9182 95 public function testSetValues() {
6a488035 96
9099cab3 97 $params = [
6a488035 98 'title' => 'Test Contribution Page',
e6ff1593 99 'financial_type_id' => $this->_financialTypeID,
6a488035 100 'is_active' => 1,
9099cab3 101 ];
6a488035 102
23ead872 103 $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
6a488035 104
23ead872 105 $id = $contributionPage->id;
9099cab3 106 $values = [];
23ead872 107 CRM_Contribute_BAO_ContributionPage::setValues($id, $values);
6a488035
TO
108
109 $this->assertEquals($params['title'], $values['title'], 'Verify contribution title.');
e6ff1593 110 $this->assertEquals($this->_financialTypeID, $values['financial_type_id'], 'Verify financial types id.');
6a488035 111 $this->assertEquals(1, $values['is_active'], 'Verify contribution is_active value.');
9099cab3 112 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
6a488035
TO
113 }
114
115 /**
100fef9d 116 * Test copy() method
6a488035 117 */
00be9182 118 public function testcopy() {
9099cab3 119 $params = [
6a488035
TO
120 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
121 'title' => 'Test Contribution Page',
e6ff1593 122 'financial_type_id' => $this->_financialTypeID,
6a488035
TO
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' => '',
9099cab3 136 ];
6a488035 137
23ead872 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.');
9099cab3
CW
142 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
143 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $copyContributionPage->id]);
6a488035
TO
144 }
145
6a488035 146}