Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
7d61e75f TO |
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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 10 | */ |
6a488035 | 11 | |
e9479dcf EM |
12 | /** |
13 | * Class api_v3_PriceFieldTest | |
acb109b7 | 14 | * @group headless |
e9479dcf | 15 | */ |
6a488035 TO |
16 | class api_v3_PriceFieldTest extends CiviUnitTestCase { |
17 | protected $_apiversion = 3; | |
18 | protected $_params; | |
19 | protected $id = 0; | |
20 | protected $priceSetID = 0; | |
21 | protected $_entity = 'price_field'; | |
b7c9bc4c | 22 | |
6a488035 TO |
23 | public $DBResetRequired = TRUE; |
24 | ||
25 | public function setUp() { | |
26 | parent::setUp(); | |
27 | // put stuff here that should happen before all tests in this unit | |
9099cab3 | 28 | $priceSetparams = [ |
92915c55 | 29 | # [domain_id] => |
6a488035 TO |
30 | 'name' => 'default_goat_priceset', |
31 | 'title' => 'Goat accomodation', | |
32 | 'is_active' => 1, | |
33 | 'help_pre' => "Where does your goat sleep", | |
34 | 'help_post' => "thank you for your time", | |
35 | 'extends' => 2, | |
36 | 'financial_type_id' => 1, | |
37 | 'is_quick_config' => 1, | |
38 | 'is_reserved' => 1, | |
9099cab3 | 39 | ]; |
6a488035 | 40 | |
6c6e6187 | 41 | $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams); |
6a488035 TO |
42 | $this->priceSetID = $price_set['id']; |
43 | ||
9099cab3 | 44 | $this->_params = [ |
92915c55 | 45 | 'price_set_id' => $this->priceSetID, |
6a488035 TO |
46 | 'name' => 'grassvariety', |
47 | 'label' => 'Grass Variety', | |
48 | 'html_type' => 'Text', | |
49 | 'is_enter_qty' => 1, | |
50 | 'is_active' => 1, | |
9099cab3 | 51 | ]; |
6a488035 TO |
52 | } |
53 | ||
00be9182 | 54 | public function tearDown() { |
9099cab3 | 55 | $tablesToTruncate = [ |
92915c55 TO |
56 | 'civicrm_contact', |
57 | 'civicrm_contribution', | |
9099cab3 | 58 | ]; |
6a488035 TO |
59 | $this->quickCleanup($tablesToTruncate); |
60 | ||
9099cab3 | 61 | $delete = $this->callAPISuccess('PriceSet', 'delete', [ |
92915c55 | 62 | 'id' => $this->priceSetID, |
9099cab3 | 63 | ]); |
6a488035 TO |
64 | |
65 | $this->assertAPISuccess($delete); | |
fda18dc3 | 66 | parent::tearDown(); |
6a488035 TO |
67 | } |
68 | ||
69 | public function testCreatePriceField() { | |
7fbb4198 | 70 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); |
ba4a1892 TM |
71 | $this->assertEquals(1, $result['count']); |
72 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
6a488035 TO |
73 | $this->getAndCheck($this->_params, $result['id'], $this->_entity); |
74 | } | |
75 | ||
76 | public function testGetBasicPriceField() { | |
7fbb4198 | 77 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
6a488035 TO |
78 | $this->id = $createResult['id']; |
79 | $this->assertAPISuccess($createResult); | |
9099cab3 | 80 | $getParams = [ |
6a488035 | 81 | 'name' => 'contribution_amount', |
9099cab3 | 82 | ]; |
7fbb4198 | 83 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
ba4a1892 | 84 | $this->assertEquals(1, $getResult['count']); |
9099cab3 | 85 | $this->callAPISuccess('price_field', 'delete', ['id' => $createResult['id']]); |
6a488035 TO |
86 | } |
87 | ||
88 | public function testDeletePriceField() { | |
9099cab3 | 89 | $startCount = $this->callAPISuccess($this->_entity, 'getcount', []); |
7fbb4198 | 90 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
9099cab3 | 91 | $deleteParams = ['id' => $createResult['id']]; |
7fbb4198 | 92 | $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); |
a15773db | 93 | $this->assertAPISuccess($deleteResult); |
9099cab3 | 94 | $endCount = $this->callAPISuccess($this->_entity, 'getcount', []); |
a15773db | 95 | $this->assertEquals($startCount, $endCount); |
6a488035 TO |
96 | } |
97 | ||
98 | public function testGetFieldsPriceField() { | |
9099cab3 | 99 | $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); |
6a488035 TO |
100 | $this->assertEquals(1, $result['values']['options_per_line']['type']); |
101 | } | |
102 | ||
e1defd06 SL |
103 | /** |
104 | * CRM-19741 | |
105 | * Test updating the label of a texte price field and ensure price field value label is also updated | |
106 | */ | |
107 | public function testUpdatePriceFieldLabel() { | |
108 | $field = $this->callAPISuccess($this->_entity, 'create', $this->_params); | |
9099cab3 | 109 | $this->callAPISuccess('price_field_value', 'create', [ |
e1defd06 SL |
110 | 'price_field_id' => $field['id'], |
111 | 'name' => 'rye grass', | |
112 | 'label' => 'juicy and healthy', | |
113 | 'amount' => 1, | |
114 | 'financial_type_id' => 1, | |
9099cab3 CW |
115 | ]); |
116 | $priceField = $this->callAPISuccess($this->_entity, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']); | |
117 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]); | |
e1defd06 | 118 | $this->assertEquals($priceField['values'][$priceField['id']]['label'], $priceFieldValue['values'][$priceFieldValue['id']]['label']); |
9099cab3 CW |
119 | $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]); |
120 | $this->callAPISuccess($this->_entity, 'delete', ['id' => $field['id']]); | |
e1defd06 SL |
121 | } |
122 | ||
123 | /** | |
124 | * CRM-19741 | |
125 | * Confirm value label only updates if fiedl type is html. | |
126 | */ | |
127 | public function testUpdatePriceFieldLabelNotUpdateField() { | |
9099cab3 CW |
128 | $field = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, ['html_type' => 'Radio'])); |
129 | $this->callAPISuccess('price_field_value', 'create', [ | |
e1defd06 SL |
130 | 'price_field_id' => $field['id'], |
131 | 'name' => 'rye grass', | |
132 | 'label' => 'juicy and healthy', | |
133 | 'amount' => 1, | |
134 | 'financial_type_id' => 1, | |
9099cab3 CW |
135 | ]); |
136 | $priceField = $this->callAPISuccess($this->_entity, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']); | |
137 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]); | |
e1defd06 | 138 | $this->assertEquals('juicy and healthy', $priceFieldValue['values'][$priceFieldValue['id']]['label']); |
9099cab3 CW |
139 | $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]); |
140 | $this->callAPISuccess($this->_entity, 'delete', ['id' => $field['id']]); | |
e1defd06 SL |
141 | } |
142 | ||
6a488035 | 143 | } |