Ejemplo n.º 1
0
 protected function setUp()
 {
     $serviceManager = new ServiceManager();
     $serviceLocator = new FormElementManager();
     $serviceLocator->setServiceLocator($serviceManager);
     $pAccounts = $this->getMock('Balance\\Model\\Persistence\\ValueOptionsInterface');
     $pAccounts->method('getValueOptions')->will($this->returnValue([]));
     $serviceManager->setService('Balance\\Model\\Persistence\\Accounts', $pAccounts);
     $serviceLocator->setService('Currency', new CurrencyElement());
     $view = new View();
     $view->getEventManager()->attach(ViewEvent::EVENT_RENDERER, function () {
         $renderer = (new PhpRenderer())->setResolver(new TemplateMapResolver(['layout/page-header' => './module/Balance/view/layout/page-header.phtml', 'balance/postings/edit' => './module/Balance/view/balance/postings/edit.phtml', 'tests/postings/before-entries-a' => './module/Balance/test/BalanceTest/View/Scripts/postings-before-entries-a.phtml', 'tests/postings/before-entries-b' => './module/Balance/test/BalanceTest/View/Scripts/postings-before-entries-b.phtml']));
         $helpers = $renderer->getHelperPluginManager();
         $helpers->get('BasePath')->setBasePath('/');
         $match = $this->getMockBuilder('Zend\\Mvc\\Router\\RouteMatch')->disableOriginalConstructor()->getMock();
         $match->method('getMatchedRouteName')->will($this->returnValue('default'));
         $helpers->get('Url')->setRouter($this->getMock('Zend\\Mvc\\Router\\RouteStackInterface'))->setRouteMatch($match);
         $configs = new HelperConfig();
         $configs->configureServiceManager($helpers);
         return $renderer;
     });
     $form = new PostingsForm();
     $form->setServiceLocator($serviceLocator);
     $model = (new ViewModel())->setTemplate('balance/postings/edit')->setVariable('form', $form)->setOption('has_parent', true);
     $form->init();
     $this->view = $view;
     $this->model = $model;
 }
Ejemplo n.º 2
0
 public function getView()
 {
     $view = new View();
     $libPath = __DIR__ . '/../../../library';
     $view->addHelperPath($libPath . '/Zend/View/Helper');
     return $view;
 }
Ejemplo n.º 3
0
 /**
  * @param  ContainerInterface $container
  * @param  string $name
  * @param  null|array $options
  * @return View
  */
 public function __invoke(ContainerInterface $container, $name, array $options = null)
 {
     $view = new View();
     $events = $container->get('EventManager');
     $view->setEventManager($events);
     $container->get(PhpRendererStrategy::class)->attach($events);
     return $view;
 }
Ejemplo n.º 4
0
 /**
  * Return the Zend View Service
  *
  * @return View
  */
 protected function getView()
 {
     if ($this->view == null) {
         $this->view = clone $this->getServiceLocator()->get('View');
         $this->view->setResponse(new Response());
     }
     return $this->view;
 }
Ejemplo n.º 5
0
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     $this->markTestSkipped('Skipped until Zend\\Paginator is completed');
     $view = new View\View();
     $view->addBasePath(dirname(__FILE__) . '/_files');
     Helper\PaginationControl::setDefaultViewPartial(null);
     $this->_viewHelper = new Helper\PaginationControl();
     $this->_viewHelper->setView($view);
     $this->_paginator = Paginator\Paginator::factory(range(1, 101));
 }
Ejemplo n.º 6
0
 /**
  * 
  * @param ModelInterface $model
  * @return string
  */
 public function render(ModelInterface $model)
 {
     $event = new ViewEvent();
     $event->setName(ViewEvent::EVENT_RENDERER);
     $event->setModel($model);
     $renderers = $this->view->getEventManager()->triggerEventUntil(function ($result) {
         return $result instanceof RendererInterface;
     }, $event);
     return $renderers->last()->render($model);
 }
