Merge pull request #11965 from colemanw/CRM-21855
[civicrm-core.git] / tests / phpunit / api / v3 / BatchTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035 27
6a488035
TO
28/**
29 * Test class for Batch API - civicrm_batch_*
30 *
6c6e6187 31 * @package CiviCRM_APIv3
acb109b7 32 * @group headless
6a488035
TO
33 */
34class api_v3_BatchTest extends CiviUnitTestCase {
b7c9bc4c 35
23c385a2 36 protected $_params = array();
37 protected $_entity = 'batch';
38
6a488035
TO
39 /**
40 * Sets up the fixture, for example, opens a network connection.
fe482240 41 *
6a488035 42 * This method is called before a test is executed.
6a488035
TO
43 */
44 protected function setUp() {
6a488035 45 parent::setUp();
7d27f8fe 46 $this->useTransaction(TRUE);
23c385a2 47 }
6a488035 48
6a488035
TO
49 /**
50 * Test civicrm_batch_get - success expected.
51 */
52 public function testGet() {
53 $params = array(
54 'id' => $this->batchCreate(),
6a488035 55 );
23c385a2 56 $result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__);
ba4a1892 57 $this->assertEquals($params['id'], $result['id']);
6a488035
TO
58 }
59
6a488035
TO
60 /**
61 * Test civicrm_batch_create - success expected.
62 */
00be9182 63 public function testCreate() {
6a488035
TO
64 $params = array(
65 'name' => 'New_Batch_03',
66 'title' => 'New Batch 03',
67 'description' => 'This is description for New Batch 03',
68 'total' => '300.33',
69 'item_count' => 3,
70 'status_id' => 1,
6a488035
TO
71 );
72
23c385a2 73 $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__);
ba4a1892 74 $this->assertNotNull($result['id']);
23c385a2 75 $this->getAndCheck($params, $result['id'], $this->_entity);
6a488035
TO
76 }
77
78 /**
79 * Test civicrm_batch_create with id.
80 */
00be9182 81 public function testUpdate() {
6a488035
TO
82 $params = array(
83 'name' => 'New_Batch_04',
84 'title' => 'New Batch 04',
85 'description' => 'This is description for New Batch 04',
86 'total' => '400.44',
87 'item_count' => 4,
6a488035
TO
88 'id' => $this->batchCreate(),
89 );
90
23c385a2 91 $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__);
ba4a1892 92 $this->assertNotNull($result['id']);
23c385a2 93 $this->getAndCheck($params, $result['id'], $this->_entity);
6a488035
TO
94 }
95
96 /**
97 * Test civicrm_batch_delete using the old $params['batch_id'] syntax.
98 */
00be9182 99 public function testBatchDeleteOldSyntax() {
6a488035
TO
100 $batchID = $this->batchCreate();
101 $params = array(
102 'batch_id' => $batchID,
6a488035 103 );
23c385a2 104 $result = $this->callAPISuccess('batch', 'delete', $params);
6a488035
TO
105 }
106
107 /**
d177a2a6 108 * Test civicrm_batch_delete using the new $params['id'] syntax.
6a488035 109 */
00be9182 110 public function testBatchDeleteCorrectSyntax() {
6a488035
TO
111 $batchID = $this->batchCreate();
112 $params = array(
113 'id' => $batchID,
6a488035 114 );
23c385a2 115 $result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__);
6a488035
TO
116 }
117
118}