Skip to content

Commit

Permalink
Implementing REDIRECTTEST: Add section class and test
Browse files Browse the repository at this point in the history
  • Loading branch information
zoe slattery committed May 20, 2012
1 parent 06ec4c5 commit fd9a5da
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 55 deletions.
3 changes: 1 addition & 2 deletions src/rtClassMap.php
Expand Up @@ -36,11 +36,9 @@
'rtUnixConfiguration' => 'configuration/unix/rtUnixConfiguration.php', 'rtUnixConfiguration' => 'configuration/unix/rtUnixConfiguration.php',
'rtUnixEnvironmentVariables' => 'configuration/unix/rtUnixEnvironmentVariables.php', 'rtUnixEnvironmentVariables' => 'configuration/unix/rtUnixEnvironmentVariables.php',
'rtUnixPreConditionList' => 'configuration/unix/rtUnixPreConditionList.php', 'rtUnixPreConditionList' => 'configuration/unix/rtUnixPreConditionList.php',
'rtUnixSettingList' => 'configuration/unix/rtUnixSettingList.php',
'rtWinConfiguration' => 'configuration/windows/rtWinConfiguration.php', 'rtWinConfiguration' => 'configuration/windows/rtWinConfiguration.php',
'rtWinEnvironmentVariables' => 'configuration/windows/rtWinEnvironmentVariables.php', 'rtWinEnvironmentVariables' => 'configuration/windows/rtWinEnvironmentVariables.php',
'rtWinPreConditionList' => 'configuration/windows/rtWinPreConditionList.php', 'rtWinPreConditionList' => 'configuration/windows/rtWinPreConditionList.php',
'rtWinSettingList' => 'configuration/windows/rtWinSettingList.php',
'rtAutoload' => 'rtAutoload.php', 'rtAutoload' => 'rtAutoload.php',
'rtClassMap' => 'rtClassMap.php', 'rtClassMap' => 'rtClassMap.php',
'rtDirectoryList' => 'rtDirectoryList.php', 'rtDirectoryList' => 'rtDirectoryList.php',
Expand All @@ -61,6 +59,7 @@
'rtHasMandatorySections' => 'testcase/preconditions/rtHasMandatorySections.php', 'rtHasMandatorySections' => 'testcase/preconditions/rtHasMandatorySections.php',
'rtHasNoDuplicateSections' => 'testcase/preconditions/rtHasNoDuplicateSections.php', 'rtHasNoDuplicateSections' => 'testcase/preconditions/rtHasNoDuplicateSections.php',
'rtHasNoEmptySections' => 'testcase/preconditions/rtHasNoEmptySections.php', 'rtHasNoEmptySections' => 'testcase/preconditions/rtHasNoEmptySections.php',
'rtIsNotRedirected' => 'testcase/preconditions/rtIsNotRedirected.php',
'rtIsSectionImplemented' => 'testcase/preconditions/rtIsSectionImplemented.php', 'rtIsSectionImplemented' => 'testcase/preconditions/rtIsSectionImplemented.php',
'rtIsValidSectionName' => 'testcase/preconditions/rtIsValidSectionName.php', 'rtIsValidSectionName' => 'testcase/preconditions/rtIsValidSectionName.php',
'rtPhpRunner' => 'testcase/rtPhpRunner.php', 'rtPhpRunner' => 'testcase/rtPhpRunner.php',
Expand Down
5 changes: 5 additions & 0 deletions src/testcase/preconditions/rtHasMandatorySections.php
Expand Up @@ -35,10 +35,15 @@ public function isMet(array $testContents, array $sectionHeaders)
{ {


if (in_array('TEST', $sectionHeaders )) { if (in_array('TEST', $sectionHeaders )) {

if (in_array('FILE', $sectionHeaders ) || in_array('FILEOF', $sectionHeaders) || in_array('FILE_EXTERNAL', $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)) { if (in_array('EXPECT', $sectionHeaders ) || in_array('EXPECTF', $sectionHeaders) || in_array('EXPECTREGEX', $sectionHeaders)) {
return true; return true;
} }
} else {
if(in_array('REDIRECTTEST', $sectionHeaders)) {
return true;
}
} }
} }


