From e37c8468eba845430e5461b58098f250886bb21a Mon Sep 17 00:00:00 2001 From: bzick Date: Tue, 23 Jul 2013 11:32:31 +0400 Subject: [PATCH] Update docs and add tests --- CHANGELOG.md | 1 + docs/ext/extenstions.md | 5 +++++ docs/readme.md | 1 + src/Fenom.php | 12 +++++++----- tests/cases/FenomTest.php | 36 ++++++++++++++++++++++++++++++------ 5 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 docs/ext/extenstions.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 45e4b3b..d3a9d83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ CHANGELOG - Internal optimization - Add options for benchmark - Add stress test (thanks to @klkvsk) +- Bugs-- - Comments++ - Docs++ - Test++ diff --git a/docs/ext/extenstions.md b/docs/ext/extenstions.md new file mode 100644 index 0000000..9374920 --- /dev/null +++ b/docs/ext/extenstions.md @@ -0,0 +1,5 @@ +Extensions +========== + +* [Extra pack](https://github.com/bzick/fenom-extra) basic add-ons for web-base project. +* *Smarty pack* (planned) Smarty3 adapter \ No newline at end of file diff --git a/docs/readme.md b/docs/readme.md index 08c4425..cda38db 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -56,6 +56,7 @@ Documentation ### Extends +* [Extensions](./ext/extensions.md) * [Add tags](./ext/tags.md) * [Add modificators](./ext/mods.md) * [Add template provider](./ext/provider.md) diff --git a/src/Fenom.php b/src/Fenom.php index 4334b33..9a04cdf 100644 --- a/src/Fenom.php +++ b/src/Fenom.php @@ -35,7 +35,7 @@ class Fenom { const DISABLE_CACHE = 0x400; const FORCE_VERIFY = 0x800; // reserved const AUTO_TRIM = 0x1000; // reserved - const DENY_STATIC_METHODS = 0x2000; // reserved + const DENY_STATICS = 0x2000; // reserved /* Default parsers */ const DEFAULT_CLOSE_COMPILER = 'Fenom\Compiler::stdClose'; @@ -48,7 +48,7 @@ class Fenom { * @var int[] of possible options, as associative array * @see setOptions */ - private static $_option_list = array( + private static $_options_list = array( "disable_methods" => self::DENY_METHODS, "disable_native_funcs" => self::DENY_INLINE_FUNCS, "disable_cache" => self::DISABLE_CACHE, @@ -56,7 +56,9 @@ class Fenom { "auto_reload" => self::AUTO_RELOAD, "force_include" => self::FORCE_INCLUDE, "auto_escape" => self::AUTO_ESCAPE, - "force_verify" => self::FORCE_VERIFY + "force_verify" => self::FORCE_VERIFY, + "auto_trim" => self::AUTO_TRIM, + "disable_statics" => self::DENY_STATICS, ); /** @@ -530,7 +532,7 @@ class Fenom { */ public function setOptions($options) { if(is_array($options)) { - $options = self::_makeMask($options, self::$_option_list); + $options = self::_makeMask($options, self::$_options_list, $this->_options); } $this->_storage = array(); $this->_options = $options; @@ -742,7 +744,7 @@ class Fenom { * @throws \RuntimeException if key from custom assoc doesn't exists into possible values */ private static function _makeMask(array $values, array $options, $mask = 0) { - foreach ($values as $key=>$value) { + foreach ($values as $key => $value) { if (isset($options[$key])) { if ($options[$key]) { $mask |= $options[$key]; diff --git a/tests/cases/FenomTest.php b/tests/cases/FenomTest.php index b4b61e6..8131885 100644 --- a/tests/cases/FenomTest.php +++ b/tests/cases/FenomTest.php @@ -5,6 +5,19 @@ use Fenom\Render, class FenomTest extends \Fenom\TestCase { + public static function providerOptions() { + return array( + array("disable_methods", Fenom::DENY_METHODS), + array("disable_native_funcs", Fenom::DENY_INLINE_FUNCS), + array("disable_cache", Fenom::DISABLE_CACHE), + array("force_compile", Fenom::FORCE_COMPILE), + array("auto_reload", Fenom::AUTO_RELOAD), + array("force_include", Fenom::FORCE_INCLUDE), + array("auto_escape", Fenom::AUTO_ESCAPE), + array("force_verify", Fenom::FORCE_VERIFY) + ); + } + public function testCompileFile() { $a = array( "a" => "a", @@ -22,10 +35,6 @@ class FenomTest extends \Fenom\TestCase { public function testStorage() { $this->tpl('custom.tpl', 'Custom template'); $this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array())); - //$this->fenom->clearCompiledTemplate('custom.tpl', false); - - //$this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array())); - $this->tpl('custom.tpl', 'Custom template 2'); $this->assertSame("Custom template", $this->fenom->fetch('custom.tpl', array())); } @@ -78,6 +87,21 @@ class FenomTest extends \Fenom\TestCase { $this->tpl('custom.tpl', 'Custom compiler {myblockcompiler name="bar"} block1 {tag name="baz"} block2 {/myblockcompiler}'); $this->assertSame("Custom compiler PHP_VERSION: ".PHP_VERSION." (for bar) block1 Tag baz of compiler block2 End of compiler", $this->fenom->fetch('custom.tpl', array())); } -} -?> + /** + * @dataProvider providerOptions + */ + public function testOptions($code, $option) { + static $options = array(); + static $flags = 0; + $options[$code] = true; + $flags |= $option; + + $this->fenom->setOptions($options); + $this->assertSame($this->fenom->getOptions(), $flags); +// printf("from %010b, flags %010b\n", $this->fenom->getOptions(), $flags); +// $this->fenom->setOptions(array($code => false)); +// printf("remove %010b from option %010b, flags %010b\n", $option, $this->fenom->getOptions(), $flags & ~$option); +// $this->assertSame($this->fenom->getOptions(), $flags & ~$option); + } +} \ No newline at end of file