Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
6a488035 TO |
28 | |
29 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
30 | class api_v3_PriceFieldTest extends CiviUnitTestCase { | |
31 | protected $_apiversion = 3; | |
32 | protected $_params; | |
33 | protected $id = 0; | |
34 | protected $priceSetID = 0; | |
35 | protected $_entity = 'price_field'; | |
36 | public $_eNoticeCompliant = TRUE; | |
37 | public $DBResetRequired = TRUE; | |
38 | ||
39 | public function setUp() { | |
40 | parent::setUp(); | |
41 | // put stuff here that should happen before all tests in this unit | |
42 | $priceSetparams = array( | |
43 | 'version' => 3, | |
44 | # [domain_id] => | |
45 | 'name' => 'default_goat_priceset', | |
46 | 'title' => 'Goat accomodation', | |
47 | 'is_active' => 1, | |
48 | 'help_pre' => "Where does your goat sleep", | |
49 | 'help_post' => "thank you for your time", | |
50 | 'extends' => 2, | |
51 | 'financial_type_id' => 1, | |
52 | 'is_quick_config' => 1, | |
53 | 'is_reserved' => 1, | |
54 | ); | |
55 | ||
56 | $price_set = civicrm_api('price_set', 'create',$priceSetparams); | |
57 | $this->priceSetID = $price_set['id']; | |
58 | ||
59 | $this->_params = array( | |
60 | 'version' => $this->_apiversion, | |
61 | 'price_set_id' => $this->priceSetID, | |
62 | 'name' => 'grassvariety', | |
63 | 'label' => 'Grass Variety', | |
64 | 'html_type' => 'Text', | |
65 | 'is_enter_qty' => 1, | |
66 | 'is_active' => 1, | |
67 | ); | |
68 | } | |
69 | ||
70 | function tearDown() { | |
71 | $tablesToTruncate = array( | |
72 | 'civicrm_contact', | |
73 | 'civicrm_contribution', | |
74 | ); | |
75 | $this->quickCleanup($tablesToTruncate); | |
76 | ||
77 | $delete = civicrm_api('PriceSet','delete', array( | |
78 | 'version' => 3, | |
79 | 'id' => $this->priceSetID, | |
80 | )); | |
81 | ||
82 | $this->assertAPISuccess($delete); | |
83 | } | |
84 | ||
85 | public function testCreatePriceField() { | |
86 | $result = civicrm_api($this->_entity, 'create', $this->_params); | |
87 | $this->id = $result['id']; | |
88 | $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__); | |
89 | $this->assertAPISuccess($result, 'In line ' . __LINE__); | |
90 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); | |
91 | $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); | |
92 | $this->getAndCheck($this->_params, $result['id'], $this->_entity); | |
93 | } | |
94 | ||
95 | public function testGetBasicPriceField() { | |
96 | $createResult = civicrm_api($this->_entity, 'create', $this->_params); | |
97 | $this->id = $createResult['id']; | |
98 | $this->assertAPISuccess($createResult); | |
99 | $getParams = array( | |
100 | 'version' => $this->_apiversion, | |
101 | 'name' => 'contribution_amount', | |
102 | ); | |
103 | $getResult = civicrm_api($this->_entity, 'get', $getParams); | |
104 | $this->documentMe($getParams, $getResult, __FUNCTION__, __FILE__); | |
105 | $this->assertAPISuccess($getResult, 'In line ' . __LINE__); | |
106 | $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__); | |
107 | civicrm_api('price_field','delete', array('version' => 3, 'id' => $createResult['id'])); | |
108 | } | |
109 | ||
110 | public function testDeletePriceField() { | |
111 | $startCount = civicrm_api($this->_entity, 'getcount', array( | |
112 | 'version' => $this->_apiversion, | |
113 | )); | |
114 | $createResult = civicrm_api($this->_entity, 'create', $this->_params); | |
115 | $deleteParams = array('version' => $this->_apiversion, 'id' => $createResult['id']); | |
116 | $deleteResult = civicrm_api($this->_entity, 'delete', $deleteParams); | |
117 | $this->documentMe($deleteParams, $deleteResult, __FUNCTION__, __FILE__); | |
118 | $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__); | |
119 | $endCount = civicrm_api($this->_entity, 'getcount', array( | |
120 | 'version' => $this->_apiversion, | |
121 | )); | |
122 | $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__); | |
123 | } | |
124 | ||
125 | public function testGetFieldsPriceField() { | |
126 | $result = civicrm_api($this->_entity, 'getfields', array('version' => $this->_apiversion, 'action' => 'create')); | |
127 | $this->assertAPISuccess($result, 'In line ' . __LINE__); | |
128 | $this->assertEquals(1, $result['values']['options_per_line']['type']); | |
129 | } | |
130 | ||
131 | } | |
132 |