public function testCanSetResolverInstance()
 {
     $resolver = new TemplatePathStack();
     $this->renderer->setResolver($resolver);
     $this->assertSame($resolver, $this->renderer->resolver());
     $this->assertSame($this->phpRenderer->resolver(), $this->renderer->resolver());
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->helper = new SnippetHelper();
     $view = new PhpRenderer();
     $view->resolver()->addPath(__DIR__ . '/../../../view');
     $view->resolver()->addPath(__DIR__ . '/_files/modules');
     $this->helper->setView($view);
 }
示例#3
0
 /**
  * Prepares the environment before running a test
  *
  */
 protected function setUp()
 {
     $cwd = __DIR__;
     // read navigation config
     $this->_files = $cwd . '/_files';
     $config = ConfigFactory::fromFile($this->_files . '/navigation.xml', true);
     // setup containers from config
     $this->_nav1 = new Navigation($config->get('nav_test1'));
     $this->_nav2 = new Navigation($config->get('nav_test2'));
     // setup view
     $view = new PhpRenderer();
     $view->resolver()->addPath($cwd . '/_files/mvc/views');
     // create helper
     $this->_helper = new $this->_helperName();
     $this->_helper->setView($view);
     // set nav1 in helper as default
     $this->_helper->setContainer($this->_nav1);
     // setup service manager
     $smConfig = array('modules' => array(), 'module_listener_options' => array('config_cache_enabled' => false, 'cache_dir' => 'data/cache', 'module_paths' => array(), 'extra_config' => array('service_manager' => array('factories' => array('Config' => function () use($config) {
         return array('navigation' => array('default' => $config->get('nav_test1')));
     })))));
     $sm = $this->serviceManager = new ServiceManager(new ServiceManagerConfig());
     $sm->setService('ApplicationConfig', $smConfig);
     $sm->get('ModuleManager')->loadModules();
     $sm->get('Application')->bootstrap();
     $sm->setFactory('Navigation', 'Zend\\Navigation\\Service\\DefaultNavigationFactory');
     $sm->setService('nav1', $this->_nav1);
     $sm->setService('nav2', $this->_nav2);
     $app = $this->serviceManager->get('Application');
     $app->getMvcEvent()->setRouteMatch(new RouteMatch(array('controller' => 'post', 'action' => 'view', 'id' => '1337')));
 }
 public function setUp()
 {
     $view = new View();
     $base = str_replace('/', DIRECTORY_SEPARATOR, '/../_templates');
     $view->resolver()->addPath(__DIR__ . $base);
     $view->vars()->setStrictVars(true);
     $this->view = $view;
 }
示例#5
0
文件: Module.php 项目: t4web/Modules
 public function getControllerConfig()
 {
     return array('factories' => array('Modules\\Controller\\Console\\List' => function (ControllerManager $cm) {
         $sl = $cm->getServiceLocator();
         $renderer = new PhpRenderer();
         $renderer->resolver()->setPaths([__DIR__ . '/view']);
         return new Controller\Console\ListController(new ComposerInfo('composer.lock'), $sl->get('ModuleManager'), new ListViewModel(), $renderer);
     }, 'Modules\\Controller\\Console\\Init' => function (ControllerManager $cm) {
         $sl = $cm->getServiceLocator();
         return new Controller\Console\InitController($sl->get('Zend\\Db\\Adapter\\Adapter'), $sl->get('Zend\\Db\\Metadata\\Metadata'));
     }));
 }
示例#6
0
 public function _before(FunctionalTester $I)
 {
     $application = $I->getApplication();
     $this->event = $application->getMvcEvent();
     $this->routeMatch = new RouteMatch(array('controller' => 'Modules\\Controller\\Console\\List'));
     $this->event->setRouteMatch($this->routeMatch);
     $renderer = new PhpRenderer();
     $renderer->resolver()->setPaths([dirname(dirname(dirname(__DIR__))) . '/view']);
     $this->viewModel = new ListViewModel();
     $this->controller = new ListController(new ComposerInfo('composer.lock'), $application->getServiceManager()->get('Zend\\ModuleManager\\ModuleManager'), $this->viewModel, $renderer);
     $this->controller->setEvent($this->event);
     $this->controller->setEventManager($application->getEventManager());
     $this->controller->setServiceLocator($application->getServiceManager());
 }
