From 07866a266f140b6df8c1766dde83d2ab6ffac7ad Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Fri, 3 Oct 2014 17:16:47 +0300 Subject: [PATCH 1/6] added metadata merge with '__APPEND__' --- application/Espo/Core/Utils/Config.php | 2 +- .../Core/Utils/Database/Orm/Converter.php | 9 +- application/Espo/Core/Utils/File/Manager.php | 10 +- application/Espo/Core/Utils/File/Unifier.php | 17 +- application/Espo/Core/Utils/Language.php | 2 +- application/Espo/Core/Utils/Metadata.php | 4 +- application/Espo/Core/Utils/Util.php | 134 +-- tests/Espo/Core/Utils/UtilTest.php | 817 ++++++++---------- 8 files changed, 427 insertions(+), 568 deletions(-) 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 From ca40ed79ee4b41824998bb0fb3cf1d4f8265753d Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Mon, 6 Oct 2014 10:20:26 +0300 Subject: [PATCH 2/6] added a new item to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 34ccd197b5..65bfe8106b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,6 @@ /test.php /main.html /tests/testData/Utils/Config/config.php +/tests/testData/*/cache/* composer.phar vendor/ From efefd8864c0da0d52544a1e3eb690ac12a245ff0 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Mon, 6 Oct 2014 10:25:07 +0300 Subject: [PATCH 3/6] installer improvements --- install/core/i18n/en_US/install.json | 6 +++++- install/core/tpl/finish.tpl | 18 +++++++++++++++--- install/css/install.css | 25 ++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/install/core/i18n/en_US/install.json b/install/core/i18n/en_US/install.json index 5e9553e5b6..fc9661efd6 100644 --- a/install/core/i18n/en_US/install.json +++ b/install/core/i18n/en_US/install.json @@ -13,7 +13,11 @@ "Errors page title": "Errors", "Finish page title": "Installation is complete", "Congratulation! Welcome to EspoCRM": "Congratulation! EspoCRM has been successfully installed.", - "More Information": "For more information,
please visit our blog: {BLOG}
follow us on twitter: {TWITTER}

If you have any suggestions or questions, please ask on the forum:
{FORUM}", + "More Information": "For more information, please visit our {BLOG}, follow us on {TWITTER}.

If you have any suggestions or questions, please ask on the {FORUM}.", + "share": "If you like EspoCRM, share it with your friends. Let them know about this great product.", + "blog": "blog", + "twitter": "twitter", + "forum": "forum", "Installation Guide": "Installation Guide", "admin": "admin", "localhost": "localhost", diff --git a/install/core/tpl/finish.tpl b/install/core/tpl/finish.tpl index 2c7b3d2625..b0e25d6226 100644 --- a/install/core/tpl/finish.tpl +++ b/install/core/tpl/finish.tpl @@ -7,10 +7,22 @@ {$langs['labels']['Congratulation! Welcome to EspoCRM']} +
+ + +
- {assign var="blogLink" value="{$config['blog']}"} - {assign var="twitterLink" value="{$config['twitter']}"} - {assign var="forumLink" value="{$config['forum']}"} + {assign var="blogLink" value="{$langs['labels']['blog']}"} + {assign var="twitterLink" value="{$langs['labels']['twitter']}"} + {assign var="forumLink" value="{$langs['labels']['forum']}"} {assign var="message" value="{$langs['labels']['More Information']|replace:'{BLOG}':$blogLink}"} {assign var="message" value="{$message|replace:'{TWITTER}':$twitterLink}"} diff --git a/install/css/install.css b/install/css/install.css index b3dbcc97ff..3266d02a60 100644 --- a/install/css/install.css +++ b/install/css/install.css @@ -124,6 +124,29 @@ span.ok { .more-information { line-height: 1.5; font-size: 16px; - margin-top: 100px; + margin-top: 70px; + text-align: left; } +.likes { + border-left-color: #D7983B; + -moz-border-bottom-colors: none; + -moz-border-left-colors: #F1AF4E; + -moz-border-right-colors: none; + -moz-border-top-colors: none; + border-color: #eee; + border-image: none; + border-radius: 3px; + border-style: solid; + border-width: 1px 1px 1px 5px; + margin: 20px 0; + padding: 10px; + text-align: center; +} + +.likes p { + color: #B56F08; + font-size: 15px; +} + + From 982e3bd9b786526ae418bb26c065ca7f1fc409ef Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Mon, 6 Oct 2014 13:19:28 +0300 Subject: [PATCH 4/6] .gitignore changes --- .gitignore | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.gitignore b/.gitignore index 65bfe8106b..844d3378f2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,12 +5,6 @@ /data/.backup/* /data/config.php /custom -/application/Espo/Resources/metadata/scopes/CustomTest.json -/application/Espo/Modules/Crm/Resources/metadata/scopes/CustomTest.json -/application/Espo/Resources/layouts/CustomTest/* -/application/Espo/Modules/Crm/Resources/layouts/CustomTest/* -/application/Espo/Resources/metadata/customTest/* -/application/Espo/Modules/Crm/Resources/metadata/customTest/* /build /node_modules /client From 40e6c6a6486d262b33f48edad0c5e8ab0e93e7d3 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Mon, 6 Oct 2014 13:27:48 +0300 Subject: [PATCH 5/6] fix get server type --- application/Espo/Core/Utils/System.php | 2 +- tests/Espo/Core/Utils/SystemTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/application/Espo/Core/Utils/System.php b/application/Espo/Core/Utils/System.php index 012b022f36..dfc1d84dae 100644 --- a/application/Espo/Core/Utils/System.php +++ b/application/Espo/Core/Utils/System.php @@ -35,7 +35,7 @@ class System preg_match('/^(.*?)\//i', $serverSoft, $match); if (empty($match[1])) { - preg_match('/^(.*?)\/?/i', $serverSoft, $match); + preg_match('/^(.*)\/?/i', $serverSoft, $match); } $serverName = strtolower( trim($match[1]) ); diff --git a/tests/Espo/Core/Utils/SystemTest.php b/tests/Espo/Core/Utils/SystemTest.php index bbce6ee339..9bebc3334e 100644 --- a/tests/Espo/Core/Utils/SystemTest.php +++ b/tests/Espo/Core/Utils/SystemTest.php @@ -32,6 +32,9 @@ class SystemTest extends \PHPUnit_Framework_TestCase $_SERVER['SERVER_SOFTWARE'] = 'Microsoft-IIS/8.0'; $this->assertEquals( 'microsoft-iis', $this->object->getServerType()); + + $_SERVER['SERVER_SOFTWARE'] = 'apache/2.4.10 (win32) openssl/1.0.1i php'; + $this->assertEquals( 'apache', $this->object->getServerType()); } From dc6ba1128dbbbcc12e305e6134157721df458b7c Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Mon, 6 Oct 2014 16:04:24 +0300 Subject: [PATCH 6/6] tests corrections --- tests/Api/FieldManagerTest.php | 125 ------------------ tests/Api/LayoutTest.php | 97 -------------- tests/Api/RestTesterClass.php | 86 ------------ tests/Api/config.php | 10 -- tests/Espo/Core/Upgrades/BaseTest.php | 11 -- tests/Espo/Core/Utils/ConfigTest.php | 2 +- tests/Espo/Core/Utils/FieldManagerTest.php | 32 ++++- .../Utils/Config/{ => cache}/config.php | 7 +- 8 files changed, 35 insertions(+), 335 deletions(-) delete mode 100644 tests/Api/FieldManagerTest.php delete mode 100644 tests/Api/LayoutTest.php delete mode 100644 tests/Api/RestTesterClass.php delete mode 100644 tests/Api/config.php rename tests/testData/Utils/Config/{ => cache}/config.php (97%) diff --git a/tests/Api/FieldManagerTest.php b/tests/Api/FieldManagerTest.php deleted file mode 100644 index 991fe14a90..0000000000 --- a/tests/Api/FieldManagerTest.php +++ /dev/null @@ -1,125 +0,0 @@ -markTestSkipped('API tests are not enabled.'); - } - - require_once('tests/Api/RestTesterClass.php'); - $this->fixture = new RestTesterClass(); - - /****************************************/ - $this->fixture->setUrl('/Admin/fieldManager'); - /****************************************/ - } - - protected function tearDown() - { - $this->fixture = NULL; - } - - - public function testCreate() - { - $this->fixture->setType('POST'); - - $this->fixture->setUrl('/Admin/fieldManager/CustomEntity'); - - $input = '{"name":"customField","type":"varchar","maxLength":50}'; - $result = '{"type":"varchar","maxLength":50,"isCustom":true}'; - - $this->assertEquals($result, $this->fixture->getResponse($input)['response']); - } - - public function testCreateSameField() - { - $this->fixture->setType('POST'); - - $this->fixture->setUrl('/Admin/fieldManager/CustomEntity'); - - $input = '{"name":"customField","type":"varchar","maxLength":50}'; - - $this->assertEquals(500, $this->fixture->getResponse($input)['code']); - } - - - public function testReadAfterCreate() - { - $this->fixture->setType('GET'); - - $this->fixture->setUrl('/Admin/fieldManager/CustomEntity/customField'); - $data = '{"type":"varchar","maxLength":50,"isCustom":true}'; - $this->assertEquals($data, $this->fixture->getResponse()['response']); - } - - public function testUpdate() - { - $this->fixture->setType('PUT'); - - $this->fixture->setUrl('/Admin/fieldManager/CustomEntity/customField'); - - $input = '{"type":"varchar","maxLength":50,"default":"this is a test"}'; - $result = '{"type":"varchar","maxLength":50,"isCustom":true,"default":"this is a test"}'; - - $this->assertEquals($result, $this->fixture->getResponse($input)['response']); - } - - public function testUpdateCoreField() - { - $this->fixture->setType('PUT'); - - $this->fixture->setUrl('/Admin/fieldManager/Account/name'); - - $input = '{"type":"varchar","maxLength":50,"default":"this is a test"}'; - - $this->assertEquals(500, $this->fixture->getResponse($input)['code']); - } - - public function testReadAfterUpdate() - { - $this->fixture->setType('GET'); - - $this->fixture->setUrl('/Admin/fieldManager/CustomEntity/customField'); - $data = '{"type":"varchar","maxLength":50,"isCustom":true,"default":"this is a test"}'; - $this->assertEquals($data, $this->fixture->getResponse()['response']); - } - - public function testDelete() - { - $this->fixture->setType('DELETE'); - - $this->fixture->setUrl('/Admin/fieldManager/CustomEntity/customField'); - $this->assertEquals('true', $this->fixture->getResponse()['response']); - } - - public function testReadAfterDetele() - { - $this->fixture->setType('GET'); - - $this->fixture->setUrl('/Admin/fieldManager/CustomEntity/customField'); - $response= $this->fixture->getResponse(); - $this->assertEquals(404, $response['code']); - } - - public function testDeleteTestFile() - { - $file = 'custom/Espo/Custom/Resources/metadata/entityDefs/CustomEntity.json'; - if (file_exists($file)) { - @unlink($file); - } - } - - - - -} - -?> \ No newline at end of file diff --git a/tests/Api/LayoutTest.php b/tests/Api/LayoutTest.php deleted file mode 100644 index 632ef02f71..0000000000 --- a/tests/Api/LayoutTest.php +++ /dev/null @@ -1,97 +0,0 @@ -markTestSkipped('API tests are not enabled.'); - } - - require_once('tests/Api/RestTesterClass.php'); - $this->fixture = new RestTesterClass(); - - /****************************************/ - $this->fixture->setUrl('/layout'); - /****************************************/ - } - - protected function tearDown() - { - $this->fixture = NULL; - } - - - function testPut() - { - $this->fixture->setType('PUT'); - - $this->fixture->setUrl('/CustomTest/layout/testPut'); - $data= '["amount","account","closeDate","leadSource","stage","probability","assignedUser"]'; - $this->assertTrue($this->fixture->isSuccess( $data )); - - //check if file exists - $file = 'application/Espo/Custom/Resources/layouts/CustomTest/testPut.json'; - - $fileExists = file_exists($file); - $this->assertTrue($fileExists); - - if ($fileExists) { - $content = file_get_contents($file); - - $this->assertEquals($data, $content); - - @unlink($file); - } - } - - function testPatch() - { - $this->fixture->setType('PATCH'); - - $this->fixture->setUrl('/CustomTest/layout/testPatch'); - $data= '[{"label":"MyLabel"}]'; - $this->assertTrue($this->fixture->isSuccess( $data )); - - $data= '[{"isPathed":true}]'; - $this->assertTrue($this->fixture->isSuccess( $data )); - - //check if file exists - $file = 'application/Espo/Custom/Resources/layouts/CustomTest/testPatch.json'; - - $fileExists = file_exists($file); - $this->assertTrue($fileExists); - - if ($fileExists) { - - $content = file_get_contents($file); - - //$data= '[{"label":"MyLabel","isPathed":true}]'; - $data= '[{"isPathed":true}]'; //now PATCH works like PUT - $this->assertEquals($data, $content); - - @unlink($file); - } - } - - function testGet() - { - $this->fixture->setType('GET'); - - $this->fixture->setUrl('/CustomTest/layout/detail'); - $this->assertTrue($this->fixture->isSuccess( )); - - $this->fixture->setUrl('/needToBeNotReal/layout/notReal'); - $response= $this->fixture->getResponse(); - $this->assertEquals(404, $response['code']); - } - - -} - -?> \ No newline at end of file diff --git a/tests/Api/RestTesterClass.php b/tests/Api/RestTesterClass.php deleted file mode 100644 index 3ea81d66a5..0000000000 --- a/tests/Api/RestTesterClass.php +++ /dev/null @@ -1,86 +0,0 @@ -apiUrl = $config['apiUrl']; - $this->username = $config['username']; - $this->password = $config['password']; - } - - function setType($name) - { - $this->type= strtoupper($name); - } - - function setUrl($url) - { - $this->url= (substr($url, 0,1)=='/') ? $this->apiUrl.$url : $this->apiUrl.'/'.$url; - } - - function getResponse($jsonData='', $output=false) - { - $ch = curl_init($this->url); - - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_USERPWD, $this->username.':'.$this->password); - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_USERAGENT, 'Sample Code'); - - //curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PUT')); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->type); - - if (!empty($jsonData)) { - curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($jsonData)) - ); - } - - $response = curl_exec($ch); - $resultStatus = curl_getinfo($ch); - - curl_close($ch); - - //echo '
';
-		//echo $response;
-
-		if($resultStatus['http_code'] == 200) {
-			if ($output) {
-				echo "\r\n".$response."\r\n\r\n";
-			}
-		} else {
-			if ($output) {
-		    	echo 'CALL FAILED: '.print_r($resultStatus, true).'
'.$response; - } - } - - return array('response'=>$response, 'code'=>$resultStatus['http_code']); - } - - function isSuccess($jsonData='', $output=false) - { - $response= $this->getResponse($jsonData, $output); - - return ($response['code'] == 200) ? true : false; - } - -} - -?> \ No newline at end of file diff --git a/tests/Api/config.php b/tests/Api/config.php deleted file mode 100644 index 1792cddb78..0000000000 --- a/tests/Api/config.php +++ /dev/null @@ -1,10 +0,0 @@ - false, - 'apiUrl' => 'http://172.20.0.1/taras/espo/api/v1', - 'username' => 'admin', - 'password' => '1', -); - -?> \ No newline at end of file diff --git a/tests/Espo/Core/Upgrades/BaseTest.php b/tests/Espo/Core/Upgrades/BaseTest.php index d2b2888249..b8eec5f4da 100644 --- a/tests/Espo/Core/Upgrades/BaseTest.php +++ b/tests/Espo/Core/Upgrades/BaseTest.php @@ -80,7 +80,6 @@ class BaseTest extends \PHPUnit_Framework_TestCase $this->assertEquals( $upgradeId, $this->reflection->invokeMethod('getUpgradeId', array()) ); } - public function testCreateUpgradeId() { $upgradeId = $this->reflection->setProperty('upgradeId', null); @@ -97,7 +96,6 @@ class BaseTest extends \PHPUnit_Framework_TestCase $this->reflection->invokeMethod('getUpgradeId', array()); } - public function testGetManifestIncorrect() { $this->setExpectedException('\Espo\Core\Exceptions\Error'); @@ -114,7 +112,6 @@ class BaseTest extends \PHPUnit_Framework_TestCase $this->reflection->invokeMethod('getManifest', array()); } - public function testGetManifest() { $manifest = '{ @@ -162,7 +159,6 @@ class BaseTest extends \PHPUnit_Framework_TestCase ); } - /** * @dataProvider acceptableDataFalse */ @@ -184,7 +180,6 @@ class BaseTest extends \PHPUnit_Framework_TestCase ); } - public function testGetUpgradePath() { $upgradeId = $this->reflection->invokeMethod('getUpgradeId', array()); @@ -195,12 +190,6 @@ class BaseTest extends \PHPUnit_Framework_TestCase $postfix = $this->reflection->getProperty('packagePostfix'); $this->assertEquals( $upgradePath.$postfix, $this->reflection->invokeMethod('getUpgradePath', array(true)) ); } - - - - - - } ?> diff --git a/tests/Espo/Core/Utils/ConfigTest.php b/tests/Espo/Core/Utils/ConfigTest.php index 96dd5ee181..619a88c620 100644 --- a/tests/Espo/Core/Utils/ConfigTest.php +++ b/tests/Espo/Core/Utils/ConfigTest.php @@ -11,7 +11,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase protected $objects; - protected $configPath = 'tests/testData/Utils/Config/config.php'; + protected $configPath = 'tests/testData/Utils/Config/cache/config.php'; protected $systemConfigPath = 'tests/testData/Utils/Config/systemConfig.php'; diff --git a/tests/Espo/Core/Utils/FieldManagerTest.php b/tests/Espo/Core/Utils/FieldManagerTest.php index c5667a1564..2c978b6f1f 100644 --- a/tests/Espo/Core/Utils/FieldManagerTest.php +++ b/tests/Espo/Core/Utils/FieldManagerTest.php @@ -65,14 +65,14 @@ class FieldManagerTest extends \PHPUnit_Framework_TestCase ); $this->objects['metadata'] - ->expects($this->exactly(3)) + ->expects($this->exactly(6)) ->method('get') ->will($this->returnValue($data)); $this->assertTrue($this->object->update('name', $data, 'Account')); } - public function testUpdateCustomField() + public function testUpdateCustomFieldIsNotChanged() { $data = array( "type" => "varchar", @@ -85,11 +85,39 @@ class FieldManagerTest extends \PHPUnit_Framework_TestCase ->method('get') ->will($this->returnValue($data)); + $this->objects['metadata'] + ->expects($this->never()) + ->method('set') + ->will($this->returnValue(true)); + + $this->assertTrue($this->object->update('varName', $data, 'CustomEntity')); + } + + public function testUpdateCustomField() + { + $data = array( + "type" => "varchar", + "maxLength" => "50", + "isCustom" => true, + ); + + $this->objects['metadata'] + ->expects($this->exactly(6)) + ->method('get') + ->will($this->returnValue($data)); + $this->objects['metadata'] ->expects($this->once()) ->method('set') ->will($this->returnValue(true)); + $data = array( + "type" => "varchar", + "maxLength" => "150", + "required" => true, + "isCustom" => true, + ); + $this->assertTrue($this->object->update('varName', $data, 'CustomEntity')); } diff --git a/tests/testData/Utils/Config/config.php b/tests/testData/Utils/Config/cache/config.php similarity index 97% rename from tests/testData/Utils/Config/config.php rename to tests/testData/Utils/Config/cache/config.php index bba9d3119b..846ec89553 100644 --- a/tests/testData/Utils/Config/config.php +++ b/tests/testData/Utils/Config/cache/config.php @@ -1,6 +1,10 @@ 1412600573, + 'removeOption' => 'Test', + 'testOption' => 'Another Wrong Value', + 'testOption2' => 'Test2', 'database' => array ( 'driver' => 'pdo_mysql', @@ -102,9 +106,6 @@ return array ( 8 => 'Prospect', ), 'isInstalled' => true, - 'cacheTimestamp' => 1404901977, - 'testOption' => 'Another Wrong Value', - 'testOption2' => 'Test2', ); ?> \ No newline at end of file