Ejemplo n.º 7
0
 /**
  * Render the provided model.
  *
  * @param ModelInterface $model
  * @return string
  */
 public function render(ModelInterface $model)
 {
     if ($this->layout && !$model->terminate()) {
         $this->layout->addChild($model);
         $model = $this->layout;
     }
     // hack, force ZendView to return its output instead of triggering an event
     // see: http://mateusztymek.pl/blog/using-standalone-zend-view
     $model->setOption('has_parent', true);
     return $this->zendView->render($model);
 }
Ejemplo n.º 8
0
 public function testOnRenderAttachesJsonStrategy()
 {
     $jsonLDJsonStrategy = $this->getMockBuilder('ZF\\JsonLD\\View\\HalJsonStrategy')->disableOriginalConstructor()->getMock();
     $view = new View();
     $eventManager = $this->getMock('Zend\\EventManager\\EventManager');
     $eventManager->expects($this->once())->method('attach')->with($jsonLDJsonStrategy, 200);
     $view->setEventManager($eventManager);
     $serviceManager = new ServiceManager();
     $serviceManager->setService('ZF\\JsonLD\\JsonStrategy', $jsonLDJsonStrategy)->setService('View', $view);
     $application = $this->getMock('Zend\\Mvc\\ApplicationInterface');
     $application->expects($this->once())->method('getServiceManager')->will($this->returnValue($serviceManager));
     $mvcEvent = $this->getMock('Zend\\Mvc\\MvcEvent');
     $mvcEvent->expects($this->at(0))->method('getResult')->will($this->returnValue(new JsonLDModel()));
     $mvcEvent->expects($this->at(1))->method('getTarget')->will($this->returnValue($application));
     $this->module->onRender($mvcEvent);
 }
Ejemplo n.º 9
0
 /**
  * Processes a view script and returns the output.
  *
  * @param  string|ModelInterface   $nameOrModel The script/resource process, or a view model
  * @param  null|array|\ArrayAccess $values      Values to use during rendering
  * @return string|null The script output.
  * @throws \Zend\View\Exception\DomainException
  */
 public function render($nameOrModel, $values = array())
 {
     $model = null;
     if ($nameOrModel instanceof ModelInterface) {
         $model = $nameOrModel;
         $nameOrModel = $model->getTemplate();
         if (empty($nameOrModel)) {
             throw new Exception\DomainException(sprintf('%s: received View Model argument, but template is empty', __METHOD__));
         }
         $values = (array) $model->getVariables();
     }
     if (!$this->canRender($nameOrModel)) {
         return null;
     }
     if ($model && $this->canRenderTrees() && $model->hasChildren()) {
         if (!isset($values['content'])) {
             $values['content'] = '';
         }
         foreach ($model as $child) {
             /** @var \Zend\View\Model\ViewModel $child */
             if ($this->canRender($child->getTemplate())) {
                 $template = $this->resolver->resolve($child->getTemplate(), $this);
                 return $template->render((array) $child->getVariables());
             }
             $child->setOption('has_parent', true);
             $values['content'] .= $this->view->render($child);
         }
     }
     /** @var $template \Twig_Template */
     $template = $this->resolver->resolve($nameOrModel, $this);
     return $template->render((array) $values);
 }
Ejemplo n.º 10
0
 /**
  *
  * @return \Zend\View\View
  */
 public function getView()
 {
     if ($this->view) {
         return $this->view;
     }
     $helperManager = $this->serviceLocator->get('ViewHelperManager');
     $resolver = $this->serviceLocator->get('ViewResolver');
     $renderer = new PhpRenderer();
     $renderer->setHelperPluginManager($helperManager);
     $renderer->setResolver($resolver);
     $rendererStrategy = new PhpRendererStrategy($renderer);
     $this->view = new View();
     $this->view->setEventManager($this->serviceLocator->get('EventManager'));
     $this->view->getEventManager()->attach($rendererStrategy);
     return $this->view;
 }
