CmsCompoundObject::hasComponent() now resolves registered codes for comparison
This commit is contained in:
parent
5d3b1996a7
commit
a324f01678
|
|
@ -3,13 +3,13 @@
|
|||
use Cache;
|
||||
use Config;
|
||||
use Validator;
|
||||
use Cms\Classes\CodeBase;
|
||||
use SystemException;
|
||||
use Cms\Classes\FileHelper;
|
||||
use ValidationException;
|
||||
use Cms\Classes\ViewBag;
|
||||
use Cms\Twig\Extension as CmsTwigExtension;
|
||||
use Cms\Classes\CodeBase;
|
||||
use Cms\Classes\FileHelper;
|
||||
use Cms\Twig\Loader as TwigLoader;
|
||||
use Cms\Twig\Extension as CmsTwigExtension;
|
||||
use System\Twig\Extension as SystemTwigExtension;
|
||||
use Twig_Environment;
|
||||
|
||||
|
|
@ -165,9 +165,6 @@ class CmsCompoundObject extends CmsObject
|
|||
|
||||
$settingParts = explode(' ', $setting);
|
||||
$settingName = $settingParts[0];
|
||||
// if (!$manager->hasComponent($settingName)) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
$components[$setting] = $value;
|
||||
unset($this->settings[$setting]);
|
||||
|
|
@ -299,20 +296,31 @@ class CmsCompoundObject extends CmsObject
|
|||
*/
|
||||
public function hasComponent($componentName)
|
||||
{
|
||||
$componentManager = ComponentManager::instance();
|
||||
$componentName = $componentManager->resolve($componentName);
|
||||
|
||||
foreach ($this->settings['components'] as $sectionName => $values) {
|
||||
|
||||
$result = $sectionName;
|
||||
|
||||
if ($sectionName == $componentName) {
|
||||
return $componentName;
|
||||
return $result;
|
||||
}
|
||||
|
||||
$parts = explode(' ', $sectionName);
|
||||
if (count($parts) > 1) {
|
||||
$sectionName = trim($parts[0]);
|
||||
|
||||
if (count($parts) < 2) {
|
||||
continue;
|
||||
if ($sectionName == $componentName) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
if (trim($parts[0]) == $componentName) {
|
||||
return $sectionName;
|
||||
$sectionName = $componentManager->resolve($sectionName);
|
||||
if ($sectionName == $componentName) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
var = value
|
||||
[testArchive firstAlias]
|
||||
posts-per-page = "6"
|
||||
|
||||
[October\Tester\Components\Post secondAlias]
|
||||
show-featured = "true"
|
||||
==
|
||||
<p>This is a paragraph</p>
|
||||
|
|
@ -62,6 +62,30 @@ class CmsCompoundObjectTest extends TestCase
|
|||
$this->assertEquals(10, $obj->settings['components']['testArchive']['posts-per-page']);
|
||||
}
|
||||
|
||||
public function testHasComponent()
|
||||
{
|
||||
$theme = Theme::load('test');
|
||||
|
||||
$obj = TestCmsCompoundObject::load($theme, 'components.htm');
|
||||
$this->assertArrayHasKey('components', $obj->settings);
|
||||
|
||||
$this->assertInternalType('array', $obj->settings['components']);
|
||||
$this->assertArrayHasKey('testArchive firstAlias', $obj->settings['components']);
|
||||
$this->assertArrayHasKey('October\Tester\Components\Post secondAlias', $obj->settings['components']);
|
||||
|
||||
// Explicit
|
||||
$this->assertEquals('testArchive firstAlias', $obj->hasComponent('testArchive'));
|
||||
$this->assertEquals('October\Tester\Components\Post secondAlias', $obj->hasComponent('October\Tester\Components\Post'));
|
||||
|
||||
// Resolved
|
||||
$this->assertEquals('testArchive firstAlias', $obj->hasComponent('October\Tester\Components\Archive'));
|
||||
$this->assertEquals('October\Tester\Components\Post secondAlias', $obj->hasComponent('testPost'));
|
||||
|
||||
// Negative test
|
||||
$this->assertFalse($obj->hasComponent('yooHooBigSummerBlowOut'));
|
||||
$this->assertFalse($obj->hasComponent('October\Tester\Components\BigSummer'));
|
||||
}
|
||||
|
||||
public function testCache()
|
||||
{
|
||||
$theme = Theme::load('test');
|
||||
|
|
|
|||
Loading…
Reference in New Issue