Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 114 lines (101 sloc) 2.452 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
#!/usr/bin/php
<?php
/**
* Because PHPUnit cannot run a particular case from the data provider,
* we provide our own utility that allows to run and study a single test
* case that uses the filesystem wrapper.
*
* This script runs the templates in the backward compatibility mode.
*
* Usage: run-bc.php /directory/something.txt
*/

if($argc != 2 && $argc != 3)
{
die("Invalid call!\n");
}

define('CPL_DIR', './Cache/');
require('./Bootstrap.php');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';

require('./Extra/TestFS.php');

if($argc == 3)
{
require('./Extra/'.$argv[2]);
}

class test
{
protected $tpl;

public function init()
{
$tpl = new Opt_Class;
$tpl->sourceDir = 'test://templates/';
$tpl->compileDir = CPL_DIR;
$tpl->compileMode = Opt_Class::CM_REBUILD;
$tpl->parser = Opt_Class::HTML_MODE;
$tpl->stripWhitespaces = false;
$tpl->prologRequired = true;
$tpl->backwardCompatibility = true;
$tpl->setup();
$this->tpl = $tpl;
} // end init();

public function run($test)
{
Extra_TestFS::loadFilesystem($test);
$view = new Opt_View('test.tpl');
if(file_exists('test://data.php'))
{
eval(file_get_contents('test://data.php'));
}

$out = new Opt_Output_Return;
$expected = file_get_contents('test://expected.txt');

if(strpos($expected, 'OUTPUT') === 0)
{
// This test shoud give correct results
try
{
$result = $out->render($view);
if($this->stripWs(trim(file_get_contents('test://result.txt'))) === ($o = $this->stripWs(trim($result))))
{
return true;
}
echo $result;
die('Invalid output: '.$o."\n");
}
catch(Opt_Exception $e)
{
die('Exception returned: #'.get_class($e).': '.$e->getMessage()."\n");
}
}
else
{
// This test should generate an exception
$expected = trim($expected);
try
{
$out->render($view);
}
catch(Opt_Exception $e)
{
if($expected != get_class($e))
{
die('Invalid exception returned: #'.get_class($e).', '.$expected." expected.\n");
}
return true;
}
die("Exception NOT returned, but should be: ".$expected."\n");
}
} // end run();

private function stripWs($text)
{
return str_replace(array("\r", "\n"),array('', ''), $text);
} // end stripws();
} // end test;

if(!file_exists($argv[1]))
{
die("The specified test does not exist!\n");
}

$test = new test;
$test->init();
if($test->run($argv[1]))
{
die("OK\n");
}
Something went wrong with that request. Please try again.