com phpruntests: cookie section: src/testcase/preconditions/rtIsSectionImplemented.php src/testcase/rtTestConfiguration.php
src/testcase/sections/configurationsections/rtCookieSection.php src/testcase/sections/rtSection.php tests/testcase/rtCookieExecutionTest.php
tests/testcase/sections/configurationsections/rtCookieSectionTest.php

From: Date: Mon, 04 May 2009 17:02:37 +0000
Subject: com phpruntests: cookie section: src/testcase/preconditions/rtIsSectionImplemented.php src/testcase/rtTestConfiguration.php
src/testcase/sections/configurationsections/rtCookieSection.php src/testcase/sections/rtSection.php tests/testcase/rtCookieExecutionTest.php
tests/testcase/sections/configurationsections/rtCookieSectionTest.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-66492@lists.php.net to get a copy of this message
Commit: 3bdfeaf00228d88ec34459942bcf348f6261ea12 Author: Zoe Slattery <zoe@php.net> Mon, 4 May 2009 17:02:37 +0000 Parents: d755a3e80e45fc070192c5f30bbd912135fcb33b Branches: master Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=3bdfeaf00228d88ec34459942bcf348f6261ea12 Log: cookie section Changed paths: M src/testcase/preconditions/rtIsSectionImplemented.php M src/testcase/rtTestConfiguration.php A src/testcase/sections/configurationsections/rtCookieSection.php M src/testcase/sections/rtSection.php A tests/testcase/rtCookieExecutionTest.php A tests/testcase/sections/configurationsections/rtCookieSectionTest.php

