Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-07-14-22-39-05
[civicrm-core.git] / tests / phpunit / api / v3 / BatchTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 {
36 public $_eNoticeCompliant = TRUE;
37 protected $_params = array();
38 protected $_entity = 'batch';
39
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() {
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 */
65 protected function tearDown() {
66 $tablesToTruncate = array('civicrm_batch');
67 $this->quickCleanup($tablesToTruncate);
68 }
69
70 /**
71 * Create a sample batch
72 */
73 function batchCreate() {
74 $params = $this->_params;
75 $params['name'] = $params['title'] = 'Batch_433397';
76 $params['status_id'] = 1;
77 $result = $this->callAPISuccess('batch', 'create', $params);
78 return $result['id'];
79 }
80
81 /**
82 * Test civicrm_batch_get - success expected.
83 */
84 public function testGet() {
85 $params = array(
86 'id' => $this->batchCreate(),
87 );
88 $result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__);
89 $this->assertEquals($params['id'], $result['id'], 'In line ' . __LINE__);
90 }
91
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,
103 );
104
105 $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__);
106 $this->assertNotNull($result['id'], 'In line ' . __LINE__);
107 $this->getAndCheck($params, $result['id'], $this->_entity);
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,
120 'id' => $this->batchCreate(),
121 );
122
123 $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__);
124 $this->assertNotNull($result['id'], 'In line ' . __LINE__);
125 $this->getAndCheck($params, $result['id'], $this->_entity);
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,
135 );
136 $result = $this->callAPISuccess('batch', 'delete', $params);
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,
146 );
147 $result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__);
148 }
149
150 }