Add 'name' field to pseudoconstant schema CRM-12464
[civicrm-core.git] / tests / phpunit / api / v3 / ContributionPageTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30
31/**
32 * Test APIv3 civicrm_contribute_recur* functions
33 *
34 * @package CiviCRM_APIv3
35 * @subpackage API_Contribution
36 */
37
38class api_v3_ContributionPageTest extends CiviUnitTestCase {
39 protected $_apiversion = 3;
40 protected $testAmount = 34567;
41 protected $params;
42 protected $id = 0;
43 protected $contactIds = array();
44 protected $_entity = 'contribution_page';
45 protected $contribution_result = null;
46 public $_eNoticeCompliant = TRUE;
47 public $DBResetRequired = TRUE;
48 public function setUp() {
49 parent::setUp();
50 $this->contactIds[] = $this->individualCreate();
51 $this->params = array(
52 'version' => $this->_apiversion,
53 'title' => "Test Contribution Page",
54 'financial_type_id' => 1,
55 'currency' => 'NZD',
56 'goal_amount' => $this->testAmount,
57 );
58 }
59
60 function tearDown() {
61 foreach ($this->contactIds as $id) {
62 civicrm_api('contact', 'delete', array('version' => $this->_apiversion, 'id' => $id));
63 }
64 civicrm_api('contribution_page', 'delete', array('version' => $this->_apiversion, 'id' => $this->id));
65 }
66
67 public function testCreateContributionPage() {
68 $result = civicrm_api($this->_entity, 'create', $this->params);
69 $this->id = $result['id'];
70 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
71 $this->assertAPISuccess($result, 'In line ' . __LINE__);
72 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
73 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
74 $this->getAndCheck($this->params, $result['id'], $this->_entity);
75 }
76
77 public function testGetBasicContributionPage() {
78 $createResult = civicrm_api($this->_entity, 'create', $this->params);
79 $this->id = $createResult['id'];
80 $this->assertAPISuccess($createResult);
81 $getParams = array(
82 'version' => $this->_apiversion,
83 'currency' => 'NZD',
84 'financial_type_id' => 1,
85 );
86 $getResult = civicrm_api($this->_entity, 'get', $getParams);
87 $this->documentMe($getParams, $getResult, __FUNCTION__, __FILE__);
88 $this->assertAPISuccess($getResult, 'In line ' . __LINE__);
89 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__);
90 }
91
92 public function testGetContributionPageByAmount() {
93 $createResult = civicrm_api($this->_entity, 'create', $this->params);
94 $this->id = $createResult['id'];
95 $this->assertAPISuccess($createResult);
96 $getParams = array(
97 'version' => $this->_apiversion,
98 'amount' => ''. $this->testAmount, // 3456
99 'currency' => 'NZD',
100 'financial_type_id' => 1,
101 );
102 $getResult = civicrm_api($this->_entity, 'get', $getParams);
103 $this->documentMe($getParams, $getResult, __FUNCTION__, __FILE__);
104 $this->assertAPISuccess($getResult, 'In line ' . __LINE__);
105 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__);
106 }
107
108 public function testDeleteContributionPage() {
109 $createResult = civicrm_api($this->_entity, 'create', $this->params);
110 $deleteParams = array('version' => $this->_apiversion, 'id' => $createResult['id']);
111 $deleteResult = civicrm_api($this->_entity, 'delete', $deleteParams);
112 $this->documentMe($deleteParams, $deleteResult, __FUNCTION__, __FILE__);
113 $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__);
114 $checkDeleted = civicrm_api($this->_entity, 'get', array(
115 'version' => $this->_apiversion,
116 ));
117 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
118 }
119
120 public function testGetFieldsContributionPage() {
121 $result = civicrm_api($this->_entity, 'getfields', array('version' => $this->_apiversion, 'action' => 'create'));
122 $this->assertAPISuccess($result, 'In line ' . __LINE__);
123 $this->assertEquals(12, $result['values']['start_date']['type']);
124 }
125
126 public static function setUpBeforeClass() {
127 // put stuff here that should happen before all tests in this unit
128 }
129
130 public static function tearDownAfterClass(){
131 $tablesToTruncate = array(
132 'civicrm_contact',
133 'civicrm_financial_type',
134 'civicrm_contribution',
135 'civicrm_contribution_page',
136 );
137 $unitTest = new CiviUnitTestCase();
138 $unitTest->quickCleanup($tablesToTruncate);
139 }
140}
141