Ejemplo n.º 11
0
 public function testOnRenderAttachesJsonStrategy()
 {
     $strategy = new HalJsonStrategy(new HalJsonRenderer(new ApiProblemRenderer()));
     $view = new View();
     $eventManager = $this->getMockBuilder('Zend\\EventManager\\EventManager')->getMock();
     $eventManager->expects($this->exactly(2))->method('attach');
     $view->setEventManager($eventManager);
     $serviceManager = new ServiceManager();
     $serviceManager->setService('ZF\\Hal\\JsonStrategy', $strategy);
     $serviceManager->setService('View', $view);
     $application = $this->getMockBuilder('Zend\\Mvc\\ApplicationInterface')->getMock();
     $application->expects($this->once())->method('getServiceManager')->will($this->returnValue($serviceManager));
     $mvcEvent = $this->getMockBuilder('Zend\\Mvc\\MvcEvent')->getMock();
     $mvcEvent->expects($this->at(0))->method('getResult')->will($this->returnValue(new HalJsonModel()));
     $mvcEvent->expects($this->at(1))->method('getTarget')->will($this->returnValue($application));
     $this->module->onRender($mvcEvent);
 }
Ejemplo n.º 12
0
 /**
  * @param $name
  * @param $path
  * @return View
  */
 private function createView($name, $path)
 {
     $ar = new Resolver\AggregateResolver();
     $helper = $this->helpers;
     $map = new Resolver\TemplateMapResolver(array($name => $path));
     $ar->attach($map);
     foreach ($this->resolvers as $r) {
         $ar->attach($r);
     }
     $renderer = new PhpRenderer();
     $renderer->setHelperPluginManager($helper);
     $renderer->setResolver($ar);
     $strategy = new PhpRendererStrategy($renderer);
     $view = new View();
     $view->setEventManager(clone $this->events);
     $view->setResponse(new Response());
     $view->getEventManager()->attach($strategy);
     return $view;
 }
Ejemplo n.º 13
0
 /**
  * Processes a view script and returns the output.
  *
  * @param  string|ModelInterface $nameOrModel The script/resource process, or a view model
  * @param  array|\ArrayAccess $values Values to use during rendering
  * @throws \Zend\View\Exception\DomainException
  * @return string The script output.
  */
 public function render($nameOrModel, $values = array())
 {
     $model = null;
     if ($nameOrModel instanceof ModelInterface) {
         $model = $nameOrModel;
         $nameOrModel = $model->getTemplate();
         if (empty($nameOrModel)) {
             throw new Exception\DomainException(sprintf('%s: received View Model, but template is empty', __METHOD__));
         }
         $options = $model->getOptions();
         foreach ($options as $setting => $value) {
             $method = 'set' . $setting;
             if (method_exists($this, $method)) {
                 $this->{$method}($value);
             }
             unset($method, $setting, $value);
         }
         unset($options);
         $values = (array) $model->getVariables();
     }
     // check if we can render the template
     if (!$this->canRender($nameOrModel)) {
         return null;
     }
     // handle tree rendering
     if ($model && $this->canRenderTrees() && $model->hasChildren()) {
         if (!isset($values['content'])) {
             $values['content'] = '';
         }
         foreach ($model as $child) {
             /** @var \Zend\View\Model\ViewModel $child */
             if ($this->canRender($child->getTemplate())) {
                 $file = $this->resolver->resolve($child->getTemplate(), $this);
                 $this->smarty->addTemplateDir(dirname($file));
                 $childVariables = (array) $child->getVariables();
                 $childVariables['this'] = $this;
                 $this->smarty->assign($childVariables);
                 return $this->smarty->fetch($file);
             }
             $child->setOption('has_parent', true);
             $values['content'] .= $this->view->render($child);
         }
     }
     // give the template awareness of the Renderer
     $values['this'] = $this;
     // assign the variables
     $this->smarty->assign($values);
     // resolve the template
     $file = $this->resolver->resolve($nameOrModel);
     $this->smarty->addTemplateDir(dirname($file));
     // render
     return $this->smarty->fetch($file);
 }
