0a25ac6c4067d0c92a31757d4c62a0853bc0ad16
3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Tests for the generic validate API action.
31 * @package CiviCRM_APIv3
34 class api_v3_ValidateTest
extends CiviUnitTestCase
{
37 * This method is called before a test is executed.
39 protected function setUp() {
43 public function testEmptyContactValidate() {
44 $validation = $this->callAPISuccess('Contact', 'validate', array('action' => "create"));
46 'contact_type' => array(
47 'message' => "Mandatory key(s) missing from params array: contact_type",
48 'code' => "mandatory_missing",
51 $this->assertEquals($validation['values'][0], $expectedOut);
54 public function testContributionValidate() {
55 $validation = $this->callAPISuccess('Contribution', 'validate', array('action' => "create", 'total_amount' => "100w"));
56 $totalAmountErrors = array(
57 'message' => "total_amount is not a valid amount: 100w",
58 'code' => "incorrect_value",
61 $contactIdErrors = array(
62 'message' => "Mandatory key(s) missing from params array: contact_id",
63 'code' => "mandatory_missing",
66 $this->assertEquals($validation['values'][0]['total_amount'], $totalAmountErrors);
67 $this->assertEquals($validation['values'][0]['contact_id'], $contactIdErrors);
70 public function testContributionDateValidate() {
73 'financial_type_id' => "1",
74 'total_amount' => "100",
76 'receive_date' => 'abc',
78 $validation = $this->callAPISuccess('Contribution', 'validate', $params);
81 'receive_date' => array(
82 'message' => "receive_date is not a valid date: abc",
83 'code' => "incorrect_value",
87 $this->assertEquals($validation['values'][0], $expectedOut);