Browse files

Implementing REDIRECTTEST: Add section class and test

  • Loading branch information...
1 parent 06ec4c5 commit fd9a5da89df77bc5478633c300b74697a106b844 zoe slattery committed May 20, 2012
View
3 src/rtClassMap.php
@@ -36,11 +36,9 @@
'rtUnixConfiguration' => 'configuration/unix/rtUnixConfiguration.php',
'rtUnixEnvironmentVariables' => 'configuration/unix/rtUnixEnvironmentVariables.php',
'rtUnixPreConditionList' => 'configuration/unix/rtUnixPreConditionList.php',
- 'rtUnixSettingList' => 'configuration/unix/rtUnixSettingList.php',
'rtWinConfiguration' => 'configuration/windows/rtWinConfiguration.php',
'rtWinEnvironmentVariables' => 'configuration/windows/rtWinEnvironmentVariables.php',
'rtWinPreConditionList' => 'configuration/windows/rtWinPreConditionList.php',
- 'rtWinSettingList' => 'configuration/windows/rtWinSettingList.php',
'rtAutoload' => 'rtAutoload.php',
'rtClassMap' => 'rtClassMap.php',
'rtDirectoryList' => 'rtDirectoryList.php',
@@ -61,6 +59,7 @@
'rtHasMandatorySections' => 'testcase/preconditions/rtHasMandatorySections.php',
'rtHasNoDuplicateSections' => 'testcase/preconditions/rtHasNoDuplicateSections.php',
'rtHasNoEmptySections' => 'testcase/preconditions/rtHasNoEmptySections.php',
+ 'rtIsNotRedirected' => 'testcase/preconditions/rtIsNotRedirected.php',
'rtIsSectionImplemented' => 'testcase/preconditions/rtIsSectionImplemented.php',
'rtIsValidSectionName' => 'testcase/preconditions/rtIsValidSectionName.php',
'rtPhpRunner' => 'testcase/rtPhpRunner.php',
View
5 src/testcase/preconditions/rtHasMandatorySections.php
@@ -35,10 +35,15 @@ public function isMet(array $testContents, array $sectionHeaders)
{
if (in_array('TEST', $sectionHeaders )) {
+
if (in_array('FILE', $sectionHeaders ) || in_array('FILEOF', $sectionHeaders) || in_array('FILE_EXTERNAL', $sectionHeaders)) {
if (in_array('EXPECT', $sectionHeaders ) || in_array('EXPECTF', $sectionHeaders) || in_array('EXPECTREGEX', $sectionHeaders)) {
return true;
}
+ } else {
+ if(in_array('REDIRECTTEST', $sectionHeaders)) {
+ return true;
+ }
}
}
View
31 src/testcase/preconditions/rtIsNotRedirected.php
@@ -0,0 +1,31 @@
+<?php
+class rtIsNotRedirected implements rtTestPreCondition
+{
+
+ /** Return the message associated with a redirected test section
+ *
+ * @return text
+ */
+ public function getMessage()
+ {
+ return rtText::get('isRedirected');
+ }
+
+ /**
+ * Check whether there is a REDIRECT section
+ *
+ * @param array $testCaseContents, array $sectionHeaders
+ * @return boolean
+ */
+ public function isMet(array $testContents, array $sectionHeaders)
+ {
+ foreach ($sectionHeaders as $section) {
+
+ if ($section == "REDIRECTTEST") {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+?>
View
28 src/testcase/preconditions/rtIsSectionImplemented.php
@@ -15,29 +15,9 @@
*/
class rtIsSectionImplemented implements rtTestPreCondition
{
- protected $sectionMap = array(
- 'TEST' => 'rtTestHeaderSection',
- 'DESCRIPTION' => 'rtDescriptionSection',
- 'SKIPIF' => 'rtSkipIfSection',
- 'FILE' => 'rtFileSection',
- 'EXPECT' => 'rtExpectSection',
- 'EXPECTF' => 'rtExpectFSection',
- 'EXPECTREGEX' => 'rtExpectRegexSection',
- 'INI' => 'rtIniSection',
- 'ARGS' => 'rtArgsSection',
- 'ENV' => 'rtEnvSection',
- 'STDIN' => 'rtStdinSection',
- 'CREDITS' => 'rtCreditsSection',
- 'CLEAN' => 'rtCleanSection',
- 'XFAIL' => 'rtXfailSection',
- 'GET' => 'rtGetSection',
- 'POST' => 'rtPostSection',
- 'GZIP_POST' => 'rtGzipPostSection',
- 'DEFLATE_POST' => 'rtDeflatePostSection',
- 'POST_RAW' => 'rtPostRawSection',
- 'COOKIE' => 'rtCookieSection',
- 'FILE_EXTERNAL' => 'rtFileExternalSection',
- 'EXPECTHEADERS' => 'rtExpectHeadersSection',
+ protected $sectionsNotImplementedMap = array(
+ 'PUT' => 'rtPutSection',
+ 'FILEEOF' => 'rtDescriptionSection',
);
/** Return the message associated with an unimplemented test section
@@ -58,7 +38,7 @@ public function getMessage()
public function isMet(array $testContents, array $sectionHeaders)
{
foreach ($sectionHeaders as $section) {
- if (!array_key_exists($section, $this->sectionMap)) {
+ if (array_key_exists($section, $this->sectionsNotImplementedMap)) {
return false;
}
}
View
6 src/testcase/preconditions/rtIsValidSectionName.php
@@ -15,6 +15,7 @@
*/
class rtIsValidSectionName implements rtTestPreCondition
{
+ //NOTE: The sections REQUEST, CGI, HEADERS are implemented in server-tests.php only
protected $validSectionNames = array(
'TEST',
'DESCRIPTION',
@@ -37,15 +38,16 @@ class rtIsValidSectionName implements rtTestPreCondition
'GZIP_POST',
'DEFLATE_POST',
'POST_RAW',
+ 'PUT',
'GET',
'COOKIE',
'REDIRECTTEST',
'HEADERS',
- 'EXPECTHEADERS',
+ 'EXPECTHEADERS',
);
/**
- * Return the message associated with a duplicate test section
+ * Return the message associated with an invalid test section
*
* @return text
*/
View
27 src/testcase/rtPhpTestFile.php
@@ -29,6 +29,7 @@ class rtPhpTestFile
'rtIsValidSectionName',
'rtIsSectionImplemented',
'rtHasNoEmptySections',
+ 'rtIsNotRedirected',
);
protected function isSectionHeading($string) {
@@ -75,32 +76,6 @@ public function normaliseLineEndings()
}
}
- /*
- * Removes and discards any empty test sections
- * Constructs a list of section headingg, stripped of their -- identifiers.
- */
- /* public function removeEmptySections() {
- $tempArray = array();
-
- for ($i=0; $i<count($this->testContents) - 1; $i++) {
- $nextLine = $this->testContents[$i+1];
- $thisLine = $this->testContents[$i];
- if ($this->isSectionHeading($thisLine)) {
- if (!$this->isSectionHeading($nextLine)) {
- $tempArray[] = $this->getUntrimmedSectionHeading($thisLine);
- $this->sectionHeadings[] = $this->getSectionHeading($thisLine);
- }
- } else {
- $tempArray[] = $thisLine;
- }
- }
-
- if($this->isSectionHeading(end($this->testContents))) {
- $this->sectionHeadings[] = $this->getSectionHeading(end($this->testContents));
- }
- $tempArray[] = end($this->testContents);
- $this->testContents = $tempArray;
- }*/
public function arePreConditionsMet()
{
View
1 src/texts/isRedirected.txt
@@ -0,0 +1 @@
+This test has a REDIRECTTEST section
View
23 tests/testcase/preconditions/rtIsNotRedirectedTest.php
@@ -0,0 +1,23 @@
+<?php
+require_once dirname(__FILE__) . '../../../../src/rtAutoload.php';
+
+class rtIsNotRedirectedTest extends PHPUnit_Framework_TestCase
+{
+ public function testIs()
+ {
+ $precondition = new rtIsNotRedirected();
+ $test = array('TEST', 'FILE', 'EXPECT');
+
+ $this->assertTrue($precondition->isMet(array(), $test));
+ }
+
+ public function testIsNot()
+ {
+ $precondition = new rtIsNotRedirected();
+ $test = array('UEXPECT', 'REDIRECTTEST');
+
+ $this->assertEquals("This test has a REDIRECTTEST section", trim($precondition->getMessage()));
+ $this->assertFalse($precondition->isMet(array(), $test));
+ }
+}
+?>
View
2 tests/testcase/preconditions/rtIsSectionImplementedTest.php
@@ -15,7 +15,7 @@ public function testIs()
public function testIsNot()
{
$precondition = new rtIsSectionImplemented();
- $test = array('UEXPECT', 'FILE');
+ $test = array('FILEEOF', 'FILE');
$this->assertEquals("The test contains a section which is not implemented yet.", trim($precondition->getMessage()));
$this->assertFalse($precondition->isMet(array(), $test));

0 comments on commit fd9a5da

Please sign in to comment.