Esempio n. 1
0
 public function testStandardRender()
 {
     $view = new View();
     $view->setBasePath(__DIR__ . '/../');
     $view->setViewsDir('unit-tests/views/');
     $this->assertEquals($view->getViewsDir(), 'unit-tests/views/');
     //Standard Render
     $view->start();
     $view->render('test2', 'index');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>here</html>' . PHP_EOL);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     //Variables
     $view->setParamToView('a_cool_var', 'le-this');
     $view->start();
     $view->render('test3', 'another');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lol<p>le-this</p></html>' . PHP_EOL);
     //Templates
     $view->setTemplateAfter('test');
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>zuplolhere</html>' . PHP_EOL);
     $view->cleanTemplateAfter();
     //Render Levels
     $view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     $view->setRenderLevel(View::LEVEL_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'lolhere');
     $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'here');
     //Pick View
     $view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
     $view->start();
     $view->pick('test3/yup');
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolyup</html>' . PHP_EOL);
     //No Render
     $view->setRenderLevel(View::LEVEL_NO_RENDER);
     $view->start();
     $view->pick('test3/yup');
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '');
 }
Esempio n. 2
0
 /**
  * Tests the View::getActiveRenderPath
  *
  * @issue  12139
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2014-08-14
  */
 public function testGetActiveRenderPath()
 {
     $this->specify('The View::getActiveRenderPath returns unexpected result', function () {
         $view = new View();
         $eventsManager = new Manager();
         $eventsManager->attach('view', new ViewAfterRenderListener());
         $view->setViewsDir(PATH_DATA . 'views');
         $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
         $view->setEventsManager($eventsManager);
         expect($view->getActiveRenderPath())->equals('');
         $view->start();
         $view->render('test15', 'index');
         $view->finish();
         $view->getContent();
         expect($view->getActiveRenderPath())->equals(PATH_DATA . 'views' . DIRECTORY_SEPARATOR . 'test15' . DIRECTORY_SEPARATOR . 'index.phtml');
         $view->setViewsDir([PATH_DATA . 'views', PATH_DATA . 'views2']);
         expect($view->getActiveRenderPath())->equals([PATH_DATA . 'views' . DIRECTORY_SEPARATOR . 'test15' . DIRECTORY_SEPARATOR . 'index.phtml']);
     });
 }
Esempio n. 3
0
 protected function _getViewDisabled($level = null)
 {
     $view = new Phalcon\Mvc\View();
     $view->setViewsDir('unit-tests/views/');
     $view->setTemplateAfter('after');
     $view->setTemplateBefore('before');
     if ($level !== null) {
         $view->disableLevel($level);
     }
     $view->start();
     $view->render('test13', 'index');
     $view->finish();
     return $view;
 }
Esempio n. 4
0
 public function testIssue907()
 {
     $view = new View();
     $view->setBasePath(__DIR__ . '/../');
     $view->setViewsDir('unit-tests/views/');
     $listener = new \ViewAfterRenderListener();
     $eventsManager = new \Phalcon\Events\Manager();
     $eventsManager->attach('view', $listener);
     $view->setEventsManager($eventsManager);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     $this->assertEquals('1,3,6', $listener->getLevels());
     $listener->reset();
     //Templates
     $view->setTemplateAfter('test');
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>zuplolhere</html>' . PHP_EOL);
     $this->assertEquals('1,3,5,6', $listener->getLevels());
     $listener->reset();
     $view->cleanTemplateAfter();
     //Render Levels
     $view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), '<html>lolhere</html>' . PHP_EOL);
     $this->assertEquals('1,3,6', $listener->getLevels());
     $listener->reset();
     $view->setRenderLevel(View::LEVEL_LAYOUT);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'lolhere');
     $this->assertEquals('1,3', $listener->getLevels());
     $listener->reset();
     $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     $view->start();
     $view->render('test3', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), 'here');
     $this->assertEquals('1', $listener->getLevels());
     $listener->reset();
 }
