Allow to pass additional record data to simple record api test
authorMichael Spahn <m.spahn@metaways.de>
Sat, 15 Jul 2017 11:59:12 +0000 (13:59 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Sat, 15 Jul 2017 13:28:10 +0000 (15:28 +0200)
 - allow to disable description field for check

Change-Id: Ie80cc3f80687aec3b79855ad11dd486a50d87912
Reviewed-on: http://gerrit.tine20.com/customers/5193
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Michael Spahn <m.spahn@metaways.de>
Tested-by: Michael Spahn <m.spahn@metaways.de>
tests/tine20/TestCase.php

index dd6d3d4..34ed439 100644 (file)
@@ -543,30 +543,57 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
         return $out;
     }
 
+
     /**
      * test record json api
      *
-     * @param $modelName
+     * @param string $modelName
+     * @param string $nameField
+     * @param string $descriptionField
+     * @param bool $delete
+     * @param array $recordData
      * @return array
+     * @throws Exception
      */
-    protected function _testSimpleRecordApi($modelName, $nameField = 'name', $descriptionField = 'description', $delete = true)
-    {
+    protected function _testSimpleRecordApi(
+        $modelName,
+        $nameField = 'name',
+        $descriptionField = 'description',
+        $delete = true,
+        $recordData = [],
+        $description = true
+    ) {
         $uit = $this->_getUit();
         if (!$uit instanceof Tinebase_Frontend_Json_Abstract) {
             throw new Exception('only allowed for json frontend tests suites');
         }
 
         $newRecord = array(
-            $nameField          => 'my test ' . $modelName,
-            $descriptionField   => 'my test description'
+            $nameField => 'my test ' . $modelName
         );
-        $savedRecord = call_user_func(array($uit, 'save' . $modelName), $newRecord);
 
+        if ($description) {
+            $newRecord[$descriptionField] = 'my test description';
+        }
+
+        $savedRecord = call_user_func(array($uit, 'save' . $modelName), array_merge($newRecord, $recordData));
         $this->assertEquals('my test ' . $modelName, $savedRecord[$nameField], print_r($savedRecord, true));
-        $savedRecord[$descriptionField] = 'my updated description';
 
-        $updatedRecord = call_user_func(array($uit, 'save' . $modelName), $savedRecord);
-        $this->assertEquals('my updated description', $updatedRecord[$descriptionField]);
+        // Update description if record has
+        if ($description) {
+            $savedRecord[$descriptionField] = 'my updated description';
+            $updatedRecord = call_user_func(array($uit, 'save' . $modelName), $savedRecord);
+            $this->assertEquals('my updated description', $updatedRecord[$descriptionField]);
+        }
+
+        if (!$description) {
+            $updatedRecord = $savedRecord;
+        }
+
+        // update name as well!
+        $updatedRecord[$nameField] = 'my updated namefield';
+        $updatedRecord = call_user_func(array($uit, 'save' . $modelName), $updatedRecord);
+        $this->assertEquals('my updated namefield', $updatedRecord[$nameField]);
 
         $filter = array(array('field' => 'id', 'operator' => 'equals', 'value' => $updatedRecord['id']));
         $result = call_user_func(array($uit, 'search' . $modelName . 's'), $filter, array());