X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fapi%2Fv3%2FUFFieldTest.php;h=a422c8ebd86b78cfa866f26093c4dc963a2bdca7;hb=a0741dc66a56012dca28350f8c1ddaad5ec03918;hp=8e39fa1411515dd26e4ec274bcd3b507aa0c0b07;hpb=c8115b6a584df05d3992d4ef86ac6fd5344a5e28;p=civicrm-core.git diff --git a/tests/phpunit/api/v3/UFFieldTest.php b/tests/phpunit/api/v3/UFFieldTest.php index 8e39fa1411..a422c8ebd8 100644 --- a/tests/phpunit/api/v3/UFFieldTest.php +++ b/tests/phpunit/api/v3/UFFieldTest.php @@ -27,18 +27,29 @@ /** * Test class for UFGroup API - civicrm_uf_* + * * @todo Split UFGroup and UFJoin tests * * @package CiviCRM * @group headless */ class api_v3_UFFieldTest extends CiviUnitTestCase { - // ids from the uf_group_test.xml fixture + + /** + * ids from the uf_group_test.xml fixture + * + * @var int + */ protected $_ufGroupId = 11; + protected $_ufFieldId; + protected $_contactId = 69; + protected $_apiversion = 3; + protected $_params; + protected $_entity = 'uf_field'; /** @@ -49,14 +60,14 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { protected function setUp() { parent::setUp(); $this->quickCleanup( - array( + [ 'civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_match', - ) + ] ); $op = new PHPUnit_Extensions_Database_Operation_Insert(); @@ -65,9 +76,9 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml') ); - $this->callAPISuccess('uf_field', 'getfields', array('cache_clear' => 1)); + $this->callAPISuccess('uf_field', 'getfields', ['cache_clear' => 1]); - $this->_params = array( + $this->_params = [ 'field_name' => 'phone', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', @@ -78,7 +89,7 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { 'location_type_id' => 1, 'phone_type_id' => 1, 'uf_group_id' => $this->_ufGroupId, - ); + ]; } /** @@ -88,13 +99,13 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanup( - array( + [ 'civicrm_group', 'civicrm_contact', 'civicrm_uf_group', 'civicrm_uf_join', 'civicrm_uf_match', - ) + ] ); } @@ -124,8 +135,8 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { * Failure test for bad parameters. */ public function testCreateUFFieldWithWrongParams() { - $this->callAPIFailure('uf_field', 'create', array('field_name' => 'test field')); - $this->callAPIFailure('uf_field', 'create', array('label' => 'name-less field')); + $this->callAPIFailure('uf_field', 'create', ['field_name' => 'test field']); + $this->callAPIFailure('uf_field', 'create', ['label' => 'name-less field']); } /** @@ -137,21 +148,21 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { $params1 = $this->_params; $ufField1 = $this->callAPISuccess('uf_field', 'create', $params1); $this->assertEquals(1, $ufField1['values'][$ufField1['id']]['weight']); - $this->assertDBQuery(1, 'SELECT weight FROM civicrm_uf_field WHERE id = %1', array( - 1 => array($ufField1['id'], 'Int'), - )); + $this->assertDBQuery(1, 'SELECT weight FROM civicrm_uf_field WHERE id = %1', [ + 1 => [$ufField1['id'], 'Int'], + ]); $params2 = $this->_params; // needs to be a different field $params2['location_type_id'] = 2; $ufField2 = $this->callAPISuccess('uf_field', 'create', $params2); $this->assertEquals(1, $ufField2['values'][$ufField2['id']]['weight']); - $this->assertDBQuery(1, 'SELECT weight FROM civicrm_uf_field WHERE id = %1', array( - 1 => array($ufField2['id'], 'Int'), - )); - $this->assertDBQuery(2, 'SELECT weight FROM civicrm_uf_field WHERE id = %1', array( - 1 => array($ufField1['id'], 'Int'), - )); + $this->assertDBQuery(1, 'SELECT weight FROM civicrm_uf_field WHERE id = %1', [ + 1 => [$ufField2['id'], 'Int'], + ]); + $this->assertDBQuery(2, 'SELECT weight FROM civicrm_uf_field WHERE id = %1', [ + 1 => [$ufField1['id'], 'Int'], + ]); } /** @@ -159,9 +170,9 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { */ public function testDeleteUFField() { $ufField = $this->callAPISuccess('uf_field', 'create', $this->_params); - $params = array( + $params = [ 'field_id' => $ufField['id'], - ); + ]; $this->callAPIAndDocument('uf_field', 'delete', $params, __FUNCTION__, __FILE__); } @@ -170,7 +181,7 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { */ public function testGetUFFieldSuccess() { $this->callAPISuccess($this->_entity, 'create', $this->_params); - $result = $this->callAPIAndDocument($this->_entity, 'get', array(), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument($this->_entity, 'get', [], __FUNCTION__, __FILE__); $this->getAndCheck($this->_params, $result['id'], $this->_entity); } @@ -178,8 +189,8 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { * Create / updating field. */ public function testReplaceUFFields() { - $baseFields = array(); - $baseFields[] = array( + $baseFields = []; + $baseFields[] = [ 'field_name' => 'first_name', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', @@ -187,8 +198,8 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { 'label' => 'Test First Name', 'is_searchable' => 1, 'is_active' => 1, - ); - $baseFields[] = array( + ]; + $baseFields[] = [ 'field_name' => 'country', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', @@ -197,8 +208,8 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { 'is_searchable' => 1, 'is_active' => 1, 'location_type_id' => 1, - ); - $baseFields[] = array( + ]; + $baseFields[] = [ 'field_name' => 'phone', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', @@ -208,17 +219,17 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { 'is_active' => 1, 'location_type_id' => 1, 'phone_type_id' => 1, - ); + ]; - $params = array( + $params = [ 'uf_group_id' => $this->_ufGroupId, 'option.autoweight' => FALSE, 'values' => $baseFields, 'check_permissions' => TRUE, - ); + ]; $result = $this->callAPIAndDocument('uf_field', 'replace', $params, __FUNCTION__, __FILE__); - $inputsByName = CRM_Utils_Array::index(array('field_name'), $params['values']); + $inputsByName = CRM_Utils_Array::index(['field_name'], $params['values']); $this->assertEquals(count($params['values']), count($result['values'])); foreach ($result['values'] as $outUfField) { $this->assertTrue(is_string($outUfField['field_name'])); @@ -241,7 +252,7 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { */ public function testProfilesWithoutACL() { $this->createLoggedInUser(); - $baseFields[] = array( + $baseFields[] = [ 'field_name' => 'first_name', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', @@ -249,14 +260,14 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { 'label' => 'Test First Name', 'is_searchable' => 1, 'is_active' => 1, - ); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); - $params = array( + ]; + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; + $params = [ 'uf_group_id' => $this->_ufGroupId, 'option.autoweight' => FALSE, 'values' => $baseFields, 'check_permissions' => TRUE, - ); + ]; $this->_loggedInUser = CRM_Core_Session::singleton()->get('userID'); $this->callAPIFailure('uf_field', 'replace', $params); } @@ -266,11 +277,11 @@ class api_v3_UFFieldTest extends CiviUnitTestCase { */ public function testACLPermissionforProfiles() { $this->createLoggedInUser(); - $this->_permissionedGroup = $this->groupCreate(array( + $this->_permissionedGroup = $this->groupCreate([ 'title' => 'Edit Profiles', 'is_active' => 1, 'name' => 'edit-profiles', - )); + ]); $this->setupACL(TRUE); $this->testReplaceUFFields(); }