示例#7
0
 /**
  * 
  * @return \Zend\View\Renderer\PhpRenderer
  */
 public function getRenderer()
 {
     if ($this->renderer === null) {
         $renderer = new PhpRenderer();
         // register view helpers
         $formHelperConfig = new ZendFormHelperConfig();
         $formHelperConfig->configureServiceManager($renderer->getHelperPluginManager());
         // register view helpers
         $formHelperConfig = new FormHelperConfig();
         $formHelperConfig->configureServiceManager($renderer->getHelperPluginManager());
         // set base path
         $path = $this->templatePath ?: __DIR__ . '/view/scripts';
         $renderer->resolver()->addPath($path);
         $this->setRenderer($renderer);
     }
     return $this->renderer;
 }
示例#8
0
 /**
  * Prepares the environment before running a test
  *
  */
 protected function setUp()
 {
     $cwd = __DIR__;
     // read navigation config
     $this->_files = $cwd . '/_files';
     $config = ConfigFactory::fromFile($this->_files . '/navigation.xml', true);
     // setup containers from config
     $this->_nav1 = new Navigation($config->get('nav_test1'));
     $this->_nav2 = new Navigation($config->get('nav_test2'));
     // setup view
     $view = new PhpRenderer();
     $view->resolver()->addPath($cwd . '/_files/mvc/views');
     // create helper
     $this->_helper = new $this->_helperName();
     $this->_helper->setView($view);
     // set nav1 in helper as default
     $this->_helper->setContainer($this->_nav1);
 }
示例#9
0
 /**
  * Add path in Zend\View\Resolver\TemplatePathStack
  *
  * @param string $dir Directory
  *
  * @return \Gc\View\Renderer
  */
 public function addPath($dir)
 {
     $this->checkRenderer();
     $this->renderer->resolver()->addPath($dir);
     return $this;
 }
示例#10
0
 public function testRendersWithPartial()
 {
     $view = new View\Renderer\PhpRenderer();
     $view->resolver()->addPath(__DIR__ . '/_files/scripts');
     Helper\PaginationControl::setDefaultViewPartial('partial.phtml');
     $this->paginator->setView($view);
     $string = $this->paginator->__toString();
     $this->assertEquals('partial rendered successfully', $string);
 }
示例#11
0
 public function testShouldNotConvertToArrayRecursivelyIfModelIsTraversable()
 {
     $rIterator = new RecursiveIteratorTest();
     for ($i = 0; $i < 5; ++$i) {
         $data = array('message' => 'foo' . $i);
         $rIterator->addItem(new IteratorTest($data));
     }
     $view = new View();
     $view->resolver()->addPath($this->basePath . '/application/views/scripts');
     $this->helper->setView($view);
     $this->helper->setObjectKey('obj');
     $result = $this->helper->__invoke('partialLoopShouldNotConvertToArrayRecursively.phtml', $rIterator);
     foreach ($rIterator as $item) {
         foreach ($item as $key => $value) {
             $this->assertContains('This is an iteration: ' . $value, $result, var_export($value, 1));
         }
     }
 }
示例#12
0
 public function testCanPassViewModelAsSoleArgument()
 {
     $model = new ViewModel(array('foo' => 'bar', 'bar' => 'baz'));
     $model->setTemplate('partialVars.phtml');
     $view = new View();
     $view->resolver()->addPath($this->basePath . '/application/views/scripts');
     $this->helper->setView($view);
     $return = $this->helper->__invoke($model);
     foreach ($model->getVariables() as $key => $value) {
         $string = sprintf('%s: %s', $key, $value);
         $this->assertContains($string, $return);
     }
 }