Ejemplo n.º 14
0
 private function createZendView(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Configuration');
     if (isset($config['view_manager'], $config['view_manager']['template_path_stack'])) {
         $templatePaths = $config['view_manager']['template_path_stack'];
     } else {
         $templatePaths = [];
     }
     $resolver = new TemplatePathStack(['script_paths' => $templatePaths]);
     $phpRenderer = new PhpRenderer();
     $phpRenderer->setResolver($resolver);
     $zendView = new ZendView();
     $zendView->getEventManager()->attach(ViewEvent::EVENT_RENDERER, function () use($phpRenderer) {
         return $phpRenderer;
     });
     // view helpers?
     if (isset($config['view_helpers'])) {
         $helperManagerConfig = new Config($config['view_helpers']);
         $pluginManager = new HelperPluginManager($helperManagerConfig);
         $pluginManager->setServiceLocator($serviceLocator);
         $phpRenderer->setHelperPluginManager($pluginManager);
     }
     return $zendView;
 }
Ejemplo n.º 15
0
 /**
  * @group ZF-9000
  */
 public function testAddingStreamSchemeAsScriptPathShouldNotReverseSlashesOnWindows()
 {
     if (false === strstr(strtolower(PHP_OS), 'windows')) {
         $this->markTestSkipped('Windows-only test');
     }
     $view = new View();
     $path = rtrim('file://' . str_replace('\\', '/', realpath(__DIR__)), '/') . '/';
     $view->addScriptPath($path);
     $paths = $view->getScriptPaths();
     $this->assertContains($path, $paths, var_export($paths, 1));
 }
