g2              Fri May 15 09:58:22 2009 UTC

  Added files:                 
    /phpruntests/src/testcase/sections/executablesections       
                                                                
rtFileExternalSection.php 
                                                                
_rtFileExternalSection.php 

  Modified files:              
    /phpruntests/src/testcase/sections  rtSection.php 
    /phpruntests/src/testcase/preconditions     rtIsSectionImplemented.php 
    /phpruntests/src    rtClassMap.php 
  Log:
  phpruntests - implemented FILE_EXTERNAL-section (not final)
  
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/sections/rtSection.php?r1=1.9&r2=1.10&diff_format=u
Index: phpruntests/src/testcase/sections/rtSection.php
diff -u phpruntests/src/testcase/sections/rtSection.php:1.9 
phpruntests/src/testcase/sections/rtSection.php:1.10
--- phpruntests/src/testcase/sections/rtSection.php:1.9 Thu May 14 19:56:30 2009
+++ phpruntests/src/testcase/sections/rtSection.php     Fri May 15 09:58:21 2009
@@ -24,6 +24,7 @@
         'DEFLATE_POST'  => 'rtDeflatePostSection',
         'POST_RAW'  => 'rtPostRawSection',
         'COOKIE'    => 'rtCookieSection',
+        'FILE_EXTERNAL' =>  'rtFileExternalSection',
         'EXPECTHEADERS' => 'rtExpectHeadersSection',
     );
 
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/preconditions/rtIsSectionImplemented.php?r1=1.8&r2=1.9&diff_format=u
Index: phpruntests/src/testcase/preconditions/rtIsSectionImplemented.php
diff -u phpruntests/src/testcase/preconditions/rtIsSectionImplemented.php:1.8 
phpruntests/src/testcase/preconditions/rtIsSectionImplemented.php:1.9
--- phpruntests/src/testcase/preconditions/rtIsSectionImplemented.php:1.8       
Thu May 14 19:56:30 2009
+++ phpruntests/src/testcase/preconditions/rtIsSectionImplemented.php   Fri May 
15 09:58:21 2009
@@ -23,6 +23,7 @@
         'DEFLATE_POST'       => 'rtDeflatePostSection',
         'POST_RAW'    => 'rtPostRawSection',
         'COOKIE'    => 'rtCookieSection',
+        'FILE_EXTERNAL' =>  'rtFileExternalSection',
         'EXPECTHEADERS' => 'rtExpectHeadersSection',
     );    
 
http://cvs.php.net/viewvc.cgi/phpruntests/src/rtClassMap.php?r1=1.8&r2=1.9&diff_format=u
Index: phpruntests/src/rtClassMap.php
diff -u phpruntests/src/rtClassMap.php:1.8 phpruntests/src/rtClassMap.php:1.9
--- phpruntests/src/rtClassMap.php:1.8  Thu May 14 19:56:30 2009
+++ phpruntests/src/rtClassMap.php      Fri May 15 09:58:21 2009
@@ -73,6 +73,7 @@
     'rtPostRawSection'                         => 
'testcase/sections/configurationsections/rtPostRawSection.php',
     'rtPostSection'                            => 
'testcase/sections/configurationsections/rtPostSection.php',
     'rtCleanSection'                           => 
'testcase/sections/executablesections/rtCleanSection.php',
+    'rtFileExternalSection'                    => 
'testcase/sections/executablesections/rtFileExternalSection.php',
     'rtFileSection'                            => 
'testcase/sections/executablesections/rtFileSection.php',
     'rtSkipIfSection'                          => 
'testcase/sections/executablesections/rtSkipIfSection.php',
     'rtCreditsSection'                         => 
'testcase/sections/informationsections/rtCreditsSection.php',

http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/sections/executablesections/rtFileExternalSection.php?view=markup&rev=1.1
Index: 
phpruntests/src/testcase/sections/executablesections/rtFileExternalSection.php
+++ 
phpruntests/src/testcase/sections/executablesections/rtFileExternalSection.php
<?php
/**
 * rtFileExternalSection
 * Executes the code in the --FILE_EXTERNAL-- section
 *
 * @category  Testing
 * @package   RUNTESTS
 * @author    Zoe Slattery <z...@php.net>
 * @author    Stefan Priebsch <sprieb...@php.net>
 * @author    Georg Gradwohl <g...@php.net>
 * @copyright 2009 The PHP Group
 * @license   http://www.php.net/license/3_01.txt PHP License 3.01
 * @link      http://qa.php.net/
 */