示例#13
0
 /**
  * @group ZF-5174
  */
 public function testPartialLoopPartialCounterResets()
 {
     $data = array(array('message' => 'foo'), array('message' => 'bar'), array('message' => 'baz'), array('message' => 'bat'));
     $view = new View();
     $view->resolver()->addPath($this->basePath . '/application/views/scripts');
     $this->helper->setView($view);
     $result = $this->helper->__invoke('partialLoopCouter.phtml', $data);
     foreach ($data as $key => $item) {
         $string = 'This is an iteration: ' . $item['message'] . ', pointer at ' . ($key + 1);
         $this->assertContains($string, $result);
     }
     $result = $this->helper->__invoke('partialLoopCouter.phtml', $data);
     foreach ($data as $key => $item) {
         $string = 'This is an iteration: ' . $item['message'] . ', pointer at ' . ($key + 1);
         $this->assertContains($string, $result);
     }
 }
示例#14
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content'));
     $this->view->save();
     $this->layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content'));
     $this->layout->save();
     $this->user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1));
     $this->user->setPassword('test');
     $this->user->save();
     $this->documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $this->view->getId(), 'user_id' => $this->user->getId()));
     $this->documentType->save();
     $this->document = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => 0));
     $this->document->save();
     $this->object = new Documents();
     $view = new View();
     $view->resolver()->addPath(__DIR__ . '/_files/views');
     $view->setHelperPluginManager(Registry::get('Application')->getServiceManager()->get('viewhelpermanager'));
     $this->object->setView($view);
 }
示例#15
0
 /**
  * Test
  *
  * @return void
  */
 public function testGetDocument()
 {
     $parent = new ViewModel();
     $parent->setTemplate('layout');
     $view = new View();
     $renderer = Registry::get('Application')->getServiceManager()->get('Zend\\View\\Renderer\\PhpRenderer');
     $view->setHelperPluginManager($renderer->getHelperPluginManager());
     $view->plugin('view_model')->setRoot($parent);
     $view->resolver()->addPath(__DIR__ . '/_files/views');
     $this->object->setView($view);
     $this->assertInstanceOf('Gc\\Document\\Model', $this->object->getDocument());
 }
示例#16
0
 public function testObjectModelSetInObjectKeyWhenKeyPresent()
 {
     $this->helper->setObjectKey('foo');
     $model = new \stdClass();
     $model->footest = 'bar';
     $model->bartest = 'baz';
     $view = new View();
     $view->resolver()->addPath($this->basePath . '/application/views/scripts');
     $this->helper->setView($view);
     $return = $this->helper->__invoke('partialObj.phtml', $model);
     $this->assertNotContains('No object model passed', $return);
     foreach (get_object_vars($model) as $key => $value) {
         $string = sprintf('%s: %s', $key, $value);
         $this->assertContains($string, $return, "Checking for '{$return}' containing '{$string}'");
     }
 }
示例#17
0
 public function getView()
 {
     $view = new View();
     $view->resolver()->addPath(__DIR__ . '/../TestAsset/views/');
     return $view;
 }
示例#18
0
 /**
  * @group ZF-5174
  */
 public function testPartialLoopPartialCounterResets()
 {
     $data = array(array('message' => 'foo'), array('message' => 'bar'), array('message' => 'baz'), array('message' => 'bat'));
     $view = new View();
     $view->resolver()->addPath($this->basePath . '/application/views/scripts');
     $this->helper->setView($view);
     $this->helper->__invoke('partialLoopCouter.phtml', $data);
     $this->assertEquals(4, $this->helper->getPartialCounter());
     $this->helper->__invoke('partialLoopCouter.phtml', $data);
     $this->assertEquals(4, $this->helper->getPartialCounter());
 }