mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +09:00
Add unit tests for path conversion utilities in Template class
This commit is contained in:
parent
325c2c2b13
commit
ca5c96d02a
2 changed files with 62 additions and 2 deletions
54
tests/unit/framework/TemplateTest.php
Normal file
54
tests/unit/framework/TemplateTest.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
class TemplateTest extends \Codeception\Test\Unit
|
||||
{
|
||||
public function _before()
|
||||
{
|
||||
Context::init();
|
||||
}
|
||||
|
||||
public function testIsRelativePath()
|
||||
{
|
||||
$tmpl = new \Rhymix\Framework\Template('./tests/_data/template', 'empty.html');
|
||||
|
||||
$this->assertTrue($tmpl->isRelativePath('foo.html'));
|
||||
$this->assertTrue($tmpl->isRelativePath('foo/bar.html'));
|
||||
$this->assertTrue($tmpl->isRelativePath('../foo/bar.html'));
|
||||
$this->assertTrue($tmpl->isRelativePath('foo/../bar.html'));
|
||||
$this->assertTrue($tmpl->isRelativePath('^/foo/../bar.html'));
|
||||
$this->assertFalse($tmpl->isRelativePath('/foo/bar.html'));
|
||||
$this->assertFalse($tmpl->isRelativePath('https://foo.com/bar.html'));
|
||||
$this->assertFalse($tmpl->isRelativePath('file:///C:/foo/bar.html'));
|
||||
$this->assertFalse($tmpl->isRelativePath('data:image/png;base64,AAAAAAAAAAA="'));
|
||||
$this->assertFalse($tmpl->isRelativePath('{$foo}'));
|
||||
}
|
||||
|
||||
public function testConvertPath()
|
||||
{
|
||||
$tmpl = new \Rhymix\Framework\Template('./tests/_data/template', 'empty.html');
|
||||
|
||||
$source = 'foo.html';
|
||||
$target = 'tests/_data/template/foo.html';
|
||||
$this->assertEquals($target, $tmpl->convertPath($source));
|
||||
|
||||
$source = 'foo/bar.js';
|
||||
$target = 'tests/_data/template/foo/bar.js';
|
||||
$this->assertEquals($target, $tmpl->convertPath($source));
|
||||
|
||||
$source = '../foo.scss';
|
||||
$target = 'tests/_data/foo.scss';
|
||||
$this->assertEquals($target, $tmpl->convertPath($source));
|
||||
|
||||
$source = '../../_output/foo/../bar.jpg';
|
||||
$target = 'tests/_output/bar.jpg';
|
||||
$this->assertEquals($target, $tmpl->convertPath($source));
|
||||
|
||||
$source = '/foo/bar.blade.php';
|
||||
$target = 'tests/_data/template/foo/bar.blade.php';
|
||||
$this->assertEquals($target, $tmpl->convertPath($source));
|
||||
|
||||
$source = '^/foo/bar.gif';
|
||||
$target = '/rhymix/foo/bar.gif';
|
||||
$this->assertEquals($target, $tmpl->convertPath($source));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue