Metadata: get metadata in object format
This commit is contained in:
@@ -236,17 +236,39 @@ class Metadata
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllObjects($isJSON = false, $reload = false)
|
||||
protected function getObjData($reload = false)
|
||||
{
|
||||
if (!isset($this->objData) || $reload) {
|
||||
$this->objInit($reload);
|
||||
}
|
||||
|
||||
return $this->objData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object Metadata
|
||||
*
|
||||
* @param mixed string|array $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getObjects($key = null, $default = null)
|
||||
{
|
||||
$objData = $this->getObjData();
|
||||
|
||||
return Util::getValueByKey($objData, $key, $default);
|
||||
}
|
||||
|
||||
public function getAllObjects($isJSON = false, $reload = false)
|
||||
{
|
||||
$objData = $this->getObjData($reload);
|
||||
|
||||
if ($isJSON) {
|
||||
return Json::encode($this->objData);
|
||||
return Json::encode($objData);
|
||||
}
|
||||
|
||||
return $this->objData;
|
||||
return $objData;
|
||||
}
|
||||
|
||||
public function getAllForFrontend()
|
||||
|
||||
@@ -40,9 +40,10 @@ class MetadataTest extends \PHPUnit\Framework\TestCase
|
||||
protected $reflection;
|
||||
|
||||
protected $defaultCacheFile = 'tests/unit/testData/Utils/Metadata/metadata.php';
|
||||
protected $defaultObjCacheFile = 'tests/unit/testData/Utils/Metadata/metadata.php';
|
||||
|
||||
protected $cacheFile = 'tests/unit/testData/cache/metadata.php';
|
||||
protected $ormCacheFile = 'tests/unit/testData/Utils/Metadata/ormMetadata.php';
|
||||
protected $objCacheFile = 'tests/unit/testData/cache/objMetadata.php';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
@@ -51,6 +52,10 @@ class MetadataTest extends \PHPUnit\Framework\TestCase
|
||||
copy($this->defaultCacheFile, $this->cacheFile);
|
||||
}
|
||||
|
||||
if (!file_exists($this->objCacheFile)) {
|
||||
copy($this->defaultObjCacheFile, $this->objCacheFile);
|
||||
}
|
||||
|
||||
$this->objects['fileManager'] = new \Espo\Core\Utils\File\Manager();
|
||||
|
||||
$this->objects['log'] = $this->getMockBuilder('\\Espo\\Core\\Utils\\Log')->disableOriginalConstructor()->getMock();
|
||||
@@ -60,6 +65,7 @@ class MetadataTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->reflection = new ReflectionHelper($this->object);
|
||||
$this->reflection->setProperty('cacheFile', $this->cacheFile);
|
||||
$this->reflection->setProperty('objCacheFile', $this->objCacheFile);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
@@ -333,4 +339,19 @@ class MetadataTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
unlink($savedFile);
|
||||
}
|
||||
|
||||
public function testGetObjects()
|
||||
{
|
||||
$result = 'System';
|
||||
$this->assertEquals($result, $this->object->getObjects('app.adminPanel.system.label'));
|
||||
|
||||
$result = 'fields';
|
||||
$this->assertObjectHasAttribute($result, $this->object->getObjects('entityDefs.User'));
|
||||
|
||||
$result = (object) [
|
||||
'type' => 'bool',
|
||||
'tooltip' => true
|
||||
];
|
||||
$this->assertEquals($result, $this->object->getObjects('entityDefs.User.fields.isAdmin'));
|
||||
}
|
||||
}
|
||||
@@ -1437,6 +1437,38 @@ class UtilTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals('customReturns', Util::getValueByKey($inputArray, 'Contact.notExists', 'customReturns'));
|
||||
}
|
||||
|
||||
public function testGetValueByKeyWithObjects()
|
||||
{
|
||||
$inputObject = (object) [
|
||||
'Account' => (object) [
|
||||
'useCache' => true,
|
||||
'sub' => (object) [
|
||||
'subV' => '125',
|
||||
'subO' => (object) [
|
||||
'subOV' => '125',
|
||||
'subOV2' => '125',
|
||||
],
|
||||
],
|
||||
],
|
||||
'Contact' => (object) [
|
||||
'useCache' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($inputObject, Util::getValueByKey($inputObject));
|
||||
$this->assertEquals($inputObject, Util::getValueByKey($inputObject, ''));
|
||||
|
||||
$this->assertEquals('125', Util::getValueByKey($inputObject, 'Account.sub.subV'));
|
||||
|
||||
$result = (object) ['useCache' => true];
|
||||
$this->assertEquals($result, Util::getValueByKey($inputObject, 'Contact'));
|
||||
|
||||
$this->assertNull(Util::getValueByKey($inputObject, 'Contact.notExists'));
|
||||
|
||||
$this->assertEquals('customReturns', Util::getValueByKey($inputObject, 'Contact.notExists', 'customReturns'));
|
||||
$this->assertNotEquals('customReturns', Util::getValueByKey($inputObject, 'Contact.useCache', 'customReturns'));
|
||||
}
|
||||
|
||||
public function testUnsetInArrayByValue()
|
||||
{
|
||||
$newArray = json_decode('[
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user