Make WordPress Core

Changeset 919 in tests for trunk/includes/trac.php


Ignore:
Timestamp:
07/19/2012 04:14:52 PM (14 years ago)
Author:
nacin
Message:

Cache to disk the list of open tickets from a Trac install, in case you wish to run the tests offline. Handles a failed HTTP request to a Trac install a bit more gracefully. see [891].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/trac.php

    r891 r919  
    1616        public static function isTracTicketClosed( $trac_url, $ticket_id ) {
    1717                if ( ! isset( self::$trac_ticket_cache[ $trac_url ] ) ) {
    18                         $tickets = file_get_contents( $trac_url . '/query?status=%21closed&format=csv&col=id' );
    19                         $tickets = substr( $tickets, 2 ); // remove 'id'
    20                         $tickets = trim( $tickets );
     18                        // In case you're running the tests offline, keep track of open tickets.
     19                        $file = DIR_TESTDATA . '/.trac-ticket-cache.' . str_replace( array( 'http://', 'https://' ), '', $trac_url );
     20                        $tickets = @file_get_contents( $trac_url . '/query?status=%21closed&format=csv&col=id' );
     21                        // Check if our HTTP request failed.
     22                        if ( false === $tickets ) {
     23                                if ( file_exists( $file ) ) {
     24                                        register_shutdown_function( array( 'TracTickets', 'usingLocalCache' ) );
     25                                        $tickets = file_get_contents( $file );
     26                                } else {
     27                                        register_shutdown_function( array( 'TracTickets', 'forcingKnownBugs' ) );
     28                                        self::$trac_ticket_cache[ $trac_url ] = array();
     29                                        return true; // Assume the ticket is closed, which means it gets run.
     30                                }
     31                        } else {
     32                                $tickets = substr( $tickets, 2 ); // remove 'id' column header
     33                                $tickets = trim( $tickets );
     34                                file_put_contents( $file, $tickets );
     35                        }
    2136                        $tickets = explode( "\r\n", $tickets );
    2237                        self::$trac_ticket_cache[ $trac_url ] = $tickets;
     
    2540                return ! in_array( $ticket_id, self::$trac_ticket_cache[ $trac_url ] );
    2641        }
     42
     43        public static function usingLocalCache() {
     44                echo PHP_EOL . "Trac was inaccessible, so a local ticket status cache was used." . PHP_EOL;
     45        }
     46
     47        public static function forcingKnownBugs() {
     48                echo PHP_EOL . "Trac was inaccessible, so known bugs weren't able to be skipped." . PHP_EOL;
     49        }
    2750}
Note: See TracChangeset for help on using the changeset viewer.