Expand Down
31 changes: 31 additions & 0 deletions 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;
}
}
?>
28 changes: 4 additions & 24 deletions src/testcase/preconditions/rtIsSectionImplemented.php
Expand Up @@ -15,29 +15,9 @@
*/ */
class rtIsSectionImplemented implements rtTestPreCondition class rtIsSectionImplemented implements rtTestPreCondition
{ {
protected $sectionMap = array( protected $sectionsNotImplementedMap = array(
'TEST' => 'rtTestHeaderSection', 'PUT' => 'rtPutSection',
'DESCRIPTION' => 'rtDescriptionSection', 'FILEEOF' => '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',
); );


/** Return the message associated with an unimplemented test section /** Return the message associated with an unimplemented test section
Expand All @@ -58,7 +38,7 @@ public function getMessage()
public function isMet(array $testContents, array $sectionHeaders) public function isMet(array $testContents, array $sectionHeaders)
{ {
foreach ($sectionHeaders as $section) { foreach ($sectionHeaders as $section) {
if (!array_key_exists($section, $this->sectionMap)) { if (array_key_exists($section, $this->sectionsNotImplementedMap)) {
return false; return false;
} }
} }
Expand Down
6 changes: 4 additions & 2 deletions src/testcase/preconditions/rtIsValidSectionName.php
Expand Up @@ -15,6 +15,7 @@
*/ */
class rtIsValidSectionName implements rtTestPreCondition class rtIsValidSectionName implements rtTestPreCondition
{ {
//NOTE: The sections REQUEST, CGI, HEADERS are implemented in server-tests.php only
protected $validSectionNames = array( protected $validSectionNames = array(
'TEST', 'TEST',
'DESCRIPTION', 'DESCRIPTION',
Expand All @@ -37,15 +38,16 @@ class rtIsValidSectionName implements rtTestPreCondition
'GZIP_POST', 'GZIP_POST',
'DEFLATE_POST', 'DEFLATE_POST',
'POST_RAW', 'POST_RAW',
'PUT',
'GET', 'GET',
'COOKIE', 'COOKIE',
'REDIRECTTEST', 'REDIRECTTEST',
'HEADERS', 'HEADERS',
'EXPECTHEADERS', 'EXPECTHEADERS',
); );


/** /**
* Return the message associated with a duplicate test section * Return the message associated with an invalid test section
* *
* @return text * @return text
*/ */
Expand Down
27 changes: 1 addition & 26 deletions src/testcase/rtPhpTestFile.php
Expand Up @@ -29,6 +29,7 @@ class rtPhpTestFile
'rtIsValidSectionName', 'rtIsValidSectionName',
'rtIsSectionImplemented', 'rtIsSectionImplemented',
'rtHasNoEmptySections', 'rtHasNoEmptySections',
'rtIsNotRedirected',
); );


protected function isSectionHeading($string) { protected function isSectionHeading($string) {
Expand Down Expand Up @@ -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() public function arePreConditionsMet()
{ {
Expand Down
1 change: 1 addition & 0 deletions src/texts/isRedirected.txt
@@ -0,0 +1 @@
This test has a REDIRECTTEST section
23 changes: 23 additions & 0 deletions 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));
}
}
?>
Expand Up @@ -15,7 +15,7 @@ public function testIs()
public function testIsNot() public function testIsNot()
{ {
$precondition = new rtIsSectionImplemented(); $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->assertEquals("The test contains a section which is not implemented yet.", trim($precondition->getMessage()));
$this->assertFalse($precondition->isMet(array(), $test)); $this->assertFalse($precondition->isMet(array(), $test));
Expand Down

0 comments on commit fd9a5da

Please sign in to comment.