| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
| 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 | /** |
| 29 | * Test class for Batch API - civicrm_batch_* |
| 30 | * |
| 31 | * @package CiviCRM_APIv3 |
| 32 | * @group headless |
| 33 | */ |
| 34 | class api_v3_BatchTest extends CiviUnitTestCase { |
| 35 | |
| 36 | protected $_params = array(); |
| 37 | protected $_entity = 'batch'; |
| 38 | |
| 39 | /** |
| 40 | * Sets up the fixture, for example, opens a network connection. |
| 41 | * |
| 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 | * Test civicrm_batch_get - success expected. |
| 51 | */ |
| 52 | public function testGet() { |
| 53 | $params = array( |
| 54 | 'id' => $this->batchCreate(), |
| 55 | ); |
| 56 | $result = $this->callAPIAndDocument('batch', 'get', $params, __FUNCTION__, __FILE__); |
| 57 | $this->assertEquals($params['id'], $result['id']); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Test civicrm_batch_create - success expected. |
| 62 | */ |
| 63 | public function testCreate() { |
| 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, |
| 71 | ); |
| 72 | |
| 73 | $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); |
| 74 | $this->assertNotNull($result['id']); |
| 75 | $this->getAndCheck($params, $result['id'], $this->_entity); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Test civicrm_batch_create with id. |
| 80 | */ |
| 81 | public function testUpdate() { |
| 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, |
| 88 | 'id' => $this->batchCreate(), |
| 89 | ); |
| 90 | |
| 91 | $result = $this->callAPIAndDocument('batch', 'create', $params, __FUNCTION__, __FILE__); |
| 92 | $this->assertNotNull($result['id']); |
| 93 | $this->getAndCheck($params, $result['id'], $this->_entity); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Test civicrm_batch_delete using the old $params['batch_id'] syntax. |
| 98 | */ |
| 99 | public function testBatchDeleteOldSyntax() { |
| 100 | $batchID = $this->batchCreate(); |
| 101 | $params = array( |
| 102 | 'batch_id' => $batchID, |
| 103 | ); |
| 104 | $result = $this->callAPISuccess('batch', 'delete', $params); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Test civicrm_batch_delete using the new $params['id'] syntax. |
| 109 | */ |
| 110 | public function testBatchDeleteCorrectSyntax() { |
| 111 | $batchID = $this->batchCreate(); |
| 112 | $params = array( |
| 113 | 'id' => $batchID, |
| 114 | ); |
| 115 | $result = $this->callAPIAndDocument('batch', 'delete', $params, __FUNCTION__, __FILE__); |
| 116 | } |
| 117 | |
| 118 | } |