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