diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php index 19270a24a0..09cde9ef46 100644 --- a/application/Espo/Core/Utils/Config.php +++ b/application/Espo/Core/Utils/Config.php @@ -150,7 +150,7 @@ class Config $removeData = empty($this->removeData) ? null : $this->removeData; - $result = $this->getFileManager()->mergeContentsPHP($this->configPath, $values, 1, $removeData); + $result = $this->getFileManager()->mergeContentsPHP($this->configPath, $values, $removeData); if ($result) { $this->changedData = array(); $this->removeData = array(); diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index 083502015d..cbdc1a3bf1 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -164,8 +164,9 @@ class Converter { $entityDefs = $this->getEntityDefs(); + $currentOrmMeta = $ormMeta; //load custom field definitions and customCodes - foreach($ormMeta as $entityName => &$entityParams) { + foreach($currentOrmMeta as $entityName => $entityParams) { foreach($entityParams['fields'] as $fieldName => $fieldParams) { //load custom field definitions @@ -184,15 +185,15 @@ class Converter } $ormMeta = Util::merge($ormMeta, $fieldResult); - } //END: load custom field definitions + } //END: load custom field definitions //todo move to separate file //add a field 'isFollowed' for scopes with 'stream => true' $scopeDefs = $this->getMetadata()->get('scopes.'.$entityName); if (isset($scopeDefs['stream']) && $scopeDefs['stream']) { if (!isset($entityParams['fields']['isFollowed'])) { - $entityParams['fields']['isFollowed'] = array( + $ormMeta[$entityName]['fields']['isFollowed'] = array( 'type' => 'varchar', 'notStorable' => true, ); @@ -302,7 +303,7 @@ class Converter { /** set default type if exists */ if (!isset($fieldParams['type']) || empty($fieldParams['type'])) { - $GLOBALS['log']->warning('Field type does not exist for '.$entityName.':'.$fieldName.'. Use default type ['.$this->defaultFieldType.']'); + $GLOBALS['log']->debug('Field type does not exist for '.$entityName.':'.$fieldName.'. Use default type ['.$this->defaultFieldType.']'); $fieldParams['type'] = $this->defaultFieldType; } /** END: set default type if exists */ diff --git a/application/Espo/Core/Utils/File/Manager.php b/application/Espo/Core/Utils/File/Manager.php index f60a8aac3d..6d0c5734f1 100644 --- a/application/Espo/Core/Utils/File/Manager.php +++ b/application/Espo/Core/Utils/File/Manager.php @@ -225,13 +225,12 @@ class Manager * @param string | array $path * @param string $content JSON string * @param bool $isJSON - * @param string | array $mergeOptions * @param string | array $removeOptions - List of unset keys from content * @param bool $isReturn - Is result to be returned or stored * * @return bool | array */ - public function mergeContents($path, $content, $isJSON = false, $mergeOptions = null, $removeOptions = null, $isReturn = false) + public function mergeContents($path, $content, $isJSON = false, $removeOptions = null, $isReturn = false) { $fileContent = $this->getContents($path); @@ -243,7 +242,7 @@ class Manager $newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions); } - $data = Utils\Util::merge($savedDataArray, $newDataArray, $mergeOptions); + $data = Utils\Util::merge($savedDataArray, $newDataArray); if ($isJSON) { $data = Utils\Json::encode($data, JSON_PRETTY_PRINT); } @@ -260,13 +259,12 @@ class Manager * * @param string | array $path * @param string $content JSON string - * @param string | array $mergeOptions * @param string | array $removeOptions - List of unset keys from content * @return bool */ - public function mergeContentsPHP($path, $content, $mergeOptions = null, $removeOptions = null) + public function mergeContentsPHP($path, $content, $removeOptions = null) { - $data = $this->mergeContents($path, $content, false, $mergeOptions, $removeOptions, true); + $data = $this->mergeContents($path, $content, false, $removeOptions, true); return $this->putContentsPHP($path, $data); } diff --git a/application/Espo/Core/Utils/File/Unifier.php b/application/Espo/Core/Utils/File/Unifier.php index c0b365eeee..355a3c215f 100644 --- a/application/Espo/Core/Utils/File/Unifier.php +++ b/application/Espo/Core/Utils/File/Unifier.php @@ -38,24 +38,21 @@ class Unifier $this->fileManager = $fileManager; } - protected function getFileManager() { return $this->fileManager; } - /** * Unite file content to the file * - * @param [type] $name [description] - * @param [type] $paths [description] + * @param string $name + * @param array $paths * @param boolean $recursively Note: only for first level of sub directory, other levels of sub directories will be ignored - * @param [type] $mergeLevel - merge level, see Espo\Core\Utils\Util::merge() * * @return array */ - public function unify($name, $paths, $recursively = false, $mergeLevel = null, $mergeKeyName = null) + public function unify($name, $paths, $recursively = false) { $content = $this->unifySingle($paths['corePath'], $name, $recursively); @@ -65,19 +62,17 @@ class Unifier foreach ($dirList as $dirName) { $curPath = str_replace('{*}', $dirName, $paths['modulePath']); - $content = Utils\Util::merge($content, $this->unifySingle($curPath, $name, $recursively, $dirName), $mergeLevel, $mergeKeyName); + $content = Utils\Util::merge($content, $this->unifySingle($curPath, $name, $recursively, $dirName)); } } if (!empty($paths['customPath'])) { - $content = Utils\Util::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively), $mergeLevel, $mergeKeyName); + $content = Utils\Util::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively)); } return $content; } - - /** * Unite file content to the file for one directory [NOW ONLY FOR METADATA, NEED TO CHECK FOR LAYOUTS AND OTHERS] * @@ -161,7 +156,7 @@ class Unifier * * @return array */ - protected function loadDefaultValues($name, $type='metadata') + protected function loadDefaultValues($name, $type = 'metadata') { $defaultPath = $this->params['defaultsPath']; diff --git a/application/Espo/Core/Utils/Language.php b/application/Espo/Core/Utils/Language.php index c5f6de1d19..abe599192b 100644 --- a/application/Espo/Core/Utils/Language.php +++ b/application/Espo/Core/Utils/Language.php @@ -241,7 +241,7 @@ class Language $i18nCacheFile = str_replace('{*}', $i18nName, $this->cacheFile); if ($i18nName != $this->defaultLanguage) { - $i18nData = Util::merge($this->fullData[$this->defaultLanguage], $i18nData, null, null, true); + $i18nData = Util::merge($this->fullData[$this->defaultLanguage], $i18nData); } $result &= $this->getFileManager()->putContentsPHP($i18nCacheFile, $i18nData); } diff --git a/application/Espo/Core/Utils/Metadata.php b/application/Espo/Core/Utils/Metadata.php index 9a55bf4a28..06acc37400 100644 --- a/application/Espo/Core/Utils/Metadata.php +++ b/application/Espo/Core/Utils/Metadata.php @@ -186,7 +186,7 @@ class Metadata { $data = false; if (!file_exists($this->cacheFile) || $reload) { - $data = $this->getUnifier()->unify($this->name, $this->paths, true, 5, 'options'); + $data = $this->getUnifier()->unify($this->name, $this->paths, true); if ($data === false) { $GLOBALS['log']->emergency('Metadata:getMetadata() - metadata unite file cannot be created'); @@ -246,7 +246,7 @@ class Metadata { $path = $this->paths['customPath']; - $result = $this->getFileManager()->mergeContents(array($path, $type, $scope.'.json'), $data, true, array(3, 'options')); + $result = $this->getFileManager()->mergeContents(array($path, $type, $scope.'.json'), $data, true); if ($result === false) { throw new Error("Error saving metadata. See log file for details."); } diff --git a/application/Espo/Core/Utils/Util.php b/application/Espo/Core/Utils/Util.php index cd575e71ef..8d15417e4f 100644 --- a/application/Espo/Core/Utils/Util.php +++ b/application/Espo/Core/Utils/Util.php @@ -109,103 +109,47 @@ class Util } /** - * Merge arrays (default PHP function is not suitable) + * Merge arrays recursively (default PHP function is not suitable) * - * @param array $array - * @param array $mainArray - chief array (priority is same as for array_merge()) - * @param array $rewriteLevel - Merge by rewrite level, level numering starts from 1. Ex. - * array( - * 'level1' => array( - * 'level2' => array( - * 'level3' => array( - * 'key1' => 'value', - * 'key2' => 'value', - * ), - * ), - * ), - * ) - * @param $rewriteKeyName string - Rewrite key name. It is ignored if $rewriteLevel is NULL. - * @param $rewriteArrays bool - Rewrite single arrays. Examples: - * TRUE: array is [0, 1, 2], main array is [3, 4, 5], Result is [3, 4, 5]. - * FALSE: array is [0, 1, 2], main array is [3, 4, 5], Result is [0, 1, 2, 3, 4, 5]. + * @param array $currentArray + * @param array $newArray - chief array (priority is same as for array_merge()) * * @return array */ - public static function merge($array, $mainArray, $rewriteLevel = null, $rewriteKeyName = null, $rewriteArrays = false) + public static function merge($currentArray, $newArray) { - if (is_array($array) && !is_array($mainArray)) { - return $array; - } else if (!is_array($array) && is_array($mainArray)) { - return $mainArray; - } else if (!is_array($array) && !is_array($mainArray)) { + $mergeIdentifier = '__APPEND__'; + + if (is_array($currentArray) && (!is_array($newArray) || empty($newArray))) { + return $currentArray; + } else if ((!is_array($currentArray) || empty($currentArray)) && is_array($newArray)) { + return $newArray; + } else if ((!is_array($currentArray) || empty($currentArray)) && (!is_array($newArray) || empty($newArray))) { return array(); } - if (is_array($rewriteLevel)) { - if (isset($rewriteLevel[1])) { - $rewriteKeyName = $rewriteLevel[1]; - } - if (isset($rewriteLevel[0])) { - $rewriteLevel = $rewriteLevel[0]; - } - } + /** add root items from currentArray */ + foreach ($currentArray as $currentName => $currentValue) { - foreach($mainArray as $mainKey => $mainValue) { + if (!isset($newArray[$currentName])) { - $found = false; - foreach($array as $key => $value) { + $newArray[$currentName] = $currentValue; - if ((string)$mainKey == (string)$key) { + } else if (is_array($currentValue) && is_array($newArray[$currentName])) { - $found = true; - if (is_array($mainValue) || is_array($value)) { - - $rowRewriteLevel = $rewriteLevel; - - /** check the $rewriteKeyName */ - if (isset($rowRewriteLevel) && $rowRewriteLevel == 1 && isset($rewriteKeyName)) { - $rewriteKeyName = is_array($rewriteKeyName) ? $rewriteKeyName : (array) $rewriteKeyName; - - if (!in_array((string)$key, $rewriteKeyName)) { - $rowRewriteLevel = null; - } - } /** END: check the $rewriteKeyName */ - - if (!isset($rowRewriteLevel) || $rowRewriteLevel != 1) { - $array[$mainKey] = static::merge((array) $value, (array) $mainValue, --$rowRewriteLevel, $rewriteKeyName, $rewriteArrays); - continue; - } - - $mergeValue = array('mergeLevel' => (array) $value); - $mergeMainValue = array('mergeLevel' => (array) $mainValue); - $mergeRes = array_merge($mergeValue, $mergeMainValue); - $array[$mainKey] = $mergeRes['mergeLevel']; - continue; - } - - /** merge logic */ - if (!is_numeric($mainKey)) { - $array[$mainKey] = $mainValue; - } - elseif (!in_array($mainValue, $array)) { - if ($rewriteArrays) { - $array[$mainKey] = $mainValue; - } else { - $array[] = $mainValue; - } - } /** END: merge logic */ - - break; + /** check __APPEND__ identifier */ + $appendKey = array_search($mergeIdentifier, $newArray[$currentName], true); + if ($appendKey !== false) { + unset($newArray[$currentName][$appendKey]); + $newArray[$currentName] = array_merge($currentValue, $newArray[$currentName]); + } else { + $newArray[$currentName] = static::merge($currentValue, $newArray[$currentName]); } - } - /** add an item if key not found */ - if (!$found) { - $array[$mainKey] = $mainValue; - } + } } - return $array; + return $newArray; } /** @@ -239,7 +183,6 @@ class Util return $folderPath . static::getSeparator() . $filePath; } - /** * Convert array to object format recursively * @@ -255,7 +198,6 @@ class Util } } - /** * Convert object to array format recursively * @@ -285,7 +227,6 @@ class Util return $name; } - /** * Get Naming according to prefix or postfix type * @@ -306,7 +247,6 @@ class Util return null; } - /** * Replace $search in array recursively * @@ -390,7 +330,6 @@ class Util return $content; } - /** * Get class name from the file path * @@ -407,7 +346,6 @@ class Util return $className; } - /** * Return values of defined $key. * @@ -446,15 +384,33 @@ class Util public static function isEquals($var1, $var2) { if (is_array($var1)) { - ksort($var1); + static::ksortRecursive($var1); } if (is_array($var2)) { - ksort($var2); + static::ksortRecursive($var2); } return ($var1 === $var2); } + /** + * Sort array recursively + * @param array $array + * @return bool + */ + public static function ksortRecursive(&$array) + { + if (!is_array($array)) { + return false; + } + + ksort($array); + foreach ($array as $key => $value) { + static::ksortRecursive($array[$key]); + } + + return true; + } } diff --git a/tests/Espo/Core/Utils/UtilTest.php b/tests/Espo/Core/Utils/UtilTest.php index 1e78ccc98f..885adfcb6b 100644 --- a/tests/Espo/Core/Utils/UtilTest.php +++ b/tests/Espo/Core/Utils/UtilTest.php @@ -4,23 +4,21 @@ namespace tests\Espo\Core\Utils; use Espo\Core\Utils\Util; - class UtilTest extends \PHPUnit_Framework_TestCase { - - function testGetSeparator() + public function testGetSeparator() { $this->assertEquals(DIRECTORY_SEPARATOR, Util::getSeparator()); } - function testToCamelCase() + public function testToCamelCase() { $this->assertEquals('detail', Util::toCamelCase('detail')); $this->assertEquals('detailView', Util::toCamelCase('detail-view')); $this->assertEquals('myDetailView', Util::toCamelCase('my-detail-view')); } - function testFromCamelCase() + public function testFromCamelCase() { $this->assertEquals('detail', Util::fromCamelCase('detail')); $this->assertEquals('detail-view', Util::fromCamelCase('detailView')); @@ -61,7 +59,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals($result, Util::merge($array1, $array2Main)); - $array1= array( 'datetime' => array ( @@ -114,436 +111,383 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals($result, Util::merge($array1, $array2Main)); } - public function testMergeLevel1() + public function testMergeWithAppend() { - $basicArr = array( - 'useCache' => 111, - 'useCache1' => 111, - 'sub' => array ( - 'subV' => '1111', - 'subV1' => '1111', - 'subO' => array( - 'subOV' => '11111', - 'subOV1' => '11111', - 'subOT' => array( - 'subOTT' => '11111', - 'subOT1' => '11111', - ), - ), - ), - ); - - $advArr = array( - 'useCache' => 222, - 'useCache2' => 222, - 'sub' => array ( - 'subV' => '222222', - 'subV2' => '222222', - 'subO' => array( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => array( - 'subOTT' => '22222', - 'subOT2' => '22222', - ), - ), - ), - ); - - $result = array ( - 'useCache' => 222, - 'useCache1' => 111, - 'useCache2' => 222, - 'sub' => array ( - 'subV' => '222222', - 'subV2' => '222222', - 'subO' => array( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => array( - 'subOTT' => '22222', - 'subOT2' => '22222', - ), - ), - ), - ); - - $this->assertEquals($result, Util::merge($basicArr, $advArr, 1)); - $this->assertEquals($result, Util::merge($basicArr, $advArr, array(1))); - } - - - public function testMergeLevel1WithMergeKeyName() - { - $basicArr = array( - 'useCache' => 111, - 'useCache1' => 111, - 'sub' => array ( - 'subV' => '1111', - 'subV1' => '1111', - 'subO' => array( - 'subOV' => '11111', - 'subOV1' => '11111', - 'subOT' => array( - 'subOTT' => '11111', - 'subOT1' => '11111', - ), - ), - ), - ); - - $advArr = array( - 'useCache' => 222, - 'useCache2' => 222, - 'sub' => array ( - 'subV' => '222222', - 'subV2' => '222222', - 'subO' => array( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => array( - 'subOTT' => '22222', - 'subOT2' => '22222', - ), - ), - ), - ); - - $result = array ( - 'useCache' => 222, - 'useCache1' => 111, - 'sub' => - array ( - 'subV' => '222222', - 'subV1' => '1111', - 'subO' => - array ( - 'subOV' => '22222', - 'subOV1' => '11111', - 'subOT' => + $currentArray = array( + 'entityDefs' => array ( - 'subOTT' => '22222', - 'subOT1' => '11111', - 'subOT2' => '22222', - ), - 'subOV2' => '22222', - ), - 'subV2' => '222222', - ), - 'useCache2' => 222, - ); - - $this->assertEquals($result, Util::merge($basicArr, $advArr, 1, 'useCache')); - $this->assertEquals( $result, Util::merge($basicArr, $advArr, array(1, 'useCache')) ); - - $result = array ( - 'useCache' => 222, - 'useCache1' => 111, - 'sub' => - array ( - 'subV' => '222222', - 'subV2' => '222222', - 'subO' => array( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => array( - 'subOTT' => '22222', - 'subOT2' => '22222', - ), - ), - ), - 'useCache2' => 222, - ); - - $this->assertEquals($result, Util::merge($basicArr, $advArr, 1, 'sub')); - $this->assertEquals( $result, Util::merge($basicArr, $advArr, array(1, 'sub')) ); - } - - public function testMergeLevel2() - { - $basicArr = array( - 'useCache' => 111, - 'useCache1' => 111, - 'sub' => array ( - 'subV' => '1111', - 'subV1' => '1111', - 'subO' => array( - 'subOV' => '11111', - 'subOV1' => '11111', - 'subOT' => array( - 'subOTT' => '11111', - 'subOT1' => '11111', + 'Attachment' => + array ( + 'fields' => + array ( + 'name' => + array ( + 'type' => 'varchar', + 'required' => true, ), - ), - ), - ); - - $advArr = array( - 'useCache' => 222, - 'useCache2' => 222, - 'sub' => array ( - 'subV' => '222222', - 'subV2' => '222222', - 'subO' => array( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => array( - 'subOTT' => '22222', - 'subOT2' => '22222', + 'type' => + array ( + 'type' => 'varchar', + 'maxLength' => 36, ), + 'size' => + array ( + 'type' => 'enum', + 'value' => ["v1", "v2", "v3"], + ), + 'sizeInt' => + array ( + 'type' => 'enum', + 'value' => [0, 1, 2], + ), + 'merged' => + array ( + 'type' => 'enum', + 'value' => ["v1", "v2", "v3"], + ), + 'mergedInt' => + array ( + 'type' => 'enum', + 'value' => [0, 1, 2], + ), + ), + ), + 'Contact' => + array ( + 'fields' => + array ( + 'name' => + array ( + 'type' => 'varchar', + 'required' => true, + ), + 'type' => + array ( + 'type' => 'varchar', + 'maxLength' => 36, + ), + 'size' => + array ( + 'type' => 'enum', + 'value' => ["v1", "v2", "v3"], + ), + 'merged' => + array ( + 'type' => 'enum', + 'value' => ["v1", "v2", "v3"], + ), + ), ), ), - ); - - $result = array ( - 'useCache' => 222, - 'useCache1' => 111, - 'sub' => - array ( - 'subV' => '222222', - 'subV1' => '1111', - 'subO' => + 'MyCustom' => array ( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => + 'fields' => array ( - 'subOTT' => '22222', - 'subOT2' => '22222', + 'name' => + array ( + 'type' => 'varchar', + 'required' => true, + ), ), ), - 'subV2' => '222222', - ), - 'useCache2' => 222, ); - $this->assertEquals($result, Util::merge($basicArr, $advArr, 2)); - $this->assertEquals($result, Util::merge($basicArr, $advArr, array(2))); + $newArray = array( + 'entityDefs' => + array ( + 'Attachment' => + array ( + 'fields' => + array ( + 'name' => + array ( + 'type' => 'varchar', + 'required' => false, + 'NEW' => 'NEWVAL', + ), + 'type' => + array ( + 'type' => 'NETYPE', + ), + 'size' => + array ( + 'type' => 'enum', + 'value' => ["B1", "B2", "B3"], + ), + 'sizeInt' => + array ( + 'type' => 'enum', + 'value' => [5, 8, 9], + ), + 'merged' => + array ( + 'type' => 'enum', + 'value' => ["__APPEND__", "B1", "B2", "B3"], + ), + 'mergedInt' => + array ( + 'type' => 'enum', + 'value' => ['__APPEND__', 5, 8, 9], + ), + ), + 'list' => + array ( + 'test' => 'Here', + ), + ), + 'Contact' => + array ( + 'fields' => + array ( + 'name' => + array ( + 'type' => 'varchar', + 'required' => false, + 'NEW' => 'NEWVAL', + ), + 'type' => + array ( + 'type' => 'NEW', + 'maxLength' => 1000000, + ), + 'size' => + array ( + 'type' => 'enum', + 'value' => ["B1", "B2", "B3"], + ), + 'merged' => + array ( + 'type' => 'enum', + 'value' => ["__APPEND__", "B1", "B2", "B3"], + ), + ), + ), + ), + ); + + + $result = array ( + 'entityDefs' => + array ( + 'Attachment' => + array ( + 'fields' => + array ( + 'name' => + array ( + 'type' => 'varchar', + 'required' => false, + 'NEW' => 'NEWVAL', + ), + 'type' => + array ( + 'type' => 'NETYPE', + 'maxLength' => 36, + ), + 'size' => + array ( + 'type' => 'enum', + 'value' => + array ( + 0 => 'B1', + 1 => 'B2', + 2 => 'B3', + ), + ), + 'sizeInt' => + array ( + 'type' => 'enum', + 'value' => + array ( + 0 => 5, + 1 => 8, + 2 => 9, + ), + ), + 'merged' => + array ( + 'type' => 'enum', + 'value' => + array ( + 0 => 'v1', + 1 => 'v2', + 2 => 'v3', + 3 => 'B1', + 4 => 'B2', + 5 => 'B3', + ), + ), + 'mergedInt' => + array ( + 'type' => 'enum', + 'value' => + array ( + 0 => 0, + 1 => 1, + 2 => 2, + 3 => 5, + 4 => 8, + 5 => 9, + ), + ), + ), + 'list' => + array ( + 'test' => 'Here', + ), + ), + 'Contact' => + array ( + 'fields' => + array ( + 'name' => + array ( + 'type' => 'varchar', + 'required' => false, + 'NEW' => 'NEWVAL', + ), + 'type' => + array ( + 'type' => 'NEW', + 'maxLength' => 1000000, + ), + 'size' => + array ( + 'type' => 'enum', + 'value' => + array ( + 0 => 'B1', + 1 => 'B2', + 2 => 'B3', + ), + ), + 'merged' => + array ( + 'type' => 'enum', + 'value' => + array ( + 0 => 'v1', + 1 => 'v2', + 2 => 'v3', + 3 => 'B1', + 4 => 'B2', + 5 => 'B3', + ), + ), + ), + ), + ), + 'MyCustom' => + array ( + 'fields' => + array ( + 'name' => + array ( + 'type' => 'varchar', + 'required' => true, + ), + ), + ), + ); + + $this->assertEquals($result, Util::merge($currentArray, $newArray)); } - public function testMergeLevel2WithMergeKeyName() + public function testMergeWithBool() { - $basicArr = array( - 'useCache' => 111, - 'useCache1' => 111, - 'sub' => array ( - 'subV' => '1111', - 'subV1' => '1111', - 'subO' => array( - 'subOV' => '11111', - 'subOV1' => '11111', - 'subOT' => array( - 'subOTT' => '11111', - 'subOT1' => '11111', - ), - ), + $currentArray = array ( + 'fields' => + array ( + 'accountId' => + array ( + 'type' => 'varchar', + 'where' => + array ( + '=' => 'contact.id IN ({value})', + ), + 'len' => 255, ), + 'deleted' => + array ( + 'type' => 'bool', + 'default' => false, + 'trueValue' => true, + ), + ), + 'relations' => + array ( + ), ); - $advArr = array( - 'useCache' => 222, - 'useCache2' => 222, - 'sub' => array ( - 'subV' => '222222', - 'subV2' => '222222', - 'subO' => array( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => array( - 'subOTT' => '22222', - 'subOT2' => '22222', - ), - ), + $newArray = array ( + 'fields' => + array ( + 'accountName' => + array ( + 'type' => 'foreign', + 'relation' => 'account', + 'foreign' => 'name', ), + 'accountId' => + array ( + 'type' => 'foreignId', + 'index' => true, + ), + ), + 'relations' => + array ( + 'createdBy' => + array ( + 'type' => 'belongsTo', + 'entity' => 'User', + 'key' => 'createdById', + 'foreignKey' => 'id', + ), + ), ); $result = array ( - 'useCache' => 222, - 'useCache1' => 111, - 'sub' => + 'fields' => array ( - 'subV' => '222222', - 'subV1' => '1111', - 'subO' => - array ( - 'subOV' => '22222', - 'subOV1' => '11111', - 'subOT' => - array ( - 'subOTT' => '22222', - 'subOT1' => '11111', - 'subOT2' => '22222', - ), - 'subOV2' => '22222', - ), - 'subV2' => '222222', + 'accountName' => + array ( + 'type' => 'foreign', + 'relation' => 'account', + 'foreign' => 'name', + ), + 'accountId' => + array ( + 'type' => 'foreignId', + 'index' => true, + 'where' => + array ( + '=' => 'contact.id IN ({value})', + ), + 'len' => 255, + ), + 'deleted' => + array ( + 'type' => 'bool', + 'default' => false, + 'trueValue' => true, + ), + ), + 'relations' => + array ( + 'createdBy' => + array ( + 'type' => 'belongsTo', + 'entity' => 'User', + 'key' => 'createdById', + 'foreignKey' => 'id', + ), ), - 'useCache2' => 222, ); - $this->assertEquals($result, Util::merge($basicArr, $advArr, 2, 'subOV')); - $this->assertEquals( $result, Util::merge($basicArr, $advArr, array(2, 'subOV')) ); - - $result = array ( - 'useCache' => 222, - 'useCache1' => 111, - 'sub' => - array ( - 'subV' => '222222', - 'subV1' => '1111', - 'subO' => - array ( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => - array ( - 'subOTT' => '22222', - 'subOT2' => '22222', - ), - ), - 'subV2' => '222222', - ), - 'useCache2' => 222, - ); - - $this->assertEquals($result, Util::merge($basicArr, $advArr, 2, 'subO')); - $this->assertEquals( $result, Util::merge($basicArr, $advArr, array(2, 'subO')) ); + $this->assertEquals($result, Util::merge($currentArray, $newArray)); } - - public function testMergeLevel3() - { - $basicArr = array( - 'useCache' => 111, - 'useCache1' => 111, - 'sub' => array ( - 'subV' => '1111', - 'subV1' => '1111', - 'subO' => array( - 'subOV' => '11111', - 'subOV1' => '11111', - 'subOT' => array( - 'subOTT' => '11111', - 'subOT1' => '11111', - ), - ), - ), - ); - - $advArr = array( - 'useCache' => 222, - 'useCache2' => 222, - 'sub' => array ( - 'subV' => '222222', - 'subV2' => '222222', - 'subO' => array( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => array( - 'subOTT' => '22222', - 'subOT2' => '22222', - ), - ), - ), - ); - - $result = array ( - 'useCache' => 222, - 'useCache1' => 111, - 'sub' => - array ( - 'subV' => '222222', - 'subV1' => '1111', - 'subO' => - array ( - 'subOV' => '22222', - 'subOV1' => '11111', - 'subOT' => - array ( - 'subOTT' => '22222', - 'subOT2' => '22222', - ), - 'subOV2' => '22222', - ), - 'subV2' => '222222', - ), - 'useCache2' => 222, - ); - - $this->assertEquals($result, Util::merge($basicArr, $advArr, 3)); - } - - public function testMergeLevel4Plus() - { - $basicArr = array( - 'useCache' => 111, - 'useCache1' => 111, - 'sub' => array ( - 'subV' => '1111', - 'subV1' => '1111', - 'subO' => array( - 'subOV' => '11111', - 'subOV1' => '11111', - 'subOT' => array( - 'subOTT' => '11111', - 'subOT1' => '11111', - ), - ), - ), - ); - - $advArr = array( - 'useCache' => 222, - 'useCache2' => 222, - 'sub' => array ( - 'subV' => '222222', - 'subV2' => '222222', - 'subO' => array( - 'subOV' => '22222', - 'subOV2' => '22222', - 'subOT' => array( - 'subOTT' => '22222', - 'subOT2' => '22222', - ), - ), - ), - ); - - $result = array ( - 'useCache' => 222, - 'useCache1' => 111, - 'sub' => - array ( - 'subV' => '222222', - 'subV1' => '1111', - 'subO' => - array ( - 'subOV' => '22222', - 'subOV1' => '11111', - 'subOT' => - array ( - 'subOTT' => '22222', - 'subOT1' => '11111', - 'subOT2' => '22222', - ), - 'subOV2' => '22222', - ), - 'subV2' => '222222', - ), - 'useCache2' => 222, - ); - - $this->assertEquals($result, Util::merge($basicArr, $advArr, 4)); - - $this->assertEquals($result, Util::merge($basicArr, $advArr, 5)); - - $this->assertEquals($result, Util::merge($basicArr, $advArr, 6)); - - $this->assertEquals($result, Util::merge($basicArr, $advArr)); - } - - - function testToFormat() + public function testToFormat() { $this->assertEquals('/Espo/Core/Utils', Util::toFormat('/Espo/Core/Utils', '/')); $this->assertEquals('\Espo\Core\Utils', Util::toFormat('/Espo/Core/Utils', '\\')); @@ -552,7 +496,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals('\Espo\Core\Utils', Util::toFormat('\Espo\Core\Utils', '\\')); } - function testConcatPath() + public function testConcatPath() { $result= 'dir1/dir2/file1.json'; $this->assertEquals($result, Util::concatPath('dir1/dir2', 'file1.json')); @@ -573,7 +517,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase } - function testArrayToObject() + public function testArrayToObject() { $testArr= array( 'useCache' => true, @@ -599,7 +543,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase } - function testObjectToArray() + public function testObjectToArray() { $testObj= (object) array( 'useCache' => true, @@ -624,7 +568,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals($testResult, Util::objectToArray($testObj)); } - function testGetNaming() + public function testGetNaming() { $this->assertEquals('myPrefixMyName', Util::getNaming('myName', 'myPrefix', 'prefix')); @@ -633,7 +577,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals('myNameMyPostfix', Util::getNaming('my_name', 'my_postfix', 'postfix', '_')); } - function testReplaceInArray() + public function testReplaceInArray() { $testArray = array( 'option' => array( @@ -657,7 +601,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase } - function testGetClassName() + public function testGetClassName() { $this->assertEquals('\Espo\EntryPoints\Donwload', Util::getClassName('application/Espo/EntryPoints/Donwload.php')); $this->assertEquals('\Espo\EntryPoints\Donwload', Util::getClassName('custom/Espo/EntryPoints/Donwload.php')); @@ -665,7 +609,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals('\Espo\EntryPoints\Donwload', Util::getClassName('application/Espo/EntryPoints/Donwload')); } - function testUnsetInArrayNotSingle() + public function testUnsetInArrayNotSingle() { $input = array( 'Account' => array( @@ -700,7 +644,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals($result, Util::unsetInArray($input, $unsets)); } - function testUnsetInArraySingle() + public function testUnsetInArraySingle() { $input = array( 'Account' => array( @@ -734,7 +678,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase } - function testUnsetInArrayTogether() + public function testUnsetInArrayTogether() { $input = array( 'Account' => array( @@ -771,7 +715,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase } - function testUnsetInArray() + public function testUnsetInArray() { $input = array( 'Account' => array( @@ -826,7 +770,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals($result, Util::unsetInArray($input, $unsets)); } - function testGetValueByKey() + public function testGetValueByKey() { $inputArray = array( 'Account' => array( @@ -858,41 +802,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertEquals('customReturns', Util::getValueByKey($inputArray, 'Contact.notExists', 'customReturns')); $this->assertNotEquals('customReturns', Util::getValueByKey($inputArray, 'Contact.useCache', 'customReturns')); } - - - - /*function testGetScopeModuleName() - { - $this->assertEquals('Crm', $this->fixture->getScopeModuleName('Account')); - $this->assertEquals('Crm', $this->fixture->getScopeModuleName('account')); - $this->assertNotEquals('crm', $this->fixture->getScopeModuleName('account')); - - $this->assertEquals('', $this->fixture->getScopeModuleName('User')); - $this->assertEquals('', $this->fixture->getScopeModuleName('user')); - $this->assertNotEquals('Crm', $this->fixture->getScopeModuleName('User')); - } - - - function testGetScopePath() - { - $this->assertEquals('Modules/Crm', $this->fixture->getScopePath('Account', '/')); - $this->assertEquals('Modules\Crm', $this->fixture->getScopePath('Account', '\\')); - $this->assertEquals('Modules\Crm', $this->fixture->getScopePath('account', '\\')); - - $this->assertEquals('Espo', $this->fixture->getScopePath('User', '/')); - $this->assertEquals('Espo', $this->fixture->getScopePath('User', '\\')); - $this->assertEquals('Espo', $this->fixture->getScopePath('user', '\\')); - } - - - function testGetScopes() - { - $this->assertArrayHasKey('User', $this->fixture->getScopes() ); - } */ - - - - } ?> \ No newline at end of file