sigma_api_testcase.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 401 行 · 第 1/2 页

PHP
401
字号
    {        if (!$this->_methodExists('setOption')) {            return;        }        $this->tpl->setTemplate('{placeholder1},{placeholder2},{placeholder3}', true, true);        $this->tpl->setOption('preserve_data', true);        $this->tpl->setVariable(array(            'placeholder1' => 'var1',            'placeholder2' => 'var2',            'placeholder3' => 'var3{stuff}'        ));        $this->assertEquals('var1,var2,var3{stuff}', $this->tpl->get());    }    function testPlaceholderExists()    {        $this->tpl->setTemplate('{var}');        $this->assertTrue($this->tpl->placeholderExists('var'), 'Existing placeholder \'var\' reported as nonexistant');        $this->assertTrue(!$this->tpl->placeholderExists('foobar'), 'Nonexistant placeholder \'foobar\' reported as existing');        $this->assertTrue($this->tpl->placeholderExists('var', '__global__'), 'Existing in block \'__global__\' placeholder \'var\' reported as nonexistant');        $this->assertTrue(!$this->tpl->placeholderExists('foobar', '__global__'), 'Nonexistant in block \'__global__\' placeholder \'foobar\' reported as existing');    }    function testBlockExists()    {        $this->tpl->setTemplate('{var}');        $this->assertTrue($this->tpl->blockExists('__global__'), 'Existing block \'__global__\' reported as nonexistant');        $this->assertTrue(!$this->tpl->blockExists('foobar'), 'Nonexistant block \'foobar\' reported as existing');    }    function testAddBlock()    {        $result = $this->tpl->loadTemplatefile('blocks.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        $this->tpl->addBlock('var', 'added', 'added:{new_var}');        $this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing');        $this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template');        $this->tpl->setVariable('new_var', 'new_value');        $this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get()));    }    function testAddBlockfile()    {        $result = $this->tpl->loadTemplatefile('blocks.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        $result = $this->tpl->addBlockfile('var', 'added', 'addblock.html');        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error adding block from file: '. $result->getMessage());        }        $this->assertTrue($this->tpl->blockExists('added'), 'The new block seems to be missing');        $this->assertTrue(!$this->tpl->placeholderExists('var'), 'The old variable seems to be still present in the template');        $this->tpl->setVariable('new_var', 'new_value');        $this->assertEquals('added:new_value', $this->_stripWhitespace($this->tpl->get()));    }    function testReplaceBlock()    {        $result = $this->tpl->loadTemplatefile('blocks.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        $this->tpl->setVariable('old_var', 'old_value');        $this->tpl->parse('old_block');        // old_block's contents should be discarded        $this->tpl->replaceBlock('old_block', 'replaced:{replaced_var}#', false);        $this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'),                          'The replaced block\'s contents seem to be still present');        $this->tpl->setVariable('replaced_var', 'replaced_value');        $this->tpl->parse('old_block');        // this time old_block's contents should be preserved        $this->tpl->replaceBlock('old_block', 'replaced_again:{brand_new_var}', true);        $this->tpl->setVariable('brand_new_var', 'brand_new_value');        $this->assertEquals('replaced:replaced_value#replaced_again:brand_new_value', $this->_stripWhitespace($this->tpl->get()));    }    function testReplaceBlockfile()    {        $result = $this->tpl->loadTemplatefile('blocks.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        $this->tpl->setVariable('old_var', 'old_value');        $this->tpl->parse('old_block');        // old_block's contents should be discarded        $result = $this->tpl->replaceBlockfile('old_block', 'replaceblock.html', false);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage());        }        $this->assertTrue(!$this->tpl->blockExists('old_inner_block') && !$this->tpl->placeholderExists('old_var'),                          'The replaced block\'s contents seem to be still present');        $this->tpl->setVariable(array(            'replaced_var'       => 'replaced_value',            'replaced_inner_var' => 'inner_value'        ));        $this->tpl->parse('old_block');        // this time old_block's contents should be preserved        $result = $this->tpl->replaceBlockfile('old_block', 'addblock.html', true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error replacing block from file: '. $result->getMessage());        }        $this->tpl->setVariable('new_var', 'again');        $this->assertEquals('replaced:replaced_value|inner_value#added:again', $this->_stripWhitespace($this->tpl->get()));    }    function testCallback()    {        $result = $this->tpl->loadTemplatefile('callback.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        $this->tpl->setVariable('username', 'luser');        $this->tpl->setCallbackFunction('uppercase', 'strtoupper');        $this->tpl->setCallbackFunction('russian', array(&$this, '_doRussian'), true);        $this->tpl->setCallbackFunction('lowercase', 'strtolower');        $this->tpl->setCallBackFunction('noarg', array(&$this, '_doCallback'));        $this->assertEquals('callback#word#HELLO,LUSER!#橡桠弪,luser!', $this->_stripWhitespace($this->tpl->get()));    }    function _doCallback()    {        return 'callback';    }    function _doRussian($arg)    {        $ary = array('Hello, {username}!' => '橡桠弪, {username}!');        return isset($ary[$arg])? $ary[$arg]: $arg;    }    function testGetBlockList()    {        // expected tree...        $tree = array(            'name'     => '__global__',            'children' => array(                array(                    'name'     => 'outer_block',                    'children' => array(                        array('name' => 'inner_block')                    )                )            )        );        $result = $this->tpl->loadTemplatefile('blockiteration.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        $this->assertEquals($tree, $this->tpl->getBlockList('__global__', true));        $this->assertEquals(array('inner_block'), $this->tpl->getBlockList('outer_block'));    }        function testGetPlaceholderList()    {        $result = $this->tpl->loadTemplatefile('blockiteration.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        $this->assertEquals(array('outer'), $this->tpl->getPlaceholderList('outer_block'));    }    function testCallbackShorthand()    {        $this->tpl->setTemplate('{var}|{var:h}|{var:u}|{var:j}|{var:uppercase}', true, true);        $this->tpl->setCallbackFunction('uppercase', 'strtoupper');        $this->tpl->setVariable('var', '"m&m"');        $this->assertEquals('"m&m"|&quot;m&amp;m&quot;|%22m%26m%22|\\"m&m\\"|"M&M"', $this->tpl->get());    }    function testClearVariables()    {        if (!$this->_methodExists('clearVariables')) {            return;        }        $this->tpl->setTemplate('<!-- BEGIN block -->{var_1}:<!-- END block -->{var_2}', true, true);        $this->tpl->setVariable(array(            'var_1' => 'a',            'var_2' => 'b'        ));        $this->tpl->parse('block');        $this->tpl->clearVariables();        $this->assertEquals('a:', $this->_stripWhitespace($this->tpl->get()));    }    function testCallbackParametersQuoting()    {        $this->tpl->setTemplate(            '|func_fake(\' foo \')|func_fake( foo )|func_fake(<a href="javascript:foo(bar,baz)">foo</a>)' .            '|func_fake("O\'really")|func_fake(\'\\\\O\\\'really\\\\\')|func_fake("\\\\O\\"really\\\\")|'        );        $this->assertEquals('| foo |foo|<a href="javascript:foo(bar,baz)">foo</a>|O\'really|\\O\'really\\|\\O"really\\|', $this->tpl->get());    }}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?