sigma_usage_testcase.php

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

PHP
132
字号
<?php/** * Unit tests for HTML_Template_Sigma package. *  * @author Alexey Borzov <avb@php.net> *  * $Id: Sigma_usage_testcase.php,v 1.3 2004/04/10 10:28:45 avb Exp $ */class Sigma_Usage_TestCase extends PHPUnit_TestCase{   /**    * A template object    * @var object    */    var $tpl;    function Sigma_Usage_TestCase($name)    {        $this->PHPUnit_TestCase($name);    }    function setUp()    {        $className = 'HTML_Template_' . $GLOBALS['IT_class'];        $this->tpl =& new $className('./templates');    }    function tearDown()    {        unset($this->tpl);    }    function _stripWhitespace($str)    {        return preg_replace('/\\s+/', '', $str);    }    function _methodExists($name)     {        if (in_array(strtolower($name), array_map('strtolower', get_class_methods($this->tpl)))) {            return true;        }        $this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->tpl));        return false;    }   /**    * Tests iterations over two blocks    *    */    function testBlockIteration()    {        $data = array(            'a',            array('b', array('1', '2', '3', '4')),            'c',            array('d', array('5', '6', '7'))        );                $result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        foreach ($data as $value) {            if (is_array($value)) {                $this->tpl->setVariable('outer', $value[0]);                foreach ($value[1] as $v) {                    $this->tpl->setVariable('inner', $v);                    $this->tpl->parse('inner_block');                }            } else {                $this->tpl->setVariable('outer', $value);            }            $this->tpl->parse('outer_block');        }        $this->assertEquals('a#b|1|2|3|4#c#d|5|6|7#', $this->_stripWhitespace($this->tpl->get()));    }   /**    *     *    */    function testTouchBlockIteration()    {        $data = array('a','b','c','d','e');        $result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        for ($i = 0; $i < count($data); $i++) {            $this->tpl->setVariable('outer', $data[$i]);            // the inner_block is empty and should be removed            if (0 == $i % 2) {                $this->tpl->touchBlock('inner_block');            }            $this->tpl->parse('outer_block');        }        $this->assertEquals('a|#b#c|#d#e|#', $this->_stripWhitespace($this->tpl->get()));    }   /**    *    */    function testHideBlockIteration()    {        if (!$this->_methodExists('hideBlock')) {            return;        }        $data = array('a','b','c','d','e');        $result = $this->tpl->loadTemplateFile('blockiteration.html', true, true);        if (PEAR::isError($result)) {            $this->assertTrue(false, 'Error loading template file: '. $result->getMessage());        }        for ($i = 0; $i < count($data); $i++) {            $this->tpl->setVariable(array(                'inner' => $i + 1,                'outer' => $data[$i]            ));            // the inner_block is not empty, but should be removed            if (0 == $i % 2) {                $this->tpl->hideBlock('inner_block');            }            $this->tpl->parse('outer_block');        }        $this->assertEquals('a#b|2#c#d|4#e#', $this->_stripWhitespace($this->tpl->get()));    }}?>

⌨️ 快捷键说明

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