diff --git a/tests/unit/Espo/Core/Utils/UtilTest.php b/tests/unit/Espo/Core/Utils/UtilTest.php index 94684fa8f8..dece8631a5 100644 --- a/tests/unit/Espo/Core/Utils/UtilTest.php +++ b/tests/unit/Espo/Core/Utils/UtilTest.php @@ -46,14 +46,14 @@ class UtilTest extends \PHPUnit\Framework\TestCase $this->assertEquals('AdvancedPack', Util::toCamelCase('Advanced Pack', ' ', true)); $this->assertEquals('advancedPack', Util::toCamelCase('Advanced Pack', ' ')); - $input = array( + $input = [ 'detail', 'my_detail_view', - ); - $result = array( + ]; + $result = [ 'detail', 'myDetailView', - ); + ]; $this->assertEquals($result, Util::toCamelCase($input)); } @@ -64,16 +64,16 @@ class UtilTest extends \PHPUnit\Framework\TestCase $this->assertEquals('my_detail_view', Util::fromCamelCase('myDetailView')); $this->assertEquals('my_f_f', Util::fromCamelCase('myFF')); - $input = array( + $input = [ 'detail', 'myDetailView', 'myFF', - ); - $result = array( + ]; + $result = [ 'detail', 'my_detail_view', 'my_f_f', - ); + ]; $this->assertEquals($result, Util::fromCamelCase($input)); } @@ -84,54 +84,54 @@ class UtilTest extends \PHPUnit\Framework\TestCase $this->assertEquals('my_detail_view', Util::toUnderScore('myDetailView')); $this->assertEquals('my_f_f', Util::toUnderScore('myFF')); - $input = array( + $input = [ 'detail', 'detailView', 'myDetailView', 'myFF', - ); - $result = array( + ]; + $result = [ 'detail', 'detail_view', 'my_detail_view', 'my_f_f', - ); + ]; $this->assertEquals($result, Util::toUnderScore($input)); } public function testMerge2() { - $d1 = array( + $d1 = [ 'hello' => 'world', - 'man' => array( + 'man' => [ 'test' => [ 0 => ['name' => 'test 1'], 1 => ['name' => 'test 2'] ] - ) - ); - $d2 = array( + ] + ]; + $d2 = [ 'test' => [] - ); - $d3 = array( - 'man' => array( + ]; + $d3 = [ + 'man' => [ 'test' => [ 0 => '__APPEND__', 1 => ['name' => 'test 3'] ] - ) - ); - $expected = array( + ] + ]; + $expected = [ 'test' => [], 'hello' => 'world', - 'man' => array( + 'man' => [ 'test' => [ 0 => ['name' => 'test 1'], 1 => ['name' => 'test 2'], 2 => ['name' => 'test 3'] ] - ) - ); + ] + ]; $result = Util::merge(Util::merge($d2, $d1), $d3); $this->assertEquals($expected, $result); @@ -139,359 +139,359 @@ class UtilTest extends \PHPUnit\Framework\TestCase public function testMerge() { - $array1= array( + $array1= [ 'defaultPermissions', 'logger', 'devMode' - ); - $array2Main= array( + ]; + $array2Main= [ 45 => '125', - 'sub' => array ( + 'sub' => [ 'subV' => '125', - ), - ); - $result= array( + ], + ]; + $result= [ 'defaultPermissions', 'logger', 'devMode', 45 => '125', - 'sub' => array ( + 'sub' => [ 'subV' => '125', - ), - ); + ], + ]; $this->assertEquals($result, Util::merge($array1, $array2Main)); - $array1= array( + $array1= [ 'datetime' => - array ( + [ 'dateFormat' => 'Y-m-d', 'timeFormat' => 'H:i:s', - ), - ); - $array2Main= array( + ], + ]; + $array2Main= [ 'datetime' => - array ( + [ 'dateFormat' => 'MyDateFormat', - ), - ); - $result= array( + ], + ]; + $result= [ 'datetime' => - array ( + [ 'dateFormat' => 'MyDateFormat', 'timeFormat' => 'H:i:s', - ), - ); + ], + ]; $this->assertEquals($result, Util::merge($array1, $array2Main)); - $array1= array( + $array1= [ 'database' => - array ( + [ 'driver' => 'pdo_mysql', 'host' => 'localhost', 'dbname' => 'espocrm', 'user' => 'root', 'password' => '', - ), - ); - $array2Main= array( + ], + ]; + $array2Main= [ 'database' => - array ( + [ 'password' => 'MyPass', - ), - ); - $result= array( + ], + ]; + $result= [ 'database' => - array ( + [ 'driver' => 'pdo_mysql', 'host' => 'localhost', 'dbname' => 'espocrm', 'user' => 'root', 'password' => 'MyPass', - ), - ); + ], + ]; $this->assertEquals($result, Util::merge($array1, $array2Main)); } public function testMergeWithAppend() { - $currentArray = array( + $currentArray = [ 'entityDefs' => - array ( + [ 'Attachment' => - array ( + [ 'fields' => - array ( + [ 'name' => - array ( + [ 'type' => 'varchar', 'required' => true, - ), + ], '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"], - ), - ), - ), - ), + ], + ], + ], + ], 'MyCustom' => - array ( + [ 'fields' => - array ( + [ 'name' => - array ( + [ 'type' => 'varchar', 'required' => true, - ), - ), - ), - ); + ], + ], + ], + ]; - $newArray = array( + $newArray = [ '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 ( + $result = [ '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)); } @@ -578,229 +578,229 @@ class UtilTest extends \PHPUnit\Framework\TestCase public function testMergeWithBool() { - $currentArray = array ( + $currentArray = [ 'fields' => - array ( + [ 'accountId' => - array ( + [ 'type' => 'varchar', 'where' => - array ( + [ '=' => 'contact.id IN ({value})', - ), + ], 'len' => 255, - ), + ], 'deleted' => - array ( + [ 'type' => 'bool', 'default' => false, 'trueValue' => true, - ), - ), + ], + ], 'relations' => - array ( - ), - ); + [ + ], + ]; - $newArray = array ( + $newArray = [ '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 ( + $result = [ 'fields' => - array ( + [ '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', - ), - ), - ); + ], + ], + ]; $this->assertEquals($result, Util::merge($currentArray, $newArray)); } public function testMergeWithFieldsDefs() { - $currentArray = array ( + $currentArray = [ 'fields' => - array ( + [ 'aaa1' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ 0 => 'a1', 1 => 'a3', 2 => 'a3', - ), + ], 'isCustom' => true, - ), + ], 'hfghgfh' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => 'hfghfgh', - ), + ], 'jghjghj' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => 'jghjghjhg', - ), + ], 'gdfgdfg' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => 'gdfgdfg', 'maxLength' => 70, - ), - ), - ); + ], + ], + ]; - $newArray = array ( + $newArray = [ 'fields' => - array ( + [ 'aaa1' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ 0 => 'a1', - ), + ], 'isCustom' => true, - ), - ), - ); + ], + ], + ]; - $result = array ( + $result = [ 'fields' => - array ( + [ 'aaa1' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ 0 => 'a1', - ), + ], 'isCustom' => true, - ), + ], 'hfghgfh' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => 'hfghfgh', - ), + ], 'jghjghj' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => 'jghjghjhg', - ), + ], 'gdfgdfg' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => 'gdfgdfg', 'maxLength' => 70, - ), - ), - ); + ], + ], + ]; $this->assertEquals($result, Util::merge($currentArray, $newArray)); } public function testMergeEmptyArray() { - $currentArray = array( - 'Call' =>array ( + $currentArray = [ + 'Call' => [ 'fields' => - array ( + [ 'accountId' => - array ( + [ 'type' => 'varchar', 'where' => - array ( + [ '=' => 'contact.id IN ({value})', - ), + ], 'len' => 255, - ), + ], 'deleted' => - array ( + [ 'type' => 'bool', 'default' => false, 'trueValue' => true, - ), - ), - ), - ); + ], + ], + ], + ]; - $newArray = array( - 'Call' =>array ( + $newArray = [ + 'Call' => [ 'fields' => - array ( - ), - ), - ); + [ + ], + ], + ]; $result = $currentArray; @@ -809,32 +809,32 @@ class UtilTest extends \PHPUnit\Framework\TestCase public function testMergeEmptyArray2() { - $currentArray = array( - 'Call' => array ( + $currentArray = [ + 'Call' => [ 'fields' => - array ( + [ 'accountId' => - array ( + [ 'type' => 'varchar', 'where' => - array ( + [ '=' => 'contact.id IN ({value})', - ), + ], 'len' => 255, - ), + ], 'deleted' => - array ( + [ 'type' => 'bool', 'default' => false, 'trueValue' => true, - ), - ), - ), - ); + ], + ], + ], + ]; - $newArray = array( - 'Call' => array (), - ); + $newArray = [ + 'Call' => [], + ]; $result = $currentArray; @@ -843,31 +843,31 @@ class UtilTest extends \PHPUnit\Framework\TestCase public function testMergeEmptyArray3() { - $currentArray = array( - 'Call' =>array ( + $currentArray = [ + 'Call' => [ 'fields' => - array ( + [ 'accountId' => - array ( + [ 'type' => 'varchar', 'where' => - array ( + [ '=' => 'contact.id IN ({value})', - ), + ], 'len' => 255, - ), + ], 'deleted' => - array ( + [ 'type' => 'bool', 'default' => false, 'trueValue' => true, - ), - ), - ), - ); + ], + ], + ], + ]; - $newArray = array( - ); + $newArray = [ + ]; $result = $currentArray; @@ -876,167 +876,167 @@ class UtilTest extends \PHPUnit\Framework\TestCase public function testMergeCompleteTest() { - $currentArray = array ( + $currentArray = [ 'fields' => - array ( + [ 'aaa1' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ 0 => 'a1', 1 => 'a3', 2 => 'a3', - ), + ], 'isCustom' => true, - ), + ], 'append' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ 'b1', 'b3', 'b3', - ), - ), + ], + ], 't1111' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => '11111', - ), + ], 't2222' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => '2222', - ), + ], 't3333' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => '3333', 'maxLength' => 70, - ), - ), - ); + ], + ], + ]; - $newArray = array ( + $newArray = [ 'fields' => - array ( + [ 'aaa1' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ 'a1', - ), + ], 'isCustom' => false, 'newValue' => 'NNNNN', - ), + ], 'new111' => - array ( + [ 'type' => 'varchar', 'required' => false, - ), + ], 'append' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ '__APPEND__', 'b4', 'b5', - ), - ), + ], + ], 'aloneAppend' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ '__APPEND__', 'c1', 'c2', - ), - ), - ), - ); + ], + ], + ], + ]; - $result = array ( + $result = [ 'fields' => - array ( + [ 'aaa1' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ 0 => 'a1', - ), + ], 'isCustom' => false, 'newValue' => 'NNNNN', - ), + ], 'append' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ 'b1', 'b3', 'b3', 'b4', 'b5', - ), - ), + ], + ], 't1111' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => '11111', - ), + ], 't2222' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => '2222', - ), + ], 't3333' => - array ( + [ 'type' => 'varchar', 'required' => false, 'isCustom' => true, 'default' => '3333', 'maxLength' => 70, - ), + ], 'new111' => - array ( + [ 'type' => 'varchar', 'required' => false, - ), + ], 'aloneAppend' => - array ( + [ 'type' => 'enum', 'required' => false, 'options' => - array ( + [ 'c1', 'c2', - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals($result, Util::merge($currentArray, $newArray)); } @@ -1107,25 +1107,25 @@ class UtilTest extends \PHPUnit\Framework\TestCase public function testObjectToArray() { - $testObj= (object) array( + $testObj= (object) [ 'useCache' => true, - ); - $testObj->sub = (object) array ( + ]; + $testObj->sub = (object) [ 'subV' => '125', - ); - $testObj->sub->subO = (object) array ( + ]; + $testObj->sub->subO = (object) [ 'subOV' => '125', - ); + ]; - $testResult= array( + $testResult= [ 'useCache' => true, - 'sub' => array ( + 'sub' => [ 'subV' => '125', - 'subO' => array( + 'subO' => [ 'subOV' => '125', - ), - ), - ); + ], + ], + ]; $this->assertEquals($testResult, Util::objectToArray($testObj)); } @@ -1141,23 +1141,23 @@ class UtilTest extends \PHPUnit\Framework\TestCase public function testReplaceInArray() { - $testArray = array( - 'option' => array( + $testArray = [ + 'option' => [ 'default' => '{0}', - 'testKey' => array( + 'testKey' => [ '{0}' => 'testVal', - ), - ), - ); + ], + ], + ]; - $testResult = array( - 'option' => array( + $testResult = [ + 'option' => [ 'default' => 'DONE', - 'testKey' => array( + 'testKey' => [ 'DONE' => 'testVal', - ), - ), - ); + ], + ], + ]; $this->assertEquals($testResult, Util::replaceInArray('{0}', 'DONE', $testArray, true)); } @@ -1165,234 +1165,243 @@ class UtilTest extends \PHPUnit\Framework\TestCase /** * @dataProvider dp_classNames */ - public function testGetClassName($path, $expectedClassName = 'Espo\EntryPoints\Donwload') + public function testGetClassName1($path, $expectedClassName = 'Espo\EntryPoints\Download') { $this->assertEquals($expectedClassName, Util::getClassName($path)); } + + public function testGetClassName2() + { + $this->assertEquals( + 'Espo\Modules\MyModule\EntryPoints\Test', + Util::getClassName('custom/Espo/Modules/MyModule/EntryPoints/Test') + ); + } + public function dp_classNames() { return [ - "application/Espo/EntryPoints/Donwload.php" => ['application/Espo/EntryPoints/Donwload.php'], - "custom/Espo/EntryPoints/Donwload.php" => ['custom/Espo/EntryPoints/Donwload.php'], - "Espo/EntryPoints/Donwload.php" => ['Espo/EntryPoints/Donwload.php'], - "application/Espo/EntryPoints/Donwload" => ['application/Espo/EntryPoints/Donwload'], - "\application\Espo\EntryPoints\Donwload" => ['application\Espo\EntryPoints\Donwload'], + "application/Espo/EntryPoints/Download.php" => ['application/Espo/EntryPoints/Download.php'], + "custom/Espo/Modules/MyModule/EntryPoints/Download.php" => ['custom/Espo/EntryPoints/Download.php'], + "Espo/EntryPoints/Download.php" => ['Espo/EntryPoints/Download.php'], + "application/Espo/EntryPoints/Download" => ['application/Espo/EntryPoints/Download'], + "\application\Espo\EntryPoints\Download" => ['application\Espo\EntryPoints\Download'], ]; } public function testUnsetInArrayNotSingle() { - $input = array( - 'Account' => array( + $input = [ + 'Account' => [ 'useCache' => true, - 'sub' => array ( + 'sub' => [ 'subV' => '125', - 'subO' => array( + 'subO' => [ 'subOV' => '125', 'subOV2' => '125', - ), - ), - ), - ); + ], + ], + ], + ]; - $unsets = array( - 'Account' => array( + $unsets = [ + 'Account' => [ 'sub.subO.subOV', 'sub.subV', - ), - ); + ], + ]; - $result = array( - 'Account' => array( + $result = [ + 'Account' => [ 'useCache' => true, - 'sub' => array ( - 'subO' => array( + 'sub' => [ + 'subO' => [ 'subOV2' => '125', - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals($result, Util::unsetInArray($input, $unsets)); } public function testUnsetInArraySingle() { - $input = array( - 'Account' => array( + $input = [ + 'Account' => [ 'useCache' => true, - 'sub' => array ( + 'sub' => [ 'subV' => '125', - 'subO' => array( + 'subO' => [ 'subOV' => '125', 'subOV2' => '125', - ), - ), - ), - ); + ], + ], + ], + ]; - $unsets = array( + $unsets = [ 'Account.sub.subO.subOV', 'Account.sub.subV', - ); + ]; - $result = array( - 'Account' => array( + $result = [ + 'Account' => [ 'useCache' => true, - 'sub' => array ( - 'subO' => array( + 'sub' => [ + 'subO' => [ 'subOV2' => '125', - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals($result, Util::unsetInArray($input, $unsets)); } public function testUnsetInArrayTogether() { - $input = array( - 'Account' => array( + $input = [ + 'Account' => [ 'useCache' => true, - 'sub' => array ( + 'sub' => [ 'subV' => '125', - 'subO' => array( + 'subO' => [ 'subOV' => '125', 'subOV2' => '125', - ), - ), - ), - ); + ], + ], + ], + ]; - $unsets = array( - 'Account' => array( + $unsets = [ + 'Account' => [ 'sub.subO.subOV', - ), + ], 'Account.sub.subV', - ); + ]; - $result = array( - 'Account' => array( + $result = [ + 'Account' => [ 'useCache' => true, - 'sub' => array ( - 'subO' => array( + 'sub' => [ + 'subO' => [ 'subOV2' => '125', - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals($result, Util::unsetInArray($input, $unsets)); } public function testUnsetInArray() { - $input = array( - 'Account' => array( + $input = [ + 'Account' => [ 'useCache' => true, - 'sub' => array ( + 'sub' => [ 'subV' => '125', - 'subO' => array( + 'subO' => [ 'subOV' => '125', 'subOV2' => '125', - ), - ), - ), - 'Contact' => array( + ], + ], + ], + 'Contact' => [ 'useCache' => true, - ), - ); + ], + ]; - $unsets = array( + $unsets = [ 'Account', - ); + ]; - $result = array( - 'Contact' => array( + $result = [ + 'Contact' => [ 'useCache' => true, - ), - ); + ], + ]; $this->assertEquals($result, Util::unsetInArray($input, $unsets)); } public function testUnsetInArrayByString() { - $input = array( - 'Account' => array( + $input = [ + 'Account' => [ 'useCache' => true, - ), - 'Contact' => array( + ], + 'Contact' => [ 'useCache' => true, - ), - ); + ], + ]; $unsets = 'Account.useCache'; - $result = array( - 'Account' => array( - ), - 'Contact' => array( + $result = [ + 'Account' => [ + ], + 'Contact' => [ 'useCache' => true, - ), - ); + ], + ]; $this->assertEquals($result, Util::unsetInArray($input, $unsets)); } public function testUnsetInArrayEmptyParent() { - $input = array( - 'Account' => array( + $input = [ + 'Account' => [ 'useCache' => true, - 'sub' => array ( + 'sub' => [ 'subV' => '125', - 'subO' => array( + 'subO' => [ 'subOV' => '125', 'subOV2' => '125', - ), - ), - ), - 'Contact' => array( + ], + ], + ], + 'Contact' => [ 'useCache' => true, - ), - 'Lead' => array( + ], + 'Lead' => [ 'useCache' => true, - ) - ); + ] + ]; - $unsets = array( + $unsets = [ 'Account.useCache', 'Account.sub', 'Lead.useCache' - ); + ]; - $result = array( - 'Contact' => array( + $result = [ + 'Contact' => [ 'useCache' => true, - ) - ); + ] + ]; $this->assertEquals($result, Util::unsetInArray($input, $unsets, true)); } public function testGetValueByKey() { - $inputArray = array( - 'Account' => array( + $inputArray = [ + 'Account' => [ 'useCache' => true, - 'sub' => array ( + 'sub' => [ 'subV' => '125', - 'subO' => array( + 'subO' => [ 'subOV' => '125', 'subOV2' => '125', - ), - ), - ), - 'Contact' => array( + ], + ], + ], + 'Contact' => [ 'useCache' => true, - ), - ); + ], + ]; $this->assertEquals($inputArray, Util::getValueByKey($inputArray)); @@ -1411,38 +1420,38 @@ class UtilTest extends \PHPUnit\Framework\TestCase public function testGetValueByKey2() { - $inputArray = array( - 'fields' => array( - 'varchar' => array ( + $inputArray = [ + 'fields' => [ + 'varchar' => [ 'params' => - array ( - array ( + [ + [ 'name' => 'required', 'type' => 'bool', 'default' => false, - ), - array ( + ], + [ 'name' => 'default', 'type' => 'varchar', - ), - array ( + ], + [ 'name' => 'maxLength', 'type' => 'int', - ), - array ( + ], + [ 'name' => 'trim', 'type' => 'bool', 'default' => true, - ), - array ( + ], + [ 'name' => 'audited', 'type' => 'bool', - ), - ), + ], + ], 'filter' => true, - ), - ) - ); + ], + ] + ]; $this->assertNull(Util::getValueByKey($inputArray, 'fields.varchar.hookClassName')); $this->assertNull(Util::getValueByKey($inputArray, ['fields', 'varchar', 'hookClassName']));