2013-02-13 18:52:47 +04:00
|
|
|
<?php
|
2013-06-28 11:53:53 +04:00
|
|
|
namespace Fenom;
|
|
|
|
use Fenom;
|
2013-07-13 12:00:19 +04:00
|
|
|
use Fenom\TestCase;
|
2013-02-13 18:52:47 +04:00
|
|
|
|
2013-07-13 12:00:19 +04:00
|
|
|
class ProviderTest extends TestCase {
|
2013-02-13 18:52:47 +04:00
|
|
|
/**
|
2013-06-28 11:53:53 +04:00
|
|
|
* @var Provider
|
2013-02-13 18:52:47 +04:00
|
|
|
*/
|
|
|
|
public $provider;
|
|
|
|
|
|
|
|
public function setUp() {
|
2013-02-20 18:12:23 +04:00
|
|
|
parent::setUp();
|
|
|
|
$this->tpl("template1.tpl", 'Template 1 {$a}');
|
|
|
|
$this->tpl("template2.tpl", 'Template 2 {$a}');
|
2013-07-13 12:00:19 +04:00
|
|
|
$this->tpl("sub/template3.tpl", 'Template 3 {$a}');
|
2013-06-28 11:53:53 +04:00
|
|
|
$this->provider = new Provider(FENOM_RESOURCES.'/template');
|
2013-07-13 12:00:19 +04:00
|
|
|
clearstatcache();
|
2013-02-13 18:52:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsTemplateExists() {
|
2013-07-13 12:00:19 +04:00
|
|
|
clearstatcache();
|
2013-07-04 01:28:10 +04:00
|
|
|
$this->assertTrue($this->provider->templateExists("template1.tpl"));
|
|
|
|
$this->assertFalse($this->provider->templateExists("unexists.tpl"));
|
2013-02-13 18:52:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSource() {
|
2013-07-13 12:00:19 +04:00
|
|
|
clearstatcache();
|
2013-02-13 18:52:47 +04:00
|
|
|
$src = $this->provider->getSource("template1.tpl", $time);
|
|
|
|
clearstatcache();
|
2013-06-28 11:53:53 +04:00
|
|
|
$this->assertEquals(file_get_contents(FENOM_RESOURCES.'/template/template1.tpl'), $src);
|
|
|
|
$this->assertEquals(filemtime(FENOM_RESOURCES.'/template/template1.tpl'), $time);
|
2013-02-13 18:52:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \RuntimeException
|
|
|
|
*/
|
|
|
|
public function testGetSourceInvalid() {
|
|
|
|
$this->provider->getSource("unexists.tpl", $time);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLastModified() {
|
|
|
|
$time = $this->provider->getLastModified("template1.tpl");
|
|
|
|
clearstatcache();
|
2013-06-28 11:53:53 +04:00
|
|
|
$this->assertEquals(filemtime(FENOM_RESOURCES.'/template/template1.tpl'), $time);
|
2013-02-13 18:52:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \RuntimeException
|
|
|
|
*/
|
|
|
|
public function testGetLastModifiedInvalid() {
|
|
|
|
$this->provider->getLastModified("unexists.tpl");
|
|
|
|
}
|
|
|
|
|
2013-07-13 12:00:19 +04:00
|
|
|
public function testVerify() {
|
|
|
|
$templates = array(
|
|
|
|
"template1.tpl" => filemtime(FENOM_RESOURCES.'/template/template1.tpl'),
|
|
|
|
"template2.tpl" => filemtime(FENOM_RESOURCES.'/template/template2.tpl')
|
|
|
|
);
|
2013-02-13 18:52:47 +04:00
|
|
|
clearstatcache();
|
2013-07-13 12:00:19 +04:00
|
|
|
$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));
|
2013-02-13 18:52:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-13 12:00:19 +04:00
|
|
|
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));
|
|
|
|
}
|
2013-02-13 18:52:47 +04:00
|
|
|
|
2013-07-13 12:00:19 +04:00
|
|
|
public function testGetAll() {
|
|
|
|
$list = $this->provider->getList();
|
|
|
|
sort($list);
|
|
|
|
$this->assertSame(array(
|
|
|
|
"sub/template3.tpl",
|
|
|
|
"template1.tpl",
|
|
|
|
"template2.tpl"
|
|
|
|
), $list);
|
2013-02-13 18:52:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|