CRM-12274
[civicrm-core.git] / tests / phpunit / api / v3 / PriceFieldTest.php
CommitLineData
6a488035
TO
1<?php
2// $Id$
3
4require_once 'CiviTest/CiviUnitTestCase.php';
5class api_v3_PriceFieldTest extends CiviUnitTestCase {
6 protected $_apiversion = 3;
7 protected $_params;
8 protected $id = 0;
9 protected $priceSetID = 0;
10 protected $_entity = 'price_field';
11 public $_eNoticeCompliant = TRUE;
12 public $DBResetRequired = TRUE;
13
14 public function setUp() {
15 parent::setUp();
16 // put stuff here that should happen before all tests in this unit
17 $priceSetparams = array(
18 'version' => 3,
19 # [domain_id] =>
20 'name' => 'default_goat_priceset',
21 'title' => 'Goat accomodation',
22 'is_active' => 1,
23 'help_pre' => "Where does your goat sleep",
24 'help_post' => "thank you for your time",
25 'extends' => 2,
26 'financial_type_id' => 1,
27 'is_quick_config' => 1,
28 'is_reserved' => 1,
29 );
30
31 $price_set = civicrm_api('price_set', 'create',$priceSetparams);
32 $this->priceSetID = $price_set['id'];
33
34 $this->_params = array(
35 'version' => $this->_apiversion,
36 'price_set_id' => $this->priceSetID,
37 'name' => 'grassvariety',
38 'label' => 'Grass Variety',
39 'html_type' => 'Text',
40 'is_enter_qty' => 1,
41 'is_active' => 1,
42 );
43 }
44
45 function tearDown() {
46 $tablesToTruncate = array(
47 'civicrm_contact',
48 'civicrm_contribution',
49 );
50 $this->quickCleanup($tablesToTruncate);
51
52 $delete = civicrm_api('PriceSet','delete', array(
53 'version' => 3,
54 'id' => $this->priceSetID,
55 ));
56
57 $this->assertAPISuccess($delete);
58 }
59
60 public function testCreatePriceField() {
61 $result = civicrm_api($this->_entity, 'create', $this->_params);
62 $this->id = $result['id'];
63 $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
64 $this->assertAPISuccess($result, 'In line ' . __LINE__);
65 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
66 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
67 $this->getAndCheck($this->_params, $result['id'], $this->_entity);
68 }
69
70 public function testGetBasicPriceField() {
71 $createResult = civicrm_api($this->_entity, 'create', $this->_params);
72 $this->id = $createResult['id'];
73 $this->assertAPISuccess($createResult);
74 $getParams = array(
75 'version' => $this->_apiversion,
76 'name' => 'contribution_amount',
77 );
78 $getResult = civicrm_api($this->_entity, 'get', $getParams);
79 $this->documentMe($getParams, $getResult, __FUNCTION__, __FILE__);
80 $this->assertAPISuccess($getResult, 'In line ' . __LINE__);
81 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__);
82 civicrm_api('price_field','delete', array('version' => 3, 'id' => $createResult['id']));
83 }
84
85 public function testDeletePriceField() {
86 $startCount = civicrm_api($this->_entity, 'getcount', array(
87 'version' => $this->_apiversion,
88 ));
89 $createResult = civicrm_api($this->_entity, 'create', $this->_params);
90 $deleteParams = array('version' => $this->_apiversion, 'id' => $createResult['id']);
91 $deleteResult = civicrm_api($this->_entity, 'delete', $deleteParams);
92 $this->documentMe($deleteParams, $deleteResult, __FUNCTION__, __FILE__);
93 $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__);
94 $endCount = civicrm_api($this->_entity, 'getcount', array(
95 'version' => $this->_apiversion,
96 ));
97 $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__);
98 }
99
100 public function testGetFieldsPriceField() {
101 $result = civicrm_api($this->_entity, 'getfields', array('version' => $this->_apiversion, 'action' => 'create'));
102 $this->assertAPISuccess($result, 'In line ' . __LINE__);
103 $this->assertEquals(1, $result['values']['options_per_line']['type']);
104 }
105
106}
107