From 7e398d41d9bc95908bf610c772d2252f79ad51f0 Mon Sep 17 00:00:00 2001 From: fzerorubigd Date: Thu, 7 Nov 2013 21:47:57 +0330 Subject: [PATCH] Add some test, need more test :) just for start address #22 --- .gitignore | 4 + composer.json | 15 ++- phpunit.xml.dist | 15 +++ tests/Xamin/HandlebarsTest.php | 116 ++++++++++++++++++++++ tests/bootstrap.php | 3 + tests/fixture/Handlebars/Example/Test.php | 10 ++ tests/fixture/Handlebars/Test.php | 11 ++ 7 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 phpunit.xml.dist create mode 100644 tests/Xamin/HandlebarsTest.php create mode 100644 tests/bootstrap.php create mode 100644 tests/fixture/Handlebars/Example/Test.php create mode 100644 tests/fixture/Handlebars/Test.php diff --git a/.gitignore b/.gitignore index ce8c145..fbc0d5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ vendor *.swp *.swo +composer.phar +composer.lock +*.iml +.idea \ No newline at end of file diff --git a/composer.json b/composer.json index 855d4fe..4232c6a 100644 --- a/composer.json +++ b/composer.json @@ -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/" + } } -} \ No newline at end of file +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..b2a2929 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,15 @@ + + + + + + tests/Xamin/ + + + + + + src/ + + + diff --git a/tests/Xamin/HandlebarsTest.php b/tests/Xamin/HandlebarsTest.php new file mode 100644 index 0000000..f6ad30b --- /dev/null +++ b/tests/Xamin/HandlebarsTest.php @@ -0,0 +1,116 @@ +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' + ), + ); + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..49c8ad4 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,3 @@ +