Ejemplo n.º 16
0
    public function test()
    {
        /*
        $viewConfigExample = [
            'some-view' => [ // view name
                'template' => 'some-template', // html template
                //--- not required options
                'viewModel' => 'some-view-model|\Some\ViewModel::class', // Instance of ViewModel
                'extend' => 'parent-view', // extended view
                'capture' => 'some-capture', // for grouping views
                'children' => [
                    'child-view'// array of views
                ],
                'childrenDynamicLists' => [ // will be generated by list from one of child
                    'child-view' => 'listVar' // every entry in listVar will be setted to genereted child
                ],
                'data' => [ // required data
                    'fromGlobal' => 'varName', // // will be set as variables from global data
                    'fromParent' => 'varName', // will be set as variables by calling getVariable('varName') from parent
                    'static' => [ // will be set as variables
                        'key' => 'value'
                    ],
                ],
            ],
        ];
        */
        $renderer = new PhpRenderer();
        $resolver = new Resolver\AggregateResolver();
        $map = new Resolver\TemplateMapResolver(array('page' => __DIR__ . '/view/page.phtml', 'comments-list' => __DIR__ . '/view/comments-list.phtml', 'comment' => __DIR__ . '/view/comment.phtml', 'user' => __DIR__ . '/view/user.phtml'));
        $stack = new Resolver\TemplatePathStack(array('script_paths' => array(__DIR__ . '/view')));
        $resolver->attach($map)->attach($stack)->attach(new Resolver\RelativeFallbackResolver($map))->attach(new Resolver\RelativeFallbackResolver($stack));
        $renderer->setResolver($resolver);
        $view = new View();
        $response = new Response();
        $view->setResponse($response);
        $strategy = new PhpRendererStrategy($renderer);
        $strategy->attach($view->getEventManager());
        $viewConfig = ['layouts' => ['layout' => ['template' => 'layout']], 'contents' => ['page' => ['layout' => 'layout', 'template' => 'page', 'children' => ['comments-list' => ['extend' => 'comments-list', 'template' => 'comments-list'], 'comment-create' => ['template' => 'comment-create', 'children' => ['myself-info' => ['viewModel' => \Sebaks\ViewTest\MyselfViewModel::class, 'template' => 'user'], 'comment-create-form' => ['template' => 'form', 'children' => ['form-element-textarea' => ['capture' => 'form-element', 'template' => 'form-element-textarea'], 'form-element-button' => ['capture' => 'form-element', 'template' => 'form-element-button']]]]], 'users-table' => ['template' => 'table', 'children' => ['table-head-rows' => ['template' => 'table-tr', 'data' => ['fromParent' => 'rows'], 'children' => ['table-th' => ['template' => 'table-th', 'capture' => 'table-td', 'data' => ['fromParent' => 'value']]], 'childrenDynamicLists' => ['table-th' => 'rows']], 'table-body-rows' => ['template' => 'table-tr', 'data' => ['fromParent' => 'rows'], 'children' => ['table-td' => ['template' => 'table-td', 'data' => ['fromParent' => 'value']]], 'childrenDynamicLists' => ['table-td' => 'rows']]], 'childrenDynamicLists' => ['table-body-rows' => 'bodyRows', 'table-head-rows' => 'headRows'], 'data' => ['static' => ['headRows' => [['Id', 'Name']], 'bodyRows' => [['1', 'John'], ['2', 'Helen']]]]]]]], 'blocks' => ['comments-list' => ['children' => ['comment' => ['viewModel' => \Sebaks\ViewTest\CommentViewModel::class, 'template' => 'comment', 'children' => ['user' => ['viewModel' => \Sebaks\ViewTest\UserViewModel::class, 'template' => 'user', 'data' => ['fromParent' => 'userId', 'static' => ['class' => 'user']], 'children' => ['location' => ['viewModel' => \Sebaks\ViewTest\LocationViewModel::class, 'template' => 'location', 'data' => ['fromParent' => 'countryId']]]]], 'data' => ['fromParent' => ['foo' => 'bar', 'comment' => 'comment']]]], 'childrenDynamicLists' => ['comment' => 'comments'], 'data' => ['fromGlobal' => ['foo' => 'bar', 'result' => 'comments']]]]];
        $data = ['result' => [['id' => 'c1', 'userId' => 'u1', 'text' => 'text of c1'], ['id' => 'c2', 'userId' => 'u2', 'text' => 'text of c2']]];
        $serviceLocator = new \Zend\ServiceManager\ServiceManager();
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\CommentViewModel::class, \Sebaks\ViewTest\CommentViewModel::class, false);
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\UserViewModel::class, \Sebaks\ViewTest\UserViewModel::class, false);
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\LocationViewModel::class, \Sebaks\ViewTest\LocationViewModel::class, false);
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\MyselfViewModel::class, \Sebaks\ViewTest\MyselfViewModel::class, false);
        /////////////////////
        $config = ['sebaks-view' => $viewConfig];
        $serviceLocator->setService('config', $config);
        $serviceLocator->setService('EventManager', new EventManager());
        $request = new Request();
        $serviceLocator->setService('Request', $request);
        //$response = new Response();
        $serviceLocator->setService('Response', $response);
        $e = new MvcEvent();
        $e->setRequest($request);
        $e->setResponse($response);
        $dispatchResult = new ViewModel();
        $dispatchResult->setVariables($data);
        $e->setResult($dispatchResult);
        $routeMatch = new RouteMatch([]);
        $routeMatch->setMatchedRouteName('page');
        $e->setRouteMatch($routeMatch);
        $application = new Application([], $serviceLocator);
        $e->setApplication($application);
        /////////////////////
        $viewBuilder = new BuildViewListener();
        $viewBuilder->injectLayout($e);
        $pageViewModel = $e->getViewModel();
        $view->render($pageViewModel);
        $result = $response->getBody();
        $expected = '<body><ul><li>text of c1
<div class="user">John<span class="location">Ukraine</span></div></li><li>text of c2
<div class="user">Helen<span class="location">United States</span></div></li></ul>
<div class="">Me</div><form><textarea></textarea><button type="submit">Submit</button></form><table>
    <thead>
        <tr><th>Id</th><th>Name</th></tr>    </thead>
    <tbody>
        <tr><td>1</td><td>John</td></tr><tr><td>2</td><td>Helen</td></tr>    </tbody>
</table></body>';
        $this->assertEquals($expected, $result);
    }
