function main() { // include_once($_SERVER['DOCUMENT_ROOT'].'/ScarletFinal/classes/Template.php'); // $template = new Template('main.tpl/'); include('header.php'); // $template->compile('main.tpl'); require_once '../Sandbox.php'; include '../PHPUnit.php'; if(isset($_GET['path']) && is_dir($_GET['path'])) { $suite = (isset($_GET['test'])) ? $_GET['test'] : ''; $phpunit = new PHPUnit($_GET['path'], $suite); chdir($_GET['path']); } else { throw new Exception("Could not find the specified tests directory: <strong>".$_GET['path'].'</strong>', 1); } $results = $phpunit->run(); // print_r($results); echo $phpunit->toHTML($results); include('footer.php'); // include('main.php'); }
function check_for_errors() { function toHTML($type, $e) { $left = '<div class="box rounded error">'; $out = '<div class="light rounded">!</div> <div class="message">'.$type.': '.$e['message'].'</div> <div class="line">'.$e['line'].'</div> <div class="file">'.$e['file'].'</div>'; $right = '</div>'; return $left.$out.$right; } $results_so_far = ''; if(stristr(@ob_get_contents(),"<body>")) { //this is already HTML //do nothing for now. In the future we may change behaviour } elseif (@ob_get_contents()) { //this is json output, process it. $results_so_far = @ob_get_contents(); @ob_clean(); echo PHPUnit::toHTML($results_so_far); } if( false === is_null($aError = error_get_last()) ) { switch($aError['type']) { case E_NOTICE: echo toHTML("Notice", $aError); break; case E_WARNING: echo toHTML("Warning", $aError); break; case E_ERROR: echo toHTML("Error", $aError); break; case E_PARSE: echo toHTML("Parse", $aError); break; default: echo toHTML("Unknown", $aError); echo "<br/>"; break; } } if($results_so_far) { include('Main/footer.php'); } exit(1); }
function runTest($name) { $test = strToLower($name); include_once "test_{$test}.php"; echo "# Starting unit test for {$name}:\n"; $tc =& new PhpUnit_TestSuite('File_Passwd' . ($name != 'File_Passwd' ? '_' . $name : '') . 'Test'); $rs = PHPUnit::run($tc); echo $rs->toString() . "\n"; flush(); }
/** * this prints the HTML code straight out * */ function show() { $request = $_REQUEST; $showPassed = FALSE; $submitted = @$request['submitted']; if ($submitted) { $showPassed = @$request['showOK'] ? TRUE : FALSE; } $suiteResults = array(); foreach ($this->_suites as $aSuite) { $aSuiteResult = array(); // remove the first directory's name from the test-suite name, since it // mostly is something like 'tests' or alike $removablePrefix = explode('_', $aSuite->getName()); $aSuiteResult['name'] = str_replace($removablePrefix[0] . '_', '', $aSuite->getName()); if ($submitted && isset($request[$aSuiteResult['name']])) { $result = PHPUnit::run($aSuite); $aSuiteResult['counts']['run'] = $result->runCount(); $aSuiteResult['counts']['error'] = $result->errorCount(); $aSuiteResult['counts']['failure'] = $result->failureCount(); $aSuiteResult['results'] = $this->_prepareResult($result, $showPassed); $per = 100 / $result->runCount(); $failed = $per * $result->errorCount() + $per * $result->failureCount(); $aSuiteResult['percent'] = round(100 - $failed, 2); } else { $aSuiteResult['addInfo'] = 'NOT EXECUTED'; } $suiteResults[] = $aSuiteResult; } $final['name'] = 'OVERALL RESULT'; $final['counts'] = array(); $final['percent'] = 0; $numExecutedTests = 0; foreach ($suiteResults as $aSuiteResult) { if (sizeof(@$aSuiteResult['counts'])) { foreach ($aSuiteResult['counts'] as $key => $aCount) { if (!isset($final['counts'][$key])) { $final['counts'][$key] = 0; } $final['counts'][$key] += $aCount; } } } if (isset($final['counts']['run'])) { $per = 100 / $final['counts']['run']; $failed = $per * $final['counts']['error'] + $per * $final['counts']['failure']; $final['percent'] = round(100 - $failed, 2); } else { $final['percent'] = 0; } array_unshift($suiteResults, $final); include 'PHPUnit/GUI/HTML.tpl'; }
function check_for_errors() { function toHTML($type, $e) { $left = '<div class="box rounded error">'; $out = '<div class="light rounded">!</div> <div class="message">' . $type . ': ' . $e['message'] . '</div> <div class="line">' . $e['line'] . '</div> <div class="file">' . $e['file'] . '</div>'; $right = '</div>'; return $left . $out . $right; } $results_so_far = ''; if (@ob_get_contents()) { $results_so_far = @ob_get_contents(); @ob_clean(); echo PHPUnit::toHTML($results_so_far); } if (false === is_null($aError = error_get_last())) { switch ($aError['type']) { case E_NOTICE: echo toHTML("Notice", $aError); break; case E_WARNING: echo toHTML("Warning", $aError); break; case E_ERROR: echo toHTML("Error", $aError); break; case E_PARSE: echo toHTML("Parse", $aError); break; default: echo toHTML("Unknown", $aError); echo "<br/>"; break; } } if ($results_so_far) { include 'Main/footer.php'; } exit(1); }
$message2->delete(); $message->fetch(); $threadCount2 = $message->getNumMessagesInThread(); if ($threadCount != ($threadCount2 + 1)) { $this->fail("Thread stats not updated correctly."); } } } // class PhorumMessage_test class PhorumForum_test extends PHPUnit_TestCase { } $suite = new PHPUnit_TestSuite("PhorumUser_Test"); $suite->addTestSuite("PhorumMessage_Test"); $result = PHPUnit::run($suite); echo $result->toHtml(); //$message = new Phorum_message(1); //camp_dump($message); ?>
$this->assertEquals($value, $this->entry->author); } function test_entryContributor() { $value = 'Sam Ruby'; $this->assertEquals($value, $this->entry->contributor); } function test_entryContributorOffset() { $value = 'Joe Gregorio'; $this->assertEquals($value, $this->entry->contributor(1)); } # According to RFC4287 section 4.2.7.2: # [..]If the 'rel' attribute is not present, the link element MUST be # interpreted as if the link relation type is "alternate". function test_getsLinkWithoutRel() { $source = '<?xml version="1.0" ?> <entry xmlns="http://www.w3.org/2005/Atom"> <link href="http://example.org/2005/04/02/atom" /> </entry> '; $feed = new XML_Feed_Parser($source); $entry = $feed->getEntryByOffset(0); // Output $this->assertEquals("http://example.org/2005/04/02/atom", $entry->link(0, 'href', array('rel' => 'alternate'))); } } $suite = new PHPUnit_TestSuite('XML_Feed_Parser_Atom_valueValidity_TestCase'); $result = PHPUnit::run($suite, '123'); echo $result->toString();
if (OS_WINDOWS) { $this->assertTrue(File::isAbsolute('C:\\\\data')); $this->assertTrue(File::isAbsolute('d:/data')); $this->assertFalse(File::isAbsolute('\\')); } else { $this->assertTrue(File::isAbsolute('/')); $this->assertFalse(File::isAbsolute('\\')); $this->assertTrue(File::isAbsolute('~mike/bin')); } } function testrelativePath() { $this->assertEquals('tests/File', File::relativePath('/usr/share/pear/tests/File', '/usr/share/pear', '/')); $this->assertEquals('../etc', File::relativePath('/etc', '/usr', '/')); $this->assertEquals('D:\\Data', File::relativePath('D:\\Data', 'C:\\Data', '\\')); if (OS_WINDOWS) { $this->assertEquals('data\\dir', File::relativePath('/var/data/dir', '/var')); } else { $this->assertEquals('data/dir', File::relativePath('/var/data/dir', '/var')); } $this->assertEquals('../', File::relativePath('data', 'data/dir', '/')); } function testrealpath() { $drive = OS_WINDOWS ? substr(getcwd(), 0, 2) : ''; $this->assertEquals($drive . '/a/weird/path/is', File::realpath('/a\\weird//path\\is/that/./../', '/')); $this->assertEquals($drive . '/a/weird/path/is/that', File::realpath('/a\\weird//path\\is/that/./../that/.', '/')); } } $result =& PHPUnit::run(new PHPUnit_TestSuite('FileTest')); echo $result->toString();
} function tearDown() { } /** * Try to work with this ill-formed feed. If the tidy extension is not installed, * it expects parsing to fail. If tidy is installed and parsing fails, the test * fails. If tidy is installed and it parses, then the test passes. */ function test_Tidy() { $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); $file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "illformed_atom10.xml"); try { $feed = new XML_Feed_Parser($file, false, true, true); } catch (XML_Feed_Parser_Exception $e) { if (extension_loaded('tidy')) { $this->assertTrue(false); } else { $this->assertTrue(true); } return; } $entry = $feed->getEntryByOffset(0); $this->assertEquals($entry->author, 'Example author'); } } $suite = new PHPUnit_TestSuite(); $suite->addTestSuite("XML_Feed_Parser_Tidy_TestCase"); $result = PHPUnit::run($suite, "123"); echo $result->toString();
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n<head>\n<title>{$title}</title>\n</head>\n<body>\n<h1>{$title}</h1>\n"; } else { echo "{$title}\n\n"; } if (isset($_SERVER['REQUEST_METHOD'])) { echo "<h3>Using lib version: {$xmlrpcVersion} on PHP version: " . phpversion() . "</h3>\n"; echo '<h3>Running ' . $suite->testCount() . ' tests (some of which are multiple) against servers: http://' . htmlspecialchars($LOCALSERVER . $URI) . ' and https://' . htmlspecialchars($HTTPSSERVER . $HTTPSURI) . "\n ...</h3>\n"; flush(); } else { echo "Using lib version: {$xmlrpcVersion} on PHP version: " . phpversion() . "\n"; echo 'Running ' . $suite->testCount() . ' tests (some of which are multiple) against servers: http://' . $LOCALSERVER . $URI . ' and https://' . $HTTPSSERVER . $HTTPSURI . "\n\n"; } // do some basic timing measurement list($micro, $sec) = explode(' ', microtime()); $start_time = $sec + $micro; $PHPUnit = new PHPUnit(); $result = $PHPUnit->run($suite); list($micro, $sec) = explode(' ', microtime()); $end_time = $sec + $micro; if (!isset($_SERVER['REQUEST_METHOD'])) { echo $result->toString() . "\n"; } if (isset($_SERVER['REQUEST_METHOD'])) { echo '<h3>' . $result->failureCount() . " test failures</h3>\n"; printf("Time spent: %.2f secs<br/>\n", $end_time - $start_time); } else { echo $result->failureCount() . " test failures\n"; printf("Time spent: %.2f secs\n", $end_time - $start_time); } if ($result->failureCount() && !$DEBUG) { $target = strpos($_SERVER['PHP_SELF'], '?') ? $_SERVER['PHP_SELF'] . '&DEBUG=1' : $_SERVER['PHP_SELF'] . '?DEBUG=1';
function testExtractBody() { $testcases = array("before<body></body>after" => "", "<body>Simple</body>" => "Simple", "<Body>Ignore case</BODY>" => "Ignore case", "<body id=\"id123\">Attributes</body>" => "Attributes", "<body id=\"id123\">Html entities: &<></body >" => "Html entities: &<>", "<body><b class=\"bold\">Tags</b></body\n\n>" => " Tags ", "<body\n\n>\nNewlines\n</body\n\n>" => "\nNewlines\n"); foreach ($testcases as $html => $body) { $this->assertEquals($body, $this->indexer->extract_body($html)); } } } class IndexerFactoryTest extends PHPUnit_TestCase { var $index; function setUp() { $this->index = new IndexStub(); } function tearDown() { unset($this->index); } function testIndexer() { $testcases = array('abc.txt' => 'Fulltext_TextIndexer', 'abc.htm' => 'Fulltext_HtmlIndexer', 'abc.html' => 'Fulltext_HtmlIndexer'); foreach ($testcases as $path => $class) { $this->assertTrue(is_a(Fulltext_indexer_factory($path, $this->index), $class), $class); } } } $testcases = array('HtmlIndexerTest', 'IndexerFactoryTest'); foreach ($testcases as $testcase) { echo PHPUnit::run(new PHPUnit_TestSuite($testcase))->toString(); }
class QuickForm_table_test extends PHPUnit_TestCase { var $el; function QuickForm_table_test($name = 'QuickForm_table_test') { $this->PHPUnit_TestCase($name); } function setUp() { $this->el = new HTML_QuickForm_table('test_table', 'Testing'); $this->el->addField(new HTML_QuickForm_text('fname', 'First Name')); $this->el->addField(new HTML_QuickForm_text('lname', 'Last Name')); } function tearDown() { } function test_Html() { $this->assertEquals($this->el->toHtml(), ''); } function test_Html_with_values() { $el = unserialize(serialize($this->el)); $el->setName('test_table_2'); $el->setValue(array(array('fname' => 'John', 'lname' => 'Stamos'), array('fname' => 'Sally', 'lname' => 'Field'), array('fname' => 'Steve', 'lname' => 'Field'))); $this->assertEquals($el->toHtml(), ''); } } $test = new PHPUnit_TestSuite('QuickForm_table_test'); $result = PHPUnit::run($test); print $result->toString();
/** * Run the test suite. * * This method runs the test suite and updates the messages * for the user. When finished it changes the status line * to 'Test Complete' * * @access public * @param none * @return void */ function runTest() { // Notify the user that the test is running. $this->_showStatus('Running Test...'); // Run the test. $result = PHPUnit::run($this->suite); // Update the labels. $this->_setLabelValue($this->numberOfRuns, $result->runCount()); $this->_setLabelValue($this->numberOfErrors, $result->errorCount()); $this->_setLabelValue($this->numberOfFailures, $result->failureCount()); // Update the progress bar. $this->_updateProgress($result->runCount(), $result->errorCount(), $result->failureCount()); // Show the errors. $this->_showFailures($result->errors(), $this->dumpArea); // Show the messages from the tests. if ($this->showPassed->get_active()) { // Show failures and success. $this->_showAll($result, $this->reportArea); } else { // Show only failures. $this->_showFailures($result->failures(), $this->reportArea); } // Update the status message. $this->_showStatus('Test complete'); }
} else { echo "{$title}\n\n"; } if (isset($_SERVER['REQUEST_METHOD'])) { echo "<h3>Using lib version: {$xmlrpcVersion} on PHP version: " . phpversion() . "</h3>\n"; echo '<h3>Running ' . $suite->testCount() . ' tests (some of which are multiple) against servers: http://' . htmlspecialchars($LOCALSERVER . $URI) . ' and https://' . htmlspecialchars($HTTPSSERVER . $HTTPSURI) . "\n ...</h3>\n"; flush(); @ob_flush(); } else { echo "Using lib version: {$xmlrpcVersion} on PHP version: " . phpversion() . "\n"; echo 'Running ' . $suite->testCount() . ' tests (some of which are multiple) against servers: http://' . $LOCALSERVER . $URI . ' and https://' . $HTTPSSERVER . $HTTPSURI . "\n\n"; } // do some basic timing measurement list($micro, $sec) = explode(' ', microtime()); $start_time = $sec + $micro; $PHPUnit = new PHPUnit(); $result = $PHPUnit->run($suite, $DEBUG == 0 ? '.' : '<hr/>'); list($micro, $sec) = explode(' ', microtime()); $end_time = $sec + $micro; if (!isset($_SERVER['REQUEST_METHOD'])) { echo $result->toString() . "\n"; } if (isset($_SERVER['REQUEST_METHOD'])) { echo '<h3>' . $result->failureCount() . " test failures</h3>\n"; printf("Time spent: %.2f secs<br/>\n", $end_time - $start_time); } else { echo $result->failureCount() . " test failures\n"; printf("Time spent: %.2f secs\n", $end_time - $start_time); } if ($result->failureCount() && !$DEBUG) { $target = strpos($_SERVER['PHP_SELF'], '?') ? $_SERVER['PHP_SELF'] . '&DEBUG=1' : $_SERVER['PHP_SELF'] . '?DEBUG=1';
public function run() { $ut = new PHPUnit(); $ut->execute(); }
*/ function testdate() { $this->assertEquals(strftime('%x', $this->t), $this->l->date($this->t)); } /** * Regression test for I18Nv2_Locale.dayName method * * @access public */ function testdayName() { $dayNum = strftime('%w', $this->t); $this->assertEquals(strftime('%A', $this->t), $this->l->dayName($dayNum)); $this->assertEquals(strftime('%a', $this->t), $this->l->dayName($dayNum, true)); } /** * Regression test for I18Nv2_Locale.monthName method * * @access public */ function testmonthName() { $monthNum = strftime('%m', $this->t) - 1; $this->assertEquals(strftime('%B', $this->t), $this->l->monthName($monthNum)); $this->assertEquals(strftime('%b', $this->t), $this->l->monthName($monthNum, true)); } } $ts = new PHPUnit_TestSuite('I18Nv2_LocaleTest'); $rs = PHPUnit::run($ts); echo $rs->toString();