adds a test for record customfield resolving
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 12 Jun 2017 09:03:11 +0000 (11:03 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 12 Jun 2017 09:51:49 +0000 (11:51 +0200)
Change-Id: Ia7a8f5c68b49f2fe492289e5d2d9353d2e4e260e
Reviewed-on: http://gerrit.tine20.com/customers/4857
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Addressbook/JsonTest.php
tests/tine20/TestCase.php

index 402a7bc..e69e676 100644 (file)
@@ -417,7 +417,22 @@ class Addressbook_JsonTest extends TestCase
         $this->assertEquals('changed value', $result['customfields'][$cf->name]);
         $this->_checkChangedNote($result['id'], ' ->  ' . $cf->name . ': changed value)');
     }
-    
+
+    /**
+     * test record customfield resolving
+     */
+    public function testCustomfieldResolving()
+    {
+        $cf = $this->_createCustomfield($name = 'ContactCF', $model = 'Addressbook_Model_Contact', $type = 'record');
+        $contact = $this->_addContact();
+        $contact2 = $this->_addContact('another one');
+        $contact['customfields'][$cf->name] = $contact2['id'];
+        $result = $this->_uit->saveContact($contact);
+
+        $this->assertTrue(is_array($result['customfields'][$cf->name]), 'customfield value is not resolved');
+        $this->assertEquals($contact2['id'], $result['customfields'][$cf->name]['id']);
+    }
+
     /**
      * check 'changed' system note and modlog after tag/customfield update
      * 
index 4a2d8f1..dd6d3d4 100644 (file)
@@ -601,9 +601,12 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
      *
      * @param string $name
      * @param string $model
+     * @param string $type
      * @return Tinebase_Model_CustomField_Config
+     *
+     * TODO use a single array as param that is merged with the defaults
      */
-    protected function _createCustomField($name = 'YomiName', $model = 'Addressbook_Model_Contact')
+    protected function _createCustomField($name = 'YomiName', $model = 'Addressbook_Model_Contact', $type = 'string')
     {
         $application = substr($model, 0, strpos($model, '_'));
         $cfData = new Tinebase_Model_CustomField_Config(array(
@@ -612,7 +615,10 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
             'model'             => $model,
             'definition'        => array(
                 'label' => Tinebase_Record_Abstract::generateUID(),
-                'type'  => 'string',
+                'type'  => $type,
+                'recordConfig' => $type === 'record'
+                    ? array('value' => array('records' => 'Tine.Addressbook.Model.Contact'))
+                    : null,
                 'uiconfig' => array(
                     'xtype'  => Tinebase_Record_Abstract::generateUID(),
                     'length' => 10,