public function testLoad()
    {
        $pathPattern = self::$fixturesPath.'/templates/%name%';
        $path = self::$fixturesPath.'/templates';
        $loader = new ProjectTemplateLoader2($pathPattern);
        $storage = $loader->load(new TemplateReference($path.'/foo.php', 'php'));
        $this->assertInstanceOf('Symfony\Component\Templating\Storage\FileStorage', $storage, '->load() returns a FileStorage if you pass an absolute path');
        $this->assertEquals($path.'/foo.php', (string) $storage, '->load() returns a FileStorage pointing to the passed absolute path');

        $this->assertFalse($loader->load(new TemplateReference('bar', 'php')), '->load() returns false if the template is not found');

        $storage = $loader->load(new TemplateReference('foo.php', 'php'));
        $this->assertInstanceOf('Symfony\Component\Templating\Storage\FileStorage', $storage, '->load() returns a FileStorage if you pass a relative template that exists');
        $this->assertEquals($path.'/foo.php', (string) $storage, '->load() returns a FileStorage pointing to the absolute path of the template');

        $loader = new ProjectTemplateLoader2($pathPattern);
        $loader->setDebugger($debugger = new \ProjectTemplateDebugger());
        $this->assertFalse($loader->load(new TemplateReference('foo.xml', 'php')), '->load() returns false if the template does not exists for the given engine');
        $this->assertTrue($debugger->hasMessage('Failed loading template'), '->load() logs a "Failed loading template" message if the template is not found');

        $loader = new ProjectTemplateLoader2(array(self::$fixturesPath.'/null/%name%', $pathPattern));
        $loader->setDebugger($debugger = new \ProjectTemplateDebugger());
        $loader->load(new TemplateReference('foo.php', 'php'));
        $this->assertTrue($debugger->hasMessage('Loaded template file'), '->load() logs a "Loaded template file" message if the template is found');
    }
Beispiel #2
0
 public function testLoad()
 {
     $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . rand(111111, 999999);
     mkdir($dir, 0777, true);
     $loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), $dir);
     $loader->setDebugger($debugger = new \ProjectTemplateDebugger());
     $this->assertFalse($loader->load('foo'), '->load() returns false if the embed loader is not able to load the template');
     $loader->load('index');
     $this->assertTrue($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
     $loader->load('index');
     $this->assertTrue($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');
 }
 public function testLoad()
 {
     $pathPattern = self::$fixturesPath . '/templates/%name%.%renderer%';
     $path = self::$fixturesPath . '/templates';
     $loader = new ProjectTemplateLoader2($pathPattern);
     $storage = $loader->load($path . '/foo.php');
     $this->assertTrue($storage instanceof FileStorage, '->load() returns a FileStorage if you pass an absolute path');
     $this->assertEquals((string) $storage, $path . '/foo.php', '->load() returns a FileStorage pointing to the passed absolute path');
     $this->assertTrue($loader->load('bar') === false, '->load() returns false if the template is not found');
     $storage = $loader->load('foo');
     $this->assertTrue($storage instanceof FileStorage, '->load() returns a FileStorage if you pass a relative template that exists');
     $this->assertEquals((string) $storage, $path . '/foo.php', '->load() returns a FileStorage pointing to the absolute path of the template');
     $loader = new ProjectTemplateLoader2($pathPattern);
     $loader->setDebugger($debugger = new \ProjectTemplateDebugger());
     $this->assertTrue($loader->load('foo', array('renderer' => 'xml')) === false, '->load() returns false if the template does not exists for the given renderer');
     $this->assertTrue($debugger->hasMessage('Failed loading template'), '->load() logs a "Failed loading template" message if the template is not found');
     $loader = new ProjectTemplateLoader2(array(self::$fixturesPath . '/null/%name%', $pathPattern));
     $loader->setDebugger($debugger = new \ProjectTemplateDebugger());
     $loader->load('foo');
     $this->assertTrue($debugger->hasMessage('Loaded template file'), '->load() logs a "Loaded template file" message if the template is found');
 }
 public function testLoad()
 {
     $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . rand(111111, 999999);
     mkdir($dir, 0777, true);
     $loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), $dir);
     $loader->setDebugger($debugger = new \ProjectTemplateDebugger());
     $this->assertFalse($loader->load('foo'), '->load() returns false if the embed loader is not able to load the template');
     $loader->load('index');
     $this->assertTrue($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
     $loader->load('index');
     $this->assertTrue($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');
     // load() template compilation
     $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . rand(111111, 999999);
     mkdir($dir, 0777, true);
     $loader = new ProjectTemplateLoader(new CompilableTemplateLoader(), $dir);
     $loader->setDebugger($debugger = new \ProjectTemplateDebugger());
     $template = $loader->load('special', array('renderer' => 'comp'));
     $this->assertTrue($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
     $this->assertEquals('php', $template->getRenderer(), '->load() changes the renderer to php if the template is compilable');
     $template = $loader->load('special', array('renderer' => 'comp'));
     $this->assertTrue($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');
     $this->assertEquals('php', $template->getRenderer(), '->load() changes the renderer to php if the template is compilable');
 }
$t->diag('__construct()');
$pathPattern = $fixturesPath.'/templates/%name%.%renderer%';
$path = $fixturesPath.'/templates';
$loader = new ProjectTemplateLoader($pathPattern);
$t->is($loader->getTemplatePathPatterns(), array($pathPattern), '__construct() takes a path as its second argument');
$loader = new ProjectTemplateLoader(array($pathPattern));
$t->is($loader->getTemplatePathPatterns(), array($pathPattern), '__construct() takes an array of paths as its second argument');

// ->load()
$t->diag('->load()');
$loader = new ProjectTemplateLoader($pathPattern);
$storage = $loader->load($path.'/foo.php');
$t->ok($storage instanceof FileStorage, '->load() returns a FileStorage if you pass an absolute path');
$t->is((string) $storage, $path.'/foo.php', '->load() returns a FileStorage pointing to the passed absolute path');

$t->ok($loader->load('bar') === false, '->load() returns false if the template is not found');

$storage = $loader->load('foo');
$t->ok($storage instanceof FileStorage, '->load() returns a FileStorage if you pass a relative template that exists');
$t->is((string) $storage, $path.'/foo.php', '->load() returns a FileStorage pointing to the absolute path of the template');

$loader = new ProjectTemplateLoader($pathPattern);
$loader->setDebugger($debugger = new ProjectTemplateDebugger());
$t->ok($loader->load('foo', array('renderer' => 'xml')) === false, '->load() returns false if the template does not exists for the given renderer');
$t->ok($debugger->hasMessage('Failed loading template'), '->load() logs a "Failed loading template" message if the template is not found');

$loader = new ProjectTemplateLoader(array($fixturesPath.'/null/%name%', $pathPattern));
$loader->setDebugger($debugger = new ProjectTemplateDebugger());
$loader->load('foo');
$t->ok($debugger->hasMessage('Loaded template file'), '->load() logs a "Loaded template file" message if the template is found');
$t->ok($loader->getLoader() === $varLoader, '__construct() takes a template loader as its first argument');
$t->is($loader->getDir(), sys_get_temp_dir(), '__construct() takes a directory where to store the cache as its second argument');

// ->load()
$t->diag('->load()');

$dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.rand(111111, 999999);
mkdir($dir, 0777, true);

$loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), $dir);
$loader->setDebugger($debugger = new ProjectTemplateDebugger());
$t->ok($loader->load('foo') === false, '->load() returns false if the embed loader is not able to load the template');
$loader->load('index');
$t->ok($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
$loader->load('index');
$t->ok($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');

$t->diag('load() template compilation');
$dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.rand(111111, 999999);
mkdir($dir, 0777, true);

$loader = new ProjectTemplateLoader(new CompilableTemplateLoader(), $dir);
$loader->setDebugger($debugger = new ProjectTemplateDebugger());
$template = $loader->load('special', array('renderer' => 'comp'));
$t->ok($debugger->hasMessage('Storing template'), '->load() logs a "Storing template" message if the template is found');
$t->is($template->getRenderer(), 'php', '->load() changes the renderer to php if the template is compilable');

$template = $loader->load('special', array('renderer' => 'comp'));
$t->ok($debugger->hasMessage('Fetching template'), '->load() logs a "Storing template" message if the template is fetched from cache');
$t->is($template->getRenderer(), 'php', '->load() changes the renderer to php if the template is compilable');
$t->ok(ProjectTemplateLoader::isAbsolutePath('/foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
$t->ok(ProjectTemplateLoader::isAbsolutePath('c:\\\\foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
$t->ok(ProjectTemplateLoader::isAbsolutePath('c:/foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
$t->ok(ProjectTemplateLoader::isAbsolutePath('\\server\\foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
// __construct()
$t->diag('__construct()');
$pathPattern = $fixturesPath . '/templates/%name%.%renderer%';
$path = $fixturesPath . '/templates';
$loader = new ProjectTemplateLoader($pathPattern);
$t->is($loader->getTemplatePathPatterns(), array($pathPattern), '__construct() takes a path as its second argument');
$loader = new ProjectTemplateLoader(array($pathPattern));
$t->is($loader->getTemplatePathPatterns(), array($pathPattern), '__construct() takes an array of paths as its second argument');
// ->load()
$t->diag('->load()');
$loader = new ProjectTemplateLoader($pathPattern);
$storage = $loader->load($path . '/foo.php');
$t->ok($storage instanceof FileStorage, '->load() returns a FileStorage if you pass an absolute path');
$t->is((string) $storage, $path . '/foo.php', '->load() returns a FileStorage pointing to the passed absolute path');
$t->ok($loader->load('bar') === false, '->load() returns false if the template is not found');
$storage = $loader->load('foo');
$t->ok($storage instanceof FileStorage, '->load() returns a FileStorage if you pass a relative template that exists');
$t->is((string) $storage, $path . '/foo.php', '->load() returns a FileStorage pointing to the absolute path of the template');
$loader = new ProjectTemplateLoader($pathPattern);
$loader->setDebugger($debugger = new ProjectTemplateDebugger());
$t->ok($loader->load('foo', 'xml') === false, '->load() returns false if the template does not exists for the given renderer');
$t->ok($debugger->hasMessage('Failed loading template'), '->load() logs a "Failed loading template" message if the template is not found');
$loader = new ProjectTemplateLoader(array($fixturesPath . '/null/%name%', $pathPattern));
$loader->setDebugger($debugger = new ProjectTemplateDebugger());
$loader->load('foo');
$t->ok($debugger->hasMessage('Failed loading template'), '->load() logs a "Failed loading template" message if the template is not found');
$t->ok($debugger->hasMessage('Loaded template file'), '->load() logs a "Loaded template file" message if the template is found');