Action schedule API modifications
[civicrm-core.git] / tests / phpunit / api / v3 / UFFieldTest.php
index 1f0687133434c72f57d2d00e3accf4e102433337..9369ff324e8df6c4d4687417cda699449559346f 100644 (file)
@@ -1,8 +1,7 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -40,9 +39,9 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
   protected $_ufGroupId = 11;
   protected $_ufFieldId;
   protected $_contactId = 69;
-  protected $_apiversion;
+  protected $_apiversion = 3;
   protected $_params;
-  protected $_entity = 'UFField';
+  protected $_entity = 'uf_field';
   public $_eNoticeCompliant = TRUE;
 
   protected function setUp() {
@@ -58,7 +57,6 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
       )
     );
 
-    $this->_apiversion = 3;
     $op = new PHPUnit_Extensions_Database_Operation_Insert;
     $op->execute(
       $this->_dbconn,
@@ -66,6 +64,8 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
     );
     $this->_sethtmlGlobals();
 
+    $this->callAPISuccess('uf_field', 'getfields', array('cache_clear' => 1));
+
     $this->_params = array(
       'field_name' => 'phone',
       'field_type' => 'Contact',
@@ -76,7 +76,6 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
       'is_active' => 1,
       'location_type_id' => 1,
       'phone_type_id' => 1,
-      'version' => $this->_apiversion,
       'uf_group_id' => $this->_ufGroupId,
     );
   }
@@ -98,12 +97,9 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
    */
   public function testCreateUFField() {
     $params = $this->_params; // copy
-    $ufField = civicrm_api('uf_field', 'create', $params);
-    $this->documentMe($params, $ufField, __FUNCTION__, __FILE__);
-    unset($params['version']);
+    $ufField = $this->callAPIAndDocument('uf_field', 'create', $params, __FUNCTION__, __FILE__);
     unset($params['uf_group_id']);
     $this->_ufFieldId = $ufField['id'];
-    $this->assertEquals(0, $ufField['is_error'], " in line " . __LINE__);
     foreach ($params as $key => $value) {
       $this->assertEquals($ufField['values'][$ufField['id']][$key], $params[$key]);
     }
@@ -112,23 +108,12 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
   public function testCreateUFFieldWithBadFieldName() {
     $params = $this->_params; // copy
     $params['field_name'] = 'custom_98789'; // invalid field
-    $result = civicrm_api('uf_field', 'create', $params);
-    $this->assertEquals($result['is_error'], 1);
-  }
-
-  function testCreateUFFieldWithEmptyParams() {
-    $params = array();
-    $result = civicrm_api('uf_field', 'create', $params);
-    $this->assertEquals($result['is_error'], 1);
+    $this->callAPIFailure('uf_field', 'create', $params);
   }
 
   function testCreateUFFieldWithWrongParams() {
-    $result = civicrm_api('uf_field', 'create', array('field_name' => 'test field'));
-    $this->assertEquals($result['is_error'], 1);
-    $result = civicrm_api('uf_field', 'create', 'a string');
-    $this->assertEquals($result['is_error'], 1);
-    $result = civicrm_api('uf_field', 'create', array('label' => 'name-less field'));
-    $this->assertEquals($result['is_error'], 1);
+    $this->callAPIFailure('uf_field', 'create', array('field_name' => 'test field'));
+    $this->callAPIFailure('uf_field', 'create', array('label' => 'name-less field'));
   }
   /**
    * Create a field with 'weight=1' and then a second with 'weight=1'. The second field
@@ -136,7 +121,7 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
    */
   public function testCreateUFFieldWithDefaultAutoWeight() {
     $params1 = $this->_params; // copy
-    $ufField1 = civicrm_api('uf_field', 'create', $params1);
+    $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'),
@@ -144,7 +129,7 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
 
     $params2 = $this->_params; // copy
     $params2['location_type_id'] = 2; // needs to be a different field
-    $ufField2 = civicrm_api('uf_field', 'create', $params2);
+    $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'),
@@ -158,26 +143,16 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
    * deleting field
    */
   public function testDeleteUFField() {
-
-    $ufField = civicrm_api('uf_field', 'create', $this->_params);
-    $this->assertAPISuccess($ufField, 'in line' . __LINE__);
-    $this->_ufFieldId = $ufField['id'];
+    $ufField = $this->callAPISuccess('uf_field', 'create', $this->_params);
     $params = array(
-      'version' => $this->_apiversion,
       'field_id' => $ufField['id'],
     );
-    $result = civicrm_api('uf_field', 'delete', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, 0, 'in line' . __LINE__);
+    $result = $this->callAPIAndDocument('uf_field', 'delete', $params, __FUNCTION__, __FILE__);
   }
 
   public function testGetUFFieldSuccess() {
-
-    civicrm_api($this->_entity, 'create', $this->_params);
-    $params = array('version' => 3);
-    $result = civicrm_api($this->_entity, 'get', $params);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
-    $this->assertAPISuccess($result, 0, 'in line' . __LINE__);
+    $this->callAPISuccess($this->_entity, 'create', $this->_params);
+    $result = $this->callAPIAndDocument($this->_entity, 'get', array(), __FUNCTION__, __FILE__);
     $this->getAndCheck($this->_params, $result['id'], $this->_entity);
   }
 
@@ -218,15 +193,12 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
     );
 
     $params = array(
-      'version' => $this->_apiversion,
       'uf_group_id' => $this->_ufGroupId,
       'option.autoweight' => FALSE,
       'values' => $baseFields,
     );
 
-    $result = civicrm_api('uf_field', 'replace', $params);
-    $this->assertAPISuccess($result);
-    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument('uf_field', 'replace', $params, __FUNCTION__, __FILE__);
     $inputsByName = CRM_Utils_Array::index(array('field_name'), $params['values']);
     $this->assertEquals(count($params['values']), count($result['values']));
     foreach ($result['values'] as $outUfField) {
@@ -244,176 +216,4 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
       }
     }
   }
