private function spoofPageCode() { // Spoof all the objects we need to make a page object $theme = Theme::load('test'); $page = Page::load($theme, 'index.htm'); $layout = Layout::load($theme, 'content.htm'); $controller = new Controller($theme); $parser = new CodeParser($page); $pageObj = $parser->source($page, $layout, $controller); return $pageObj; }
/** * Looks up the Layout Cms object for this page. * @return Cms\Classes\Layout */ public function getLayoutObject() { $viewBag = $this->getViewBag(); $layout = $viewBag->property('layout'); if (!$layout) { $layouts = $this->getLayoutOptions(); $layout = count($layouts) ? array_keys($layouts)[0] : null; } if (!$layout) { return null; } $layout = Layout::load($this->theme, $layout); if (!$layout) { return null; } return $layout; }
public function testParseNoPhp() { $theme = Theme::load('test'); $layout = Layout::load($theme, 'no-php.htm'); $this->assertNotEmpty($layout); $parser = new CodeParser($layout); $info = $parser->parse(); $this->assertInternalType('array', $info); $this->assertArrayHasKey('filePath', $info); $this->assertArrayHasKey('className', $info); $this->assertArrayHasKey('source', $info); $this->assertFileExists($info['filePath']); $expectedContent = '<?php ' . PHP_EOL; $expectedContent .= 'class ' . $info['className'] . ' extends \\Cms\\Classes\\LayoutCode' . PHP_EOL; $expectedContent .= '{' . PHP_EOL; $expectedContent .= PHP_EOL; $expectedContent .= '}' . PHP_EOL; $this->assertEquals($expectedContent, file_get_contents($info['filePath'])); }