Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | * Sets up the fixture, for example, opens a network connection. | |
42 | * This method is called before a test is executed. | |
43 | * | |
44 | * @access protected | |
45 | */ | |
46 | protected function setUp() { | |
6a488035 | 47 | parent::setUp(); |
7d27f8fe | 48 | $this->useTransaction(TRUE); |
23c385a2 | 49 | } |
6a488035 TO |
50 | |
51 | /** | |
52 | * Create a sample batch | |
53 | */ | |
54 | function batchCreate() { | |
55 | $params = $this->_params; | |
23c385a2 | 56 | $params['name'] = $params['title'] = 'Batch_433397'; |
6a488035 | 57 | $params['status_id'] = 1; |
23c385a2 | 58 | $result = $this->callAPISuccess('batch', 'create', $params); |
6a488035 TO |
59 | return $result['id']; |
60 | } | |
61 | ||
6a488035 TO |
62 | /** |
63 | * Test civicrm_batch_get - success expected. | |
64 | */ | |
65 | public function testGet() { | |
66 | $params = array( | |
67 | 'id' => $this->batchCreate(), | |
6a488035 | 68 | ); |
23c385a2 | 69 | $result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
70 | $this->assertEquals($params['id'], $result['id'], 'In line ' . __LINE__); |
71 | } | |
72 | ||
6a488035 TO |
73 | /** |
74 | * Test civicrm_batch_create - success expected. | |
75 | */ | |
76 | function testCreate() { | |
77 | $params = array( | |
78 | 'name' => 'New_Batch_03', | |
79 | 'title' => 'New Batch 03', | |
80 | 'description' => 'This is description for New Batch 03', | |
81 | 'total' => '300.33', | |
82 | 'item_count' => 3, | |
83 | 'status_id' => 1, | |
6a488035 TO |
84 | ); |
85 | ||
23c385a2 | 86 | $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 | 87 | $this->assertNotNull($result['id'], 'In line ' . __LINE__); |
23c385a2 | 88 | $this->getAndCheck($params, $result['id'], $this->_entity); |
6a488035 TO |
89 | } |
90 | ||
91 | /** | |
92 | * Test civicrm_batch_create with id. | |
93 | */ | |
94 | function testUpdate() { | |
95 | $params = array( | |
96 | 'name' => 'New_Batch_04', | |
97 | 'title' => 'New Batch 04', | |
98 | 'description' => 'This is description for New Batch 04', | |
99 | 'total' => '400.44', | |
100 | 'item_count' => 4, | |
6a488035 TO |
101 | 'id' => $this->batchCreate(), |
102 | ); | |
103 | ||
23c385a2 | 104 | $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 | 105 | $this->assertNotNull($result['id'], 'In line ' . __LINE__); |
23c385a2 | 106 | $this->getAndCheck($params, $result['id'], $this->_entity); |
6a488035 TO |
107 | } |
108 | ||
109 | /** | |
110 | * Test civicrm_batch_delete using the old $params['batch_id'] syntax. | |
111 | */ | |
112 | function testBatchDeleteOldSyntax() { | |
113 | $batchID = $this->batchCreate(); | |
114 | $params = array( | |
115 | 'batch_id' => $batchID, | |
6a488035 | 116 | ); |
23c385a2 | 117 | $result = $this->callAPISuccess('batch', 'delete', $params); |
6a488035 TO |
118 | } |
119 | ||
120 | /** | |
121 | * Test civicrm_batch_delete using the new $params['id'] syntax | |
122 | */ | |
123 | function testBatchDeleteCorrectSyntax() { | |
124 | $batchID = $this->batchCreate(); | |
125 | $params = array( | |
126 | 'id' => $batchID, | |
6a488035 | 127 | ); |
23c385a2 | 128 | $result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
129 | } |
130 | ||
131 | } |