fenom/tests/cases/Cytro/ProviderTest.php

68 lines
2.1 KiB
PHP
Raw Normal View History

2013-02-13 18:52:47 +04:00
<?php
2013-04-04 10:56:44 +04:00
namespace Cytro;
use Cytro;
2013-02-13 18:52:47 +04:00
2013-04-04 10:56:44 +04:00
class FSProviderTest extends \Cytro\TestCase {
2013-02-13 18:52:47 +04:00
/**
2013-02-21 22:51:24 +04:00
* @var FSProvider
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-04-04 10:56:44 +04:00
$this->provider = new FSProvider(CYTRO_RESOURCES.'/template');
2013-02-13 18:52:47 +04:00
}
public function testIsTemplateExists() {
$this->assertTrue($this->provider->isTemplateExists("template1.tpl"));
$this->assertFalse($this->provider->isTemplateExists("unexists.tpl"));
}
public function testGetSource() {
$src = $this->provider->getSource("template1.tpl", $time);
clearstatcache();
2013-04-04 10:56:44 +04:00
$this->assertEquals(file_get_contents(CYTRO_RESOURCES.'/template/template1.tpl'), $src);
$this->assertEquals(filemtime(CYTRO_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-04-04 10:56:44 +04:00
$this->assertEquals(filemtime(CYTRO_RESOURCES.'/template/template1.tpl'), $time);
2013-02-13 18:52:47 +04:00
}
/**
* @expectedException \RuntimeException
*/
public function testGetLastModifiedInvalid() {
$this->provider->getLastModified("unexists.tpl");
}
public function testGetLastModifiedBatch() {
2013-02-20 18:12:23 +04:00
$times = $this->provider->getLastModifiedBatch($tpls = array("template1.tpl", "template2.tpl"));
$this->assertSame($tpls, array_keys($times));
2013-02-13 18:52:47 +04:00
clearstatcache();
foreach($times as $template => $time) {
2013-04-04 10:56:44 +04:00
$this->assertEquals(filemtime(CYTRO_RESOURCES."/template/$template"), $time);
2013-02-13 18:52:47 +04:00
}
}
/**
* @expectedException \RuntimeException
*/
public function testGetLastModifiedBatchInvalid() {
$this->provider->getLastModifiedBatch(array("template1.tpl", "unexists.tpl", "parent.tpl"));
}
}