<?php
/**
- +--------------------------------------------------------------------+
-| CiviCRM version 4.5 |
-+--------------------------------------------------------------------+
-| Copyright CiviCRM LLC (c) 2004-2014 |
-+--------------------------------------------------------------------+
-| This file is a part of CiviCRM. |
-| |
-| CiviCRM is free software; you can copy, modify, and distribute it |
-| under the terms of the GNU Affero General Public License |
-| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
-| |
-| CiviCRM is distributed in the hope that it will be useful, but |
-| WITHOUT ANY WARRANTY; without even the implied warranty of |
-| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
-| See the GNU Affero General Public License for more details. |
-| |
-| You should have received a copy of the GNU Affero General Public |
-| License and the CiviCRM Licensing Exception along |
-| with this program; if not, contact CiviCRM LLC |
-| at info[AT]civicrm[DOT]org. If you have questions about the |
-| GNU Affero General Public License or the licensing of CiviCRM, |
-| see the CiviCRM license FAQ at http://civicrm.org/licensing |
-+--------------------------------------------------------------------+
-*/
+ * +--------------------------------------------------------------------+
+ * | CiviCRM version 4.6 |
+ * +--------------------------------------------------------------------+
+ * | Copyright CiviCRM LLC (c) 2004-2014 |
+ * +--------------------------------------------------------------------+
+ * | This file is a part of CiviCRM. |
+ * | |
+ * | CiviCRM is free software; you can copy, modify, and distribute it |
+ * | under the terms of the GNU Affero General Public License |
+ * | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ * | |
+ * | CiviCRM is distributed in the hope that it will be useful, but |
+ * | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ * | See the GNU Affero General Public License for more details. |
+ * | |
+ * | You should have received a copy of the GNU Affero General Public |
+ * | License and the CiviCRM Licensing Exception along |
+ * | with this program; if not, contact CiviCRM LLC |
+ * | at info[AT]civicrm[DOT]org. If you have questions about the |
+ * | GNU Affero General Public License or the licensing of CiviCRM, |
+ * | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ * +--------------------------------------------------------------------+
+ */
require_once 'CiviTest/CiviUnitTestCase.php';
* Class api_v3_CustomValueTest
*/
class api_v3_CustomValueTest extends CiviUnitTestCase {
- protected $_apiversion =3;
+ protected $_apiversion = 3;
protected $individual;
protected $params;
protected $ids;
public $DBResetRequired = FALSE;
- function setUp() {
+ public function setUp() {
parent::setUp();
- $this->individual = $this->individualCreate();
- $this->params = array(
+ $this->individual = $this->individualCreate();
+ $this->params = array(
'entity_id' => $this->individual,
);
$this->ids['single'] = $this->entityCustomGroupWithSingleFieldCreate('mySingleField', 'Contacts');
- $this->ids['multi'] = $this->CustomGroupMultipleCreateWithFields();
+ $this->ids['multi'] = $this->CustomGroupMultipleCreateWithFields();
$this->ids['multi2'] = $this->CustomGroupMultipleCreateWithFields(array('title' => 'group2'));
}
- function tearDown() {
+ public function tearDown() {
$tablesToTruncate = array(
'civicrm_email',
'civicrm_custom_field',
public function testCreateCustomValue() {
$params = array(
- 'custom_' . $this->ids['single']['custom_field_id'] => 'customString') + $this->params;
+ 'custom_' . $this->ids['single']['custom_field_id'] => 'customString'
+ ) + $this->params;
$result = $this->callAPIAndDocument('custom_value', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
'custom_' . $this->ids['multi2']['custom_field_id'][2] => "vegemite",
);
-
$result = $this->callAPISuccess('Contact', 'create', $params);
$contact_id = $result['id'];
$firstCustomField = $this->ids['multi']['custom_field_id'][0];
$createParams = array(
'contact_type' => 'Individual',
'id' => $contact_id,
- 'custom_' . $firstCustomField => "value 3",
- 'custom_' . $secondCustomField => "coffee",
- 'custom_' . $thirdCustomField => "value 4",
+ 'custom_' . $firstCustomField => "value 3",
+ 'custom_' . $secondCustomField => "coffee",
+ 'custom_' . $thirdCustomField => "value 4",
);
$result = $this->callAPISuccess('Contact', 'create', $createParams);
$this->assertEquals('', $result['values'][$thirdCustomField]['1']);
$this->assertEquals('value 4', $result['values'][$thirdCustomField]['2']);
}
-
+
public function testMultipleCustomValues() {
$params = array(
'first_name' => 'abc3',
$firstCustomField = $this->ids['multi']['custom_field_id'][1];
$secondCustomField = $this->ids['single']['custom_field_id'];
$thirdCustomField = $this->ids['multi']['custom_field_id'][0];
-
+
$createParams = array(
'contact_type' => 'Individual',
'id' => $contact_id,
- 'custom_' . $firstCustomField . '-1' => "second multi value 2",
- 'custom_' . $firstCustomField . '-2' => "second multi value 3",
+ 'custom_' . $firstCustomField . '-1' => "second multi value 2",
+ 'custom_' . $firstCustomField . '-2' => "second multi value 3",
);
$result = $this->callAPISuccess('Contact', 'create', $createParams);
$result = $this->callAPISuccess('CustomValue', 'Get', $params);
// delete the contact
$this->callAPISuccess('contact', 'delete', array('id' => $contact_id));
-
+
$this->assertEquals($contact_id, $result['values'][$secondCustomField]['entity_id']);
$this->assertEquals('value 1', $result['values'][$secondCustomField]['latest']);
$this->assertEquals('value 1', $result['values'][$secondCustomField][0]);
$this->assertEquals($contact_id, $result['values'][$thirdCustomField]['entity_id']);
$this->assertEquals('multi value 1', $result['values'][$thirdCustomField][1]);
$this->assertEquals('multi value 2', $result['values'][$thirdCustomField][2]);
-
+
$this->assertEquals($contact_id, $result['values'][$firstCustomField]['entity_id']);
$this->assertEquals('second multi value 1', $result['values'][$firstCustomField][1]);
$this->assertEquals('', $result['values'][$firstCustomField][2]);
$this->assertEquals('second multi value 3', $result['values'][$firstCustomField][4]);
$this->assertEquals('second multi value 3', $result['values'][$firstCustomField]['latest']);
}
-}
\ No newline at end of file
+}