fenom/tests/cases/Fenom/ProviderTest.php

124 lines
3.9 KiB
PHP
Raw Permalink Normal View History

2013-02-13 18:52:47 +04:00
<?php
2013-06-28 11:53:53 +04:00
namespace Fenom;
2014-02-27 16:30:44 +04:00
2013-06-28 11:53:53 +04:00
use Fenom;
use Fenom\TestCase;
2013-02-13 18:52:47 +04:00
2013-07-29 14:58:14 +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;
2013-07-29 14:58:14 +04:00
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}');
$this->tpl("sub/template3.tpl", 'Template 3 {$a}');
2013-07-29 14:58:14 +04:00
$this->provider = new Provider(FENOM_RESOURCES . '/template');
clearstatcache();
2013-02-13 18:52:47 +04:00
}
2013-07-29 14:58:14 +04:00
public function testIsTemplateExists()
{
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
}
2013-07-29 14:58:14 +04:00
public function testGetSource()
{
clearstatcache();
2013-02-13 18:52:47 +04:00
$src = $this->provider->getSource("template1.tpl", $time);
clearstatcache();
2013-07-29 14:58:14 +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
*/
2013-07-29 14:58:14 +04:00
public function testGetSourceInvalid()
{
2013-02-13 18:52:47 +04:00
$this->provider->getSource("unexists.tpl", $time);
}
2013-07-29 14:58:14 +04:00
public function testGetLastModified()
{
2013-02-13 18:52:47 +04:00
$time = $this->provider->getLastModified("template1.tpl");
clearstatcache();
2013-07-29 14:58:14 +04:00
$this->assertEquals(filemtime(FENOM_RESOURCES . '/template/template1.tpl'), $time);
2013-02-13 18:52:47 +04:00
}
/**
* @expectedException \RuntimeException
*/
2013-07-29 14:58:14 +04:00
public function testGetLastModifiedInvalid()
{
2013-02-13 18:52:47 +04:00
$this->provider->getLastModified("unexists.tpl");
}
2013-07-29 14:58:14 +04:00
public function testVerify()
{
$templates = array(
2013-07-29 14:58:14 +04:00
"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();
$this->assertTrue($this->provider->verify($templates));
clearstatcache();
$templates = array(
2013-07-29 14:58:14 +04:00
"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-29 14:58:14 +04:00
public function testVerifyInvalid()
{
$templates = array(
2013-07-29 14:58:14 +04:00
"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(
2013-07-29 14:58:14 +04:00
"template1.tpl" => filemtime(FENOM_RESOURCES . '/template/template1.tpl'),
2014-05-06 14:22:58 +04:00
"unexists.tpl" => 1234567890
);
$this->assertFalse($this->provider->verify($templates));
}
2013-02-13 18:52:47 +04:00
2013-07-29 14:58:14 +04:00
public function testGetAll()
{
$list = $this->provider->getList();
sort($list);
2014-05-06 14:22:58 +04:00
$this->assertSame(
array(
"sub/template3.tpl",
"template1.tpl",
"template2.tpl"
),
$list
);
2013-02-13 18:52:47 +04:00
}
2013-09-19 23:10:19 +04:00
2014-02-27 16:30:44 +04:00
public function testRm()
{
2013-09-19 23:10:19 +04:00
$this->assertTrue(is_dir(FENOM_RESOURCES . '/template/sub'));
Provider::rm(FENOM_RESOURCES . '/template/sub');
$this->assertFalse(is_dir(FENOM_RESOURCES . '/template/sub'));
$this->assertTrue(is_file(FENOM_RESOURCES . '/template/template1.tpl'));
Provider::rm(FENOM_RESOURCES . '/template/template1.tpl');
$this->assertFalse(is_file(FENOM_RESOURCES . '/template/template1.tpl'));
$this->assertTrue(is_file(FENOM_RESOURCES . '/template/template2.tpl'));
Provider::clean(FENOM_RESOURCES . '/template/');
$this->assertFalse(is_file(FENOM_RESOURCES . '/template/template2.tpl'));
}
2013-02-13 18:52:47 +04:00
}