diff options
| author | bitweaver.org <bitweaver@users.sourceforge.net> | 2005-06-19 04:52:54 +0000 |
|---|---|---|
| committer | bitweaver.org <bitweaver@users.sourceforge.net> | 2005-06-19 04:52:54 +0000 |
| commit | a4f86515b4553ec209a154df15501d6749161e98 (patch) | |
| tree | 57446c9bb8264b88224514b971cac35a5a8e757f /test | |
| download | kernel-a4f86515b4553ec209a154df15501d6749161e98.tar.gz kernel-a4f86515b4553ec209a154df15501d6749161e98.tar.bz2 kernel-a4f86515b4553ec209a154df15501d6749161e98.zip | |
IMPORT TikiPro CLYDE FINAL
Diffstat (limited to 'test')
| -rw-r--r-- | test/README.smarty_filter_tests | 38 | ||||
| -rw-r--r-- | test/TestTikiCache.php | 61 | ||||
| -rw-r--r-- | test/TestTikiDatabase.php | bin | 0 -> 3083 bytes | |||
| -rw-r--r-- | test/TestTikiPreferences.php | 51 | ||||
| -rw-r--r-- | test/TestTikiPreferencesCache.php | 67 | ||||
| -rw-r--r-- | test/TestTikiPreferencesCacheDatabase.php | 69 | ||||
| -rw-r--r-- | test/TestTikiPreferencesDatabase.php | 82 | ||||
| -rw-r--r-- | test/TestTikiSmartyFilter.php | 127 | ||||
| -rw-r--r-- | test/bit_setup_inc.php | 3 | ||||
| -rw-r--r-- | test/index.php | 359 | ||||
| -rw-r--r-- | test/smarty_filter_tests/prefilter.tr/simple.input | 5 | ||||
| -rw-r--r-- | test/smarty_filter_tests/prefilter.tr/simple.output | 5 |
12 files changed, 867 insertions, 0 deletions
diff --git a/test/README.smarty_filter_tests b/test/README.smarty_filter_tests new file mode 100644 index 0000000..3680665 --- /dev/null +++ b/test/README.smarty_filter_tests @@ -0,0 +1,38 @@ +This file describes how to set up tescases for (Smarty)filters. +The 'TestBitSmartyFilter.php' is an input - output tester that feeds +the contents of a file to the function to be tested (in the first paramter) +and compares what the function returns with another file. + +Right now the tester is only set up to test smarty filters in the ../kernel/smarty_tiki +directory, but testing in other directories could be aded by refactoring the code. + +Follow these steps to set up a new test: + +1. Create a directory (if not allready present) that is named analogously + to the filter you want to test: + <filtertype>.<filtername>, e.g. prefilter.tr + in the 'smarty_filter_tests' directory + +1.5 'chmod' this directory so that it is writeable by your webserver, + otherwise creation of the error file, useful for debugging, + will not be possible. + +2. Create a file in the created directory that should be used as input for + the test. Name it <arbitraryname>.input + +3. Run the tests by directing your browser to http://<tikiproroot>/kernel/test + +4. The test will fail, since there is no <arbitraryname>.output file. + Instead a file named <arbitraryname>.error will be generated. + <arbitraryname> is the same name as in point 2. + +5. Inspect the <arbitraryname>.error file. If the output is the expected, + you should rename the <arbitraryname>.error to <arbitraryname>.output. + Running the test again (reloading the browser, should now be succesful). + If the output is not the expected, correct the filter and continue from + step 3. + +You can add more test by creating more files in the directory created in 1. + + +Happy testing.
\ No newline at end of file diff --git a/test/TestTikiCache.php b/test/TestTikiCache.php new file mode 100644 index 0000000..68814f2 --- /dev/null +++ b/test/TestTikiCache.php @@ -0,0 +1,61 @@ +<?php +require_once('bit_setup_inc.php'); + +class TestBitCache extends Test { + + var $test; + var $name ="TestBitCache"; + + function TestBitCache() + { + // global $gBitCache; + $this->test = new BitCache(); + Assert::equals(is_object($this->test), 'Error during initialisation'); + if (!is_object($this->test)) { + $this = NULL; + return; + } + + } + + function testGetNonexistentCachedItem() + { + Assert::equals($this->test->getCached("TestBitCache"), NULL); + } + + function testIsNonexistentItemCached() + { + Assert::equals($this->test->isCached("TestBitCache"), false); + } + + function testRemoveNonexistentCachedItem() + { + $this->test->removeCached("TestBitCache"); + Assert::equals($this->test->isCached("TestBitCache"), false); + } + + function testSetCachedItem() + { + $this->test->setCached("TestBitCache", "123"); + Assert::equals($this->test->isCached("TestBitCache"), true); + } + + function testGetCachedItem() + { + Assert::equals($this->test->getCached("TestBitCache"), "123"); + } + + function testIsItemCached() + { + Assert::equals($this->test->isCached("TestBitCache"), true); + } + + function testRemoveCachedItem() + { + $this->test->removeCached("TestBitCache"); + Assert::equals($this->test->isCached("TestBitCache") || + $this->test->getCached("TestBitCache") != NULL, false); + } +} +?> + diff --git a/test/TestTikiDatabase.php b/test/TestTikiDatabase.php Binary files differnew file mode 100644 index 0000000..0435566 --- /dev/null +++ b/test/TestTikiDatabase.php diff --git a/test/TestTikiPreferences.php b/test/TestTikiPreferences.php new file mode 100644 index 0000000..8901136 --- /dev/null +++ b/test/TestTikiPreferences.php @@ -0,0 +1,51 @@ +<?php +require_once('bit_setup_inc.php'); +require_once(KERNEL_PKG_PATH.'BitPreferences.php'); + +class TestBitPreferences extends Test { + + var $test; + + function TestBitPreferences() + { + global $gBitDb, $gCache; + $tmpDB = $gBitDb; + $tmpCache = $gCache; + $gBitDb = NULL; + $gCache = NULL; + $this->test = new BitPreferences("TestBitPreferences"); + $gBitDb = $tmpDB; + $gCache = $tmpCache; + Assert::equalsTrue($this->test != NULL, 'Error during initialisation'); + } + + function testGetNonexistentItem() + { + Assert::equals($this->test->getPreference("test"), NULL); + } + + function testSetNonexistentItem() + { + $this->test->setPreference("test", "123"); + Assert::equals($this->test->getPreference("test"), "123"); + } + + function testSetDefaultItem() + { + $this->test->setDefaultPreference("test", "456"); + Assert::equals($this->test->getPreference("test"), "123"); + } + + function testSetAsDefaultItem() + { + $this->test->setPreference("test", "456"); + Assert::equals($this->test->getPreference("test"), "456"); + } + + function testResetItem() + { + $this->test->setPreference("test", NULL); + Assert::equals($this->test->getPreference("test"), "456"); + } +} +?> diff --git a/test/TestTikiPreferencesCache.php b/test/TestTikiPreferencesCache.php new file mode 100644 index 0000000..8319559 --- /dev/null +++ b/test/TestTikiPreferencesCache.php @@ -0,0 +1,67 @@ +<?php +require_once('bit_setup_inc.php'); +require_once(KERNEL_PKG_PATH.'BitPreferences.php'); + +class TestBitPreferencesCache extends Test { + + var $name = "TestBitPreferencesCache"; + + function initBitPreferences() + { + global $gBitDb; + $tmpDB = $gBitDb; + $gBitDb = NULL; + $test = new BitPreferences($this->name); + $gBitDb = $tmpDB; + return $test; + } + + function TestBitPreferencesCache() + { + global $gCache; + if (!is_object($gCache)) { + $this = NULL; + return; + } + $test = $this->initBitPreferences(); + Assert::equals($test != NULL, 'Error during initialisation'); + + } + + function testGetNonexistentItem() + { + $test = $this->initBitPreferences(); + Assert::equals($test->getPreference("test"), NULL); + } + + function testSetNonexistentItem() + { + $test = $this->initBitPreferences(); + $test->setPreference("test", "123"); + Assert::equals($test->getPreference("test"), "123"); + } + + function testSetDefaultItem() + { + $test = $this->initBitPreferences(); + $test->setDefaultPreference("test", "456"); + Assert::equals($test->getPreference("test"), "123"); + } + + function testSetAsDefaultItem() + { + $test = $this->initBitPreferences(); + $test->setDefaultPreference("test", "456"); + $test->setPreference("test", "456"); + Assert::equals($test->getPreference("test"), "456"); + } + + function testResetItem() + { + $test = $this->initBitPreferences(); + $test->setDefaultPreference("test", "456"); + $test->setPreference("test", NULL); + Assert::equals($test->getPreference("test"), "456"); + } +} +?> diff --git a/test/TestTikiPreferencesCacheDatabase.php b/test/TestTikiPreferencesCacheDatabase.php new file mode 100644 index 0000000..be7fe04 --- /dev/null +++ b/test/TestTikiPreferencesCacheDatabase.php @@ -0,0 +1,69 @@ +<?php +require_once('bit_setup_inc.php'); +require_once(KERNEL_PKG_PATH.'BitPreferences.php'); + +class TestBitPreferencesCacheDatabase extends Test { + + var $name = "TestBitPreferencesCacheDatabase"; + + function TestBitPreferencesCacheDatabase() + { + global $gBitDb, $gBitCache; + $gBitCache = new BitCache(); + if (!is_object($gBitDb) || !is_object($gBitCache)) { + $this = NULL; + return; + } + $name = "`".$this->name."`"; + if (!$gBitDb->tableExists($name)) { + $tables = array( + $name => " + `name` C(50) PRIMARY, + `value` C(255) + "); + $gBitDb->createTables($tables); + } + $test = new BitPreferences($this->name); + Assert::equalsTrue($test != NULL, 'Error during initialisation'); + + } + + function testGetNonexistentItem() + { + $test = new BitPreferences($this->name); + Assert::equals($test->getPreference("test"), NULL); + } + + function testSetNonexistentItem() + { + $test = new BitPreferences($this->name); + $test->setPreference("test", "123"); + Assert::equals($test->getPreference("test"), "123"); + } + + function testSetDefaultItem() + { + $test = new BitPreferences($this->name); + //$test->mDebug = true; + $test->setDefaultPreference("test", "456"); + Assert::equals($test->getPreference("test"), "123"); + } + + function testSetAsDefaultItem() + { + $test = new BitPreferences($this->name); + //$test->mDebug = true; + $test->setDefaultPreference("test", "456"); + $test->setPreference("test", "456"); + Assert::equals($test->getPreference("test"), "456"); + } + + function testResetItem() + { + $test = new BitPreferences($this->name); + $test->setDefaultPreference("test", "456"); + $test->setPreference("test", NULL); + Assert::equals($test->getPreference("test"), "456"); + } +} +?> diff --git a/test/TestTikiPreferencesDatabase.php b/test/TestTikiPreferencesDatabase.php new file mode 100644 index 0000000..27b3209 --- /dev/null +++ b/test/TestTikiPreferencesDatabase.php @@ -0,0 +1,82 @@ +<?php +require_once('bit_setup_inc.php'); +require_once(KERNEL_PKG_PATH.'BitPreferences.php'); + +class TestBitPreferencesDatabase extends Test { + + var $name = "TestBitPreferencesDatabase"; + + function initBitPreferences() + { + global $gCache; + $tmpCache = $gCache; + $gCache = NULL; + $test = new BitPreferences($this->name); + $gCache = $tmpCache; + return $test; + } + + function TestBitPreferencesDatabase() + { + global $gBitDb; + if (!is_object($gBitDb)) { + $this = NULL; + return; + } + $name = "`".$this->name."`"; + if (!$gBitDb->tableExists($name)) { + $tables = array( + $name => " + `name` C(50) PRIMARY, + `value` C(255) + "); + $gBitDb->createTables($tables); + } + $test = $this->initBitPreferences(); + Assert::equalsTrue($test != NULL, 'Error during initialisation'); + + } + + function testGetNonexistentItem() + { + $test = $this->initBitPreferences(); + Assert::equals($test->getPreference("test"), NULL); + } + + function testSetNonexistentItem() + { + $test = $this->initBitPreferences(); + //$test->mDebug = true; + $test->setPreference("test", "123"); + Assert::equals($test->getPreference("test"), "123"); + } + + function testSetDefaultItem() + { + $test = $this->initBitPreferences(); + //$test->mDebug = true; + $test->setDefaultPreference("test", "456"); + Assert::equals($test->getPreference("test"), "123"); + } + + function testSetAsDefaultItem() + { + $test = $this->initBitPreferences(); + //$test->mDebug = true; + $test->setDefaultPreference("test", "456"); + $test->setPreference("test", "456"); + Assert::equals($test->getPreference("test"), "456"); + } + + function testResetItem() + { + global $gBitDb; + $tables = array("`".$this->name."`"); + $test = $this->initBitPreferences(); + $test->setDefaultPreference("test", "456"); + $test->setPreference("test", NULL); + Assert::equals($test->getPreference("test"), "456"); + $gBitDb->dropTables($tables); + } +} +?> diff --git a/test/TestTikiSmartyFilter.php b/test/TestTikiSmartyFilter.php new file mode 100644 index 0000000..e5430d4 --- /dev/null +++ b/test/TestTikiSmartyFilter.php @@ -0,0 +1,127 @@ +<?php + +require_once('bit_setup_inc.php'); +// require_once(KERNEL_PKG_PATH.'BitPreferences.php'); + + +class InputOutputTester { + +} + + +class TestBitSmartyFilter extends Test { + + var $filterTestDir; + var $smartyDir; + + + function TestBitSmartyFilter () + { + // directory that contains test directories + $this->filterTestDir = 'smarty_filter_tests'; + $this->smartyDir = KERNEL_PKG_PATH . 'smarty_tiki'; + } + + function testPrePostFilters () + { + global $gBitLanguage; + $gBitLanguage->mLanguage = 'sv'; + + Assert::assert(is_dir("$this->filterTestDir"), // Quite fatal + "$this->filterTestDir is not a directory"); + + // echo "$this->filterTestDir<br />"; + + $filterTestDirHandle = opendir($this->filterTestDir); + while (false !== ($filterTestCase = readdir($filterTestDirHandle))) { + $filterTestCaseDir = $this->filterTestDir . '/' . $filterTestCase; + Assert::assert(is_dir ($filterTestCaseDir), + "$filterTestCaseDir is not a directory"); + + // echo "$filterTestCaseDir<br />"; + if (preg_match('/(.+)filter\.(.+)/', $filterTestCase, $matches)) { + // echo "$matches[0]<br />"; + + $filterType = $matches[1]; + $filterBase = $matches[2]; + + $smartyFile = + $this->smartyDir . '/' . $filterType .'filter.' . $filterBase . '.php'; + $filterName = 'smarty_' . $filterType . 'filter_' .$filterBase; + + // echo "$smartyFile<br />"; + // echo "$filterName<br />"; + + Assert::equalsTrue(file_exists ($smartyFile), + "Smarty filter $smartyFile is missing"); + include_once($smartyFile); + + // echo "$filterTestCaseDir<br />"; + $filterTestCaseDirHandle = opendir("$filterTestCaseDir"); + while (false != ($inputFile = readdir($filterTestCaseDirHandle))) { + if (preg_match('/^(.+)\.input$/', $inputFile, $matches)) { + $baseName = $matches[1]; + $outputFile = $filterTestCaseDir . '/' . $baseName . '.output'; + $errorFile = $filterTestCaseDir . '/' . $baseName . '.error'; + $inputFile = $filterTestCaseDir . '/' . $inputFile; + + + // echo "$inputFile<br />"; + // echo "$outputFile<br />"; + // echo "$errorFile<br />"; + + Assert::equalsTrue(file_exists ($inputFile), + "Input file <strong>$inputFile</strong> " . + "is missing"); + + // remove error file if there is no error + + if (file_exists($errorFile)) { + @unlink ($errorFile); + } + + $input = file_get_contents($inputFile); + // $filterOutput = call_user_func ($filterName, $input, &$smarty); + $filterOutput = call_user_func_array ($filterName, + array($input, &$smarty)); + + if (!file_exists($outputFile)) { + // Output file does not exist - Create error file + // echo "OUTPUT does not Exists<br />"; + Assert::equalsTrue(file_exists ($outputFile), + "Output file <strong>$outputFile</strong> " . + "is missing, " . + "<strong>$errorFile</strong> created."); + + // Error handling missing when writing to file, + // final code should be encapsulated in a function. + $outHandle = fopen ($errorFile, 'wb'); + fwrite ($outHandle, $filterOutput, strlen ($filterOutput)); + fclose($outHandle); + // echo "END OUTPUT does not Exists<br />"; + // break; + } + + else { + // echo "OUTPUT Exists<br />"; + $output = file_get_contents($outputFile); + $compareResult = strcmp ($output, $filterOutput); + Assert::equals(0, $compareResult, + "<strong>$inputFile</strong> did not match " . + "output, incorrect data stored in " . + "<strong>$errorFile</strong>"); + if (0 != $compareResult) { + $outHandle = fopen ($errorFile, 'wb'); + fwrite ($outHandle, $filterOutput, strlen ($filterOutput)); + fclose($outHandle); + } + // echo "END OUTPUT Exists<br />"; + } + } + } + } + } + } +} + +?>
\ No newline at end of file diff --git a/test/bit_setup_inc.php b/test/bit_setup_inc.php new file mode 100644 index 0000000..dc4d619 --- /dev/null +++ b/test/bit_setup_inc.php @@ -0,0 +1,3 @@ +<?php +require_once('../../bit_setup_inc.php'); +?> diff --git a/test/index.php b/test/index.php new file mode 100644 index 0000000..cd36aa4 --- /dev/null +++ b/test/index.php @@ -0,0 +1,359 @@ +<?php +if (!defined('PHP_UNIT_INCLUDED')) +{ + + define('PHP_UNIT_INCLUDED', true); + +function errorHandler($errno, $errstr, $errfile, $errline) +{ + global $ERROR_FOUND, $ERROR_CRITICAL; + switch($errno) + { + case E_USER_ERROR: + echo "Fatal error: $errstr<br>"; + echo "Skipping remaining tests for this unit..."; + $ERROR_FOUND = true; + $ERROR_CRITICAL = true; + break; + case E_USER_WARNING: + echo $errstr . '<br>'; + $ERROR_FOUND = true; + break; + case E_WARNING: + echo "PHP WARNING on line <b>$errline</b> of file <b>$errfile</b>:"; + echo "$errstr<br>"; + break; + case E_NOTICE: + echo "PHP NOTICE on line <b>$errline</b> of file <b>$errfile</b>:"; + echo "$errstr<br>"; + break; + case E_ERROR: + echo "PHP ERROR on line <b>$errline</b> of file <b>$errfile</b>"; + echo "<br><b>Aborting...</b>"; + exit -1; + break; + default: + echo "PHP Unkown error $errno: $errstr<br>\n"; + break; + } +} + +class Assert +{ + function assert($bool, $message = '') + { + if (!$bool) + { + if ($message == '') + { + $message = "Assertion failed."; + } + trigger_error($message, E_USER_ERROR); + } + } + + function equals($value1, $value2, $message = '') + { + if ($value1 != $value2) + { + if ($message == '') + { + $message = "Assertion failed: <b>'$value1' != '$value2'</b>"; + } + trigger_error($message, E_USER_WARNING); + } + } + + function equalsTrue($bool, $message = '') + { + Assert::equals($bool, true, $message); + } + + function equalsFalse($bool, $message = '') + { + Assert::equals($bool, false, $message); + } +} + +class Test +{ + /*** + * Call all methods starting with 'test'. $class is the name of the class. + * Although not strictly necessary, it makes the output look better + * (properly capitalized). + ***/ + function run($class) + { + global $ERROR_FOUND, $ERROR_CRITICAL, $TESTS_COMPLETED, + $TESTS_SKIPPED, $TESTS_TOTAL; // Yikes! + if (strlen($class) > 4 && strtolower(substr($class, -4)) == 'test') + { + $class = substr($class, 0, strlen($class) - 4); + } + echo " <tr>\n"; + echo " <th colspan=2><b>$class</b></th>\n"; + echo " </tr>\n"; + $ERROR_CRITICAL = false; + $flipCss = false; + $methods = get_class_methods($this); + foreach ($methods as $method) { + // Don't continue running tests if something really bad happened. + // That is, if Assert::assert evaluated to true. + if ($ERROR_CRITICAL) { + break; + } + // Run a test if this method applies + if (strlen($method) > 4 && substr($method, 0, 4) == 'test') { + $TESTS_TOTAL++; + $ERROR_FOUND = false; + $css = $flipCss ? 'dark' : 'light'; + $flipCss = !$flipCss; + echo " <tr>\n"; + echo " <td class=$css width=50 nowrap valign=top>"; + echo substr($method, 4), "</td>\n"; + echo " <td class=$css valign=top>"; + $this->$method(); + if (!$ERROR_FOUND) { + $TESTS_COMPLETED++; + echo "<b>OK</b>"; + } + echo "</td>\n"; + echo " </tr>\n"; + } + } + } +} + +if (isset($GET['directory'])) { + $directory = dirname($GET['directory']); +} elseif (isset($_SERVER['PATH_TRANSLATED'])) { + $directory = dirname($_SERVER['PATH_TRANSLATED']); +} elseif (isset($_SERVER['SCRIPT_FILENAME'])) { + $directory = dirname($_SERVER['SCRIPT_FILENAME']); +} + +$dirValid = ($directory != '' && is_dir($directory)); + +if ($dirValid) +{ + $title = ': Results'; +} +else +{ + $title = ': Configuration'; +} +?> +<html> + <head> + <title>PHP Unit Tester<?php echo $title ?></title> + <style> + body { + background-color: rgb(95%, 95%, 100%); + font-family: Verdana, Arial, Helvetica, sans-serif; + margin-left: 10%; + margin-right: 10%; + } + + h1, h2 { + text-align: center; + } + + th { + background-color: rgb(0%, 0%, 0%); + color: white; + font-size: 15px; + font-weight: bold; + } + + td { + padding: 2px 10px 2px 10px; + font-size: 13px; + } + + table { + border: 1px solid black; + } + + td.dark { + background-color: rgb(80%, 80%, 90%); + } + + td.light { + background-color: rgb(90%, 90%, 100%); + } + + a:link { + text-decoration: none; + color: rgb(0%, 0%, 60%); + font-weight: bold; + } + + a:hover { + text-decoration: underline; + color: rgb(0%, 0%, 70%); + } + + a:visited { + color: rgb(0%, 0%, 80%); + } + </style> + </head> + + <body> + <h1>PHP Unit Tester<?php echo $title ?></h1> +<?php +if ($dirValid) +{ + $errorHandler = set_error_handler("errorHandler"); + error_reporting (E_ALL); + echo " <table align=center border=0 cellpadding=0 cellspacing=0 "; + echo "width=100%>\n"; + $TESTS_TOTAL = 0; + $TESTS_COMPLETED = 0; + $handle = opendir($directory); + while (($file = readdir($handle)) !== false) + { + if (strlen($file) > 5 && substr($file, -3) == 'php' && $file != 'bit_setup_inc.php') + { + include_once($directory . '/' . $file); + $class = substr($file, 0, strlen($file) - 4); + if (class_exists($class)) + { + $test = new $class; + if (is_subclass_of($test, 'Test')) + { + $test->run($class); + } + } + } + } + closedir($handle); + set_error_handler("errorHandler"); + echo " </table>\n"; + echo " <p>Successfully executed <b>$TESTS_COMPLETED</b> of "; + echo "<b>$TESTS_TOTAL</b> tests</p>\n"; +} +else +{ +?> + <h2>Set the Test Directory</h2> + <form> + <b>Directory</b>: <input type=text name="directory" value="<?php echo $directory ?>" + size=30> <input type=submit value="Run Tests"> + </form> + <p> + <b>Tip</b>: After setting the correct directory and clicking <b>Run Tests</b>, save + a bookmark to the resulting page. Opening that bookmark will immediately re-run all + tests. + </p> + +<?php +} // !$dirValid +?> + <h2>About the PHP Unit Tester</h2> + <p> + This small application can be used to automatically test PHP units. Although + (very!) distantly related to <a href="http://www.junit.org">jUnit</a>, it is by no + means as advanced as that particular package, nor is it intended to be. By + the way, if you're not into Object-Oriented Programming, haven't heard of + <i>Extreme Programming</i>, or the term <i>Refactoring</i> means nothing to you, + this application is probably not for you. + </p> + <p> + How does it work? Well, first put this file somewhere on your development + server. Then open it in your favorite browser (through the server), type in the + local path to the test units (e.g. <b>/data/www/tests</b>), and press + <b>Run Tests</b>. That's all! + </p> + <p> + Once a valid directory has been set, this application reads all PHP-files + (<b>*.php</b>) in that directory, and runs the tests in them. Thus, to add a + test to your suite, simply put it in mentioned directory. + </p> + <p> + Every test must be implemented in a class with the same name as the file it + is in. Thus, class <b>FileTest</b> should be in <b>FileTest.php</b>. Also, + the class must be a subclass of class <b>Test</b>. There's no need to include + this class, as this application takes care of that. + </p> + <p> + A basic test-class looks as follows (note, class <b>File</b> doesn't actually exist): + </p> + <pre><code> require_once('File.php'); // This is the class we're testing + + class FileTest extends Test + { + var $file; + + function FileTest() + { + unset($this->file); + $this->file = new File(); + } + + function testCreate() + { + Assert::assert(isset($this->file), "File object could not be instantiated"); + } + + function testOpen() + { + $this->file->open('test.dat'); + Assert::equalsTrue($this->file->isOpened(), "File couldn't be opened"); + } + + function testReadChar() + { + $char = '0'; + $char = $this->file->readChar(); + Assert::equals('a', $char); + } + + function testClose() + { + $this->file->close(); + Assert::equalsFalse($this->file->isOpened(), "File couldn't be closed"); + } + }</code></pre> + <p> + In short, the rules are as follows: + </p> + <ul> + <li>There's no need to call the parent constructor; it doesn't even exist.</li> + <li>A method that executes a test should have a name starting with <b>test</b>.</li> + <li>There should be no method with the name <b>run</b>. This is the <i>only</i> + method defined in class <b>Test</b>, and it isn't meant to be overridden.</li> + <li>Test methods are called in the order they are defined in the class. This allows + you - for example - to set up some variable in one test-method that can be + reused in a second.</li> + <li><b>Assert:assert</b> expects a boolean and an optional message string. If the + boolean evaluates to <b>false</b>, the test for that particular unit is + stopped, and the application continues with the next unit (if it exists).</li> + <li><b>Assert::equals</b> expects two values and an optional message. If the two + values aren't equal an error is printed, but all other tests for the unit will + still be executed.</li> + <li><b>Assert::equalsTrue</b> expects a value and an optional message. Its behavior + is like <b>Assert::equals</b>, with one of the values set to <b>true</b>.</li> + <li><b>Assert::equalsFalse</b> is like <b>Assert::equalsTrue</b>, with <b>false</b> + instead of <b>true</b>. (What a surprise...) + </ul> + <p> + As mentioned earlier, it's all very simple. At the same time I find it very useful. + If you want the application to do more, you are free to modify this code for your + own personal needs. + </p> + <p> + Final note: the code for this application is by no means representative for the + code I normally write! I hacked this thing together in about half an hour, so there + there you go. (Normally, I would <i>never</i> use global variables! I swear!) + </p> + <p> + Vincent Oostindië, + <a href="mailto:vincent@sunlight.tmfweb.nl">vincent@sunlight.tmfweb.nl</a>, + March 2002. + </p> + </body> +</html> +<?php +} // !defined('PHP_UNIT_INCLUDED') +?> diff --git a/test/smarty_filter_tests/prefilter.tr/simple.input b/test/smarty_filter_tests/prefilter.tr/simple.input new file mode 100644 index 0000000..48d07bc --- /dev/null +++ b/test/smarty_filter_tests/prefilter.tr/simple.input @@ -0,0 +1,5 @@ +{* Smarty *} + +This is som text that should not be translted +{tr} This is some text that should be translated, however it is not in the +dictionary, so it will not be translated, but the enclosing tr tags will dissapear {/tr}
\ No newline at end of file diff --git a/test/smarty_filter_tests/prefilter.tr/simple.output b/test/smarty_filter_tests/prefilter.tr/simple.output new file mode 100644 index 0000000..348ef47 --- /dev/null +++ b/test/smarty_filter_tests/prefilter.tr/simple.output @@ -0,0 +1,5 @@ + + +This is som text that should not be translted + This is some text that should be translated, however it is not in the +dictionary, so it will not be translated, but the enclosing tr tags will dissapear
\ No newline at end of file |
