com phpruntests: phpruntests - implemented FILE_EXTERNAL-sect ion (not final): src/rtClassMap.php src/testcas
e/preconditions/rtIsSectionImplemented.php src/testcase/sec tions/executablesections/_rtFileExternalSection.php src/t
estcase/sections/executablesections/rtFileExternalSection.php src/testcase/sections/rtSection.php
| From: | David Soria Parra | Date: | Fri, 15 May 2009 09:58:21 +0000 |
| Subject: | com phpruntests: phpruntests - implemented FILE_EXTERNAL-sect ion (not final): src/rtClassMap.php src/testcas e/preconditions/rtIsSectionImplemented.php src/testcase/sec tions/executablesections/_rtFileExternalSection.php src/t estcase/sections/executablesections/rtFileExternalSection.php src/testcase/sections/rtSection.php |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66457@lists.php.net to get a copy of this message | ||
Commit: 76126176a114eacfda38616a336d05a2d1b733f0
Author: Georg Gradwohl <g2@php.net> Fri, 15 May 2009 09:58:21 +0000
Parents: 40ee33d19fbf6218b853009511114544d06d39a2
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=76126176a114eacfda38616a336d05a2d1b733f0
Log:
phpruntests - implemented FILE_EXTERNAL-section (not final)
Changed paths:
M src/rtClassMap.php
M src/testcase/preconditions/rtIsSectionImplemented.php
A src/testcase/sections/executablesections/_rtFileExternalSection.php
A src/testcase/sections/executablesections/rtFileExternalSection.php
M src/testcase/sections/rtSection.php
Diff:
diff --git a/src/rtClassMap.php b/src/rtClassMap.php
index 351daf2..f2aba5f 100644
--- a/src/rtClassMap.php
+++ b/src/rtClassMap.php
@@ -73,6 +73,7 @@ $rtClassMap = array(
'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',
diff --git a/src/testcase/preconditions/rtIsSectionImplemented.php
b/src/testcase/preconditions/rtIsSectionImplemented.php
index f6acfba..ce44b64 100644
--- a/src/testcase/preconditions/rtIsSectionImplemented.php
+++ b/src/testcase/preconditions/rtIsSectionImplemented.php
@@ -23,6 +23,7 @@ class rtIsSectionImplemented implements rtTestPreCondition
'DEFLATE_POST' => 'rtDeflatePostSection',
'POST_RAW' => 'rtPostRawSection',
'COOKIE' => 'rtCookieSection',
+ 'FILE_EXTERNAL' => 'rtFileExternalSection',
'EXPECTHEADERS' => 'rtExpectHeadersSection',
);
diff --git a/src/testcase/sections/executablesections/_rtFileExternalSection.php
b/src/testcase/sections/executablesections/_rtFileExternalSection.php
new file mode 100644
index 0000000..452e638
--- /dev/null
+++ b/src/testcase/sections/executablesections/_rtFileExternalSection.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * rtFileExternalSection
+ * Executes the code in the --FILE_EXTERNAL-- section
+ *
+ *
+ * @category Testing
+ * @package RUNTESTS
+ * @author Zoe Slattery <zoe@php.net>
+ * @author Stefan Priebsch <spriebsch@php.net>
+ * @author Georg Gradwohl <g2@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;
+ }
+}
+?>
diff --git a/src/testcase/sections/executablesections/rtFileExternalSection.php
b/src/testcase/sections/executablesections/rtFileExternalSection.php
new file mode 100644
index 0000000..040d052
--- /dev/null
+++ b/src/testcase/sections/executablesections/rtFileExternalSection.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * rtFileExternalSection
+ * Executes the code in the --FILE_EXTERNAL-- section
+ *
+ * @category Testing
+ * @package RUNTESTS
+ * @author Zoe Slattery <zoe@php.net>
+ * @author Stefan Priebsch <spriebsch@php.net>
+ * @author Georg Gradwohl <g2@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;
+ }
+}
+?>
diff --git a/src/testcase/sections/rtSection.php b/src/testcase/sections/rtSection.php
index b9cea91..e18e639 100644
--- a/src/testcase/sections/rtSection.php
+++ b/src/testcase/sections/rtSection.php
@@ -24,6 +24,7 @@ abstract class rtSection
'DEFLATE_POST' => 'rtDeflatePostSection',
'POST_RAW' => 'rtPostRawSection',
'COOKIE' => 'rtCookieSection',
+ 'FILE_EXTERNAL' => 'rtFileExternalSection',
'EXPECTHEADERS' => 'rtExpectHeadersSection',
);