Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | * Test class for Batch API - civicrm_batch_* | |
32 | * | |
33 | * @package CiviCRM_APIv3 | |
34 | */ | |
35 | class api_v3_BatchTest extends CiviUnitTestCase { | |
b7c9bc4c | 36 | |
23c385a2 | 37 | protected $_params = array(); |
38 | protected $_entity = 'batch'; | |
39 | ||
6a488035 TO |
40 | /** |
41 | * Constructor | |
42 | * | |
43 | * Initialize configuration | |
44 | */ | |
45 | function __construct() { | |
46 | parent::__construct(); | |
47 | } | |
48 | ||
49 | /** | |
50 | * Sets up the fixture, for example, opens a network connection. | |
51 | * This method is called before a test is executed. | |
52 | * | |
53 | * @access protected | |
54 | */ | |
55 | protected function setUp() { | |
6a488035 TO |
56 | parent::setUp(); |
57 | } | |
58 | ||
59 | /** | |
60 | * Tears down the fixture, for example, closes a network connection. | |
61 | * This method is called after a test is executed. | |
62 | * | |
63 | * @access protected | |
64 | */ | |
23c385a2 | 65 | protected function tearDown() { |
66 | $tablesToTruncate = array('civicrm_batch'); | |
67 | $this->quickCleanup($tablesToTruncate); | |
68 | } | |
6a488035 TO |
69 | |
70 | /** | |
71 | * Create a sample batch | |
72 | */ | |
73 | function batchCreate() { | |
74 | $params = $this->_params; | |
23c385a2 | 75 | $params['name'] = $params['title'] = 'Batch_433397'; |
6a488035 | 76 | $params['status_id'] = 1; |
23c385a2 | 77 | $result = $this->callAPISuccess('batch', 'create', $params); |
6a488035 TO |
78 | return $result['id']; |
79 | } | |
80 | ||
6a488035 TO |
81 | /** |
82 | * Test civicrm_batch_get - success expected. | |
83 | */ | |
84 | public function testGet() { | |
85 | $params = array( | |
86 | 'id' => $this->batchCreate(), | |
6a488035 | 87 | ); |
23c385a2 | 88 | $result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
89 | $this->assertEquals($params['id'], $result['id'], 'In line ' . __LINE__); |
90 | } | |
91 | ||
6a488035 TO |
92 | /** |
93 | * Test civicrm_batch_create - success expected. | |
94 | */ | |
95 | function testCreate() { | |
96 | $params = array( | |
97 | 'name' => 'New_Batch_03', | |
98 | 'title' => 'New Batch 03', | |
99 | 'description' => 'This is description for New Batch 03', | |
100 | 'total' => '300.33', | |
101 | 'item_count' => 3, | |
102 | 'status_id' => 1, | |
6a488035 TO |
103 | ); |
104 | ||
23c385a2 | 105 | $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 | 106 | $this->assertNotNull($result['id'], 'In line ' . __LINE__); |
23c385a2 | 107 | $this->getAndCheck($params, $result['id'], $this->_entity); |
6a488035 TO |
108 | } |
109 | ||
110 | /** | |
111 | * Test civicrm_batch_create with id. | |
112 | */ | |
113 | function testUpdate() { | |
114 | $params = array( | |
115 | 'name' => 'New_Batch_04', | |
116 | 'title' => 'New Batch 04', | |
117 | 'description' => 'This is description for New Batch 04', | |
118 | 'total' => '400.44', | |
119 | 'item_count' => 4, | |
6a488035 TO |
120 | 'id' => $this->batchCreate(), |
121 | ); | |
122 | ||
23c385a2 | 123 | $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 | 124 | $this->assertNotNull($result['id'], 'In line ' . __LINE__); |
23c385a2 | 125 | $this->getAndCheck($params, $result['id'], $this->_entity); |
6a488035 TO |
126 | } |
127 | ||
128 | /** | |
129 | * Test civicrm_batch_delete using the old $params['batch_id'] syntax. | |
130 | */ | |
131 | function testBatchDeleteOldSyntax() { | |
132 | $batchID = $this->batchCreate(); | |
133 | $params = array( | |
134 | 'batch_id' => $batchID, | |
6a488035 | 135 | ); |
23c385a2 | 136 | $result = $this->callAPISuccess('batch', 'delete', $params); |
6a488035 TO |
137 | } |
138 | ||
139 | /** | |
140 | * Test civicrm_batch_delete using the new $params['id'] syntax | |
141 | */ | |
142 | function testBatchDeleteCorrectSyntax() { | |
143 | $batchID = $this->batchCreate(); | |
144 | $params = array( | |
145 | 'id' => $batchID, | |
6a488035 | 146 | ); |
23c385a2 | 147 | $result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
148 | } |
149 | ||
150 | } |