PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Alexey Burkov   Dextep Template Engine   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: Test script
Class: Dextep Template Engine
Template engine based on regular expressions
Author: By
Last change:
Date: 13 years ago
Size: 1,496 bytes
 

Contents

Class file image Download
<?
require_once 'Dextep.class.php';
$template = new Dextep();

$template->setVar('str', 'Hello, world!');
$template->setVar('bool', true);
$template->setVar('float', 3.5);
$template->setVar('array', array('key' => 'value', array('str', true, 3.5)));

echo
'<strong>Pre-execution test:</strong><br />';
$template->setVar('array.key', 'upd');
echo
'testing setVar() and getVar()...<br />';
$result = $template->getVar('array.key').count($template->getVar('array.0'));
echo
'<strong>'.($result == 'upd3' ? '<span style="color:green">ok</span>' : '<span style="color:red">error</span>').'</strong>';
echo
'<br /><br />';

echo
'<strong>Template "test":</strong><br />';
echo
'testing expressions, if, for, foreach, include, preparing for test2...<br />';
$result = $template->getTemplate('test', true);
echo
'<strong>'.($result == '123.52{}key01' ? '<span style="color:green">ok</span>' : '<span style="color:red">error</span>').'</strong>';
echo
'<br /><br />';

echo
'<strong>Template "test2":</strong><br />';
echo
'testing @-prefix, local %-variables and global variable scope...<br />';
$result = $template->getTemplate('test2', true);
echo
'<strong>'.($result == 'Hello, world!' ? '<span style="color:green">ok</span>' : '<span style="color:red">error</span>').'</strong>';
echo
'<br /><br />';

echo
'<strong>Self-inclusion test (last one):</strong><br />';
echo
'should see error message below. Here we go:<br /><br />';
$template->getTemplate('self', true);
?>