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