From 23ccbb226fdae31c28a746fdb8dc4f216ebd0455 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Tue, 2 Aug 2016 13:09:14 +0300 Subject: [PATCH] Test fixes --- tests/Espo/Core/Utils/FieldManagerTest.php | 35 ++++++++++++++--- tests/Espo/Core/Utils/LayoutTest.php | 5 ++- tests/Espo/Core/Utils/MetadataTest.php | 7 +++- tests/Espo/Core/Utils/UtilTest.php | 44 +++++++++++++++++++++- 4 files changed, 80 insertions(+), 11 deletions(-) diff --git a/tests/Espo/Core/Utils/FieldManagerTest.php b/tests/Espo/Core/Utils/FieldManagerTest.php index 1a920766ca..cc0cb77713 100644 --- a/tests/Espo/Core/Utils/FieldManagerTest.php +++ b/tests/Espo/Core/Utils/FieldManagerTest.php @@ -91,10 +91,17 @@ class FieldManagerTest extends \PHPUnit_Framework_TestCase "label" => "Name", ); + $map = array( + ['entityDefs.Account.fields.name', null, $data], + [['entityDefs', 'Account', 'fields', 'name', 'type'], null, $data['type']], + ['fields.varchar', null, null], + [['fields', 'varchar', 'hookClassName'], null, null], + ); + $this->objects['metadata'] - ->expects($this->exactly(6)) + ->expects($this->any()) ->method('get') - ->will($this->returnValue($data)); + ->will($this->returnValueMap($map)); $this->object->update('name', $data, 'Account'); } @@ -107,10 +114,18 @@ class FieldManagerTest extends \PHPUnit_Framework_TestCase "isCustom" => true, ); + $map = array( + ['entityDefs.CustomEntity.fields.varName', null, $data], + ['entityDefs.CustomEntity.fields.varName.type', null, $data['type']], + [['entityDefs', 'CustomEntity', 'fields', 'varName'], null, $data], + ['fields.varchar', null, null], + [['fields', 'varchar', 'hookClassName'], null, null], + ); + $this->objects['metadata'] - ->expects($this->exactly(3)) + ->expects($this->any()) ->method('get') - ->will($this->returnValue($data)); + ->will($this->returnValueMap($map)); $this->objects['metadata'] ->expects($this->never()) @@ -128,10 +143,18 @@ class FieldManagerTest extends \PHPUnit_Framework_TestCase "isCustom" => true, ); + $map = array( + ['entityDefs.CustomEntity.fields.varName', null, $data], + ['entityDefs.CustomEntity.fields.varName.type', null, $data['type']], + [['entityDefs', 'CustomEntity', 'fields', 'varName'], null, $data], + ['fields.varchar', null, null], + [['fields', 'varchar', 'hookClassName'], null, null], + ); + $this->objects['metadata'] - ->expects($this->exactly(6)) + ->expects($this->any()) ->method('get') - ->will($this->returnValue($data)); + ->will($this->returnValueMap($map)); $this->objects['metadata'] ->expects($this->once()) diff --git a/tests/Espo/Core/Utils/LayoutTest.php b/tests/Espo/Core/Utils/LayoutTest.php index 181d31339e..0729213a1e 100644 --- a/tests/Espo/Core/Utils/LayoutTest.php +++ b/tests/Espo/Core/Utils/LayoutTest.php @@ -1,4 +1,4 @@ -objects['fileManager'] = $this->getMockBuilder('\\Espo\\Core\\Utils\\File\\Manager')->disableOriginalConstructor()->getMock(); $this->objects['metadata'] = $this->getMockBuilder('\\Espo\\Core\\Utils\\Metadata')->disableOriginalConstructor()->getMock(); + $this->objects['user'] = $this->getMockBuilder('\\Espo\\Entities\\User')->disableOriginalConstructor()->getMock(); - $this->object = new \Espo\Core\Utils\Layout($this->objects['fileManager'], $this->objects['metadata']); + $this->object = new \Espo\Core\Utils\Layout($this->objects['fileManager'], $this->objects['metadata'], $this->objects['user']); $this->reflection = new ReflectionHelper($this->object); $this->reflection->setProperty('params', array( diff --git a/tests/Espo/Core/Utils/MetadataTest.php b/tests/Espo/Core/Utils/MetadataTest.php index 38219b8058..7159320c88 100644 --- a/tests/Espo/Core/Utils/MetadataTest.php +++ b/tests/Espo/Core/Utils/MetadataTest.php @@ -51,9 +51,12 @@ class MetadataTest extends \PHPUnit_Framework_TestCase copy($this->defaultCacheFile, $this->cacheFile); } - $this->objects['config'] = $this->getMockBuilder('\Espo\Core\Utils\Config')->disableOriginalConstructor()->getMock(); + $this->objects['config'] = $this->getMockBuilder('\\Espo\\Core\\Utils\\Config')->disableOriginalConstructor()->getMock(); $this->objects['fileManager'] = new \Espo\Core\Utils\File\Manager(); - $this->objects['Unifier'] = $this->getMockBuilder('\Espo\Core\Utils\File\Unifier')->disableOriginalConstructor()->getMock(); + $this->objects['Unifier'] = $this->getMockBuilder('\\Espo\\Core\\Utils\\File\\Unifier')->disableOriginalConstructor()->getMock(); + + $this->objects['log'] = $this->getMockBuilder('\\Espo\\Core\\Utils\\Log')->disableOriginalConstructor()->getMock(); + $GLOBALS['log'] = $this->objects['log']; //set to use cache $this->objects['config'] diff --git a/tests/Espo/Core/Utils/UtilTest.php b/tests/Espo/Core/Utils/UtilTest.php index 2129c49b29..c55cf003be 100644 --- a/tests/Espo/Core/Utils/UtilTest.php +++ b/tests/Espo/Core/Utils/UtilTest.php @@ -120,6 +120,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase ) ); $expected = array( + 'test' => [], 'hello' => 'world', 'man' => array( 'test' => [ @@ -129,7 +130,8 @@ class UtilTest extends \PHPUnit_Framework_TestCase ] ) ); - $result = Util::merge($d3, Util::merge($d2, $d1)); + + $result = Util::merge(Util::merge($d2, $d1), $d3); $this->assertEquals($expected, $result); } @@ -1381,6 +1383,46 @@ class UtilTest extends \PHPUnit_Framework_TestCase $this->assertNotEquals('customReturns', Util::getValueByKey($inputArray, 'Contact.useCache', 'customReturns')); } + public function testGetValueByKey2() + { + $inputArray = array( + 'fields' => array( + 'varchar' => array ( + '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'])); + $this->assertEquals('customReturns', Util::getValueByKey($inputArray, 'Contact.notExists', 'customReturns')); + } + public function testUnsetInArrayByValue() { $newArray = json_decode('[