diff options
author | Andrew Nacin <nacin@git.wordpress.org> | 2013-08-29 18:39:34 +0000 |
---|---|---|
committer | Andrew Nacin <nacin@git.wordpress.org> | 2013-08-29 18:39:34 +0000 |
commit | 8045afd81b7c80f6ef5b327c115a5bbb43e4b65c (patch) | |
tree | 15d457007610c451577debda89bd9e9cd3d74551 /tests/phpunit/includes/trac.php | |
parent | d34baebc1d8111c9c1014e11001957face778e52 (diff) | |
download | wordpress-8045afd81b7c80f6ef5b327c115a5bbb43e4b65c.tar.gz wordpress-8045afd81b7c80f6ef5b327c115a5bbb43e4b65c.zip |
Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root.
see #25088.
git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests/phpunit/includes/trac.php')
-rw-r--r-- | tests/phpunit/includes/trac.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/phpunit/includes/trac.php b/tests/phpunit/includes/trac.php new file mode 100644 index 0000000000..70b56a0a13 --- /dev/null +++ b/tests/phpunit/includes/trac.php @@ -0,0 +1,54 @@ +<?php + +class TracTickets { + /** + * When open tickets for a Trac install is requested, the results are stored here. + * + * @var array + */ + protected static $trac_ticket_cache = array(); + + /** + * Checks if track ticket #$ticket_id is resolved + * + * @return bool|null true if the ticket is resolved, false if not resolved, null on error + */ + public static function isTracTicketClosed( $trac_url, $ticket_id ) { + if ( ! isset( self::$trac_ticket_cache[ $trac_url ] ) ) { + // In case you're running the tests offline, keep track of open tickets. + $file = DIR_TESTDATA . '/.trac-ticket-cache.' . str_replace( array( 'http://', 'https://', '/' ), array( '', '', '-' ), rtrim( $trac_url, '/' ) ); + $tickets = @file_get_contents( $trac_url . '/query?status=%21closed&format=csv&col=id' ); + // Check if our HTTP request failed. + if ( false === $tickets ) { + if ( file_exists( $file ) ) { + register_shutdown_function( array( 'TracTickets', 'usingLocalCache' ) ); + $tickets = file_get_contents( $file ); + } else { + register_shutdown_function( array( 'TracTickets', 'forcingKnownBugs' ) ); + self::$trac_ticket_cache[ $trac_url ] = array(); + return true; // Assume the ticket is closed, which means it gets run. + } + } else { + $tickets = substr( $tickets, 2 ); // remove 'id' column header + $tickets = trim( $tickets ); + file_put_contents( $file, $tickets ); + } + $tickets = explode( "\r\n", $tickets ); + self::$trac_ticket_cache[ $trac_url ] = $tickets; + } + + return ! in_array( $ticket_id, self::$trac_ticket_cache[ $trac_url ] ); + } + + public static function usingLocalCache() { + echo PHP_EOL . "\x1b[0m\x1b[30;43m\x1b[2K"; + echo 'INFO: Trac was inaccessible, so a local ticket status cache was used.' . PHP_EOL; + echo "\x1b[0m\x1b[2K"; + } + + public static function forcingKnownBugs() { + echo PHP_EOL . "\x1b[0m\x1b[37;41m\x1b[2K"; + echo "ERROR: Trac was inaccessible, so known bugs weren't able to be skipped." . PHP_EOL; + echo "\x1b[0m\x1b[2K"; + } +} |