Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | require_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 | ||
38 | class 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; | |
b7c9bc4c | 46 | |
6a488035 TO |
47 | public $DBResetRequired = TRUE; |
48 | public function setUp() { | |
49 | parent::setUp(); | |
50 | $this->contactIds[] = $this->individualCreate(); | |
51 | $this->params = array( | |
6a488035 TO |
52 | 'title' => "Test Contribution Page", |
53 | 'financial_type_id' => 1, | |
54 | 'currency' => 'NZD', | |
55 | 'goal_amount' => $this->testAmount, | |
56 | ); | |
57 | } | |
58 | ||
59 | function tearDown() { | |
60 | foreach ($this->contactIds as $id) { | |
fc928539 | 61 | $this->callAPISuccess('contact', 'delete', array('id' => $id)); |
62 | }if(!empty($this->id)){ | |
63 | $this->callAPISuccess('contribution_page', 'delete', array('id' => $this->id)); | |
6a488035 | 64 | } |
6a488035 TO |
65 | } |
66 | ||
67 | public function testCreateContributionPage() { | |
fc928539 | 68 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__); |
69 | $this->assertEquals(1, $result['count']); | |
70 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
6a488035 TO |
71 | $this->getAndCheck($this->params, $result['id'], $this->_entity); |
72 | } | |
73 | ||
74 | public function testGetBasicContributionPage() { | |
fc928539 | 75 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); |
6a488035 | 76 | $this->id = $createResult['id']; |
6a488035 | 77 | $getParams = array( |
6a488035 TO |
78 | 'currency' => 'NZD', |
79 | 'financial_type_id' => 1, | |
80 | ); | |
fc928539 | 81 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
82 | $this->assertEquals(1, $getResult['count']); | |
6a488035 TO |
83 | } |
84 | ||
85 | public function testGetContributionPageByAmount() { | |
fc928539 | 86 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); |
6a488035 | 87 | $this->id = $createResult['id']; |
6a488035 | 88 | $getParams = array( |
6a488035 TO |
89 | 'amount' => ''. $this->testAmount, // 3456 |
90 | 'currency' => 'NZD', | |
91 | 'financial_type_id' => 1, | |
92 | ); | |
fc928539 | 93 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
94 | $this->assertEquals(1, $getResult['count']); | |
6a488035 TO |
95 | } |
96 | ||
97 | public function testDeleteContributionPage() { | |
fc928539 | 98 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params); |
99 | $deleteParams = array('id' => $createResult['id']); | |
100 | $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); | |
101 | $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); | |
102 | $this->assertEquals(0, $checkDeleted['count']); | |
6a488035 TO |
103 | } |
104 | ||
105 | public function testGetFieldsContributionPage() { | |
fc928539 | 106 | $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); |
6a488035 TO |
107 | $this->assertEquals(12, $result['values']['start_date']['type']); |
108 | } | |
109 | ||
110 | public static function setUpBeforeClass() { | |
111 | // put stuff here that should happen before all tests in this unit | |
112 | } | |
113 | ||
114 | public static function tearDownAfterClass(){ | |
115 | $tablesToTruncate = array( | |
116 | 'civicrm_contact', | |
117 | 'civicrm_financial_type', | |
118 | 'civicrm_contribution', | |
119 | 'civicrm_contribution_page', | |
120 | ); | |
121 | $unitTest = new CiviUnitTestCase(); | |
122 | $unitTest->quickCleanup($tablesToTruncate); | |
123 | } | |
124 | } | |
125 |