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