Index: TestCase.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phpunit/lib/DrupalTest/TestCase.php,v
retrieving revision 1.4
diff -u -r1.4 TestCase.php
--- TestCase.php	12 Mar 2009 06:37:52 -0000	1.4
+++ TestCase.php	13 Mar 2009 07:09:04 -0000
@@ -36,10 +36,19 @@
    */
   protected function setUp() {
     parent::setUp();
-    // Save the current working directory. 
-    $this->currentWorkingDir = getcwd();
-    // Put us in the root path of the drupal install. 
-    chdir(DrupalTest_Bootstrap::getInstance()->drupalRoot);
+
+    // setUp operations when using the command line test runner.
+    if (PHP_SAPI == 'cli') {
+      // Put ourselves in the correct working directory for Drupal. 
+      $working_dir = getcwd();
+      $drupal_root = DrupalTest_Bootstrap::getInstance()->drupalRoot;
+      if ($working_dir != $drupal_root) {
+        // Save the current working directory. 
+        $this->currentWorkingDir = $working_dir;
+        // Put us in the root path of the drupal install. 
+        chdir($drupal_root);
+      }
+    }
 
     /** 
      * Supress devel footer output.
@@ -57,7 +66,13 @@
    */
   protected function tearDown() {
     parent::tearDown();
-    // Return us to our starting working directory. 
-    chdir($this->currentWorkingDir);
+
+    // tearDown operations when using the command line test runner.
+    if (PHP_SAPI == 'cli') {
+      // Return us to our starting working directory. 
+      if (!empty($this->currentWorkingDir)) {
+        chdir($this->currentWorkingDir);
+      }
+    }
   }
 }
\ No newline at end of file
Index: TestSuite.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phpunit/lib/DrupalTest/TestSuite.php,v
retrieving revision 1.2
diff -u -r1.2 TestSuite.php
--- TestSuite.php	24 Feb 2009 07:46:49 -0000	1.2
+++ TestSuite.php	13 Mar 2009 07:07:10 -0000
@@ -8,8 +8,15 @@
 * @package DrupalTest
 * @author  Christopher Hopper <christopher.jf.hopper@gmail.com>
 */
-class DrupalTest_TestSuite extends PHPUnit_Framework_TestSuite
-{
+class DrupalTest_TestSuite extends PHPUnit_Framework_TestSuite {
+  /**
+  * A location where we can store the working directory we started in 
+  * before we put ourselves in the root path of the drupal install. 
+  * 
+  * @var string
+  */
+  protected $currentWorkingDir;
+  
   /**
    * @return DrupalTest_TestSuite
    *    Instance of the DrupalTest TestSuite.
@@ -24,9 +31,24 @@
    * @return void
    */
   protected function setUp() {
+    parent::setUp();
+
     // Back-up the Drupal Database prior to running Test Suite.
 //    DrupalTest_Bootstrap::getInstance()->backupDatabase();
     
+    // setUp operations when using the command line test runner.
+    if (PHP_SAPI == 'cli') {
+      // Put ourselves in the correct working directory for Drupal. 
+      $working_dir = getcwd();
+      $drupal_root = DrupalTest_Bootstrap::getInstance()->drupalRoot;
+      if ($working_dir != $drupal_root) {
+        // Save the current working directory. 
+        $this->currentWorkingDir = $working_dir;
+        // Put us in the root path of the drupal install. 
+        chdir($drupal_root);
+      }
+    }
+
     // Create a shared test_user fixture that will exist for all tests in 
     // the test suite.
     $test_user = array(
@@ -48,12 +70,21 @@
    * @return void
    */
   protected function tearDown() {
+    parent::tearDown();
     
     // Remove the test user created for our shared fixture in setUp. 
     if (isset($this->test_user->uid)) {
       user_delete(array(), $this->test_user->uid);
     }
     
+    // tearDown operations when using the command line test runner.
+    if (PHP_SAPI == 'cli') {
+      // Return us to our starting working directory. 
+      if (!empty($this->currentWorkingDir)) {
+        chdir($this->currentWorkingDir);
+      }
+    }
+    
     // Restore the Drupal Database back to the state saved prior to 
     // running our Test Suite.
 //    DrupalTest_Bootstrap::getInstance()->restoreDatabase();

