Source for file smarty.class.php
Documentation is available at smarty.class.php
* test case for smarty wrapper
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @author m2mtech <tech@m2m.at>
* @copyright 2007 m2m server software gmbh
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
* @version $Id: smarty.class.php 103 2007-07-31 19:27:19Z m2mtech $
* @link http://www.ea-geier.at/
require_once('code/base/smarty.class.php');
* work around for quick template testing
require_once(eaSMARTY_DIR . 'plugins/function.eval.php');
* tast case for smarty wrapper
$this->UnitTestCase('Test Smarty Wrapper');
* - checks if german is the native language
* - checks folder availibilty
$this->assertEqual($smarty->language, 'de', 'german is not native language');
$this->assertTrue(is_dir($smarty->config_dir), 'ini folder not available');
$this->assertTrue(is_dir($smarty->compile_dir), 'compile folder not available');
$this->assertTrue(is_dir($smarty->cache_dir), 'cache folder not available');
* tests the changeLanguage methode
* - checks unavailable language
* - checks available language
* - checks effective change
* - checks changed values
* - checks folder availibility
$vars = array('config_dir', 'compile_dir', 'cache_dir');
foreach ($vars as $var) $old[$var] = $smarty->$var;
$this->assertFalse($smarty->changeLanguage('xx'), 'invalid change possible');
$this->assertTrue($smarty->changeLanguage('en'), 'valid change not possible');
$this->assertEqual($smarty->language, 'en', 'change effective');
$this->assertNotEqual($old[$var], $smarty->$var, 'value ' . $var . ' did not change');
$this->assertTrue(is_dir($smarty->$var), 'folder ' . $var . ' not available');
* tests the {eaInput} function plugin
error_log('the following error message is part of unit testing');
$template = array('var' => '{eaInput}');
$this->expectError("Smarty error: eaInput: 'name' missing", 'no error message');
smarty_function_eval($template, $smarty);
$template = array('var' => '{eaInput name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<input type="text" name="test" id="test" />', $result, 'wrong default type');
$template = array('var' => '{eaInput name=test type=nothing}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<input type="text" name="test" id="test" />', $result, 'wrong type accepted');
$template = array('var' => '{eaInput name=test type=text}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<input type="text" name="test" id="test" />', $result, 'type text not working');
$template = array('var' => '{eaInput name=test type=password}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<input type="password" name="test" id="test" />', $result, 'type password not working');
$smarty->assign('data', array('test' => 'testvalue'));
$template = array('var' => '{eaInput name=test type=text}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<input type="text" name="test" id="test" value="testvalue" />', $result, 'value not working');
$smarty->clear_assign('data');
$smarty->assign('error', array('test' => 'testvalue'));
$template = array('var' => '{eaInput name=test type=text}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<input type="text" name="test" id="test" class="error" />', $result, 'error class not working');
$smarty->clear_assign('error');
$smarty->_config[0]['vars']['helptest'] = 'helpcontent';
$template = array('var' => '{eaInput name=test type=text}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<input type="text" name="test" id="test" title="helpcontent" />', $result, 'title not working');
$smarty->_config[0]['vars']['labeltest'] = 'testlabel';
$template = array('var' => '{eaInput name=test type=text}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label for="test">testlabel</label><input type="text" name="test" id="test" />', $result, 'label not working');
$template = array('var' => '{eaInput name=test align=right}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<input type="text" name="test" id="test" style="text-align: right" />', $result);
$template = array('var' => '{eaInput name=test onchange=something()}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<input type="text" name="test" id="test" onchange="something()" />', $result);
* tests the {eaSelect} block plugin
* checks missing end tag, missing name, error, title label
error_log('the following error message is part of unit testing');
$template = array('var' => '{eaSelect}');
$this->assertFalse(smarty_function_eval($template, $smarty));
error_log('the following error message is part of unit testing');
$template = array('var' => '{eaSelect}test{/eaSelect}');
$this->assertFalse(smarty_function_eval($template, $smarty));
$template = array('var' => '{eaSelect name=test}test{/eaSelect}');
$this->assertTrue($result = smarty_function_eval($template, $smarty));
$this->assertEqual('<select name="test" id="test" >test</select>', $result);
$smarty->assign('error', array('test' => 'testvalue'));
$template = array('var' => '{eaSelect name=test}test{/eaSelect}');
$this->assertTrue($result = smarty_function_eval($template, $smarty));
$this->assertEqual('<select name="test" id="test" class="error" >test</select>', $result);
$smarty->clear_assign('error');
$smarty->_config[0]['vars']['helptest'] = 'helpcontent';
$template = array('var' => '{eaSelect name=test}test{/eaSelect}');
$this->assertTrue($result = smarty_function_eval($template, $smarty));
$this->assertEqual('<select name="test" id="test" title="helpcontent" >test</select>', $result);
$smarty->_config[0]['vars']['labeltest'] = 'testlabel';
$template = array('var' => '{eaSelect name=test}test{/eaSelect}');
$this->assertTrue($result = smarty_function_eval($template, $smarty));
$this->assertEqual('<label for="test">testlabel</label><select name="test" id="test" >test</select>', $result);
* tests the {eaSubmitButton} function plugin
error_log('the following error message is part of unit testing');
$template = array('var' => '{eaSubmitButton}');
$this->expectError('Smarty error: trigger error for testing:');
$smarty->trigger_error('trigger error for testing:', E_USER_NOTICE);
$this->expectError("Smarty error: eaSubmitButton: 'name' missing", 'no error message');
smarty_function_eval($template, $smarty);
$template = array('var' => '{eaSubmitButton name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label> </label><input type="submit" name="test" value="submit" class="submit" />', $result);
$smarty->_config[0]['vars']['test'] = 'testsubmit';
$template = array('var' => '{eaSubmitButton name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label> </label><input type="submit" name="test" value="testsubmit" class="submit" />', $result);
* tests the {eaURL} function plugin
$template = array('var' => '{eaURL state=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertTrue('test', $result, 'missing types');
$template = array('var' => '{eaURL state=testdummy type=short}');
$result = smarty_function_eval($template, $smarty);
$this->assertPattern('/\/testdummy/', $result, 'short url');
$template = array('var' => '{eaURL state=testdummy type=long}');
$result = smarty_function_eval($template, $smarty);
$this->assertPattern('/\?state=testdummy/', $result, 'long url');
* tests the {eaCheckBox} function plugin
error_log('the following error message is part of unit testing');
$template = array('var' => '{eaCheckBox}');
$this->expectError("Smarty error: eaCheckBox: 'name' missing");
smarty_function_eval($template, $smarty);
$template = array('var' => '{eaCheckBox name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('', $result);
$smarty->assign('opt', array('test' => array(1 => true, 2 => true)));
$template = array('var' => '{eaCheckBox name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label><input type="checkbox" name="test[]" value="1" /></label>' . "\n" . '<label><input type="checkbox" name="test[]" value="2" /></label>', $result);
$smarty->_config[0]['vars']['opttest1'] = 'abc';
$smarty->_config[0]['vars']['opttest2'] = 'def';
$template = array('var' => '{eaCheckBox name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label><input type="checkbox" name="test[]" value="1" />abc</label>' . "\n" . '<label><input type="checkbox" name="test[]" value="2" />def</label>', $result);
$smarty->assign('data', array('test' => '1'));
$template = array('var' => '{eaCheckBox name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label><input type="checkbox" name="test[]" value="1" checked="checked" />abc</label>' . "\n" . '<label><input type="checkbox" name="test[]" value="2" />def</label>', $result);
$smarty->assign('data', array('test' => array(1, 2)));
$template = array('var' => '{eaCheckBox name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label><input type="checkbox" name="test[]" value="1" checked="checked" />abc</label>' . "\n" . '<label><input type="checkbox" name="test[]" value="2" checked="checked" />def</label>', $result);
$smarty->assign('error', array('test' => 'testvalue'));
$smarty->assign('opt', array('test' => array(1 => true)));
$template = array('var' => '{eaCheckBox name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label><input type="checkbox" name="test[]" value="1" checked="checked" class="error" /></label>', $result);
$smarty->clear_assign('error');
$smarty->_config[0]['vars']['helptest'] = 'helpcontent';
$template = array('var' => '{eaCheckBox name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label><input type="checkbox" name="test[]" value="1" checked="checked" title="helpcontent" /></label>', $result);
$smarty->_config[0]['vars']['labeltest'] = 'testlabel';
$template = array('var' => '{eaCheckBox name=test}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<label for="test">testlabel</label><label><input type="checkbox" name="test[]" value="1" checked="checked" /></label>', $result);
* tests the {eaPage} function plugin
$template = array('var' => '{eaPage}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('1', $result);
$template = array('var' => '{eaPage pages=1 cur=1}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('1', $result);
// two pages first selected
$template = array('var' => '{eaPage pages=2 cur=1}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('1 <a href="page2">2</a><a href="page2">></a>', $result);
// two pages second selected
$template = array('var' => '{eaPage pages=2 cur=2}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<a href="page1"><</a><a href="page1">1</a> 2', $result);
// multiple pages first selected
$template = array('var' => '{eaPage pages=20 cur=1}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('1 <a href="page2">2</a> <a href="page3">3</a> <a href="page4">4</a><a href="page2">></a>', $result);
// multiple pages second selected
$template = array('var' => '{eaPage pages=20 cur=2}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<a href="page1"><</a><a href="page1">1</a> 2 <a href="page3">3</a> <a href="page4">4</a> <a href="page5">5</a><a href="page3">></a>', $result);
// multiple pages third selected
$template = array('var' => '{eaPage pages=20 cur=2}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<a href="page1"><</a><a href="page1">1</a> 2 <a href="page3">3</a> <a href="page4">4</a> <a href="page5">5</a><a href="page3">></a>', $result);
// multiple pages last selected
$template = array('var' => '{eaPage pages=20 cur=20}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<a href="page19"><</a><a href="page17">17</a> <a href="page18">18</a> <a href="page19">19</a> 20', $result);
// multiple pages second last selected
$template = array('var' => '{eaPage pages=20 cur=19}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<a href="page18"><</a><a href="page16">16</a> <a href="page17">17</a> <a href="page18">18</a> 19 <a href="page20">20</a><a href="page20">></a>', $result);
// multiple pages third selected
$template = array('var' => '{eaPage pages=20 cur=18}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<a href="page17"><</a><a href="page15">15</a> <a href="page16">16</a> <a href="page17">17</a> 18 <a href="page19">19</a> <a href="page20">20</a><a href="page19">></a>', $result);
// multiple pages middle selected
$template = array('var' => '{eaPage pages=20 cur=10}');
$result = smarty_function_eval($template, $smarty);
$this->assertEqual('<a href="page9"><</a><a href="page7">7</a> <a href="page8">8</a> <a href="page9">9</a> 10 <a href="page11">11</a> <a href="page12">12</a> <a href="page13">13</a><a href="page11">></a>', $result);
|