Esempio n. 5
0
 public function testViewOptions()
 {
     $config = array('cache' => array('service' => 'otherCache'));
     $date = date("r");
     $content = '<html>' . $date . '</html>' . PHP_EOL;
     $di = $this->_getDi('otherCache');
     $view = new View($config);
     $view->setDI($di);
     $view->setViewsDir('unit-tests/views/');
     $view->setVar("date", $date);
     $view->start();
     $view->cache(true);
     $view->render('test8', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), $content);
     $view->reset();
     sleep(1);
     $view->setVar("date", date("r"));
     $view->start();
     $view->cache(true);
     $view->render('test8', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), $content);
 }
Esempio n. 6
0
    public function testVoltMacrosIssue11771()
    {
        $this->specify("Volt macros can't accept objects", function () {
            $this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
            Di::reset();
            $view = new View();
            $di = new Di();
            $di->set('escaper', function () {
                return new Escaper();
            });
            $di->set('tag', function () {
                return new Tag();
            });
            $di->set('url', function () {
                return (new Url())->setBaseUri('/');
            });
            $view->setDI($di);
            $view->setViewsDir(PATH_DATA . 'views/');
            $view->registerEngines(array('.volt' => function ($view, $di) {
                return new Volt($view, $di);
            }));
            $object = new \stdClass();
            $object->foo = "bar";
            $object->baz = "buz";
            $object->pi = 3.14;
            $object->ary = ["some array"];
            $object->obj = clone $object;
            $view->setVar('object', $object);
            $view->start();
            $view->render('macro', 'list');
            $view->finish();
            ob_start();
            var_dump($object);
            $actual = ob_get_clean();
            // Trim xdebug first line (file path)
            $actual = substr($actual, strpos($actual, 'class'));
            $expected = substr($view->getContent(), strpos($view->getContent(), 'class'));
            expect($actual)->equals($expected);
            $form = new Form();
            $form->add(new Password('password'));
            $view->setVar('formLogin', $form);
            $view->start();
            $view->render('macro', 'form_row');
            $view->finish();
            $actual = <<<FORM
<div class="form-group">
    <label class="col-sm-2 control-label" for="password">password:</label>
    <div class="col-sm-6"><input type="password" id="password" name="password" class="form-control " /></div>
</div>
FORM;
            expect($actual)->equals($view->getContent());
            $this->removeFiles([PATH_DATA . 'views/macro/list.volt.php', PATH_DATA . 'views/macro/form_row.volt.php']);
        });
    }
Esempio n. 7
0
 public function testVoltEngineBuiltInFunctions()
 {
     @unlink('unit-tests/views/test11/index.volt.php');
     $di = new Phalcon\DI();
     $view = new Phalcon\Mvc\View();
     $view->setDI($di);
     $view->setViewsDir('unit-tests/views/');
     $view->registerEngines(array('.volt' => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
     $view->setVar('arr', array(1, 2, 3, 4));
     $view->setVar('obj', new SomeObject(array(1, 2, 3, 4)));
     $view->setVar('str', 'hello');
     $view->setVar('no_str', 1234);
     $view->start();
     $view->render('test11', 'index');
     $view->finish();
     $this->assertEquals($view->getContent(), 'Length Array: 4Length Object: 4Length String: 5Length No String: 4Slice Array: 1,2,3,4Slice Array: 2,3Slice Array: 1,2,3Slice Object: 2,3,4Slice Object: 2,3Slice Object: 1,2Slice String: helSlice String: elSlice String: lloSlice No String: 123Slice No String: 23Slice No String: 34');
 }
Esempio n. 8
0
 public function testViewOptions()
 {
     $this->specify("Views are not cached properly when passing options to the constructor", function () {
         $this->_clearCache();
         $config = array('cache' => array('service' => 'otherCache'));
         $date = date("r");
         $content = '<html>' . $date . '</html>' . PHP_EOL;
         $di = $this->_getDi('otherCache');
         $view = new View($config);
         $view->setDI($di);
         $view->setViewsDir(PATH_DATA . 'views' . DIRECTORY_SEPARATOR);
         $view->setVar("date", $date);
         $view->start();
         $view->cache(true);
         $view->render('test8', 'other');
         $view->finish();
         expect($view->getContent())->equals($content);
         $view->reset();
         sleep(1);
         $view->setVar("date", date("r"));
         $view->start();
         $view->cache(true);
         $view->render('test8', 'other');
         $view->finish();
         expect($view->getContent())->equals($content);
     });
 }