📄 test_cases.php
字号:
} function test_get_plugin_filepath() { $this->assertTrue(method_exists($this->smarty, '_get_plugin_filepath')); } function test_clear_compiled_tpl() { $this->assertTrue($this->smarty->clear_compiled_tpl()); } /* DISPLAY TESTS */ // test that display() executes properly function test_call_to_display() { ob_start(); $this->smarty->display('index.tpl'); $output = ob_get_contents(); ob_end_clean(); $this->assertEquals($output, 'TEST STRING'); } /* FETCH TESTS */ // test that fetch() executes properly function test_call_to_fetch() { $this->assertEquals($this->smarty->fetch('index.tpl'), 'TEST STRING'); } /* ASSIGN TESTS */ // test assigning a simple template variable function test_assign_var() { $this->smarty->assign('foo', 'bar'); $this->assertEquals($this->smarty->fetch('assign_var.tpl'), 'bar'); } /* PARSING TESTS */ // test assigning and calling an object function test_parse_obj_meth() { $obj = new Obj(); $this->smarty->assign('obj', $obj); $this->smarty->assign('foo', 'foo'); $this->assertEquals('foo:2.52.5:foo2.5:bval:foofoo:valfoo:fooone:2foo:foo:b', $this->smarty->fetch('parse_obj_meth.tpl')); } // test assigning and calling an object function test_parse_math() { $obj = new Obj(); $this->smarty->assign('obj', $obj); $this->smarty->assign('flt', 2.5); $this->smarty->assign('items', array(1, 2)); $this->assertEquals('33.571144.581212.52516208.57', $this->smarty->fetch('parse_math.tpl')); } /* CONFIG FILE TESTS */ // test assigning a double quoted global variable function test_config_load_globals_double_quotes() { // load the global var $this->smarty->config_load('globals_double_quotes.conf'); // test that it is assigned $this->assertEquals($this->smarty->_config[0]['vars']['foo'], 'bar'); } // test assigning a single quoted global variable function test_config_load_globals_single_quotes() { // load the global var $this->smarty->config_load('globals_single_quotes.conf'); // test that it is assigned $this->assertEquals($this->smarty->_config[0]['vars']['foo'], 'bar'); } // test loading and running modifier.escape.php function test_escape_modifier_get_plugins_filepath() { $filepath = $this->smarty->_get_plugin_filepath('modifier', 'escape'); $this->assertTrue($filepath); } function test_escape_modifier_include_file() { $filepath = $this->smarty->_get_plugin_filepath('modifier', 'escape'); $this->assertTrue(include($filepath)); } function test_escape_modifier_function_exists() { $this->assertTrue(function_exists('smarty_modifier_escape')); } function test_escape_modifier_escape_default() { $string = smarty_modifier_escape("<html><body></body></html>"); $this->assertEquals('<html><body></body></html>', $string); } function test_escape_modifier_escape_html() { $string = smarty_modifier_escape("<html><body></body></html>", 'html'); $this->assertEquals('<html><body></body></html>', $string); } function test_escape_modifier_escape_htmlall() { $string = smarty_modifier_escape("<html><body></body></html>", 'htmlall'); $this->assertEquals('<html><body></body></html>', $string); } function test_escape_modifier_escape_url() { $string = smarty_modifier_escape("http://test.com?foo=bar", 'url'); $this->assertEquals('http%3A%2F%2Ftest.com%3Ffoo%3Dbar', $string); } function test_escape_modifier_escape_quotes() { $string = smarty_modifier_escape("'\\'\\''", 'quotes'); $this->assertEquals("\\'\\'\\'\\'", $string); } function test_escape_modifier_escape_hex() { $string = smarty_modifier_escape("abcd", 'hex'); $this->assertEquals('%61%62%63%64', $string); } function test_escape_modifier_escape_hexentity() { $string = smarty_modifier_escape("ABCD", 'hexentity'); $this->assertEquals('ABCD', $string); } function test_escape_modifier_escape_javascript() { $string = smarty_modifier_escape("\r\n\\", 'javascript'); $this->assertEquals('\\r\\n\\\\', $string); } function test_core_is_secure_file_exists() { $file = SMARTY_CORE_DIR . 'core.is_secure.php'; $this->assertTrue(file_exists($file)); } function test_core_is_secure_file_include() { $file = SMARTY_CORE_DIR . 'core.is_secure.php'; $this->assertTrue(include($file)); } function test_core_is_secure_function_exists() { $this->assertTrue(function_exists('smarty_core_is_secure')); } function test_core_is_secure_function_is_secure_true() { $security = $this->smarty->security; $this->smarty->security = true; /* check if index.tpl is secure (should be true) */ $params = array('resource_type' => 'file', 'resource_base_path' => dirname(__FILE__) . '/templates', 'resource_name' => dirname(__FILE__) . '/templates/index.tpl'); $this->assertTrue(smarty_core_is_secure($params, $this->smarty)); $this->smarty->security = $security; } function test_core_is_secure_function_is_secure_false() { $security = $this->smarty->security; $this->smarty->security = true; /* check if test_cases.php is secure (should be false) */ $params = array('resource_type' => 'file', 'resource_base_path' => dirname(__FILE__) . '/templates', 'resource_name' => __FILE__); $this->assertFalse(smarty_core_is_secure($params, $this->smarty)); $this->smarty->security = $security; } // test constants and security function test_core_is_secure_function_smarty_var_const() { define('TEST_CONSTANT', 'test constant'); $this->assertEquals('test constant', $this->smarty->fetch('constant.tpl', null, 'var_const')); } function test_core_is_secure_function_smarty_var_const_allowed() { $security = $this->smarty->security; $security_settings = $this->smarty->security_settings; $this->smarty->security_settings['ALLOW_CONSTANTS'] = true; $this->smarty->security = true; $this->assertEquals('test constant', $this->smarty->fetch('constant.tpl', null, 'var_const_allowed')); $this->smarty->security_settings = $security_settings; $this->smarty->security = $security; } function test_core_is_secure_function_smarty_var_const_not_allowed() { $security = $this->smarty->security; $this->smarty->security = true; /* catch errors: */ $this->errorlevel = null; set_error_handler(array(&$this, 'error_handler')); $this->smarty->fetch('constant.tpl', null, 'var_const_not_allowed'); restore_error_handler(); $this->assertEquals( $this->errorlevel, E_USER_WARNING); $this->smarty->security = $security; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -