/*
+--------------------------------------------------------------------+
- | CiviCRM version 5 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019 |
- +--------------------------------------------------------------------+
- | 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. |
+ | Copyright CiviCRM LLC. All rights reserved. |
| |
- | 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 |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
* $Id$
*
*/
$customGroup = CustomGroup::create()
->setCheckPermissions(FALSE)
- ->addValue('name', 'MyContactFields')
- ->addValue('extends', 'Contact')
+ ->addValue('name', 'MyIndividualFields')
+ ->addValue('extends', 'Individual')
->execute()
->first();
->addValue('data_type', 'String')
->execute();
+ // Individual fields should show up when contact_type = null|Individual but not other contact types
+ $getFields = Contact::getFields()->setCheckPermissions(FALSE);
+ $this->assertContains('MyIndividualFields.FavColor', $getFields->execute()->column('name'));
+ $this->assertContains('MyIndividualFields.FavColor', $getFields->setValues(['contact_type' => 'Individual'])->execute()->column('name'));
+ $this->assertNotContains('MyIndividualFields.FavColor', $getFields->setValues(['contact_type' => 'Household'])->execute()->column('name'));
+
$contactId = Contact::create()
->setCheckPermissions(FALSE)
->addValue('first_name', 'Johann')
->addValue('last_name', 'Tester')
->addValue('contact_type', 'Individual')
- ->addValue('MyContactFields.FavColor', 'Red')
+ ->addValue('MyIndividualFields.FavColor', 'Red')
->execute()
->first()['id'];
$contact = Contact::get()
->setCheckPermissions(FALSE)
->addSelect('first_name')
- ->addSelect('MyContactFields.FavColor')
+ ->addSelect('MyIndividualFields.FavColor')
->addWhere('id', '=', $contactId)
- ->addWhere('MyContactFields.FavColor', '=', 'Red')
+ ->addWhere('MyIndividualFields.FavColor', '=', 'Red')
->execute()
->first();
- $this->assertEquals('Red', $contact['MyContactFields.FavColor']);
+ $this->assertEquals('Red', $contact['MyIndividualFields.FavColor']);
Contact::update()
->addWhere('id', '=', $contactId)
- ->addValue('MyContactFields.FavColor', 'Blue')
+ ->addValue('MyIndividualFields.FavColor', 'Blue')
->execute();
$contact = Contact::get()
->setCheckPermissions(FALSE)
- ->addSelect('MyContactFields.FavColor')
+ ->addSelect('MyIndividualFields.FavColor')
->addWhere('id', '=', $contactId)
->execute()
->first();
- $this->assertEquals('Blue', $contact['MyContactFields.FavColor']);
+ $this->assertEquals('Blue', $contact['MyIndividualFields.FavColor']);
}
public function testWithTwoFields() {