Ejemplo n.º 17
0
    public function testRender()
    {
        $renderer = new PhpRenderer();
        $resolver = new Resolver\AggregateResolver();
        $map = new Resolver\TemplateMapResolver(array('page' => __DIR__ . '/view/page.phtml', 'comments-list' => __DIR__ . '/view/comments-list.phtml', 'comment' => __DIR__ . '/view/comment.phtml', 'user' => __DIR__ . '/view/user.phtml'));
        $stack = new Resolver\TemplatePathStack(array('script_paths' => array(__DIR__ . '/view')));
        $resolver->attach($map)->attach($stack)->attach(new Resolver\RelativeFallbackResolver($map))->attach(new Resolver\RelativeFallbackResolver($stack));
        $renderer->setResolver($resolver);
        $view = new View();
        $response = new Response();
        $view->setResponse($response);
        $strategy = new PhpRendererStrategy($renderer);
        $strategy->attach($view->getEventManager());
        /////////////////////////////////////////////////
        $viewConfigExample = ['some-view' => ['template' => 'some-template', 'viewModel' => 'some-view-model|\\Some\\ViewModel::class', 'extend' => 'parent-view', 'capture' => 'some-capture', 'children' => ['child-view'], 'childrenDynamicLists' => ['child-view' => 'listVar'], 'data' => ['fromGlobal' => 'varName', 'fromParent' => 'varName', 'static' => ['key' => 'value']], 'dataProvider' => 'some-view-model|\\Some\\DataProvider::class']];
        //////////////
        $viewConfig = ['page' => ['template' => 'page', 'children' => ['comments-list', 'comment-create' => ['template' => 'comment-create', 'children' => ['myself-info' => ['viewModel' => \Sebaks\ViewTest\MyselfViewModel::class, 'template' => 'user'], 'comment-create-form' => ['template' => 'form', 'children' => ['form-element-textarea' => ['capture' => 'form-element', 'template' => 'form-element-textarea'], 'form-element-button' => ['capture' => 'form-element', 'template' => 'form-element-button']]]]], 'users-table' => ['template' => 'table', 'children' => ['table-head-rows' => ['template' => 'table-tr', 'data' => ['fromParent' => 'rows'], 'children' => ['table-th' => ['template' => 'table-th', 'capture' => 'table-td', 'data' => ['fromParent' => 'value']]], 'childrenDynamicLists' => ['table-th' => 'rows']], 'table-body-rows' => ['template' => 'table-tr', 'data' => ['fromParent' => 'rows'], 'children' => ['table-td' => ['template' => 'table-td', 'data' => ['fromParent' => 'value']]], 'childrenDynamicLists' => ['table-td' => 'rows']]], 'childrenDynamicLists' => ['table-body-rows' => 'bodyRows', 'table-head-rows' => 'headRows'], 'data' => ['static' => ['headRows' => [['Id', 'Name']], 'bodyRows' => [['1', 'John'], ['2', 'Helen']]]]]]], 'comments-list' => ['template' => 'comments-list', 'children' => ['comment' => ['viewModel' => \Sebaks\ViewTest\CommentViewModel::class, 'template' => 'comment', 'children' => ['user' => ['viewModel' => \Sebaks\ViewTest\UserViewModel::class, 'template' => 'user', 'data' => ['fromParent' => ['comment:userId' => 'userId'], 'static' => ['class' => 'user']]]], 'data' => ['fromParent' => ['comment' => 'comment']]]], 'childrenDynamicLists' => ['comment' => 'comments'], 'data' => ['fromGlobal' => 'comments']]];
        $data = ['comments' => [['id' => 'c1', 'userId' => 'u1', 'text' => 'text of c1'], ['id' => 'c2', 'userId' => 'u2', 'text' => 'text of c2']]];
        $serviceLocator = new \Zend\ServiceManager\ServiceManager();
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\CommentViewModel::class, \Sebaks\ViewTest\CommentViewModel::class, false);
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\UserViewModel::class, \Sebaks\ViewTest\UserViewModel::class, false);
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\MyselfViewModel::class, \Sebaks\ViewTest\MyselfViewModel::class, false);
        /////////////////////
        $config = new Config($viewConfig);
        $viewBuilder = new ViewBuilder($config, $serviceLocator);
        $pageViewModel = $viewBuilder->build($viewConfig['page'], $data);
        /////////////////////
        $view->render($pageViewModel);
        $result = $response->getBody();
        $expected = '<ul><li>text of c1