class rtFileExternalSection extends rtFileSection
{

    public function run(rtPhpTest $testCase, rtRuntestsConfiguration 
$runConfiguration)
    {
        if ($this->copyExternalFileContent() === true) {

            return parent::run($testCase, $runConfiguration);
        }

        return $this->status;
    }

    
    private function copyExternalFileContent()
    {
        if (sizeof($this->sectionContents) == 1) {
        
                $file = $this->sectionContents[0];
                
                // don't allow tests to retrieve files from anywhere but this 
subdirectory
                $file = dirname($this->fileName).'/'.trim(str_replace('..', '', 
$file));
                
                if (file_exists($file)) {
                
                    $this->sectionContents[0] = file_get_contents($file);       
     
                    return true;
                
                } else {
                        
                        $this->status['fail'] = 'Can not open external file 
'.$file;
                }
        
        } else {
                
                $this->status['fail'] = 'One file per testcase permitted.';
        }
        
        return false;
    }
}
?>

http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/sections/executablesections/_rtFileExternalSection.php?view=markup&rev=1.1
Index: 
phpruntests/src/testcase/sections/executablesections/_rtFileExternalSection.php
+++ 
phpruntests/src/testcase/sections/executablesections/_rtFileExternalSection.php
<?php
/**
 * rtFileExternalSection
 * Executes the code in the --FILE_EXTERNAL-- section
 *
 *
 * @category  Testing
 * @package   RUNTESTS
 * @author    Zoe Slattery <z...@php.net>
 * @author    Stefan Priebsch <sprieb...@php.net>
 * @author    Georg Gradwohl <g...@php.net>
 * @copyright 2009 The PHP Group
 * @license   http://www.php.net/license/3_01.txt PHP License 3.01
 * @link      http://qa.php.net/
 */
class rtFileExternalSection extends rtExecutableSection
{
    private $twoBlankLines = '\r?\n\r?\n';
    
    public function setExecutableFileName($testName)
    {
        $this->fileName = $testName.".php";
    }

    public function run(rtPhpTest $testCase, rtRuntestsConfiguration 
$runConfiguration)
    {
        $this->status = array();
        $this->writeExecutableFile();

        $this->copyExternalFileContent();

        $phpExecutable = $testCase->testConfiguration->getPhpExecutable();

        // The CGI excutable is null if it is not available, check and SKIP if 
necessary
        if ($phpExecutable != null) {
            $phpCommand = $phpExecutable;
            $phpCommand .= ' '. 
$testCase->testConfiguration->getPhpCommandLineArguments();
            $phpCommand .= ' -f '.$this->fileName;
            $phpCommand .= ' 
'.$testCase->testConfiguration->getTestCommandLineArguments();
            $phpCommand .= ' 2>&1 
'.$testCase->testConfiguration->getInputFileString();
             

            $PhpRunner = new rtPhpRunner($phpCommand,
            $testCase->testConfiguration->getEnvironmentVariables(),
            $runConfiguration->getSetting('WorkingDirectory')
            );

            try {
                $this->output = $PhpRunner->runphp();
                
                //If it's a CGI test sort the headers out here
                if(substr($phpExecutable, -2) == '-C') {
                    
                    if (preg_match("/^(.*?)$this->twoBlankLines(.*)/s", 
$this->output, $match)) {
                        $this->output = $match[2];
                        $this->headers = $match[1];
                    }
                     
                }


            } catch (rtPhpRunnerException $e) {
                $this->status['fail'] = $e->getMessage();
            }
        } else {
            $this->status['skip'] = 'The CGI executable is unavailable';
        }

        return $this->status;
    }
    
    
    public function getHeaders()
    {
        return $this->headers;
    }
    
    
    private function copyExternalFileContent()
    {
        if (sizeof($this->sectionContents) == 1) {
        
                $c = $this->sectionContents[0];
                
                // don't allow tests to retrieve files from anywhere but this 
subdirectory
                $file = dirname($this->fileName).'/'.trim(str_replace('..', '', 
$c));
                
                if (file_exists($file)) {
                
                    $content = file_get_contents($file);         
                    file_put_contents($this->fileName, $content);
                    return true;
                
                } else {
                        
                        $this->status['fail'] = 'Can not open external file 
'.$file;
                }
        
        } else {
                
                $this->status['fail'] = 'One file per testcase permitted.';
        }
        
        return false;
    }
}
?>



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to