Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
b6708aeb | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
b6708aeb | 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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 26 | */ |
6a488035 TO |
27 | |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
e9479dcf EM |
29 | |
30 | /** | |
31 | * Class api_v3_PriceFieldTest | |
32 | */ | |
6a488035 TO |
33 | class api_v3_PriceFieldTest extends CiviUnitTestCase { |
34 | protected $_apiversion = 3; | |
35 | protected $_params; | |
36 | protected $id = 0; | |
37 | protected $priceSetID = 0; | |
38 | protected $_entity = 'price_field'; | |
b7c9bc4c | 39 | |
6a488035 TO |
40 | public $DBResetRequired = TRUE; |
41 | ||
42 | public function setUp() { | |
43 | parent::setUp(); | |
44 | // put stuff here that should happen before all tests in this unit | |
45 | $priceSetparams = array( | |
92915c55 | 46 | # [domain_id] => |
6a488035 TO |
47 | 'name' => 'default_goat_priceset', |
48 | 'title' => 'Goat accomodation', | |
49 | 'is_active' => 1, | |
50 | 'help_pre' => "Where does your goat sleep", | |
51 | 'help_post' => "thank you for your time", | |
52 | 'extends' => 2, | |
53 | 'financial_type_id' => 1, | |
54 | 'is_quick_config' => 1, | |
55 | 'is_reserved' => 1, | |
56 | ); | |
57 | ||
6c6e6187 | 58 | $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams); |
6a488035 TO |
59 | $this->priceSetID = $price_set['id']; |
60 | ||
6c6e6187 | 61 | $this->_params = array( |
92915c55 | 62 | 'price_set_id' => $this->priceSetID, |
6a488035 TO |
63 | 'name' => 'grassvariety', |
64 | 'label' => 'Grass Variety', | |
65 | 'html_type' => 'Text', | |
66 | 'is_enter_qty' => 1, | |
67 | 'is_active' => 1, | |
68 | ); | |
69 | } | |
70 | ||
00be9182 | 71 | public function tearDown() { |
6a488035 | 72 | $tablesToTruncate = array( |
92915c55 TO |
73 | 'civicrm_contact', |
74 | 'civicrm_contribution', | |
6a488035 TO |
75 | ); |
76 | $this->quickCleanup($tablesToTruncate); | |
77 | ||
6c6e6187 | 78 | $delete = $this->callAPISuccess('PriceSet', 'delete', array( |
92915c55 | 79 | 'id' => $this->priceSetID, |
6a488035 TO |
80 | )); |
81 | ||
82 | $this->assertAPISuccess($delete); | |
83 | } | |
84 | ||
85 | public function testCreatePriceField() { | |
7fbb4198 | 86 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); |
ba4a1892 TM |
87 | $this->assertEquals(1, $result['count']); |
88 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
6a488035 TO |
89 | $this->getAndCheck($this->_params, $result['id'], $this->_entity); |
90 | } | |
91 | ||
92 | public function testGetBasicPriceField() { | |
7fbb4198 | 93 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
6a488035 TO |
94 | $this->id = $createResult['id']; |
95 | $this->assertAPISuccess($createResult); | |
96 | $getParams = array( | |
6a488035 TO |
97 | 'name' => 'contribution_amount', |
98 | ); | |
7fbb4198 | 99 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
ba4a1892 | 100 | $this->assertEquals(1, $getResult['count']); |
6c6e6187 | 101 | $this->callAPISuccess('price_field', 'delete', array('id' => $createResult['id'])); |
6a488035 TO |
102 | } |
103 | ||
104 | public function testDeletePriceField() { | |
6c6e6187 | 105 | $startCount = $this->callAPISuccess($this->_entity, 'getcount', array()); |
7fbb4198 | 106 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
107 | $deleteParams = array('id' => $createResult['id']); | |
108 | $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); | |
a15773db | 109 | $this->assertAPISuccess($deleteResult); |
6c6e6187 | 110 | $endCount = $this->callAPISuccess($this->_entity, 'getcount', array()); |
a15773db | 111 | $this->assertEquals($startCount, $endCount); |
6a488035 TO |
112 | } |
113 | ||
114 | public function testGetFieldsPriceField() { | |
7fbb4198 | 115 | $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); |
6a488035 TO |
116 | $this->assertEquals(1, $result['values']['options_per_line']['type']); |
117 | } | |
118 | ||
119 | } |