diff --git a/src/testcase/preconditions/rtIsSectionImplemented.php b/src/testcase/preconditions/rtIsSectionImplemented.php index 1b69241..9be54c5 100644 --- a/src/testcase/preconditions/rtIsSectionImplemented.php +++ b/src/testcase/preconditions/rtIsSectionImplemented.php @@ -22,6 +22,7 @@ class rtIsSectionImplemented implements rtTestPreCondition 'GZIP_POST' => 'rtGzipPostSection', 'DEFLATE_POST' => 'rtDeflatePostSection', 'POST_RAW' => 'rtPostRawSection', + 'COOKIE' => 'rtCookieSection', ); /** Return the message associated with an unimplemented test section diff --git a/src/testcase/rtTestConfiguration.php b/src/testcase/rtTestConfiguration.php index cd13623..9561a82 100644 --- a/src/testcase/rtTestConfiguration.php +++ b/src/testcase/rtTestConfiguration.php @@ -48,12 +48,6 @@ class rtTestConfiguration $this->setPhpExecutable($runConfiguration, $sectionHeadings); $this->setInputFileString($runConfiguration, $sections, $sectionHeadings); - if($this->cgiTest) { - $this->environmentVariables['SCRIPT_FILENAME'] = $fileSection->getFileName(); - $this->environmentVariables['PATH_TRANSLATED'] = $fileSection->getFileName(); - //Required by when the cgi has been compiled with force-cgi-redirect. - $this->environmentVariables['REDIRECT_STATUS'] = '1'; - } } private function setEnvironmentVariables(rtRuntestsConfiguration $runConfiguration, $sections, $fileSection) @@ -63,20 +57,33 @@ class rtTestConfiguration if (array_key_exists('ENV', $sections)) { $this->environmentVariables = array_merge($this->environmentVariables, $sections['ENV']->getTestEnvironmentVariables()); } - if (array_key_exists('GET', $sections)) { - $this->environmentVariables = array_merge($this->environmentVariables, $sections['GET']->getGetVariables()); - } - if (array_key_exists('POST', $sections)) { - $this->environmentVariables = array_merge($this->environmentVariables, $sections['POST']->getPostVariables()); - } - if (array_key_exists('GZIP_POST', $sections)) { - $this->environmentVariables = array_merge($this->environmentVariables, $sections['GZIP_POST']->getPostVariables()); - } - if (array_key_exists('DEFLATE_POST', $sections)) { - $this->environmentVariables = array_merge($this->environmentVariables, $sections['DEFLATE_POST']->getPostVariables()); - } - if (array_key_exists('POST_RAW', $sections)) { - $this->environmentVariables = array_merge($this->environmentVariables, $sections['POST_RAW']->getPostVariables()); + + if($this->cgiTest) { + $this->environmentVariables['SCRIPT_FILENAME'] = $fileSection->getFileName(); + $this->environmentVariables['PATH_TRANSLATED'] = $fileSection->getFileName(); + //Required by when the cgi has been compiled with force-cgi-redirect. + $this->environmentVariables['REDIRECT_STATUS'] = '1'; + //Default is GET + $this->environmentVariables['REQUEST_METHOD'] = 'GET'; + + if (array_key_exists('GET', $sections)) { + $this->environmentVariables = array_merge($this->environmentVariables, $sections['GET']->getGetVariables()); + } + if (array_key_exists('POST', $sections)) { + $this->environmentVariables = array_merge($this->environmentVariables, $sections['POST']->getPostVariables()); + } + if (array_key_exists('GZIP_POST', $sections)) { + $this->environmentVariables = array_merge($this->environmentVariables, $sections['GZIP_POST']->getPostVariables()); + } + if (array_key_exists('DEFLATE_POST', $sections)) { + $this->environmentVariables = array_merge($this->environmentVariables, $sections['DEFLATE_POST']->getPostVariables()); + } + if (array_key_exists('POST_RAW', $sections)) { + $this->environmentVariables = array_merge($this->environmentVariables, $sections['POST_RAW']->getPostVariables()); + } + if (array_key_exists('COOKIE', $sections)) { + $this->environmentVariables = array_merge($this->environmentVariables, $sections['COOKIE']->getCookieVariables()); + } } } diff --git a/src/testcase/sections/configurationsections/rtCookieSection.php b/src/testcase/sections/configurationsections/rtCookieSection.php new file mode 100644 index 0000000..0c57725 --- /dev/null +++ b/src/testcase/sections/configurationsections/rtCookieSection.php @@ -0,0 +1,34 @@ +<?php +/** + * rtGetSection + * Sets environment variables for COOKIE section + * + * + * @category Testing + * @package RUNTESTS + * @author Zoe Slattery <zoe@php.net> + * @author Stefan Priebsch <spriebsch@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 rtCookieSection extends rtConfigurationSection +{ + private $cookieVariables = array(); + + protected function init() + { + $this->cookieVariables['HTTP_COOKIE'] = $this->sectionContents[0]; + } + + /** + * Additional GET environment variables required by the test + * + * @return array + */ + public function getCookieVariables() + { + return $this->cookieVariables; + } +} +?> \ No newline at end of file diff --git a/src/testcase/sections/rtSection.php b/src/testcase/sections/rtSection.php index 914499b..7cc07c8 100644 --- a/src/testcase/sections/rtSection.php +++ b/src/testcase/sections/rtSection.php @@ -23,6 +23,7 @@ abstract class rtSection 'GZIP_POST' => 'rtGzipPostSection', 'DEFLATE_POST' => 'rtDeflatePostSection', 'POST_RAW' => 'rtPostRawSection', + 'COOKIE' => 'rtCookieSection', ); protected $sectionName; diff --git a/tests/testcase/rtCookieExecutionTest.php b/tests/testcase/rtCookieExecutionTest.php new file mode 100644 index 0000000..9d941ba --- /dev/null +++ b/tests/testcase/rtCookieExecutionTest.php @@ -0,0 +1,56 @@ +<?php + +require_once 'PHPUnit/Framework.php'; +require_once dirname(__FILE__) . '../../../src/rtAutoload.php'; + +class rtCookieExecutionTest extends PHPUnit_Framework_TestCase +{ + private $path_to_tests; + private $sample_test; + private $sample_fail; + + public function setUp() + { + $this->php = trim(shell_exec("which php")); + $this->php_cgi = trim(shell_exec("which php-cgi")); + + $this->path_to_tests = realpath(dirname(__FILE__) . '/../../phpt-tests'); + $this->sample_test = $this->path_to_tests . '/sample_cookie.phpt'; + } + + public function tearDown() + { + @unlink($this->path-to_tests . '/sample_cookie.php'); + } + + public function testFileRun() + { + //Create a new test configuration + $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', $this->php, $this->sample_test)); + $config->setEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE',$this->php_cgi); + $config->configure(); + + //Retrieve the array of test file names + $testFiles = $config->getSetting('TestFiles'); + + //Read the test file + $testFile = new rtPhpTestFile(); + $testFile->doRead($testFiles[0]); + $testFile->normaliseLineEndings(); + + //Create a new test case + $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $config); + + //Setup and set the local environment for the test case + $testCase->executeTest($config); + + $status = $testCase->getStatus(); + + $this->assertEquals('', $status['pass']); + + + } +} + +?> +?> \ No newline at end of file diff --git a/tests/testcase/sections/configurationsections/rtCookieSectionTest.php b/tests/testcase/sections/configurationsections/rtCookieSectionTest.php new file mode 100644 index 0000000..9ded597 --- /dev/null +++ b/tests/testcase/sections/configurationsections/rtCookieSectionTest.php @@ -0,0 +1,15 @@ +<?php +require_once 'PHPUnit/Framework.php'; +require_once dirname(__FILE__) . '../../../../../src/rtAutoload.php'; + +class rtCookieSectionTest extends PHPUnit_Framework_TestCase +{ + public function testCreateInstance() + { + $cookieSection = new rtCookieSection('COOKIE', array('hello=World&goodbye=MrChips')); + $envlist = $cookieSection->getCookieVariables(); + + $this->assertEquals('hello=World&goodbye=MrChips', $envlist['HTTP_COOKIE']); + } +} +?> \ No newline at end of file
« previous php.qa (#66492) next »