[pLog-svn] r4045 - in plog/branches/lifetype-1.1.1: . class/test

oscar at devel.lifetype.net oscar at devel.lifetype.net
Mon Sep 25 19:09:50 GMT 2006


Author: oscar
Date: 2006-09-25 19:09:49 +0000 (Mon, 25 Sep 2006)
New Revision: 4045

Modified:
   plog/branches/lifetype-1.1.1/class/test/testrunner.class.php
   plog/branches/lifetype-1.1.1/runtests.php
Log:
implemented feature request #1070 (http://bugs.lifetype.net/view.php?id=1070), so that plugins can also provide their own test cases and get them integrated with the rest of LT's suite when available. Plugin test cases should go in plugins/XXX/class/tests and follow the same naming convention as core test cases (testname_test.class.php)


Modified: plog/branches/lifetype-1.1.1/class/test/testrunner.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/test/testrunner.class.php	2006-09-25 15:47:00 UTC (rev 4044)
+++ plog/branches/lifetype-1.1.1/class/test/testrunner.class.php	2006-09-25 19:09:49 UTC (rev 4045)
@@ -68,15 +68,21 @@
 		 * @param folder Where test suites are stored. Defaults to class/test/tests (relative
 		 * to PLOG_CLASS_PATH)
 		 * @param pattern Pattern that will be used to check whether a file in folder $folder
+		 * @param includePlugins Whether test cases provided by plugins should also be loaded. This feature
+		 * depends on the PluginManager class and plugins must be placed in the plugins/ folder for 
+		 * this this work. The default value is 'false'
 		 * is a test suite. Defaults to "*_test.class.php"
 		 */
-		function TestRunner( $folder = TEST_CLASS_FOLDER, $pattern = TEST_CLASS_NAME_PATTERN )
+		function TestRunner( $folders = TEST_CLASS_FOLDER, $pattern = TEST_CLASS_NAME_PATTERN )
 		{
-			$this->folder = $folder;
+			if( !is_array( $folders )) 
+				$folders = Array( $folders );
+				
+			$this->folders = $folders;
 			$this->pattern = $pattern;
 			$this->excludeFolders = explode( ",", EXCLUDE_FOLDERS_LIST );
 			
-			$this->files = $this->_findClasses( $this->folder, $this->pattern );
+			$this->files = $this->_findClasses( $this->folders, $this->pattern );
 		}
 		
 		/**
@@ -141,32 +147,35 @@
 		 * it is used to easily find all the test classes. Later on these classes will be loaded, instantiated
 		 * and a test suite will be automatically created.
 		 */
-		function _findClasses( $folder = null, $pattern = "*" )
+		function _findClasses( $folders, $pattern = "*" )
 		{
 			$list = Array();
 			
-			$files = Glob::myGlob( $folder , "*" );
-			foreach( $files as $file ) {
-				// recursive call
-				if( File::isDir( $file )) {
-					if( array_search( basename( $file ), $this->excludeFolders ) === false )
-					{
-						$res = $this->_findClasses( $file, $pattern );
-						foreach( $res as $f ) {
-							$list[] = $f;
+			// load all test cases included in core code
+			foreach( $folders as $folder ) {
+				$files = Glob::myGlob( $folder , "*" );
+				foreach( $files as $file ) {
+					// recursive call
+					if( File::isDir( $file )) {
+						if( array_search( basename( $file ), $this->excludeFolders ) === false )
+						{
+							$res = $this->_findClasses( Array( $file ), $pattern );
+							foreach( $res as $f ) {
+								$list[] = $f;
+							}
 						}
 					}
+					else {
+						if ( File::isReadable( $file )) {						
+							if( Glob::fnmatch( $pattern, $file )) {
+								// add the file only if it matched our pattern
+								$list[] = $file;
+							}
+						}
+					}					
 				}
-				else {
-					if ( File::isReadable( $file )) {						
-						if( Glob::fnmatch( $pattern, $file )) {
-							// add the file only if it matched our pattern
-							$list[] = $file;
-						}
-					}
-				}					
 			}
-			
+						
 			return( $list );
 		}
 	}

Modified: plog/branches/lifetype-1.1.1/runtests.php
===================================================================
--- plog/branches/lifetype-1.1.1/runtests.php	2006-09-25 15:47:00 UTC (rev 4044)
+++ plog/branches/lifetype-1.1.1/runtests.php	2006-09-25 19:09:49 UTC (rev 4045)
@@ -5,6 +5,8 @@
 	<body>
 <?php
 
+	define( "INCLUDE_PLUGIN_TESTS", true );
+
 	if (!defined( "PLOG_CLASS_PATH" )) {
 	    define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
 	}
@@ -16,11 +18,24 @@
 	// get the suite name from the request or run all of them if no parameter specified
 	$request = HttpVars::getRequest();
 	$suiteName = isset( $request["suite"] ) ? strtolower($request["suite"]) : "";
+	
+	// if plugins should also be included when testing, let's load them now
+	$folders = Array( TEST_CLASS_FOLDER ); 
+	if( INCLUDE_PLUGIN_TESTS ) {
+		include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+		
+		$pm =& PluginManager::getPluginManager();
+		$plugins = $pm->getPluginListFromFolder();
+		
+		foreach( $plugins as $plugin ) {
+			$folders[] = PLOG_CLASS_PATH."plugins/".$plugin."/class/tests";
+		}
+	}
 
 	// create a new TestRunner class, which will take care of loading all our
 	// tests cases, instantiate them and tell PHPUnit to run the tests specified
 	// in the request
-	$r = new TestRunner();
+	$r = new TestRunner( $folders ); 
 	
 	if( $suiteName == "" ) {
 		// no suite name was specified, let's just show what we have



More information about the pLog-svn mailing list