mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Improve providers. Renders now use bulk checks via ::verify
This commit is contained in:
@ -55,6 +55,10 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
public function tpl($name, $code) {
|
||||
$dir = dirname($name);
|
||||
if($dir != "." && !is_dir(FENOM_RESOURCES.'/template/'.$dir)) {
|
||||
mkdir(FENOM_RESOURCES.'/template/'.$dir, 0777, true);
|
||||
}
|
||||
file_put_contents(FENOM_RESOURCES.'/template/'.$name, $code);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
namespace Fenom;
|
||||
use Fenom;
|
||||
use Fenom\TestCase;
|
||||
|
||||
class FSProviderTest extends \Fenom\TestCase {
|
||||
class ProviderTest extends TestCase {
|
||||
/**
|
||||
* @var Provider
|
||||
*/
|
||||
@ -12,15 +13,19 @@ class FSProviderTest extends \Fenom\TestCase {
|
||||
parent::setUp();
|
||||
$this->tpl("template1.tpl", 'Template 1 {$a}');
|
||||
$this->tpl("template2.tpl", 'Template 2 {$a}');
|
||||
$this->tpl("sub/template3.tpl", 'Template 3 {$a}');
|
||||
$this->provider = new Provider(FENOM_RESOURCES.'/template');
|
||||
clearstatcache();
|
||||
}
|
||||
|
||||
public function testIsTemplateExists() {
|
||||
clearstatcache();
|
||||
$this->assertTrue($this->provider->templateExists("template1.tpl"));
|
||||
$this->assertFalse($this->provider->templateExists("unexists.tpl"));
|
||||
}
|
||||
|
||||
public function testGetSource() {
|
||||
clearstatcache();
|
||||
$src = $this->provider->getSource("template1.tpl", $time);
|
||||
clearstatcache();
|
||||
$this->assertEquals(file_get_contents(FENOM_RESOURCES.'/template/template1.tpl'), $src);
|
||||
@ -47,21 +52,45 @@ class FSProviderTest extends \Fenom\TestCase {
|
||||
$this->provider->getLastModified("unexists.tpl");
|
||||
}
|
||||
|
||||
public function testGetLastModifiedBatch() {
|
||||
$times = $this->provider->getLastModifiedBatch($tpls = array("template1.tpl", "template2.tpl"));
|
||||
$this->assertSame($tpls, array_keys($times));
|
||||
public function testVerify() {
|
||||
$templates = array(
|
||||
"template1.tpl" => filemtime(FENOM_RESOURCES.'/template/template1.tpl'),
|
||||
"template2.tpl" => filemtime(FENOM_RESOURCES.'/template/template2.tpl')
|
||||
);
|
||||
clearstatcache();
|
||||
foreach($times as $template => $time) {
|
||||
$this->assertEquals(filemtime(FENOM_RESOURCES."/template/$template"), $time);
|
||||
}
|
||||
$this->assertTrue($this->provider->verify($templates));
|
||||
clearstatcache();
|
||||
$templates = array(
|
||||
"template2.tpl" => filemtime(FENOM_RESOURCES.'/template/template2.tpl'),
|
||||
"template1.tpl" => filemtime(FENOM_RESOURCES.'/template/template1.tpl')
|
||||
);
|
||||
clearstatcache();
|
||||
$this->assertTrue($this->provider->verify($templates));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGetLastModifiedBatchInvalid() {
|
||||
$this->provider->getLastModifiedBatch(array("template1.tpl", "unexists.tpl", "parent.tpl"));
|
||||
public function testVerifyInvalid() {
|
||||
$templates = array(
|
||||
"template1.tpl" => filemtime(FENOM_RESOURCES.'/template/template1.tpl'),
|
||||
"template2.tpl" => filemtime(FENOM_RESOURCES.'/template/template2.tpl') + 1
|
||||
);
|
||||
clearstatcache();
|
||||
$this->assertFalse($this->provider->verify($templates));
|
||||
clearstatcache();
|
||||
$templates = array(
|
||||
"template1.tpl" => filemtime(FENOM_RESOURCES.'/template/template1.tpl'),
|
||||
"unexists.tpl" => 1234567890
|
||||
);
|
||||
$this->assertFalse($this->provider->verify($templates));
|
||||
}
|
||||
|
||||
public function testGetAll() {
|
||||
$list = $this->provider->getList();
|
||||
sort($list);
|
||||
$this->assertSame(array(
|
||||
"sub/template3.tpl",
|
||||
"template1.tpl",
|
||||
"template2.tpl"
|
||||
), $list);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user