com phpruntests: Implementing REDIRECTTEST: Add section class and test: src/rtClassMap.php src/testcase/preconditions/rtHasMandatorySections.php
src/testcase/preconditions/rtIsNotRedirected.php src/testcase/preconditions/rtIsSectionImplemented.php
src/testcase/preconditions/rtIsValidSectionName.php src/testcase/rtPhpTestFile.php src/texts/isRedirected.txt
tests/testcase/preconditions/rtIsNotRedirectedTest.php tests/testcase/preconditions/rtIsSect
| From: | Zoe Slattery | Date: | Sun, 20 May 2012 07:59:13 +0000 |
| Subject: | com phpruntests: Implementing REDIRECTTEST: Add section class and test: src/rtClassMap.php src/testcase/preconditions/rtHasMandatorySections.php src/testcase/preconditions/rtIsNotRedirected.php src/testcase/preconditions/rtIsSectionImplemented.php src/testcase/preconditions/rtIsValidSectionName.php src/testcase/rtPhpTestFile.php src/texts/isRedirected.txt tests/testcase/preconditions/rtIsNotRedirectedTest.php tests/testcase/preconditions/rtIsSect |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66587@lists.php.net to get a copy of this message | ||
Commit: fd9a5da89df77bc5478633c300b74697a106b844
Author: zoe slattery <zoe@php.net> Sun, 20 May 2012 08:59:13 +0100
Parents: 06ec4c52dd9a933904f0fd0c85d58cafd3bbe2aa
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=fd9a5da89df77bc5478633c300b74697a106b844
Log:
Implementing REDIRECTTEST: Add section class and test
Changed paths:
M src/rtClassMap.php
M src/testcase/preconditions/rtHasMandatorySections.php
A src/testcase/preconditions/rtIsNotRedirected.php
M src/testcase/preconditions/rtIsSectionImplemented.php
M src/testcase/preconditions/rtIsValidSectionName.php
M src/testcase/rtPhpTestFile.php
A src/texts/isRedirected.txt
A tests/testcase/preconditions/rtIsNotRedirectedTest.php
M tests/testcase/preconditions/rtIsSectionImplementedTest.php
diff --git a/src/rtClassMap.php b/src/rtClassMap.php index ec7f1c7..adf25d7 100644 --- a/src/rtClassMap.php +++ b/src/rtClassMap.php @@ -36,11 +36,9 @@ $rtClassMap = array( '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 @@ $rtClassMap = array( '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', diff --git a/src/testcase/preconditions/rtHasMandatorySections.php b/src/testcase/preconditions/rtHasMandatorySections.php index a43ea15..6410806 100644 --- a/src/testcase/preconditions/rtHasMandatorySections.php +++ b/src/testcase/preconditions/rtHasMandatorySections.php @@ -35,10 +35,15 @@ class rtHasMandatorySections implements rtTestPreCondition { 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; + } } } diff --git a/src/testcase/preconditions/rtIsNotRedirected.php b/src/testcase/preconditions/rtIsNotRedirected.php new file mode 100644 index 0000000..f94a4a5 --- /dev/null +++ b/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; + } +} +?> diff --git a/src/testcase/preconditions/rtIsSectionImplemented.php b/src/testcase/preconditions/rtIsSectionImplemented.php index 278ddb7..ec8465a 100644 --- a/src/testcase/preconditions/rtIsSectionImplemented.php +++ b/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 @@ class rtIsSectionImplemented implements rtTestPreCondition 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; } } diff --git a/src/testcase/preconditions/rtIsValidSectionName.php b/src/testcase/preconditions/rtIsValidSectionName.php index e8159cb..7454d2d 100644 --- a/src/testcase/preconditions/rtIsValidSectionName.php +++ b/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 */ diff --git a/src/testcase/rtPhpTestFile.php b/src/testcase/rtPhpTestFile.php index 07a0e93..1b7f8fe 100644 --- a/src/testcase/rtPhpTestFile.php +++ b/src/testcase/rtPhpTestFile.php @@ -29,6 +29,7 @@ class rtPhpTestFile 'rtIsValidSectionName', 'rtIsSectionImplemented', 'rtHasNoEmptySections', + 'rtIsNotRedirected', ); protected function isSectionHeading($string) { @@ -75,32 +76,6 @@ class rtPhpTestFile } } - /* - * 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() { diff --git a/src/texts/isRedirected.txt b/src/texts/isRedirected.txt new file mode 100644 index 0000000..fe5c6d8 --- /dev/null +++ b/src/texts/isRedirected.txt @@ -0,0 +1 @@ +This test has a REDIRECTTEST section \ No newline at end of file diff --git a/tests/testcase/preconditions/rtIsNotRedirectedTest.php b/tests/testcase/preconditions/rtIsNotRedirectedTest.php new file mode 100644 index 0000000..c55d237 --- /dev/null +++ b/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)); + } +} +?> \ No newline at end of file diff --git a/tests/testcase/preconditions/rtIsSectionImplementedTest.php b/tests/testcase/preconditions/rtIsSectionImplementedTest.php index 641e095..6aee832 100644 --- a/tests/testcase/preconditions/rtIsSectionImplementedTest.php +++ b/tests/testcase/preconditions/rtIsSectionImplementedTest.php @@ -15,7 +15,7 @@ class rtIsSectionImplementedTest extends PHPUnit_Framework_TestCase 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));
diff --git a/src/rtClassMap.php b/src/rtClassMap.php index ec7f1c7..adf25d7 100644 --- a/src/rtClassMap.php +++ b/src/rtClassMap.php @@ -36,11 +36,9 @@ $rtClassMap = array( '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 @@ $rtClassMap = array( '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', diff --git a/src/testcase/preconditions/rtHasMandatorySections.php b/src/testcase/preconditions/rtHasMandatorySections.php index a43ea15..6410806 100644 --- a/src/testcase/preconditions/rtHasMandatorySections.php +++ b/src/testcase/preconditions/rtHasMandatorySections.php @@ -35,10 +35,15 @@ class rtHasMandatorySections implements rtTestPreCondition { 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; + } } } diff --git a/src/testcase/preconditions/rtIsNotRedirected.php b/src/testcase/preconditions/rtIsNotRedirected.php new file mode 100644 index 0000000..f94a4a5 --- /dev/null +++ b/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; + } +} +?> diff --git a/src/testcase/preconditions/rtIsSectionImplemented.php b/src/testcase/preconditions/rtIsSectionImplemented.php index 278ddb7..ec8465a 100644 --- a/src/testcase/preconditions/rtIsSectionImplemented.php +++ b/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 @@ class rtIsSectionImplemented implements rtTestPreCondition 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; } } diff --git a/src/testcase/preconditions/rtIsValidSectionName.php b/src/testcase/preconditions/rtIsValidSectionName.php index e8159cb..7454d2d 100644 --- a/src/testcase/preconditions/rtIsValidSectionName.php +++ b/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 */ diff --git a/src/testcase/rtPhpTestFile.php b/src/testcase/rtPhpTestFile.php index 07a0e93..1b7f8fe 100644 --- a/src/testcase/rtPhpTestFile.php +++ b/src/testcase/rtPhpTestFile.php @@ -29,6 +29,7 @@ class rtPhpTestFile 'rtIsValidSectionName', 'rtIsSectionImplemented', 'rtHasNoEmptySections', + 'rtIsNotRedirected', ); protected function isSectionHeading($string) { @@ -75,32 +76,6 @@ class rtPhpTestFile } } - /* - * 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() { diff --git a/src/texts/isRedirected.txt b/src/texts/isRedirected.txt new file mode 100644 index 0000000..fe5c6d8 --- /dev/null +++ b/src/texts/isRedirected.txt @@ -0,0 +1 @@ +This test has a REDIRECTTEST section \ No newline at end of file diff --git a/tests/testcase/preconditions/rtIsNotRedirectedTest.php b/tests/testcase/preconditions/rtIsNotRedirectedTest.php new file mode 100644 index 0000000..c55d237 --- /dev/null +++ b/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)); + } +} +?> \ No newline at end of file diff --git a/tests/testcase/preconditions/rtIsSectionImplementedTest.php b/tests/testcase/preconditions/rtIsSectionImplementedTest.php index 641e095..6aee832 100644 --- a/tests/testcase/preconditions/rtIsSectionImplementedTest.php +++ b/tests/testcase/preconditions/rtIsSectionImplementedTest.php @@ -15,7 +15,7 @@ class rtIsSectionImplementedTest extends PHPUnit_Framework_TestCase 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));