3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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
{
36 * This method is called before a test is executed.
38 protected function setUp() {
42 public function testEmptyContactValidate() {
43 $validation = $this->callAPISuccess('Contact', 'validate', array('action' => "create"));
45 'contact_type' => array(
46 'message' => "Mandatory key(s) missing from params array: contact_type",
47 'code' => "mandatory_missing",
50 $this->assertEquals($validation['values'][0], $expectedOut);
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",
60 $contactIdErrors = array(
61 'message' => "Mandatory key(s) missing from params array: contact_id",
62 'code' => "mandatory_missing",
65 $this->assertEquals($validation['values'][0]['total_amount'], $totalAmountErrors);
66 $this->assertEquals($validation['values'][0]['contact_id'], $contactIdErrors);
69 public function testContributionDateValidate() {
72 'financial_type_id' => "1",
73 'total_amount' => "100",
75 'receive_date' => 'abc',
77 $validation = $this->callAPISuccess('Contribution', 'validate', $params);
80 'receive_date' => array(
81 'message' => "receive_date is not a valid date: abc",
82 'code' => "incorrect_value",
86 $this->assertEquals($validation['values'][0], $expectedOut);