<div class="user">John</div></li><li>text of c2
<div class="user">Helen</div></li></ul>
<div class="">Me</div><form><textarea></textarea><button type="submit">Submit</button></form><table>
    <thead>
        <tr><th>Id</th><th>Name</th></tr>    </thead>
    <tbody>
        <tr><td>1</td><td>John</td></tr><tr><td>2</td><td>Helen</td></tr>    </tbody>
</table>';
        $this->assertEquals($expected, $result);
    }
Ejemplo n.º 18
0
 public function getView()
 {
     $view = new View();
     $view->addScriptPath(__DIR__ . '/../TestAsset/views/');
     return $view;
 }
Ejemplo n.º 19
0
 /**
  * @issue ZF-7722
  */
 public function testCharset()
 {
     $view = new View\View();
     $view->doctype('HTML5');
     $view->headMeta()->setCharset('utf-8');
     $this->assertEquals('<meta charset="utf-8">', $view->headMeta()->toString());
     $view->doctype('XHTML5');
     $this->assertEquals('<meta charset="utf-8"/>', $view->headMeta()->toString());
 }
Ejemplo n.º 20
0
 public function testRendersWithPartial()
 {
     $view = new View\View();
     $view->addBasePath(__DIR__ . '/_files');
     $view->addHelperPath(__DIR__ . '/../../../trunk/library/Zend/View/Helper', 'Zend\\View\\Helper');
     Helper\PaginationControl::setDefaultViewPartial('partial.phtml');
     $this->_paginator->setView($view);
     $string = $this->_paginator->__toString();
     $this->assertEquals('partial rendered successfully', $string);
 }
Ejemplo n.º 21
0
 /**
  * @param string | \Zend\View\Model\ViewModel | Mime\Part $body
  * @return $this
  */
 public function setBody($body, $charset = null)
 {
     $mimeMessage = new Mime\Message();
     $finalBody = null;
     if (is_string($body)) {
         // Create a Mime\Part and wrap it into a Mime\Message
         $mimePart = new Mime\Part($body);
         $mimePart->type = $body != strip_tags($body) ? Mime\Mime::TYPE_HTML : Mime\Mime::TYPE_TEXT;
         $mimePart->charset = $charset ?: self::DEFAULT_CHARSET;
         $mimeMessage->setParts([$mimePart]);
         $finalBody = $mimeMessage;
     } elseif ($body instanceof Mime\Part) {
         // Overwrite the charset if the Part object if provided
         if (isset($charset)) {
             $body->charset = $charset;
         }
         // The body is a Mime\Part. Wrap it into a Mime\Message
         $mimeMessage->setParts([$body]);
         $finalBody = $mimeMessage;
     } elseif ($body instanceof ViewModel) {
         $view = new View();
         $view->setResponse(new Response());
         $view->getEventManager()->attach(new PhpRendererStrategy($this->renderer));
         $view->render($body);
         $content = $view->getResponse()->getContent();
         $mimePart = new Mime\Part($content);
         $mimePart->type = Mime\Mime::TYPE_HTML;
         $mimePart->charset = $charset ?: self::DEFAULT_CHARSET;
         $mimeMessage->setParts([$mimePart]);
         $finalBody = $mimeMessage;
     } else {
         throw new InvalidArgumentException(sprintf('Provided body is not valid. It should be one of "%s". %s provided', implode('", "', ['string', 'Zend\\Mime\\Part', 'Zend\\Mime\\Message', 'Zend\\View\\Model\\ViewModel']), is_object($body) ? get_class($body) : gettype($body)));
     }
     // The headers Content-type and Content-transfer-encoding are duplicated every time the body is set.
     // Removing them before setting the body prevents this error
     $this->message->getHeaders()->removeHeader('contenttype');
     $this->message->getHeaders()->removeHeader('contenttransferencoding');
     $this->message->setBody($finalBody);
     return $this;
 }