Example #1
0
 /**
  * Checks the test using TestFS.
  *
  * @param String $test Test case path
  * @return Boolean
  */
 protected function _checkTest($test)
 {
     Extra_TestFS::loadFilesystem($test);
     $view = new Opt_View('test.tpl');
     if (file_exists('test://data.php')) {
         //	$code = ;
         //	echo $code;
         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);
             $this->assertEquals($this->stripWs(trim(file_get_contents('test://result.txt'))), $this->stripWs(trim($result)));
         } catch (Opt_Exception $e) {
             $this->fail('Exception returned: #' . get_class($e) . ': ' . $e->getMessage());
         }
     } else {
         // This test should generate an exception
         $expected = trim($expected);
         try {
             $out->render($view);
         } catch (Opt_Exception $e) {
             if ($expected != get_class($e)) {
                 $this->fail('Invalid exception returned: #' . get_class($e) . ', ' . $expected . ' expected.');
             }
             return true;
         }
         $this->fail('Exception NOT returned, but should be: ' . $expected);
     }
 }
Example #2
0
 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");
     }
 }
Example #3
0
 /**
  * Loads the filesystem into memory.
  * @param String $fs The path to the file with the filesystem.
  */
 public static function loadFilesystem($fs)
 {
     self::$files = array();
     $lines = file($fs);
     $currentFile = null;
     foreach ($lines as $line) {
         if (strpos($line, '>>>>') === 0) {
             $currentFile = 'test://' . trim(substr($line, 4, strlen($line)));
             self::$files[$currentFile] = '';
             continue;
         }
         if (!is_null($currentFile)) {
             self::$files[$currentFile] .= $line;
         }
     }
 }