-
-  /**
-   * FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together
-   * (NB unclear if this is still required)
-   */
-  function _sethtmlGlobals() {
-    $GLOBALS['_HTML_QuickForm_registered_rules'] = array(
-      'required' => array(
-        'html_quickform_rule_required',
-        'HTML/QuickForm/Rule/Required.php'
-      ),
-      'maxlength' => array(
-        'html_quickform_rule_range',
-        'HTML/QuickForm/Rule/Range.php'
-      ),
-      'minlength' => array(
-        'html_quickform_rule_range',
-        'HTML/QuickForm/Rule/Range.php'
-      ),
-      'rangelength' => array(
-        'html_quickform_rule_range',
-        'HTML/QuickForm/Rule/Range.php'
-      ),
-      'email' => array(
-        'html_quickform_rule_email',
-        'HTML/QuickForm/Rule/Email.php'
-      ),
-      'regex' => array(
-        'html_quickform_rule_regex',
-        'HTML/QuickForm/Rule/Regex.php'
-      ),
-      'lettersonly' => array(
-        'html_quickform_rule_regex',
-        'HTML/QuickForm/Rule/Regex.php'
-      ),
-      'alphanumeric' => array(
-        'html_quickform_rule_regex',
-        'HTML/QuickForm/Rule/Regex.php'
-      ),
-      'numeric' => array(
-        'html_quickform_rule_regex',
-        'HTML/QuickForm/Rule/Regex.php'
-      ),
-      'nopunctuation' => array(
-        'html_quickform_rule_regex',
-        'HTML/QuickForm/Rule/Regex.php'
-      ),
-      'nonzero' => array(
-        'html_quickform_rule_regex',
-        'HTML/QuickForm/Rule/Regex.php'
-      ),
-      'callback' => array(
-        'html_quickform_rule_callback',
-        'HTML/QuickForm/Rule/Callback.php'
-      ),
-      'compare' => array(
-        'html_quickform_rule_compare',
-        'HTML/QuickForm/Rule/Compare.php'
-      )
-    );
-    // FIXME: â€¦ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']
-    $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array(
-      'group' => array(
-        'HTML/QuickForm/group.php',
-        'HTML_QuickForm_group'
-      ),
-      'hidden' => array(
-        'HTML/QuickForm/hidden.php',
-        'HTML_QuickForm_hidden'
-      ),
-      'reset' => array(
-        'HTML/QuickForm/reset.php',
-        'HTML_QuickForm_reset'
-      ),
-      'checkbox' => array(
-        'HTML/QuickForm/checkbox.php',
-        'HTML_QuickForm_checkbox'
-      ),
-      'file' => array(
-        'HTML/QuickForm/file.php',
-        'HTML_QuickForm_file'
-      ),
-      'image' => array(
-        'HTML/QuickForm/image.php',
-        'HTML_QuickForm_image'
-      ),
-      'password' => array(
-        'HTML/QuickForm/password.php',
-        'HTML_QuickForm_password'
-      ),
-      'radio' => array(
-        'HTML/QuickForm/radio.php',
-        'HTML_QuickForm_radio'
-      ),
-      'button' => array(
-        'HTML/QuickForm/button.php',
-        'HTML_QuickForm_button'
-      ),
-      'submit' => array(
-        'HTML/QuickForm/submit.php',
-        'HTML_QuickForm_submit'
-      ),
-      'select' => array(
-        'HTML/QuickForm/select.php',
-        'HTML_QuickForm_select'
-      ),
-      'hiddenselect' => array(
-        'HTML/QuickForm/hiddenselect.php',
-        'HTML_QuickForm_hiddenselect'
-      ),
-      'text' => array(
-        'HTML/QuickForm/text.php',
-        'HTML_QuickForm_text'
-      ),
-      'textarea' => array(
-        'HTML/QuickForm/textarea.php',
-        'HTML_QuickForm_textarea'
-      ),
-      'fckeditor' => array(
-        'HTML/QuickForm/fckeditor.php',
-        'HTML_QuickForm_FCKEditor'
-      ),
-      'tinymce' => array(
-        'HTML/QuickForm/tinymce.php',
-        'HTML_QuickForm_TinyMCE'
-      ),
-      'dojoeditor' => array(
-        'HTML/QuickForm/dojoeditor.php',
-        'HTML_QuickForm_dojoeditor'
-      ),
-      'link' => array(
-        'HTML/QuickForm/link.php',
-        'HTML_QuickForm_link'
-      ),
-      'advcheckbox' => array(
-        'HTML/QuickForm/advcheckbox.php',
-        'HTML_QuickForm_advcheckbox'
-      ),
-      'date' => array(
-        'HTML/QuickForm/date.php',
-        'HTML_QuickForm_date'
-      ),
-      'static' => array(
-        'HTML/QuickForm/static.php',
-        'HTML_QuickForm_static'
-      ),
-      'header' => array(
-        'HTML/QuickForm/header.php',
-        'HTML_QuickForm_header'
-      ),
-      'html' => array(
-        'HTML/QuickForm/html.php',
-        'HTML_QuickForm_html'
-      ),
-      'hierselect' => array(
-        'HTML/QuickForm/hierselect.php',
-        'HTML_QuickForm_hierselect'
-      ),
-      'autocomplete' => array(
-        'HTML/QuickForm/autocomplete.php',
-        'HTML_QuickForm_autocomplete'
-      ),
-      'xbutton' => array(
-        'HTML/QuickForm/xbutton.php',
-        'HTML_QuickForm_xbutton'
-      ),
-      'advmultiselect' => array(
-        'HTML/QuickForm/advmultiselect.php',
-        'HTML_QuickForm_advmultiselect'
-      )
-    );
-  }
 }