diff --git a/modules/cms/classes/ComponentManager.php b/modules/cms/classes/ComponentManager.php index 252cfe526..5402b07b5 100644 --- a/modules/cms/classes/ComponentManager.php +++ b/modules/cms/classes/ComponentManager.php @@ -205,7 +205,7 @@ class ComponentManager if (!class_exists($className)) { throw new SystemException(sprintf( - 'Component class not found %s.Check the component plugin.', + 'Component class not found %s. Check the component plugin.', $className )); } diff --git a/modules/cms/classes/PartialStack.php b/modules/cms/classes/PartialStack.php index 7779d1833..d49db3465 100644 --- a/modules/cms/classes/PartialStack.php +++ b/modules/cms/classes/PartialStack.php @@ -58,6 +58,10 @@ class PartialStack */ public function getComponent($name) { + if (!$this->activePartial) { + return null; + } + $component = $this->findComponentFromStack($name, $this->activePartial); if ($component !== null) { return $component; diff --git a/tests/fixtures/plugins/october/tester/Plugin.php b/tests/fixtures/plugins/october/tester/Plugin.php index 110cd7ea8..a0c80bac0 100644 --- a/tests/fixtures/plugins/october/tester/Plugin.php +++ b/tests/fixtures/plugins/october/tester/Plugin.php @@ -18,7 +18,9 @@ class Plugin extends PluginBase { return [ 'October\Tester\Components\Archive' => 'testArchive', - 'October\Tester\Components\Post' => 'testPost' + 'October\Tester\Components\Post' => 'testPost', + 'October\Tester\Components\MainMenu' => 'testMainMenu', + 'October\Tester\Components\ContentBlock' => 'testContentBlock' ]; } diff --git a/tests/fixtures/plugins/october/tester/components/ContentBlock.php b/tests/fixtures/plugins/october/tester/components/ContentBlock.php new file mode 100644 index 000000000..0728999b8 --- /dev/null +++ b/tests/fixtures/plugins/october/tester/components/ContentBlock.php @@ -0,0 +1,25 @@ + 'Content Block Dummy Component', + 'description' => 'Displays a editable content block.' + ]; + } + + public function onRender() + { + if ($output = $this->property('output')) { + return 'Custom output: '.$output; + } + + return 'Pass'; + } + +} \ No newline at end of file diff --git a/tests/fixtures/plugins/october/tester/components/MainMenu.php b/tests/fixtures/plugins/october/tester/components/MainMenu.php new file mode 100644 index 000000000..9e70d8910 --- /dev/null +++ b/tests/fixtures/plugins/october/tester/components/MainMenu.php @@ -0,0 +1,21 @@ + 'Menu Dummy Component', + 'description' => 'Displays a really cool menu.' + ]; + } + + public function menuItems() + { + return ['Home', 'Blog', 'About', 'Contact']; + } + +} \ No newline at end of file diff --git a/tests/fixtures/plugins/october/tester/components/mainmenu/default.htm b/tests/fixtures/plugins/october/tester/components/mainmenu/default.htm new file mode 100644 index 000000000..53681ebf0 --- /dev/null +++ b/tests/fixtures/plugins/october/tester/components/mainmenu/default.htm @@ -0,0 +1,4 @@ +
DEFAULT MARKUP: I am a post yay
\ No newline at end of file diff --git a/tests/fixtures/themes/test/pages/component-custom-render.htm b/tests/fixtures/themes/test/pages/component-custom-render.htm new file mode 100644 index 000000000..057c36365 --- /dev/null +++ b/tests/fixtures/themes/test/pages/component-custom-render.htm @@ -0,0 +1,10 @@ +url = "/component-custom-render" + +[October\Tester\Components\ContentBlock theblock] +== + +{% component 'theblock' %} + +{% component 'theblock' output="Would you look over Picasso's shoulder" %} + +{% component 'theblock' output='And tell him about his brush strokes?' %} diff --git a/tests/fixtures/themes/test/pages/component-partial-nesting.htm b/tests/fixtures/themes/test/pages/component-partial-nesting.htm new file mode 100644 index 000000000..41d18f7bb --- /dev/null +++ b/tests/fixtures/themes/test/pages/component-partial-nesting.htm @@ -0,0 +1,3 @@ +url = "/component-partial-nesting" +== +{% partial 'nesting/level1' %} \ No newline at end of file diff --git a/tests/fixtures/themes/test/pages/component-partial-override.htm b/tests/fixtures/themes/test/pages/component-partial-override.htm new file mode 100644 index 000000000..4ab21d6b6 --- /dev/null +++ b/tests/fixtures/themes/test/pages/component-partial-override.htm @@ -0,0 +1,5 @@ +url = "/component-partial-override" + +[October\Tester\Components\Post override1] +== +{% component 'override1' %} \ No newline at end of file diff --git a/tests/fixtures/themes/test/pages/component-partial.htm b/tests/fixtures/themes/test/pages/component-partial.htm new file mode 100644 index 000000000..3c796d6ce --- /dev/null +++ b/tests/fixtures/themes/test/pages/component-partial.htm @@ -0,0 +1,5 @@ +url = "/component-partial" + +[October\Tester\Components\Post post] +== +{% component 'post' %} \ No newline at end of file diff --git a/tests/fixtures/themes/test/pages/no-component-class.htm b/tests/fixtures/themes/test/pages/no-component-class.htm new file mode 100644 index 000000000..d9e406a4e --- /dev/null +++ b/tests/fixtures/themes/test/pages/no-component-class.htm @@ -0,0 +1,5 @@ +url = "/no-component-class" + +[PeterPan\Nevernever\Land noComponentExist] +== +Hey
diff --git a/tests/fixtures/themes/test/pages/no-component.htm b/tests/fixtures/themes/test/pages/no-component.htm new file mode 100644 index 000000000..0a7761b47 --- /dev/null +++ b/tests/fixtures/themes/test/pages/no-component.htm @@ -0,0 +1,3 @@ +url = "/no-component" +== +Hey
{% component 'noComponentExist' %} \ No newline at end of file diff --git a/tests/fixtures/themes/test/pages/no-partial.htm b/tests/fixtures/themes/test/pages/no-partial.htm index 846bef1f6..7ec76ee77 100644 --- a/tests/fixtures/themes/test/pages/no-partial.htm +++ b/tests/fixtures/themes/test/pages/no-partial.htm @@ -1,5 +1,4 @@ url = "/no-partial" -layout = "caramba" ==Hey
{{ partial('caramba') }} \ No newline at end of file diff --git a/tests/fixtures/themes/test/partials/nesting/level1.htm b/tests/fixtures/themes/test/partials/nesting/level1.htm new file mode 100644 index 000000000..f0ae8571e --- /dev/null +++ b/tests/fixtures/themes/test/partials/nesting/level1.htm @@ -0,0 +1,6 @@ +[October\Tester\Components\MainMenu override2] +[October\Tester\Components\Post override3] +== +I am an override partial! Yay
\ No newline at end of file diff --git a/tests/fixtures/themes/test/partials/override2/default.htm b/tests/fixtures/themes/test/partials/override2/default.htm new file mode 100644 index 000000000..7fb329768 --- /dev/null +++ b/tests/fixtures/themes/test/partials/override2/default.htm @@ -0,0 +1,7 @@ +Insert post here
\ No newline at end of file diff --git a/tests/fixtures/themes/test/partials/override4/default.htm b/tests/fixtures/themes/test/partials/override4/default.htm new file mode 100644 index 000000000..0b884776e --- /dev/null +++ b/tests/fixtures/themes/test/partials/override4/default.htm @@ -0,0 +1,3 @@ +I am another post, deep down
+ +{% partial 'nesting/level3' %} \ No newline at end of file diff --git a/tests/unit/cms/classes/ComponentManagerTest.php b/tests/unit/cms/classes/ComponentManagerTest.php index 5211a5778..99d3601d6 100644 --- a/tests/unit/cms/classes/ComponentManagerTest.php +++ b/tests/unit/cms/classes/ComponentManagerTest.php @@ -22,6 +22,8 @@ class ComponentManagerTest extends TestCase { include_once base_path() . '/tests/fixtures/plugins/october/tester/components/Archive.php'; include_once base_path() . '/tests/fixtures/plugins/october/tester/components/Post.php'; + include_once base_path() . '/tests/fixtures/plugins/october/tester/components/MainMenu.php'; + include_once base_path() . '/tests/fixtures/plugins/october/tester/components/ContentBlock.php'; $manager = ComponentManager::instance(); $components = $manager->listComponentDetails(); diff --git a/tests/unit/cms/classes/ControllerTest.php b/tests/unit/cms/classes/ControllerTest.php index 2de040214..e15220c1d 100644 --- a/tests/unit/cms/classes/ControllerTest.php +++ b/tests/unit/cms/classes/ControllerTest.php @@ -5,6 +5,31 @@ use Cms\Classes\Controller; class ControllerTest extends TestCase { + + public function testThemeUrl() + { + $theme = Theme::load('test'); + $controller = new Controller($theme); + + $url = $controller->themeUrl(); + $this->assertEquals('http://localhost/themes/test', $url); + + $url = $controller->themeUrl('foo/bar.css'); + $this->assertEquals('http://localhost/themes/test/foo/bar.css', $url); + + // + // These tests seem to bear different results + // + + // $url = $controller->themeUrl(['assets/css/style1.css', 'assets/css/style2.css']); + // $url = substr($url, 0, strpos($url, '-')); + // $this->assertEquals('/combine/88634b8fa6f4f6442ce830d38296640a', $url); + + // $url = $controller->themeUrl(['assets/js/script1.js', 'assets/js/script2.js']); + // $url = substr($url, 0, strpos($url, '-')); + // $this->assertEquals('/combine/860afc990164a60a8e90682d04da27ee', $url); + } + public function test404() { /* @@ -107,7 +132,7 @@ class ControllerTest extends TestCase } /** - * @expectedException Cms\Classes\CmsException + * @expectedException Twig_Error_Runtime * @expectedExceptionMessage is not found */ public function testPartialNotFound() @@ -341,28 +366,99 @@ ESC; $this->assertEquals('page', $content['ajax-result']); } - public function testThemeUrl() + /** + * @expectedException October\Rain\Exception\SystemException + * @expectedExceptionMessage is not registered for the component + */ + public function testComponentClassNotFound() { $theme = Theme::load('test'); $controller = new Controller($theme); + $response = $controller->run('/no-component-class')->getContent(); + } - $url = $controller->themeUrl(); - $this->assertEquals('http://localhost/themes/test', $url); - - $url = $controller->themeUrl('foo/bar.css'); - $this->assertEquals('http://localhost/themes/test/foo/bar.css', $url); - + public function testComponentNotFound() + { // - // These tests seem to bear different results + // This test should probably be throwing an exception... -sg // + $theme = Theme::load('test'); + $controller = new Controller($theme); + $response = $controller->run('/no-component')->getContent(); - // $url = $controller->themeUrl(['assets/css/style1.css', 'assets/css/style2.css']); - // $url = substr($url, 0, strpos($url, '-')); - // $this->assertEquals('/combine/88634b8fa6f4f6442ce830d38296640a', $url); + $this->assertEquals('Hey
', $response); + } - // $url = $controller->themeUrl(['assets/js/script1.js', 'assets/js/script2.js']); - // $url = substr($url, 0, strpos($url, '-')); - // $this->assertEquals('/combine/860afc990164a60a8e90682d04da27ee', $url); + public function testComponentPartial() + { + $theme = Theme::load('test'); + $controller = new Controller($theme); + $response = $controller->run('/component-partial')->getContent(); + + $this->assertEquals('DEFAULT MARKUP: I am a post yay
', $response); + } + + public function testComponentPartialOverride() + { + $theme = Theme::load('test'); + $controller = new Controller($theme); + $response = $controller->run('/component-partial-override')->getContent(); + + $this->assertEquals('I am an override partial! Yay
', $response); + } + + public function testComponentPartialNesting() + { + $theme = Theme::load('test'); + $controller = new Controller($theme); + $response = $controller->run('/component-partial-nesting')->getContent(); + + $content = <<DEFAULT MARKUP: I am a post yay
I am another post, deep down
+ +Insert post here
+ESC; + + $this->assertEquals($content, $response); + } + + public function testComponentWithOnRender() + { + $theme = Theme::load('test'); + $controller = new Controller($theme); + $response = $controller->run('/component-custom-render')->getContent(); + + $content = <<