| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
| 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 | * Tests for the generic validate API action. |
| 30 | * |
| 31 | * @package CiviCRM_APIv3 |
| 32 | * @group headless |
| 33 | */ |
| 34 | class api_v3_ValidateTest extends CiviUnitTestCase { |
| 35 | /** |
| 36 | * This method is called before a test is executed. |
| 37 | */ |
| 38 | protected function setUp() { |
| 39 | parent::setUp(); |
| 40 | } |
| 41 | |
| 42 | public function testEmptyContactValidate() { |
| 43 | $validation = $this->callAPISuccess('Contact', 'validate', array('action' => "create")); |
| 44 | $expectedOut = array( |
| 45 | 'contact_type' => array( |
| 46 | 'message' => "Mandatory key(s) missing from params array: contact_type", |
| 47 | 'code' => "mandatory_missing", |
| 48 | ), |
| 49 | ); |
| 50 | $this->assertEquals($validation['values'][0], $expectedOut); |
| 51 | } |
| 52 | |
| 53 | public function testContributionValidate() { |
| 54 | $validation = $this->callAPISuccess('Contribution', 'validate', array('action' => "create", 'total_amount' => "100w")); |
| 55 | $totalAmountErrors = array( |
| 56 | 'message' => "total_amount is not a valid amount: 100w", |
| 57 | 'code' => "incorrect_value", |
| 58 | ); |
| 59 | |
| 60 | $contactIdErrors = array( |
| 61 | 'message' => "Mandatory key(s) missing from params array: contact_id", |
| 62 | 'code' => "mandatory_missing", |
| 63 | ); |
| 64 | |
| 65 | $this->assertEquals($validation['values'][0]['total_amount'], $totalAmountErrors); |
| 66 | $this->assertEquals($validation['values'][0]['contact_id'], $contactIdErrors); |
| 67 | } |
| 68 | |
| 69 | public function testContributionDateValidate() { |
| 70 | $params = array( |
| 71 | 'action' => "create", |
| 72 | 'financial_type_id' => "1", |
| 73 | 'total_amount' => "100", |
| 74 | 'contact_id' => "1", |
| 75 | 'receive_date' => 'abc', |
| 76 | ); |
| 77 | $validation = $this->callAPISuccess('Contribution', 'validate', $params); |
| 78 | |
| 79 | $expectedOut = array( |
| 80 | 'receive_date' => array( |
| 81 | 'message' => "receive_date is not a valid date: abc", |
| 82 | 'code' => "incorrect_value", |
| 83 | ), |
| 84 | ); |
| 85 | |
| 86 | $this->assertEquals($validation['values'][0], $expectedOut); |
| 87 | } |
| 88 | |
| 89 | } |