mirror of
https://github.com/Mibew/handlebars.php.git
synced 2024-11-15 00:34:12 +03:00
parent
b8119d4acd
commit
7e398d41d9
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
||||
vendor
|
||||
*.swp
|
||||
*.swo
|
||||
composer.phar
|
||||
composer.lock
|
||||
*.iml
|
||||
.idea
|
@ -3,6 +3,8 @@
|
||||
"description": "Handlebars processor for php",
|
||||
"homepage": "https://github.com/XaminProject/handlebars.php",
|
||||
"type": "library",
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
@ -14,8 +16,15 @@
|
||||
"email": "everplays@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {},
|
||||
"require": {
|
||||
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.8.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Handlebars": "src/" }
|
||||
"psr-0": {
|
||||
"Handlebars": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
phpunit.xml.dist
Normal file
15
phpunit.xml.dist
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit bootstrap="tests/bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Handlebars.php Test suite">
|
||||
<directory>tests/Xamin/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
116
tests/Xamin/HandlebarsTest.php
Normal file
116
tests/Xamin/HandlebarsTest.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class AutoloaderTest
|
||||
*/
|
||||
class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test handlebars autoloader
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutoLoad()
|
||||
{
|
||||
Handlebars\Autoloader::register(realpath(__DIR__ . '/../fixture/'));
|
||||
|
||||
$this->assertTrue(class_exists('Handlebars\\Test'));
|
||||
$this->assertTrue(class_exists('Handlebars\\Example\\Test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic tags
|
||||
*
|
||||
* @param string $src handlebars source
|
||||
* @param array $data data
|
||||
* @param string $result expected data
|
||||
*
|
||||
* @dataProvider simpleTagdataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBasicTags($src, $data, $result)
|
||||
{
|
||||
$loader = new \Handlebars\Loader\StringLoader();
|
||||
$engine = new \Handlebars\Handlebars(array('loader' => $loader));
|
||||
$this->assertEquals($result, $engine->render($src, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple tag provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function simpleTagdataProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{{! This is comment}}',
|
||||
array(),
|
||||
''
|
||||
),
|
||||
array(
|
||||
'{{data}}',
|
||||
array('data' => 'result'),
|
||||
'result'
|
||||
),
|
||||
array(
|
||||
'{{data.key}}',
|
||||
array('data' => array('key' => 'result')),
|
||||
'result'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test helpers (internal helpers)
|
||||
*
|
||||
* @param string $src handlebars source
|
||||
* @param array $data data
|
||||
* @param string $result expected data
|
||||
*
|
||||
* @dataProvider internalHelpersdataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSimpleHelpers($src, $data, $result)
|
||||
{
|
||||
$loader = new \Handlebars\Loader\StringLoader();
|
||||
$helpers = new \Handlebars\Helpers();
|
||||
$engine = new \Handlebars\Handlebars(array('loader' => $loader, 'helpers' => $helpers));
|
||||
|
||||
$this->assertEquals($result, $engine->render($src, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple helpers provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function internalHelpersdataProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'{{#if data}}Yes{{/if}}',
|
||||
array('data' => true),
|
||||
'Yes'
|
||||
),
|
||||
array(
|
||||
'{{#if data}}Yes{{/if}}',
|
||||
array('data' => false),
|
||||
''
|
||||
),
|
||||
array(
|
||||
'{{#with data}}{{key}}{{/with}}',
|
||||
array('data' => array('key' => 'result')),
|
||||
'result'
|
||||
),
|
||||
array(
|
||||
'{{#each data}}{{this}}{{/each}}',
|
||||
array('data' => array(1,2,3,4)),
|
||||
'1234'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
3
tests/bootstrap.php
Normal file
3
tests/bootstrap.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
$loader = include __DIR__ . "/../vendor/autoload.php";
|
10
tests/fixture/Handlebars/Example/Test.php
Normal file
10
tests/fixture/Handlebars/Example/Test.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Handlebars\Example;
|
||||
/**
|
||||
* Class Handlebars_Example_Class
|
||||
*/
|
||||
class Test
|
||||
{
|
||||
|
||||
}
|
11
tests/fixture/Handlebars/Test.php
Normal file
11
tests/fixture/Handlebars/Test.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Handlebars;
|
||||
/**
|
||||
* Class Handlebars_Class
|
||||
*/
|
||||
|
||||
class Test
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user