Ejemplo n.º 1
0
// ->isAbsolutePath()
$t->diag('->isAbsolutePath()');
$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);