cvs: pear /Services_W3C_HTMLValidator/docs/examples/PHPUnit URIValidationTest.php ValidationSuite.php

From: Date: Sat, 29 Sep 2007 17:02:40 +0000
Subject: cvs: pear /Services_W3C_HTMLValidator/docs/examples/PHPUnit URIValidationTest.php ValidationSuite.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-48704@lists.php.net to get a copy of this message
saltybeagle Sat Sep 29 17:02:40 2007 UTC Added files: /pear/Services_W3C_HTMLValidator/docs/examples/PHPUnit ValidationSuite.php URIValidationTest.php Log: Sample PHPUnit html validation suite. Copy the two files to your tests directory, modify the file ValidationSuite.php to include the urls to validate, and execute with php ValidationSuite.php or add it to your existing test suite. http://cvs.php.net/viewvc.cgi/pear/Services_W3C_HTMLValidator/docs/examples/PHPUnit/ValidationSuite.php?view=markup&rev=1.1 Index: pear/Services_W3C_HTMLValidator/docs/examples/PHPUnit/ValidationSuite.php +++ pear/Services_W3C_HTMLValidator/docs/examples/PHPUnit/ValidationSuite.php <?php if (!defined("PHPUnit_MAIN_METHOD")) { define("PHPUnit_MAIN_METHOD", "ValidationTestSuite::main"); } require_once 'PHPUnit/Framework.php'; require_once "PHPUnit/Framework/TestCase.php"; require_once "PHPUnit/Framework/TestSuite.php"; require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'URIValidationTest.php'; class ValidationTestSuite extends PHPUnit_Framework_TestSuite { function __construct($name) { } /** * Runs the test suite. * * @return unknown */ public static function main() { include_once "PHPUnit/TextUI/TestRunner.php"; PHPUnit_TextUI_TestRunner::run(self::suite()); } /** * Adds the Services_W3C_HTMLValidatorTest suite. * * @return $suite */ public static function suite() { $uris_to_check = array('http://www.unl.edu/', 'http://events.unl.edu/', 'http://www.google.com/'); $suite = new PHPUnit_Framework_TestSuite('ValidationTestSuite tests'); /** Add testsuites, if there is. */ $suite->addTestSuite('ValidationTestSuite'); foreach ($uris_to_check as $uri) { $test = new URIValidationTest('testURI'); $test->uri = $uri; $suite->addTest($test); } return $suite; } } // Call Services_W3C_HTMLValidatorTest::main() if file is executed directly. if (PHPUnit_MAIN_METHOD == "ValidationTestSuite::main") { ValidationTestSuite::main(); } ?> http://cvs.php.net/viewvc.cgi/pear/Services_W3C_HTMLValidator/docs/examples/PHPUnit/URIValidationTest.php?view=markup&rev=1.1 Index: pear/Services_W3C_HTMLValidator/docs/examples/PHPUnit/URIValidationTest.php +++ pear/Services_W3C_HTMLValidator/docs/examples/PHPUnit/URIValidationTest.php <?php /** * This file tests the validation of the web accessible URIs. */ require_once 'Services/W3C/HTMLValidator.php'; require_once 'PHPUnit/Framework.php'; // Call Services_W3C_HTMLValidatorTest::main() if executed directly. if (!defined("PHPUnit_MAIN_METHOD")) { define("PHPUnit_MAIN_METHOD", "URIValidationTest::main"); } class URIValidationTest extends PHPUnit_Framework_TestCase { public $uri = 'http://www.unl.edu/'; protected $validator; /** * Runs the test methods of this class. * * @access public * @static * @return void */ public static function main() { include_once "PHPUnit/TextUI/TestRunner.php"; $suite = new PHPUnit_Framework_TestSuite("URIValidationTest"); $result = PHPUnit_TextUI_TestRunner::run($suite); } public function setUp() { $this->validator = new Services_W3C_HTMLValidator(); } public function testURI() { $r = $this->validator->validate($this->uri); $this->assertEquals(get_class($r), 'Services_W3C_HTMLValidator_Response'); if (!$r->isValid()) { $message = $this->constructErrorMessage($r); } else { $message = $r->uri.' is Valid'; } $this->assertTrue($r->isValid(), $message); } public function testFile() { $r = $this->validator->validate($this->uri); $this->assertEquals(get_class($r), 'Services_W3C_HTMLValidator_Response'); if (!$r->isValid()) { $message = $this->constructErrorMessage($r); } else { $message = $r->uri.' is Valid'; } $this->assertTrue($r->isValid(), $message); } protected function constructErrorMessage(&$r) { $message = $r->uri.' is NOT VALID: '.count($r->errors).' Errors -'.PHP_EOL; foreach ($r->errors as $error) { $message .= ' - '.$error->message.PHP_EOL; } return $message; } } // Call Services_W3C_HTMLValidatorTest::main() if file is executed directly. if (PHPUnit_MAIN_METHOD == "URIValidationTest::main") { URIValidationTest::main(); } ?>

« previous php.pear.cvs (#48704) next »