Permalink
Browse files

better filter method behavior, handling mismatching endblocks, improv…

…ed makefile with automatic testing
  • Loading branch information...
1 parent df2dac1 commit 486b0fa2956e78f00e1687c1109d5d87c9ac6de6 @arshaw committed Mar 28, 2010
View
@@ -6,16 +6,26 @@ DATE_SED = sed s/@DATE/"${DATE}"/
zip:
@rm -rf build/*
+
+ @echo "building..."
@mkdir -p build
@mkdir -p dist
@cat src/ti.php \
| ${VER_SED} \
| ${DATE_SED} \
+ | sed /require.*debug\.php/d \
> build/ti.php
@cp readme.mkd build/readme.txt
@cp license.txt build
- @cd build; zip -q phpti.zip *
- @mv build/phpti.zip dist/phpti-${VER}.zip
+
+ @echo "running tests..."
+ @if tests/run-tests -B; then \
+ echo "zipping..."; \
+ cd build; zip -q phpti.zip *; cd ..; \
+ mv build/phpti.zip dist/phpti-${VER}.zip; \
+ else \
+ echo "DID NOT PASS ALL TESTS."; \
+ fi
clean:
@rm -rf build/*
View
@@ -8,12 +8,10 @@
Released: @DATE
Website: http://phpti.com/
Author: Adam Shaw (http://arshaw.com/)
-Licensed under the MIT License (license.txt)
+Released under the MIT License (license.txt)
*/
-
-
-//require_once dirname(__FILE__) . '/debug.php';
+require_once dirname(__FILE__) . '/debug.php'; // line will be removed by Makefile
$GLOBALS['_ti_base'] = null;
@@ -44,10 +42,9 @@ function endblock($name=null) {
if ($stack) {
$block = array_pop($stack);
if ($name && $name != $block['name']) {
- _ti_warning("orphan endblock('$name')", $trace);
- }else{
- _ti_insertBlock($block);
+ _ti_warning("startblock('{$block['name']}') does not match endblock('$name')", $trace);
}
+ _ti_insertBlock($block);
}else{
_ti_warning(
$name ? "orphan endblock('$name')" : "orphan endblock()",
@@ -114,9 +111,7 @@ function flushblocks() {
function blockbase() {
- _ti_init(
- _ti_callingTrace()
- );
+ _ti_init(_ti_callingTrace());
}
@@ -170,9 +165,11 @@ function _ti_newBlock($name, $filters, $trace) {
$filters = array($filters);
}
foreach ($filters as $i => $f) {
- if ($f && is_string($f) && !function_exists($f)) {
+ if ($f && !is_callable($f)) {
_ti_warning(
- "filter '$f' is not defined",
+ is_array($f) ?
+ "filter " . implode('::', $f) . " is not defined":
+ "filter '$f' is not defined", // TODO: better messaging for methods
$trace
);
$filters[$i] = null;
View
@@ -1,5 +0,0 @@
-
-- filters with Class::method
-- filtered superblock
-- endblock with optional name
-- blockbase
View
@@ -6,7 +6,7 @@ Output outside of template, after template, gets sent to standard out
<?php
-require_once '../src/ti.php';
+require_once 'ti.php';
include 'templates/page1.php';
View
@@ -4,7 +4,7 @@ Make sure a single base template file handles the buffer correctly
--FILE--
-<? require_once '../src/ti.php' ?>
+<? require_once 'ti.php' ?>
<html>
<head>
<? startblock('head') ?>
@@ -5,7 +5,7 @@ Cannot have two blocks with same name in one file
--FILE--
<?
-require_once '../src/ti.php';
+require_once 'ti.php';
include 'templates/base.php';
?>
View
@@ -0,0 +1,23 @@
+--TEST--
+
+Make sure blockbase works on a base template that has no blocks
+
+--FILE--
+
+<? require_once 'ti.php' ?>
+<? include 'templates/base_no_blocks.php' ?>
+
+<? startblock('content') ?>
+this is the content
+<? endblock() ?>
+
+--EXPECT--
+
+<html>
+<head>
+<link rel='stylesheet' type='text/css' href='main.css' />
+<script type='text/javascript' src='main.js'></script>
+</head>
+<body>
+</body>
+</html>
@@ -4,7 +4,7 @@ two consecutive different templates
--FILE--
-<? require_once '../src/ti.php' ?>
+<? require_once 'ti.php' ?>
<? include 'templates/page1.php' ?>
<? include 'templates/page2.php' ?>
View
@@ -4,7 +4,7 @@ two consecutive same templates
--FILE--
-<? require_once '../src/ti.php' ?>
+<? require_once 'ti.php' ?>
<? include 'templates/page1.php' ?>
<? include 'templates/page1.php' ?>
View
@@ -0,0 +1,42 @@
+--TEST--
+
+Enblock with the optional name parameter
+
+--FILE--
+
+<? require_once 'ti.php' ?>
+<? include 'templates/base.php' ?>
+
+<? startblock('content') ?>
+<p>
+the page content
+</p>
+<? endblock('content') ?>
+
+<? startblock('title') ?>
+the page title
+<? endblock('title') ?>
+
+--EXPECT--
+
+<html>
+<head>
+<link rel='stylesheet' type='text/css' href='main.css' />
+<script type='text/javascript' src='main.js'></script>
+</head>
+<body>
+<div id='header'>
+<h1>
+the page title
+</h1>
+</div>
+<div id='content'>
+<p>
+the page content
+</p>
+</div>
+<div id='footer'>
+this is the default footer
+</div>
+</body>
+</html>
@@ -0,0 +1,44 @@
+--TEST--
+
+Enblock with the optional name parameter
+
+--FILE--
+
+<? require_once 'ti.php' ?>
+<? include 'templates/base.php' ?>
+
+<? startblock('content') ?>
+<p>
+the page content
+</p>
+<? endblock('xxx') ?>
+
+<? startblock('title') ?>
+the page title
+<? endblock('title') ?>
+
+--EXPECTF--
+
+<html>
+<head>
+<link rel='stylesheet' type='text/css' href='main.css' />
+<script type='text/javascript' src='main.js'></script>
+</head>
+<body>
+<div id='header'>
+<h1>
+the page title
+</h1>
+</div>
+<div id='content'>
+<p>
+the page content
+</p>
+</div>
+<div id='footer'>
+this is the default footer
+</div>
+</body>
+</html>
+
+Warning: startblock('content') does not match endblock('xxx') in %s/endblock_mismatch.php on line 9
View
@@ -5,7 +5,7 @@ test the filter argument of startblock, with filters as a string and array
--FILE--
<?
-require_once '../src/ti.php';
+require_once 'ti.php';
include 'templates/base.php';
// TODO: test for commas and spaces in filter string
View
@@ -6,7 +6,7 @@ Warns and does not execute filters that do not exist
<?php
-require_once '../src/ti.php';
+require_once 'ti.php';
include 'templates/base.php';
function filter1($s) {
@@ -4,7 +4,7 @@ Warning for nonexistant filter happens where block is defined
--FILE--
-<? require '../src/ti.php' ?>
+<? require 'ti.php' ?>
<html>
<head>
<? startblock('head') ?>
View
@@ -0,0 +1,44 @@
+--TEST--
+
+Filters work with the array('class','method')
+
+--FILE--
+
+<?
+
+require_once 'ti.php';
+include 'templates/base.php';
+
+class MyFilters {
+ function filter1($s) {
+ return '*' . trim($s) . '*';
+ }
+}
+
+?>
+
+<? startblock('content', array(array('MyFilters','filter1'), array('Nothing','method'))) ?>
+this is the content
+<? endblock() ?>
+
+--EXPECTF--
+
+<html>
+<head>
+<link rel='stylesheet' type='text/css' href='main.css' />
+<script type='text/javascript' src='main.js'></script>
+</head>
+<body>
+<div id='header'>
+<h1>
+</h1>
+</div>
+<div id='content'>
+*this is the content*</div>
+<div id='footer'>
+this is the default footer
+</div>
+</body>
+</html>
+
+Warning: filter Nothing::method is not defined in /home/adam/Projects/PHPTI/tests/filters_class.php on line 15
@@ -13,7 +13,7 @@ if (PHP_MAJOR_VERSION < 5 || PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) {
--FILE--
<?php
-require_once '../src/ti.php';
+require_once 'ti.php';
include 'templates/base.php';
$filter1 = function($s) {
@@ -5,7 +5,7 @@ flushblocks can be called when there are no blocks, just won't do anything
--FILE--
<?
-require_once '../src/ti.php';
+require_once 'ti.php';
echo "here1";
flushblocks();
echo "here2";
View
@@ -4,7 +4,7 @@ getsuperblock function
--FILE--
-<? require_once '../src/ti.php' ?>
+<? require_once 'ti.php' ?>
<? include 'templates/base.php' ?>
<? startblock('footer') ?>
View
@@ -4,7 +4,7 @@ Basic inheritance. Notice block order doesn't matter.
--FILE--
-<? require_once '../src/ti.php' ?>
+<? require_once 'ti.php' ?>
<? include 'templates/base.php' ?>
<? startblock('content') ?>
@@ -4,7 +4,7 @@ extra block
--FILE--
-<? require_once '../src/ti.php' ?>
+<? require_once 'ti.php' ?>
<? include 'templates/base.php' ?>
<? startblock('content') ?>
View
@@ -5,7 +5,7 @@ orphan endblock and dangling startblock in a base template
--FILE--
<? error_reporting(E_ALL) ?>
-<? require_once '../src/ti.php' ?>
+<? require_once 'ti.php' ?>
<? include 'templates/base_broken.php' ?>
<? startblock('content') ?>
@@ -5,7 +5,7 @@ throws a warning when omitted end tag in child template
--FILE--
<? error_reporting(E_ALL) ?>
-<? require_once '../src/ti.php'?>
+<? require_once 'ti.php'?>
<? include 'templates/base.php' ?>
<? endblock() ?>
View
@@ -4,7 +4,7 @@ nested blocks
--FILE--
-<? require_once '../src/ti.php' ?>
+<? require_once 'ti.php' ?>
<? include 'templates/3col.php' ?>
<? startblock('left') ?>
Oops, something went wrong.

0 comments on commit 486b0fa

Please sign in to comment.