X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FCore%2FBAO%2FCustomValueTableSetGetTest.php;h=1e9d7fa84b87a122e4de37038d0d03ef2983241f;hb=b5261942401633a712339b08d5c75876ba7c0d2e;hp=e633279f9a78d093ea1bab92b83a119805a41a9d;hpb=580adbd3acf4913750423339348e4e733eb19199;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php b/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php index e633279f9a..1e9d7fa84b 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomValueTableSetGetTest.php @@ -14,42 +14,43 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { * Test setValues() and GetValues() methods with custom Date field */ public function testSetGetValuesDate() { - $params = array(); - $contactID = Contact::createIndividual(); + $params = []; + $contactID = $this->individualCreate(); //create Custom Group - $customGroup = Custom::createGroup($params, 'Individual', TRUE); + $customGroup = $this->customGroupCreate(['is_multiple' => 1]); //create Custom Field of data type Date - $fields = array( - 'groupId' => $customGroup->id, - 'dataType' => 'Date', - 'htmlType' => 'Select Date', - ); - $customField = Custom::createField($params, $fields); + $fields = [ + 'custom_group_id' => $customGroup['id'], + 'data_type' => 'Date', + 'html_type' => 'Select Date', + 'default_value' => '', + ]; + $customField = $this->customFieldCreate($fields); // Retrieve the field ID for sample custom field 'test_Date' - $params = array('label' => 'test_Date'); - $field = array(); + $params = ['label' => 'test_Date']; + $field = []; CRM_Core_BAO_CustomField::retrieve($params, $field); - $fieldID = $field['id']; + $fieldID = $customField['id']; // Set test_Date to a valid date value $date = '20080608000000'; - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => $date, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::setValues($params); $this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).'); // Check that the date value is stored - $values = array(); - $params = array( + $values = []; + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); @@ -60,15 +61,15 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Now set test_Date to an invalid date value and try to reset $badDate = '20080631000000'; - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => $badDate, - ); + ]; - $errorScope = CRM_Core_TemporaryErrorScope::useException(); + CRM_Core_TemporaryErrorScope::useException(); $message = NULL; try { - $result = CRM_Core_BAO_CustomValueTable::setValues($params); + CRM_Core_BAO_CustomValueTable::setValues($params); } catch (Exception $e) { $message = $e->getMessage(); @@ -78,10 +79,10 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Check that an exception has been thrown $this->assertNotNull($message, 'Verify than an exception is thrown when bad date is passed'); - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['custom_' . $fieldID . '_1'], CRM_Utils_Date::mysqlToIso($date), @@ -89,23 +90,23 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { ); // Test setting test_Date to null - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => NULL, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::setValues($params); // Check that the date value is empty - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); // Cleanup - Custom::deleteField($customField); - Custom::deleteGroup($customGroup); + $this->customFieldDelete($customField); + $this->customGroupDelete($customGroup['id']); $this->contactDelete($contactID); } @@ -113,45 +114,43 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { * Test setValues() and getValues() methods with custom field YesNo(Boolean) Radio */ public function testSetGetValuesYesNoRadio() { - $params = array(); - $contactID = Contact::createIndividual(); + $contactID = $this->individualCreate(); - //create Custom Group - $customGroup = Custom::createGroup($params, 'Individual', TRUE); + $customGroup = $this->customGroupCreate(['is_multiple' => 1]); //create Custom Field of type YesNo(Boolean) Radio - $fields = array( - 'groupId' => $customGroup->id, - 'dataType' => 'Boolean', - 'htmlType' => 'Radio', - ); - $customField = Custom::createField($params, $fields); + $fields = [ + 'custom_group_id' => $customGroup['id'], + 'data_type' => 'Boolean', + 'html_type' => 'Radio', + 'default_value' => '', + ]; + $customField = $this->customFieldCreate($fields); // Retrieve the field ID for sample custom field 'test_Boolean' - $params = array('label' => 'test_Boolean'); - $field = array(); + $params = ['label' => 'test_Boolean']; + $field = []; //get field Id CRM_Core_BAO_CustomField::retrieve($params, $field); - $fieldID = $field['id']; + $fieldID = $customField['id']; // valid boolean value '1' for Boolean Radio $yesNo = '1'; - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => $yesNo, - ); + ]; $result = CRM_Core_BAO_CustomValueTable::setValues($params); $this->assertEquals($result['is_error'], 0, 'Verify that is_error = 0 (success).'); // Check that the YesNo radio value is stored - $values = array(); - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values['is_error'], 0, 'Verify that is_error = 0 (success).'); @@ -161,15 +160,15 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Now set YesNo radio to an invalid boolean value and try to reset $badYesNo = '20'; - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => $badYesNo, - ); + ]; - $errorScope = CRM_Core_TemporaryErrorScope::useException(); + CRM_Core_TemporaryErrorScope::useException(); $message = NULL; try { - $result = CRM_Core_BAO_CustomValueTable::setValues($params); + CRM_Core_BAO_CustomValueTable::setValues($params); } catch (Exception $e) { $message = $e->getMessage(); @@ -179,10 +178,10 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { // Check that an exception has been thrown $this->assertNotNull($message, 'Verify than an exception is thrown when bad boolean is passed'); - $params = array( + $params = [ 'entityID' => $contactID, 'custom_' . $fieldID => 1, - ); + ]; $values = CRM_Core_BAO_CustomValueTable::getValues($params); $this->assertEquals($values["custom_{$fieldID}_1"], $yesNo, @@ -190,8 +189,8 @@ class CRM_Core_BAO_CustomValueTableSetGetTest extends CiviUnitTestCase { ); // Cleanup - Custom::deleteField($customField); - Custom::deleteGroup($customGroup); + $this->customFieldDelete($customField['id']); + $this->customGroupDelete($customGroup['id']); $this->contactDelete($contactID); }