Permalink
Browse files

Adding smarty templates/config.

  • Loading branch information...
1 parent 1703fb8 commit c99418035318474046b4bf5bf8f7799960d17cfa josterholt committed Dec 10, 2011
Showing with 121 additions and 5 deletions.
  1. +4 −0 application/views/scripts/dummy/test.tpl
  2. +30 −5 test/bootstrap.php
  3. +87 −0 test/smartyTest.php
View
4 application/views/scripts/dummy/test.tpl
@@ -0,0 +1,4 @@
+{$article->title}
+{$article->author} | {$article->date|date_format:"%D"}
+{$article->body}
+{$article->author->title}
View
35 test/bootstrap.php
@@ -11,18 +11,43 @@
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
+ realpath(APPLICATION_PATH . '/../library/Smarty'),
+ realpath(APPLICATION_PATH . '/../library/Smarty/plugins'),
+ realpath(APPLICATION_PATH . '/../library/Smarty/sysplugins'),
realpath(APPLICATION_PATH . '/controllers'),
realpath(APPLICATION_PATH . '/models'),
get_include_path()
)));
+
+define('SMARTY_DIR', APPLICATION_PATH.'/../library/Smarty/');
+
/*
- * Not sure how Zend loader works in this environment (being outside of Zend framework).
+ * Not sure how Zend loader works in this environment (being outside of Zend framework).
* I'm creating a custom loader until Zend loader can be configured to load needed classes.
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
- *
+ *
*/
-function autoloader($class) {
- require_once $class.".php";
+function autoloader($class)
+{
+ foreach (explode(PATH_SEPARATOR, get_include_path()) as $path)
+ {
+ $className = $class.".php";
+ //echo realpath($path.DIRECTORY_SEPARATOR.$className)."\n";
+
+ if (file_exists($path.DIRECTORY_SEPARATOR.$className))
+ {
+ require_once($path.DIRECTORY_SEPARATOR.$className);
+ }
+
+ if (file_exists($path.DIRECTORY_SEPARATOR.strtolower($className)))
+ {
+ require_once($path.DIRECTORY_SEPARATOR.strtolower($className));
+ }
+ }
+ if (!class_exists($class))
+ {
+ require "class.$class.php";
+ }
}
-spl_autoload_register("autoloader");
+spl_autoload_register("autoloader");
View
87 test/smartyTest.php
@@ -0,0 +1,87 @@
+<?php
+
+require_once "Smarty/Smarty.class.php";
+GLOBAL $MOCK_OBJECTS;
+$MOCK_OBJECTS = array();
+function print_call_stack() {
+ $debug = debug_backtrace();
+ array_shift($debug);
+ foreach ($debug as $d) {
+ if (stripos($d['file'], "PHPUnit") === false)
+ {
+ echo "File: ".$d['file']."\n";
+ echo "Function: ".$d['function']."\n";
+ echo "Line: ".$d['line']."\n";
+ }
+
+ }
+}
+class DynamicField {
+
+ protected $value;
+
+ public function __construct($value) {
+ $this->value = $value;
+ }
+
+ public function __toString() {
+ return (string) $this->value;
+ }
+
+}
+
+class Article {
+
+ protected $title;
+ protected $author;
+ protected $date;
+ protected $body;
+
+ public function __set($key, $value) {
+ $this->$key = new DynamicField($value);
+ }
+
+ public function __get($key) {
+ echo "Accessed $key\n";
+ return $this->$key;
+ }
+
+ public function __toString() {
+ return "bar";
+ }
+
+}
+
+class smartyTest extends PHPUnit_Framework_TestCase {
+
+ function testSmarty() {
+ GLOBAL $MOCK_OBJECTS;
+ $smarty = new Smarty();
+ $smarty->setTemplateDir(APPLICATION_PATH . '/views/scripts/dummy/');
+ $smarty->setCompileDir(APPLICATION_PATH . '/views/templates_c/');
+ $smarty->setConfigDir(APPLICATION_PATH . '/configs/');
+ $smarty->setCacheDir(APPLICATION_PATH . '/views/cache/');
+ $smarty->caching = false;
+
+ $article = new Article();
+ $article->title = "Test Foo";
+ $article->author = "Author";
+ $article->date = strtotime("NOW");
+ $article->body = "Test Body";
+
+ //$foo = $article->author;
+ //echo $foo;
+
+ $smarty->assign("article", $article);
+
+ $template = $smarty->createTemplate('test.tpl');
+ $tags = $smarty->getTags($template);
+ //var_dump($tags);
+
+ print_r($MOCK_OBJECTS);
+
+
+ //$content = $smarty->fetch("test.tpl");
+ }
+
+}

0 comments on commit c994180

Please sign in to comment.