Merge pull request #16529 from mattwire/altermailing_templatetype
[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() {
19 parent::setUp();
20 $this->_financialTypeID = 1;
21 }
22
23 public function tearDown() {
24 }
25
26 /**
27 * Create() method (create Contribution Page)
28 */
29 public function testCreate() {
30
31 $params = [
32 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
33 'title' => 'Test Contribution Page',
34 'financial_type_id' => $this->_financialTypeID,
35 'intro_text' => '',
36 'footer_text' => 'Thanks',
37 'is_for_organization' => 0,
38 'for_organization' => ' I am contributing on behalf of an organization',
39 'goal_amount' => '400',
40 'is_active' => 1,
41 'honor_block_title' => '',
42 'honor_block_text' => '',
43 'start_date' => '20091022105900',
44 'start_date_time' => '10:59AM',
45 'end_date' => '19700101000000',
46 'end_date_time' => '',
47 'is_credit_card_only' => '',
48 ];
49
50 $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
51
52 $this->assertNotNull($contributionpage->id);
53 $this->assertType('int', $contributionpage->id);
54 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
55 }
56
57 /**
58 * test setIsActive() method
59 */
60 public function testsetIsActive() {
61
62 $params = [
63 'title' => 'Test Contribution Page',
64 'financial_type_id' => $this->_financialTypeID,
65 'is_active' => 1,
66 ];
67
68 $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
69 $id = $contributionpage->id;
70 $is_active = 1;
71 $pageActive = CRM_Contribute_BAO_ContributionPage::setIsActive($id, $is_active);
72 $this->assertEquals($pageActive, TRUE, 'Verify financial types record deletion.');
73 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionpage->id]);
74 }
75
76 /**
77 * Test setValues() method
78 */
79 public function testSetValues() {
80
81 $params = [
82 'title' => 'Test Contribution Page',
83 'financial_type_id' => $this->_financialTypeID,
84 'is_active' => 1,
85 ];
86
87 $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
88
89 $id = $contributionPage->id;
90 $values = [];
91 CRM_Contribute_BAO_ContributionPage::setValues($id, $values);
92
93 $this->assertEquals($params['title'], $values['title'], 'Verify contribution title.');
94 $this->assertEquals($this->_financialTypeID, $values['financial_type_id'], 'Verify financial types id.');
95 $this->assertEquals(1, $values['is_active'], 'Verify contribution is_active value.');
96 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
97 }
98
99 /**
100 * Test copy() method
101 */
102 public function testcopy() {
103 $params = [
104 'qfkey' => '9a3ef3c08879ad4c8c109b21c583400e',
105 'title' => 'Test Contribution Page',
106 'financial_type_id' => $this->_financialTypeID,
107 'intro_text' => '',
108 'footer_text' => 'Thanks',
109 'is_for_organization' => 0,
110 'for_organization' => ' I am contributing on behalf of an organization',
111 'goal_amount' => '400',
112 'is_active' => 1,
113 'honor_block_title' => '',
114 'honor_block_text' => '',
115 'start_date' => '20091022105900',
116 'start_date_time' => '10:59AM',
117 'end_date' => '19700101000000',
118 'end_date_time' => '',
119 'is_credit_card_only' => '',
120 ];
121
122 $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
123 $copyContributionPage = CRM_Contribute_BAO_ContributionPage::copy($contributionPage->id);
124 $this->assertEquals($copyContributionPage->financial_type_id, $this->_financialTypeID, 'Check for Financial type id.');
125 $this->assertEquals($copyContributionPage->goal_amount, 400, 'Check for goal amount.');
126 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $contributionPage->id]);
127 $this->callAPISuccess('ContributionPage', 'delete', ['id' => $copyContributionPage->id]);
128 }
129
130 }