Changeset 100149 in spip-zone


Ignore:
Timestamp:
Oct 25, 2016, 4:42:22 PM (2 years ago)
Author:
marcimat@…
Message:

Mise à jour de SimpleTest? à la version 1.1.8-dev commit 03db272
pour fonctionner sous PHP7.

Location:
_core_/tests/simpletest
Files:
141 added
5 deleted
78 edited

Legend:

Unmodified
Added
Removed
  • _core_/tests/simpletest/VERSION

    r80775 r100149  
    1 1.1.0
     1v1.1.8-dev
  • _core_/tests/simpletest/arguments.php

    r80775 r100149  
    11<?php
    22/**
    3  *  base include file for SimpleTest
    4  *  @package    SimpleTest
    5  *  @subpackage UnitTester
    6  *  @version    $Id: dumper.php 1909 2009-07-29 15:58:11Z dgheath $
     3 * Parses the command line arguments.
    74 */
    8 
    9 /**
    10  *    Parses the command line arguments.
    11  *    @package  SimpleTest
    12  *    @subpackage   UnitTester
    13  */
    14 class SimpleArguments {
     5class SimpleArguments
     6{
    157    private $all = array();
    168
    179    /**
    18      * Parses the command line arguments. The usual formats
    19      * are supported:
     10     * Parses the command line arguments.
     11     *
     12     * The usual formats are supported:
    2013     * -f value
    2114     * -f=value
     
    2417     * -f           (true)
    2518     * --flag       (true)
    26      * @param array $arguments      Normally the PHP $argv.
    27      */
    28     function __construct($arguments) {
     19     *
     20     * @param array $arguments Normally the PHP $argv.
     21     */
     22    public function __construct($arguments)
     23    {
    2924        array_shift($arguments);
    3025        while (count($arguments) > 0) {
     
    3530
    3631    /**
    37      * Sets the value in the argments object. If multiple
    38      * values are added under the same key, the key will
    39      * give an array value in the order they were added.
    40      * @param string $key    The variable to assign to.
    41      * @param string value   The value that would norally
    42      *                       be colected on the command line.
    43      */
    44     function assign($key, $value) {
     32     * Sets the value in the argments object. If multiple values are added under
     33     * the same key, the key will give an array value in the order they were
     34     * added.
     35     *
     36     * @param string $key The variable to assign to.
     37     * @param string value   The value that would norally be colected on the
     38     * command line.
     39     */
     40    public function assign($key, $value)
     41    {
    4542        if ($this->$key === false) {
    4643            $this->all[$key] = $value;
     
    5451    /**
    5552     * Extracts the next key and value from the argument list.
    56      * @param array $arguments      The remaining arguments to be parsed.
    57      *                              The argument list will be reduced.
    58      * @return array                Two item array of key and value.
    59      *                              If no value can be found it will
    60      *                              have the value true assigned instead.
    61      */
    62     private function parseArgument(&$arguments) {
     53     *
     54     * @param array $arguments The remaining arguments to be parsed.
     55     *                         The argument list will be reduced.
     56     *
     57     * @return array Two item array of key and value.
     58     *               If no value can be found it will
     59     *               have the value true assigned instead.
     60     */
     61    private function parseArgument(&$arguments)
     62    {
    6363        $argument = array_shift($arguments);
    6464        if (preg_match('/^-(\w)=(.+)$/', $argument, $matches)) {
     
    7474
    7575    /**
    76      * Attempts to use the next argument as a value. It
    77      * won't use what it thinks is a flag.
    78      * @param array $arguments    Remaining arguments to be parsed.
    79      *                            This variable is modified if there
    80      *                            is a value to be extracted.
    81      * @return string/boolean     The next value unless it's a flag.
    82      */
    83     private function nextNonFlagElseTrue(&$arguments) {
     76     * Attempts to use the next argument as a value.
     77     * It won't use what it thinks is a flag.
     78     *
     79     * @param array $arguments Remaining arguments to be parsed. This variable
     80     * is modified if there is a value to be extracted.
     81     *
     82     * @return string/boolean The next value unless it's a flag.
     83     */
     84    private function nextNonFlagElseTrue(&$arguments)
     85    {
    8486        return $this->valueIsNext($arguments) ? array_shift($arguments) : true;
    8587    }
     
    8890     * Test to see if the next available argument is a valid value.
    8991     * If it starts with "-" or "--" it's a flag and doesn't count.
    90      * @param array $arguments    Remaining arguments to be parsed.
    91      *                            Not affected by this call.
    92      * boolean                    True if valid value.
    93      */
    94     function valueIsNext($arguments) {
     92     *
     93     * @param array $arguments Remaining arguments to be parsed.
     94     *                         Not affected by this call.
     95     *                         boolean                    True if valid value.
     96     */
     97    public function valueIsNext($arguments)
     98    {
    9599        return isset($arguments[0]) && ! $this->isFlag($arguments[0]);
    96100    }
     
    98102    /**
    99103     * It's a flag if it starts with "-" or "--".
    100      * @param string $argument       Value to be tested.
    101      * @return boolean               True if it's a flag.
    102      */
    103     function isFlag($argument) {
     104     *
     105     * @param string $argument Value to be tested.
     106     *
     107     * @return bool True if it's a flag.
     108     */
     109    public function isFlag($argument)
     110    {
    104111        return strncmp($argument, '-', 1) == 0;
    105112    }
    106113
    107114    /**
    108      * The arguments are available as individual member
    109      * variables on the object.
    110      * @param string $key              Argument name.
    111      * @return string/array/boolean    Either false for no value,
    112      *                                 the value as a string or
    113      *                                 a list of multiple values if
    114      *                                 the flag had been specified more
    115      *                                 than once.
    116      */
    117     function __get($key) {
     115     * The arguments are available as individual member variables on the object.
     116     *
     117     * @param string $key Argument name.
     118     *
     119     * @return string/array/boolean Either false for no value,
     120     *                              the value as a string or
     121     *                              a list of multiple values if
     122     *                              the flag had been specified more
     123     *                              than once.
     124     */
     125    public function __get($key)
     126    {
    118127        if (isset($this->all[$key])) {
    119128            return $this->all[$key];
    120129        }
     130
    121131        return false;
    122132    }
     
    124134    /**
    125135     * The entire argument set as a hash.
    126      * @return hash         Each argument and it's value(s).
    127      */
    128     function all() {
     136     *
     137     * @return hash Each argument and it's value(s).
     138     */
     139    public function all()
     140    {
    129141        return $this->all;
    130142    }
     
    132144
    133145/**
    134  *    Renders the help for the command line arguments.
    135  *    @package  SimpleTest
    136  *    @subpackage   UnitTester
     146 * Renders the help for the command line arguments.
    137147 */
    138 class SimpleHelp {
     148class SimpleHelp
     149{
    139150    private $overview;
    140     private $flag_sets = array();
     151    private $flag_sets    = array();
    141152    private $explanations = array();
    142153
    143154    /**
    144155     * Sets up the top level explanation for the program.
    145      * @param string $overview        Summary of program.
    146      */
    147     function __construct($overview = '') {
     156     *
     157     * @param string $overview Summary of program.
     158     */
     159    public function __construct($overview = '')
     160    {
    148161        $this->overview = $overview;
    149162    }
     
    152165     * Adds the explanation for a group of flags that all
    153166     * have the same function.
     167     *
    154168     * @param string/array $flags       Flag and alternates. Don't
    155169     *                                  worry about leading dashes
    156170     *                                  as these are inserted automatically.
    157      * @param string $explanation       What that flag group does.
    158      */
    159     function explainFlag($flags, $explanation) {
    160         $flags = is_array($flags) ? $flags : array($flags);
    161         $this->flag_sets[] = $flags;
     171     * @param string       $explanation What that flag group does.
     172     */
     173    public function explainFlag($flags, $explanation)
     174    {
     175        $flags                = is_array($flags) ? $flags : array($flags);
     176        $this->flag_sets[]    = $flags;
    162177        $this->explanations[] = $explanation;
    163178    }
     
    165180    /**
    166181     * Generates the help text.
     182     *
    167183     * @returns string      The complete formatted text.
    168184     */
    169     function render() {
     185    public function render()
     186    {
    170187        $tab_stop = $this->longestFlag($this->flag_sets) + 4;
    171         $text = $this->overview . "\n";
    172         for ($i = 0; $i < count($this->flag_sets); $i++) {
     188        $text     = $this->overview . "\n";
     189        $numberOfFlags = count($this->flag_sets);
     190        for ($i = 0; $i < $numberOfFlags; $i++) {
    173191            $text .= $this->renderFlagSet($this->flag_sets[$i], $this->explanations[$i], $tab_stop);
    174192        }
     193
    175194        return $this->noDuplicateNewLines($text);
    176195    }
     
    178197    /**
    179198     * Works out the longest flag for formatting purposes.
    180      * @param array $flag_sets      The internal flag set list.
    181      */
    182     private function longestFlag($flag_sets) {
     199     *
     200     * @param array $flag_sets The internal flag set list.
     201     */
     202    private function longestFlag($flag_sets)
     203    {
    183204        $longest = 0;
    184205        foreach ($flag_sets as $flags) {
     
    187208            }
    188209        }
     210
    189211        return $longest;
    190212    }
     
    192214    /**
    193215     * Generates the text for a single flag and it's alternate flags.
     216     *
    194217     * @returns string           Help text for that flag group.
    195218     */
    196     private function renderFlagSet($flags, $explanation, $tab_stop) {
     219    private function renderFlagSet($flags, $explanation, $tab_stop)
     220    {
    197221        $flag = array_shift($flags);
    198222        $text = str_pad($this->renderFlag($flag), $tab_stop, ' ') . $explanation . "\n";
     
    200224            $text .= '  ' . $this->renderFlag($flag) . "\n";
    201225        }
     226
    202227        return $text;
    203228    }
     
    205230    /**
    206231     * Generates the flag name including leading dashes.
    207      * @param string $flag          Just the name.
     232     *
     233     * @param string $flag Just the name.
    208234     * @returns                     Fag with apropriate dashes.
    209235     */
    210     private function renderFlag($flag) {
     236    private function renderFlag($flag)
     237    {
    211238        return (strlen($flag) == 1 ? '-' : '--') . $flag;
    212239    }
     
    215242     * Converts multiple new lines into a single new line.
    216243     * Just there to trap accidental duplicate new lines.
    217      * @param string $text      Text to clean up.
     244     *
     245     * @param string $text Text to clean up.
    218246     * @returns string          Text with no blank lines.
    219247     */
    220     private function noDuplicateNewLines($text) {
     248    private function noDuplicateNewLines($text)
     249    {
    221250        return preg_replace('/(\n+)/', "\n", $text);
    222251    }
    223252}
    224 ?>
  • _core_/tests/simpletest/authentication.php

    r80772 r100149  
    11<?php
     2
     3require_once dirname(__FILE__) . '/http.php';
     4
    25/**
    3  *  Base include file for SimpleTest
    4  *  @package    SimpleTest
    5  *  @subpackage WebTester
    6  *  @version    $Id: authentication.php 2011 2011-04-29 08:22:48Z pp11 $
     6 * Represents a single security realm's identity.
    77 */
    8 /**
    9  *  include http class
    10  */
    11 require_once(dirname(__FILE__) . '/http.php');
    12 
    13 /**
    14  *    Represents a single security realm's identity.
    15  *    @package SimpleTest
    16  *    @subpackage WebTester
    17  */
    18 class SimpleRealm {
     8class SimpleRealm
     9{
    1910    private $type;
    2011    private $root;
     
    2314
    2415    /**
    25      *    Starts with the initial entry directory.
    26      *    @param string $type      Authentication type for this
    27      *                             realm. Only Basic authentication
    28      *                            is currently supported.
    29      *    @param SimpleUrl $url    Somewhere in realm.
    30      *    @access public
    31      */
    32     function SimpleRealm($type, $url) {
    33         $this->type = $type;
    34         $this->root = $url->getBasePath();
     16     * Starts with the initial entry directory.
     17     *
     18     * @param string $type      Authentication type for this realm. Only Basic
     19     *                          authentication is currently supported.
     20     * @param SimpleUrl $url    Somewhere in realm.
     21     */
     22    public function __construct($type, $url)
     23    {
     24        $this->type     = $type;
     25        $this->root     = $url->getBasePath();
    3526        $this->username = false;
    3627        $this->password = false;
     
    3829
    3930    /**
    40      *    Adds another location to the realm.
    41      *    @param SimpleUrl $url    Somewhere in realm.
    42      *    @access public
    43      */
    44     function stretch($url) {
     31     * Adds another location to the realm.
     32     *
     33     * @param SimpleUrl $url    Somewhere in realm.
     34     */
     35    public function stretch($url)
     36    {
    4537        $this->root = $this->getCommonPath($this->root, $url->getPath());
    4638    }
    4739
    4840    /**
    49      *    Finds the common starting path.
    50      *    @param string $first        Path to compare.
    51      *    @param string $second       Path to compare.
    52      *    @return string              Common directories.
    53      *    @access private
    54      */
    55     protected function getCommonPath($first, $second) {
    56         $first = explode('/', $first);
     41     * Finds the common starting path.
     42     *
     43     * @param string $first        Path to compare.
     44     * @param string $second       Path to compare.
     45     *
     46     * @return string              Common directories.
     47     */
     48    protected function getCommonPath($first, $second)
     49    {
     50        $first  = explode('/', $first);
    5751        $second = explode('/', $second);
    5852        for ($i = 0; $i < min(count($first), count($second)); $i++) {
     
    6155            }
    6256        }
     57
    6358        return implode('/', $first) . '/';
    6459    }
    6560
    6661    /**
    67      *    Sets the identity to try within this realm.
    68      *    @param string $username    Username in authentication dialog.
    69      *    @param string $username    Password in authentication dialog.
    70      *    @access public
    71      */
    72     function setIdentity($username, $password) {
     62     * Sets the identity to try within this realm.
     63     *
     64     * @param string $username    Username in authentication dialog.
     65     * @param string $username    Password in authentication dialog.
     66     */
     67    public function setIdentity($username, $password)
     68    {
    7369        $this->username = $username;
    7470        $this->password = $password;
     
    7672
    7773    /**
    78      *    Accessor for current identity.
    79      *    @return string        Last succesful username.
    80      *    @access public
    81      */
    82     function getUsername() {
     74     * Accessor for current identity.
     75     *
     76     * @return string        Last succesful username.
     77     */
     78    public function getUsername()
     79    {
    8380        return $this->username;
    8481    }
    8582
    8683    /**
    87      *    Accessor for current identity.
    88      *    @return string        Last succesful password.
    89      *    @access public
    90      */
    91     function getPassword() {
     84     * Accessor for current identity.
     85     *
     86     * @return string        Last succesful password.
     87     */
     88    public function getPassword()
     89    {
    9290        return $this->password;
    9391    }
    9492
    9593    /**
    96      *    Test to see if the URL is within the directory
    97      *    tree of the realm.
    98      *    @param SimpleUrl $url    URL to test.
    99      *    @return boolean          True if subpath.
    100      *    @access public
    101      */
    102     function isWithin($url) {
     94     * Test to see if the URL is within the directory tree of the realm.
     95     *
     96     * @param SimpleUrl $url    URL to test.
     97     *
     98     * @return bool          True if subpath.
     99     */
     100    public function isWithin($url)
     101    {
    103102        if ($this->isIn($this->root, $url->getBasePath())) {
    104103            return true;
     
    107106            return true;
    108107        }
     108
    109109        return false;
    110110    }
    111111
    112112    /**
    113      *    Tests to see if one string is a substring of
    114      *    another.
    115      *    @param string $part        Small bit.
    116      *    @param string $whole       Big bit.
    117      *    @return boolean            True if the small bit is
    118      *                               in the big bit.
    119      *    @access private
    120      */
    121     protected function isIn($part, $whole) {
     113     * Tests to see if one string is a substring of another.
     114     *
     115     * @param string $part        Small bit.
     116     * @param string $whole       Big bit.
     117     *
     118     * @return bool            True if the small bit is in the big bit.
     119     */
     120    protected function isIn($part, $whole)
     121    {
    122122        return strpos($whole, $part) === 0;
    123123    }
     
    125125
    126126/**
    127  *    Manages security realms.
    128  *    @package SimpleTest
    129  *    @subpackage WebTester
     127 * Manages security realms.
    130128 */
    131 class SimpleAuthenticator {
     129class SimpleAuthenticator
     130{
    132131    private $realms;
    133132
    134133    /**
    135      *    Clears the realms.
    136      *    @access public
    137      */
    138     function SimpleAuthenticator() {
     134     * Clears the realms.
     135     */
     136    public function __construct()
     137    {
    139138        $this->restartSession();
    140139    }
    141140
    142141    /**
    143      *    Starts with no realms set up.
    144      *    @access public
    145      */
    146     function restartSession() {
     142     * Starts with no realms set up.
     143     */
     144    public function restartSession()
     145    {
    147146        $this->realms = array();
    148147    }
    149148
    150149    /**
    151      *    Adds a new realm centered the current URL.
    152      *    Browsers privatey wildly on their behaviour in this
    153      *    regard. Mozilla ignores the realm and presents
    154      *    only when challenged, wasting bandwidth. IE
    155      *    just carries on presenting until a new challenge
    156      *    occours. SimpleTest tries to follow the spirit of
    157      *    the original standards committee and treats the
    158      *    base URL as the root of a file tree shaped realm.
    159      *    @param SimpleUrl $url    Base of realm.
    160      *    @param string $type      Authentication type for this
    161      *                             realm. Only Basic authentication
    162      *                             is currently supported.
    163      *    @param string $realm     Name of realm.
    164      *    @access public
    165      */
    166     function addRealm($url, $type, $realm) {
     150     * Adds a new realm centered the current URL. Browsers privatey wildly on
     151     * their behaviour in this regard. Mozilla ignores the realm and presents
     152     * only when challenged, wasting bandwidth. IE just carries on presenting
     153     * until a new challenge occours. SimpleTest tries to follow the spirit of
     154     * the original standards committee and treats the base URL as the root of a
     155     * file tree shaped realm.
     156     *
     157     * @param SimpleUrl $url    Base of realm.
     158     * @param string $type      Authentication type for this realm. Only
     159     * Basicauthentication is currently supported.
     160     * @param string $realm     Name of realm.
     161     */
     162    public function addRealm($url, $type, $realm)
     163    {
    167164        $this->realms[$url->getHost()][$realm] = new SimpleRealm($type, $url);
    168165    }
    169166
    170167    /**
    171      *    Sets the current identity to be presented
    172      *    against that realm.
    173      *    @param string $host        Server hosting realm.
    174      *    @param string $realm       Name of realm.
    175      *    @param string $username    Username for realm.
    176      *    @param string $password    Password for realm.
    177      *    @access public
    178      */
    179     function setIdentityForRealm($host, $realm, $username, $password) {
     168     * Sets the current identity to be presented against that realm.
     169     *
     170     * @param string $host        Server hosting realm.
     171     * @param string $realm       Name of realm.
     172     * @param string $username    Username for realm.
     173     * @param string $password    Password for realm.
     174     */
     175    public function setIdentityForRealm($host, $realm, $username, $password)
     176    {
    180177        if (isset($this->realms[$host][$realm])) {
    181178            $this->realms[$host][$realm]->setIdentity($username, $password);
     
    184181
    185182    /**
    186      *    Finds the name of the realm by comparing URLs.
    187      *    @param SimpleUrl $url        URL to test.
    188      *    @return SimpleRealm          Name of realm.
    189      *    @access private
    190      */
    191     protected function findRealmFromUrl($url) {
     183     * Finds the name of the realm by comparing URLs.
     184     *
     185     * @param SimpleUrl $url        URL to test.
     186     *
     187     * @return SimpleRealm          Name of realm.
     188     */
     189    protected function findRealmFromUrl($url)
     190    {
    192191        if (! isset($this->realms[$url->getHost()])) {
    193192            return false;
     
    198197            }
    199198        }
     199
    200200        return false;
    201201    }
    202202
    203203    /**
    204      *    Presents the appropriate headers for this location.
    205      *    @param SimpleHttpRequest $request  Request to modify.
    206      *    @param SimpleUrl $url              Base of realm.
    207      *    @access public
    208      */
    209     function addHeaders(&$request, $url) {
     204     * Presents the appropriate headers for this location.
     205     *
     206     * @param SimpleHttpRequest $request  Request to modify.
     207     * @param SimpleUrl $url              Base of realm.
     208     */
     209    public function addHeaders($request, $url)
     210    {
    210211        if ($url->getUsername() && $url->getPassword()) {
    211212            $username = $url->getUsername();
     
    221222
    222223    /**
    223      *    Presents the appropriate headers for this
    224      *    location for basic authentication.
    225      *    @param SimpleHttpRequest $request  Request to modify.
    226      *    @param string $username            Username for realm.
    227      *    @param string $password            Password for realm.
    228      *    @access public
    229      */
    230     static function addBasicHeaders(&$request, $username, $password) {
     224     * Presents the appropriate headers for this location for basic authentication.
     225     *
     226     * @param SimpleHttpRequest $request  Request to modify.
     227     * @param string $username            Username for realm.
     228     * @param string $password            Password for realm.
     229     */
     230    public static function addBasicHeaders(&$request, $username, $password)
     231    {
    231232        if ($username && $password) {
    232233            $request->addHeaderLine(
     
    235236    }
    236237}
    237 ?>
  • _core_/tests/simpletest/autorun.php

    r80775 r100149  
    33 *  Autorunner which runs all tests cases found in a file
    44 *  that includes this module.
    5  *  @package    SimpleTest
    6  *  @version    $Id: autorun.php 2037 2011-11-30 17:58:21Z pp11 $
    75 */
    86
    9 /**#@+
    10  * include simpletest files
    11  */
     7// include simpletest files
    128require_once dirname(__FILE__) . '/unit_tester.php';
    139require_once dirname(__FILE__) . '/mock_objects.php';
    1410require_once dirname(__FILE__) . '/collector.php';
    1511require_once dirname(__FILE__) . '/default_reporter.php';
    16 /**#@-*/
    1712
    1813$GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_CLASSES'] = get_declared_classes();
    19 $GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_PATH'] = getcwd();
     14$GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_PATH']    = getcwd();
    2015register_shutdown_function('simpletest_autorun');
    2116
    2217/**
    23  *    Exit handler to run all recent test cases and exit system if in CLI
     18 * Exit handler to run all recent test cases and exit system if in CLI
    2419 */
    25 function simpletest_autorun() {
    26         chdir($GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_PATH']);
     20function simpletest_autorun()
     21{
     22    chdir($GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_PATH']);
    2723    if (tests_have_run()) {
    28         return;
     24        return true;
    2925    }
    3026    $result = run_local_tests();
     
    3531
    3632/**
    37  *    run all recent test cases if no test has
    38  *    so far been run. Uses the DefaultReporter which can have
    39  *    it's output controlled with SimpleTest::prefer().
    40  *    @return boolean/null false if there were test failures, true if
    41  *                         there were no failures, null if tests are
    42  *                         already running
     33 * Run all recent test cases if no test has so far been run.
     34 * Uses the DefaultReporter which can have it's output
     35 * controlled with SimpleTest::prefer().
     36 *
     37 * @return boolean/null false, if there were test failures,
     38 *                      true, if there were no failures,
     39 *                      null, if tests are already running
    4340 */
    44 function run_local_tests() {
     41function run_local_tests()
     42{
    4543    try {
    4644        if (tests_have_run()) {
    47             return;
     45            return true;
    4846        }
    4947        $candidates = capture_new_classes();
    50         $loader = new SimpleFileLoader();
     48        $loader     = new SimpleFileLoader();
     49
    5150        $suite = $loader->createSuiteFromClasses(
    52                 basename(initial_file()),
    53                 $loader->selectRunnableTests($candidates));
    54         return $suite->run(new DefaultReporter());
     51            basename(initial_file()),
     52            $loader->selectRunnableTests($candidates)
     53        );
     54
     55        $reporter = new DefaultReporter();
     56
     57        if ($reporter->doCodeCoverage) {
     58            $coverage = new PHP_CodeCoverage;
     59            $filter   = $coverage->filter();
     60
     61            foreach ($reporter->excludes as $folderPath) {
     62                $filter->addDirectoryToBlacklist($folderPath);
     63            }
     64
     65            $coverage->start($_SERVER['SCRIPT_FILENAME']);
     66        }
     67
     68        $result = $suite->run($reporter);
     69
     70        if ($reporter->doCodeCoverage) {
     71            $coverage->stop();
     72
     73            $writer = new PHP_CodeCoverage_Report_HTML;
     74            $writer->process($coverage, '/tmp/coverage');
     75        }
     76
     77        return $result;
    5578    } catch (Exception $stack_frame_fix) {
    5679        print $stack_frame_fix->getMessage();
     80
    5781        return false;
    5882    }
     
    6084
    6185/**
    62  *    Checks the current test context to see if a test has
    63  *    ever been run.
    64  *    @return boolean        True if tests have run.
     86 * Checks the current test context to see if a test has ever been run.
     87 *
     88 * @return bool True if tests have run.
    6589 */
    66 function tests_have_run() {
    67     if ($context = SimpleTest::getContext()) {
    68         return (boolean)$context->getTest();
     90function tests_have_run()
     91{
     92    $context = SimpleTest::getContext();
     93    if ($context) {
     94        return (boolean) $context->getTest();
    6995    }
     96
    7097    return false;
    7198}
    7299
    73100/**
    74  *    The first autorun file.
    75  *    @return string        Filename of first autorun script.
     101 * The first autorun file.
     102 *
     103 * @return string Filename of first autorun script.
    76104 */
    77 function initial_file() {
     105function initial_file()
     106{
    78107    static $file = false;
    79108    if (! $file) {
     
    82111        } else {
    83112            $included_files = get_included_files();
    84             $file = reset($included_files);
     113            $file           = reset($included_files);
    85114        }
    86115    }
     116
    87117    return $file;
    88118}
    89119
    90120/**
    91  *    Every class since the first autorun include. This
    92  *    is safe enough if require_once() is always used.
    93  *    @return array        Class names.
     121 * Every class since the first autorun include.
     122 * This is safe enough if require_once() is always used.
     123 *
     124 * @return array Class names.
    94125 */
    95 function capture_new_classes() {
     126function capture_new_classes()
     127{
    96128    global $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES;
     129
    97130    return array_map('strtolower', array_diff(get_declared_classes(),
    98131                            $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES ?
    99132                            $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES : array()));
    100133}
    101 ?>
  • _core_/tests/simpletest/browser.php

    r80772 r100149  
    11<?php
    2 /**
    3  *  Base include file for SimpleTest
    4  *  @package    SimpleTest
    5  *  @subpackage WebTester
    6  *  @version    $Id: browser.php 2013 2011-04-29 09:29:45Z pp11 $
    7  */
    8 
    9 /**#@+
    10  *  include other SimpleTest class files
    11  */
    12 require_once(dirname(__FILE__) . '/simpletest.php');
    13 require_once(dirname(__FILE__) . '/http.php');
    14 require_once(dirname(__FILE__) . '/encoding.php');
    15 require_once(dirname(__FILE__) . '/page.php');
    16 require_once(dirname(__FILE__) . '/php_parser.php');
    17 require_once(dirname(__FILE__) . '/tidy_parser.php');
    18 require_once(dirname(__FILE__) . '/selector.php');
    19 require_once(dirname(__FILE__) . '/frames.php');
    20 require_once(dirname(__FILE__) . '/user_agent.php');
     2
     3require_once dirname(__FILE__) . '/simpletest.php';
     4require_once dirname(__FILE__) . '/http.php';
     5require_once dirname(__FILE__) . '/encoding.php';
     6require_once dirname(__FILE__) . '/page.php';
     7require_once dirname(__FILE__) . '/php_parser.php';
     8require_once dirname(__FILE__) . '/tidy_parser.php';
     9require_once dirname(__FILE__) . '/selector.php';
     10require_once dirname(__FILE__) . '/frames.php';
     11require_once dirname(__FILE__) . '/user_agent.php';
     12
    2113if (! SimpleTest::getParsers()) {
    2214    SimpleTest::setParsers(array(new SimpleTidyPageBuilder(), new SimplePHPPageBuilder()));
    2315    //SimpleTest::setParsers(array(new SimplePHPPageBuilder()));
    2416}
    25 /**#@-*/
    2617
    2718if (! defined('DEFAULT_MAX_NESTED_FRAMES')) {
     
    3021
    3122/**
    32  *    Browser history list.
    33  *    @package SimpleTest
    34  *    @subpackage WebTester
     23 * Browser history list.
    3524 */
    36 class SimpleBrowserHistory {
     25class SimpleBrowserHistory
     26{
    3727    private $sequence = array();
    3828    private $position = -1;
    3929
    4030    /**
    41      *    Test for no entries yet.
    42      *    @return boolean        True if empty.
    43      *    @access private
    44      */
    45     protected function isEmpty() {
     31     * Test for no entries yet.
     32     *
     33     * @return bool        True if empty.
     34     */
     35    protected function isEmpty()
     36    {
    4637        return ($this->position == -1);
    4738    }
    4839
    4940    /**
    50      *    Test for being at the beginning.
    51      *    @return boolean        True if first.
    52      *    @access private
    53      */
    54     protected function atBeginning() {
     41     * Test for being at the beginning.
     42     *
     43     * @return bool        True if first.
     44     */
     45    protected function atBeginning()
     46    {
    5547        return ($this->position == 0) && ! $this->isEmpty();
    5648    }
    5749
    5850    /**
    59      *    Test for being at the last entry.
    60      *    @return boolean        True if last.
    61      *    @access private
    62      */
    63     protected function atEnd() {
     51     * Test for being at the last entry.
     52     *
     53     * @return bool        True if last.
     54     */
     55    protected function atEnd()
     56    {
    6457        return ($this->position + 1 >= count($this->sequence)) && ! $this->isEmpty();
    6558    }
    6659
    6760    /**
    68      *    Adds a successfully fetched page to the history.
    69      *    @param SimpleUrl $url                 URL of fetch.
    70      *    @param SimpleEncoding $parameters     Any post data with the fetch.
    71      *    @access public
    72      */
    73     function recordEntry($url, $parameters) {
     61     * Adds a successfully fetched page to the history.
     62     *
     63     * @param SimpleUrl $url                 URL of fetch.
     64     * @param SimpleEncoding $parameters     Any post data with the fetch.
     65     */
     66    public function recordEntry($url, $parameters)
     67    {
    7468        $this->dropFuture();
    7569        array_push(
     
    8074
    8175    /**
    82      *    Last fully qualified URL for current history
    83      *    position.
    84      *    @return SimpleUrl        URL for this position.
    85      *    @access public
    86      */
    87     function getUrl() {
     76     * Last fully qualified URL for current history position.
     77     *
     78     * @return SimpleUrl        URL for this position.
     79     */
     80    public function getUrl()
     81    {
    8882        if ($this->isEmpty()) {
    8983            return false;
    9084        }
     85
    9186        return $this->sequence[$this->position]['url'];
    9287    }
    9388
    9489    /**
    95      *    Parameters of last fetch from current history
    96      *    position.
    97      *    @return SimpleFormEncoding    Post parameters.
    98      *    @access public
    99      */
    100     function getParameters() {
     90     * Parameters of last fetch from current history position.
     91     *
     92     * @return SimpleFormEncoding    Post parameters.
     93     */
     94    public function getParameters()
     95    {
    10196        if ($this->isEmpty()) {
    10297            return false;
    10398        }
     99
    104100        return $this->sequence[$this->position]['parameters'];
    105101    }
    106102
    107103    /**
    108      *    Step back one place in the history. Stops at
    109      *    the first page.
    110      *    @return boolean     True if any previous entries.
    111      *    @access public
    112      */
    113     function back() {
     104     * Step back one place in the history. Stops at the first page.
     105     *
     106     * @return bool     True if any previous entries.
     107     */
     108    public function back()
     109    {
    114110        if ($this->isEmpty() || $this->atBeginning()) {
    115111            return false;
    116112        }
    117113        $this->position--;
     114
    118115        return true;
    119116    }
    120117
    121118    /**
    122      *    Step forward one place. If already at the
    123      *    latest entry then nothing will happen.
    124      *    @return boolean     True if any future entries.
    125      *    @access public
    126      */
    127     function forward() {
     119     * Step forward one place. If already at the latest entry then nothing will happen.
     120     *
     121     * @return bool     True if any future entries.
     122     */
     123    public function forward()
     124    {
    128125        if ($this->isEmpty() || $this->atEnd()) {
    129126            return false;
    130127        }
    131128        $this->position++;
     129
    132130        return true;
    133131    }
    134132
    135133    /**
    136      *    Ditches all future entries beyond the current
    137      *    point.
    138      *    @access private
    139      */
    140     protected function dropFuture() {
     134     * Ditches all future entries beyond the current point.
     135     */
     136    protected function dropFuture()
     137    {
    141138        if ($this->isEmpty()) {
    142139            return;
     
    149146
    150147/**
    151  *    Simulated web browser. This is an aggregate of
    152  *    the user agent, the HTML parsing, request history
    153  *    and the last header set.
    154  *    @package SimpleTest
    155  *    @subpackage WebTester
     148 * Simulated web browser. This is an aggregate of the user agent,
     149 * the HTML parsing, request history and the last header set.
    156150 */
    157 class SimpleBrowser {
     151class SimpleBrowser
     152{
    158153    private $user_agent;
    159154    private $page;
     
    164159
    165160    /**
    166      *    Starts with a fresh browser with no
    167      *    cookie or any other state information. The
    168      *    exception is that a default proxy will be
    169      *    set up if specified in the options.
    170      *    @access public
    171      */
    172     function __construct() {
     161     * Starts with a fresh browser with no cookie or any other state information.
     162     * The exception is that a default proxy will be set up if specified in the options.
     163     */
     164    public function __construct()
     165    {
    173166        $this->user_agent = $this->createUserAgent();
    174167        $this->user_agent->useProxy(
     
    176169                SimpleTest::getDefaultProxyUsername(),
    177170                SimpleTest::getDefaultProxyPassword());
    178         $this->page = new SimplePage();
    179         $this->history = $this->createHistory();
    180         $this->ignore_frames = false;
     171        $this->page                  = new SimplePage();
     172        $this->history               = $this->createHistory();
     173        $this->ignore_frames         = false;
    181174        $this->maximum_nested_frames = DEFAULT_MAX_NESTED_FRAMES;
    182175    }
    183176
    184177    /**
    185      *    Creates the underlying user agent.
    186      *    @return SimpleFetcher    Content fetcher.
    187      *    @access protected
    188      */
    189     protected function createUserAgent() {
     178     * Creates the underlying user agent.
     179     *
     180     * @return SimpleUserAgent    Content fetcher.
     181     */
     182    protected function createUserAgent()
     183    {
    190184        return new SimpleUserAgent();
    191185    }
    192186
    193187    /**
    194      *    Creates a new empty history list.
    195      *    @return SimpleBrowserHistory    New list.
    196      *    @access protected
    197      */
    198     protected function createHistory() {
     188     * Creates a new empty history list.
     189     *
     190     * @return SimpleBrowserHistory    New list.
     191     */
     192    protected function createHistory()
     193    {
    199194        return new SimpleBrowserHistory();
    200195    }
    201196
    202197    /**
    203      *    Get the HTML parser to use. Can be overridden by
    204      *    setParser. Otherwise scans through the available parsers and
    205      *    uses the first one which is available.
    206      *    @return object SimplePHPPageBuilder or SimpleTidyPageBuilder
    207      */
    208     protected function getParser() {
     198     * Get the HTML parser to use. Can be overridden by setParser.
     199     * Otherwise scans through the available parsers and uses the first one which is available.
     200     *
     201     * @return object SimplePHPPageBuilder or SimpleTidyPageBuilder
     202     */
     203    protected function getParser()
     204    {
    209205        if ($this->parser) {
    210206            return $this->parser;
     
    218214
    219215    /**
    220      *    Override the default HTML parser, allowing parsers to be plugged in.
    221      *    @param object           A parser object instance.
    222      */
    223     public function setParser($parser) {
     216     * Override the default HTML parser, allowing parsers to be plugged in.
     217     *
     218     * @param object           A parser object instance.
     219     */
     220    public function setParser($parser)
     221    {
    224222        $this->parser = $parser;
    225223    }
    226224
    227225    /**
    228      *    Disables frames support. Frames will not be fetched
    229      *   and the frameset page will be used instead.
    230      *    @access public
    231      */
    232     function ignoreFrames() {
     226     * Disables frames support.
     227     * Frames will not be fetched and the frameset page will be used instead.
     228     */
     229    public function ignoreFrames()
     230    {
    233231        $this->ignore_frames = true;
    234232    }
    235233
    236234    /**
    237      *    Enables frames support. Frames will be fetched from
    238      *    now on.
    239      *    @access public
    240      */
    241     function useFrames() {
     235     * Enables frames support. Frames will be fetched from now on.
     236     */
     237    public function useFrames()
     238    {
    242239        $this->ignore_frames = false;
    243240    }
    244241
    245242    /**
    246      *    Switches off cookie sending and recieving.
    247      *    @access public
    248      */
    249     function ignoreCookies() {
     243     * Switches off cookie sending and recieving.
     244     */
     245    public function ignoreCookies()
     246    {
    250247        $this->user_agent->ignoreCookies();
    251248    }
    252249
    253250    /**
    254      *    Switches back on the cookie sending and recieving.
    255      *    @access public
    256      */
    257     function useCookies() {
     251     * Switches back on the cookie sending and recieving.
     252     */
     253    public function useCookies()
     254    {
    258255        $this->user_agent->useCookies();
    259256    }
    260257
    261258    /**
    262      *    Parses the raw content into a page. Will load further
    263      *    frame pages unless frames are disabled.
    264      *    @param SimpleHttpResponse $response    Response from fetch.
    265      *    @param integer $depth                  Nested frameset depth.
    266      *    @return SimplePage                     Parsed HTML.
    267      *    @access private
    268      */
    269     protected function parse($response, $depth = 0) {
     259     * Parses the raw content into a page.
     260     * Will load further frame pages unless frames are disabled.
     261     *
     262     * @param SimpleHttpResponse $response    Response from fetch.
     263     * @param int $depth                  Nested frameset depth.
     264     *
     265     * @return SimplePage                     Parsed HTML.
     266     */
     267    protected function parse($response, $depth = 0)
     268    {
    270269        $page = $this->buildPage($response);
    271270        if ($this->ignore_frames || ! $page->hasFrames() || ($depth > $this->maximum_nested_frames)) {
     
    277276            $frameset->addFrame($frame, $key);
    278277        }
     278
    279279        return $frameset;
    280280    }
    281281
    282282    /**
    283      *    Assembles the parsing machinery and actually parses
    284      *    a single page. Frees all of the builder memory and so
    285      *    unjams the PHP memory management.
    286      *    @param SimpleHttpResponse $response    Response from fetch.
    287      *    @return SimplePage                     Parsed top level page.
    288      */
    289     protected function buildPage($response) {
     283     * Assembles the parsing machinery and actually parses a single page.
     284     * Frees all of the builder memory and so unjams the PHP memory management.
     285     *
     286     * @param SimpleHttpResponse $response    Response from fetch.
     287     *
     288     * @return SimplePage                     Parsed top level page.
     289     */
     290    protected function buildPage($response)
     291    {
    290292        return $this->getParser()->parse($response);
    291293    }
    292294
    293295    /**
    294      *    Fetches a page. Jointly recursive with the parse()
    295      *    method as it descends a frameset.
    296      *    @param string/SimpleUrl $url          Target to fetch.
    297      *    @param SimpleEncoding $encoding       GET/POST parameters.
    298      *    @param integer $depth                 Nested frameset depth protection.
    299      *    @return SimplePage                    Parsed page.
    300      *    @access private
    301      */
    302     protected function fetch($url, $encoding, $depth = 0) {
     296     * Fetches a page.
     297     * Jointly recursive with the parse() method as it descends a frameset.
     298     *
     299     * @param string/SimpleUrl $url          Target to fetch.
     300     * @param SimpleEncoding $encoding       GET/POST parameters.
     301     * @param int $depth                 Nested frameset depth protection.
     302     *
     303     * @return SimplePage                    Parsed page.
     304     */
     305    protected function fetch($url, $encoding, $depth = 0)
     306    {
    303307        $response = $this->user_agent->fetchResponse($url, $encoding);
    304308        if ($response->isError()) {
    305309            return new SimplePage($response);
    306310        }
     311
    307312        return $this->parse($response, $depth);
    308313    }
    309314
    310315    /**
    311      *    Fetches a page or a single frame if that is the current
    312      *    focus.
    313      *    @param SimpleUrl $url                   Target to fetch.
    314      *    @param SimpleEncoding $parameters       GET/POST parameters.
    315      *    @return string                          Raw content of page.
    316      *    @access private
    317      */
    318     protected function load($url, $parameters) {
     316     * Fetches a page or a single frame if that is the current focus.
     317     *
     318     * @param SimpleUrl $url                   Target to fetch.
     319     * @param SimpleEncoding $parameters       GET/POST parameters.
     320     *
     321     * @return string                          Raw content of page.
     322     */
     323    protected function load($url, $parameters)
     324    {
    319325        $frame = $url->getTarget();
    320326        if (! $frame || ! $this->page->hasFrames() || (strtolower($frame) == '_top')) {
    321327            return $this->loadPage($url, $parameters);
    322328        }
     329
    323330        return $this->loadFrame(array($frame), $url, $parameters);
    324331    }
    325332
    326333    /**
    327      *    Fetches a page and makes it the current page/frame.
    328      *    @param string/SimpleUrl $url            Target to fetch as string.
    329      *    @param SimplePostEncoding $parameters   POST parameters.
    330      *    @return string                          Raw content of page.
    331      *    @access private
    332      */
    333     protected function loadPage($url, $parameters) {
     334     * Fetches a page and makes it the current page/frame.
     335     *
     336     * @param string/SimpleUrl $url            Target to fetch as string.
     337     * @param SimplePostEncoding $parameters   POST parameters.
     338     *
     339     * @return string                          Raw content of page.
     340     */
     341    protected function loadPage($url, $parameters)
     342    {
    334343        $this->page = $this->fetch($url, $parameters);
    335344        $this->history->recordEntry(
    336345                $this->page->getUrl(),
    337346                $this->page->getRequestData());
     347
    338348        return $this->page->getRaw();
    339349    }
    340350
    341351    /**
    342      *    Fetches a frame into the existing frameset replacing the
    343      *    original.
    344      *    @param array $frames                    List of names to drill down.
    345      *    @param string/SimpleUrl $url            Target to fetch as string.
    346      *    @param SimpleFormEncoding $parameters   POST parameters.
    347      *    @return string                          Raw content of page.
    348      *    @access private
    349      */
    350     protected function loadFrame($frames, $url, $parameters) {
     352     * Fetches a frame into the existing frameset replacing the original.
     353     *
     354     * @param array $frames                    List of names to drill down.
     355     * @param string/SimpleUrl $url            Target to fetch as string.
     356     * @param SimpleFormEncoding $parameters   POST parameters.
     357     *
     358     * @return string                          Raw content of page.
     359     */
     360    protected function loadFrame($frames, $url, $parameters)
     361    {
    351362        $page = $this->fetch($url, $parameters);
    352363        $this->page->setFrame($frames, $page);
     364
    353365        return $page->getRaw();
    354366    }
    355367
    356368    /**
    357      *    Removes expired and temporary cookies as if
    358      *    the browser was closed and re-opened.
    359      *    @param string/integer $date   Time when session restarted.
    360      *                                  If omitted then all persistent
    361      *                                  cookies are kept.
    362      *    @access public
    363      */
    364     function restart($date = false) {
     369     * Removes expired and temporary cookies as if the browser was closed and re-opened.
     370     *
     371     * @param string/integer $date   Time when session restarted. If omitted then all persistent
     372     * cookies are kept.
     373     */
     374    public function restart($date = false)
     375    {
    365376        $this->user_agent->restart($date);
    366377    }
    367378
    368379    /**
    369      *    Adds a header to every fetch.
    370      *    @param string $header       Header line to add to every
    371      *                               request until cleared.
    372      *    @access public
    373      */
    374     function addHeader($header) {
     380     * Adds a header to every fetch.
     381     *
     382     * @param string $header       Header line to add to every request until cleared.
     383     */
     384    public function addHeader($header)
     385    {
    375386        $this->user_agent->addHeader($header);
    376387    }
    377388
    378389    /**
    379      *    Ages the cookies by the specified time.
    380      *    @param integer $interval    Amount in seconds.
    381      *    @access public
    382      */
    383     function ageCookies($interval) {
     390     * Ages the cookies by the specified time.
     391     *
     392     * @param int $interval    Amount in seconds.
     393     */
     394    public function ageCookies($interval)
     395    {
    384396        $this->user_agent->ageCookies($interval);
    385397    }
    386398
    387399    /**
    388      *    Sets an additional cookie. If a cookie has
    389      *    the same name and path it is replaced.
    390      *    @param string $name       Cookie key.
    391      *    @param string $value      Value of cookie.
    392      *    @param string $host       Host upon which the cookie is valid.
    393      *    @param string $path       Cookie path if not host wide.
    394      *    @param string $expiry     Expiry date.
    395      *    @access public
    396      */
    397     function setCookie($name, $value, $host = false, $path = '/', $expiry = false) {
     400     * Sets an additional cookie.
     401     * If a cookie has the same name and path it is replaced.
     402     *
     403     * @param string $name       Cookie key.
     404     * @param string $value      Value of cookie.
     405     * @param string $host       Host upon which the cookie is valid.
     406     * @param string $path       Cookie path if not host wide.
     407     * @param string $expiry     Expiry date.
     408     */
     409    public function setCookie($name, $value, $host = false, $path = '/', $expiry = false)
     410    {
    398411        $this->user_agent->setCookie($name, $value, $host, $path, $expiry);
    399412    }
    400413
    401414    /**
    402      *    Reads the most specific cookie value from the
    403      *    browser cookies.
    404      *    @param string $host        Host to search.
    405      *    @param string $path        Applicable path.
    406      *    @param string $name        Name of cookie to read.
    407      *    @return string             False if not present, else the
    408      *                               value as a string.
    409      *    @access public
    410      */
    411     function getCookieValue($host, $path, $name) {
     415     * Reads the most specific cookie value from the browser cookies.
     416     *
     417     * @param string $host        Host to search.
     418     * @param string $path        Applicable path.
     419     * @param string $name        Name of cookie to read.
     420     *
     421     * @return string             False if not present, else the value as a string.
     422     */
     423    public function getCookieValue($host, $path, $name)
     424    {
    412425        return $this->user_agent->getCookieValue($host, $path, $name);
    413426    }
    414427
    415428    /**
    416      *    Reads the current cookies for the current URL.
    417      *    @param string $name   Key of cookie to find.
    418      *    @return string        Null if there is no current URL, false
    419      *                          if the cookie is not set.
    420      *    @access public
    421      */
    422     function getCurrentCookieValue($name) {
     429     * Reads the current cookies for the current URL.
     430     *
     431     * @param string $name   Key of cookie to find.
     432     *
     433     * @return string        Null if there is no current URL, false if the cookie is not set.
     434     */
     435    public function getCurrentCookieValue($name)
     436    {
    423437        return $this->user_agent->getBaseCookieValue($name, $this->page->getUrl());
    424438    }
    425439
    426440    /**
    427      *    Sets the maximum number of redirects before
    428      *    a page will be loaded anyway.
    429      *    @param integer $max        Most hops allowed.
    430      *    @access public
    431      */
    432     function setMaximumRedirects($max) {
     441     * Sets the maximum number of redirects before a page will be loaded anyway.
     442     *
     443     * @param int $max        Most hops allowed.
     444     */
     445    public function setMaximumRedirects($max)
     446    {
    433447        $this->user_agent->setMaximumRedirects($max);
    434448    }
    435449
    436450    /**
    437      *    Sets the maximum number of nesting of framed pages
    438      *    within a framed page to prevent loops.
    439      *    @param integer $max        Highest depth allowed.
    440      *    @access public
    441      */
    442     function setMaximumNestedFrames($max) {
     451     * Sets the maximum number of nesting of framed pages within a framed page to prevent loops.
     452     *
     453     * @param int $max        Highest depth allowed.
     454     */
     455    public function setMaximumNestedFrames($max)
     456    {
    443457        $this->maximum_nested_frames = $max;
    444458    }
    445459
    446460    /**
    447      *    Sets the socket timeout for opening a connection.
    448      *    @param integer $timeout      Maximum time in seconds.
    449      *    @access public
    450      */
    451     function setConnectionTimeout($timeout) {
     461     * Sets the socket timeout for opening a connection.
     462     *
     463     * @param int $timeout      Maximum time in seconds.
     464     */
     465    public function setConnectionTimeout($timeout)
     466    {
    452467        $this->user_agent->setConnectionTimeout($timeout);
    453468    }
    454469
    455470    /**
    456      *    Sets proxy to use on all requests for when
    457      *    testing from behind a firewall. Set URL
    458      *    to false to disable.
    459      *    @param string $proxy        Proxy URL.
    460      *    @param string $username     Proxy username for authentication.
    461      *    @param string $password     Proxy password for authentication.
    462      *    @access public
    463      */
    464     function useProxy($proxy, $username = false, $password = false) {
     471     * Sets proxy to use on all requests for when testing from behind a firewall.
     472     * Set URL to false to disable.
     473     *
     474     * @param string $proxy        Proxy URL.
     475     * @param string $username     Proxy username for authentication.
     476     * @param string $password     Proxy password for authentication.
     477     */
     478    public function useProxy($proxy, $username = false, $password = false)
     479    {
    465480        $this->user_agent->useProxy($proxy, $username, $password);
    466481    }
    467482
    468483    /**
    469      *    Fetches the page content with a HEAD request.
    470      *    Will affect cookies, but will not change the base URL.
    471      *    @param string/SimpleUrl $url                Target to fetch as string.
    472      *    @param hash/SimpleHeadEncoding $parameters  Additional parameters for
    473      *                                                HEAD request.
    474      *    @return boolean                             True if successful.
    475      *    @access public
    476      */
    477     function head($url, $parameters = false) {
     484     * Fetches the page content with a HEAD request.
     485     * Will affect cookies, but will not change the base URL.
     486     *
     487     * @param string/SimpleUrl $url                Target to fetch as string.
     488     * @param hash/SimpleHeadEncoding $parameters  Additional parameters for HEAD request.
     489     *
     490     * @return bool                             True if successful.
     491     */
     492    public function head($url, $parameters = false)
     493    {
    478494        if (! is_object($url)) {
    479495            $url = new SimpleUrl($url);
     
    482498            $url = $url->makeAbsolute($this->getUrl());
    483499        }
    484         $response = $this->user_agent->fetchResponse($url, new SimpleHeadEncoding($parameters));
     500        $response   = $this->user_agent->fetchResponse($url, new SimpleHeadEncoding($parameters));
    485501        $this->page = new SimplePage($response);
     502
    486503        return ! $response->isError();
    487504    }
    488505
    489506    /**
    490      *    Fetches the page content with a simple GET request.
    491      *    @param string/SimpleUrl $url                Target to fetch.
    492      *    @param hash/SimpleFormEncoding $parameters  Additional parameters for
    493      *                                                GET request.
    494      *    @return string                              Content of page or false.
    495      *    @access public
    496      */
    497     function get($url, $parameters = false) {
     507     * Fetches the page content with a simple GET request.
     508     *
     509     * @param string/SimpleUrl $url                Target to fetch.
     510     * @param hash/SimpleFormEncoding $parameters  Additional parameters for GET request.
     511     *
     512     * @return string                              Content of page or false.
     513     */
     514    public function get($url, $parameters = false)
     515    {
    498516        if (! is_object($url)) {
    499517            $url = new SimpleUrl($url);
     
    502520            $url = $url->makeAbsolute($this->getUrl());
    503521        }
     522
    504523        return $this->load($url, new SimpleGetEncoding($parameters));
    505524    }
    506525
    507526    /**
    508      *    Fetches the page content with a POST request.
    509      *    @param string/SimpleUrl $url                Target to fetch as string.
    510      *    @param hash/SimpleFormEncoding $parameters  POST parameters or request body.
    511      *    @param string $content_type                 MIME Content-Type of the request body
    512      *    @return string                              Content of page.
    513      *    @access public
    514      */
    515     function post($url, $parameters = false, $content_type = false) {
     527     * Fetches the page content with a POST request.
     528     *
     529     * @param string/SimpleUrl $url                Target to fetch as string.
     530     * @param hash/SimpleFormEncoding $parameters  POST parameters or request body.
     531     * @param string $content_type                 MIME Content-Type of the request body
     532     *
     533     * @return string                              Content of page.
     534     */
     535    public function post($url, $parameters = false, $content_type = false)
     536    {
    516537        if (! is_object($url)) {
    517538            $url = new SimpleUrl($url);
     
    520541            $url = $url->makeAbsolute($this->getUrl());
    521542        }
     543
    522544        return $this->load($url, new SimplePostEncoding($parameters, $content_type));
    523545    }
    524546
    525547    /**
    526      *    Fetches the page content with a PUT request.
    527      *    @param string/SimpleUrl $url                Target to fetch as string.
    528      *    @param hash/SimpleFormEncoding $parameters  PUT request body.
    529      *    @param string $content_type                 MIME Content-Type of the request body
    530      *    @return string                              Content of page.
    531      *    @access public
    532      */
    533     function put($url, $parameters = false, $content_type = false) {
     548     * Fetches the page content with a PUT request.
     549     *
     550     * @param string/SimpleUrl $url                Target to fetch as string.
     551     * @param hash/SimpleFormEncoding $parameters  PUT request body.
     552     * @param string $content_type                 MIME Content-Type of the request body
     553     *
     554     * @return string                              Content of page.
     555     */
     556    public function put($url, $parameters = false, $content_type = false)
     557    {
    534558        if (! is_object($url)) {
    535559            $url = new SimpleUrl($url);
    536560        }
     561
    537562        return $this->load($url, new SimplePutEncoding($parameters, $content_type));
    538563    }
    539564
    540565    /**
    541      *    Sends a DELETE request and fetches the response.
    542      *    @param string/SimpleUrl $url                Target to fetch.
    543      *    @param hash/SimpleFormEncoding $parameters  Additional parameters for
    544      *                                                DELETE request.
    545      *    @return string                              Content of page or false.
    546      *    @access public
    547      */
    548     function delete($url, $parameters = false) {
     566     * Sends a DELETE request and fetches the response.
     567     *
     568     * @param string/SimpleUrl $url                Target to fetch.
     569     * @param hash/SimpleFormEncoding $parameters  Additional parameters for DELETE request.
     570     *
     571     * @return string                              Content of page or false.
     572     */
     573    public function delete($url, $parameters = false)
     574    {
    549575        if (! is_object($url)) {
    550576            $url = new SimpleUrl($url);
    551577        }
     578
    552579        return $this->load($url, new SimpleDeleteEncoding($parameters));
    553580    }
    554581
    555582    /**
    556      *    Equivalent to hitting the retry button on the
    557      *    browser. Will attempt to repeat the page fetch. If
    558      *   there is no history to repeat it will give false.
    559      *    @return string/boolean   Content if fetch succeeded
    560      *                             else false.
    561      *    @access public
    562      */
    563     function retry() {
     583     * Equivalent to hitting the retry button on the browser.
     584     * Will attempt to repeat the page fetch.
     585     * If there is no history to repeat it will give false.
     586     *
     587     * @return string/boolean   Content if fetch succeeded else false.
     588     */
     589    public function retry()
     590    {
    564591        $frames = $this->page->getFrameFocus();
    565592        if (count($frames) > 0) {
     
    568595                    $this->page->getUrl(),
    569596                    $this->page->getRequestData());
     597
    570598            return $this->page->getRaw();
    571599        }
    572600        if ($url = $this->history->getUrl()) {
    573601            $this->page = $this->fetch($url, $this->history->getParameters());
     602
    574603            return $this->page->getRaw();
    575604        }
     605
    576606        return false;
    577607    }
    578608
    579609    /**
    580      *    Equivalent to hitting the back button on the
    581      *    browser. The browser history is unchanged on
    582      *    failure. The page content is refetched as there
    583      *    is no concept of content caching in SimpleTest.
    584      *    @return boolean     True if history entry and
    585      *                        fetch succeeded
    586      *    @access public
    587      */
    588     function back() {
     610     * Equivalent to hitting the back button on the browser.
     611     * The browser history is unchanged on failure.
     612     * The page content is refetched as there is no concept of content caching in SimpleTest.
     613     *
     614     * @return bool     True if history entry and fetch succeeded
     615     */
     616    public function back()
     617    {
    589618        if (! $this->history->back()) {
    590619            return false;
     
    594623            $this->history->forward();
    595624        }
     625
    596626        return $content;
    597627    }
    598628
    599629    /**
    600      *    Equivalent to hitting the forward button on the
    601      *    browser. The browser history is unchanged on
    602      *    failure. The page content is refetched as there
    603      *    is no concept of content caching in SimpleTest.
    604      *    @return boolean     True if history entry and
    605      *                        fetch succeeded
    606      *    @access public
    607      */
    608     function forward() {
     630     * Equivalent to hitting the forward button on the browser.
     631     * The browser history is unchanged on failure.
     632     * The page content is refetched as there is no concept of content caching in SimpleTest.
     633     *
     634     * @return bool     True if history entry and fetch succeeded
     635     */
     636    public function forward()
     637    {
    609638        if (! $this->history->forward()) {
    610639            return false;
     
    614643            $this->history->back();
    615644        }
     645
    616646        return $content;
    617647    }
    618648
    619649    /**
    620      *    Retries a request after setting the authentication
    621      *    for the current realm.
    622      *    @param string $username    Username for realm.
    623      *    @param string $password    Password for realm.
    624      *    @return boolean            True if successful fetch. Note
    625      *                               that authentication may still have
    626      *                               failed.
    627      *    @access public
    628      */
    629     function authenticate($username, $password) {
     650     * Retries a request after setting the authentication for the current realm.
     651     *
     652     * @param string $username    Username for realm.
     653     * @param string $password    Password for realm.
     654     *
     655     * @return bool    True if successful fetch. Note that authentication may still have failed.
     656     */
     657    public function authenticate($username, $password)
     658    {
    630659        if (! $this->page->getRealm()) {
    631660            return false;
     
    640669                $username,
    641670                $password);
     671
    642672        return $this->retry();
    643673    }
    644674
    645675    /**
    646      *    Accessor for a breakdown of the frameset.
    647      *    @return array   Hash tree of frames by name
    648      *                   or index if no name.
    649      *    @access public
    650      */
    651     function getFrames() {
     676     * Accessor for a breakdown of the frameset.
     677     *
     678     * @return array   Hash tree of frames by name or index if no name.
     679     */
     680    public function getFrames()
     681    {
    652682        return $this->page->getFrames();
    653683    }
    654684
    655685    /**
    656      *    Accessor for current frame focus. Will be
    657      *    false if no frame has focus.
    658      *    @return integer/string/boolean    Label if any, otherwise
    659      *                                      the position in the frameset
    660      *                                      or false if none.
    661      *    @access public
    662      */
    663     function getFrameFocus() {
     686     * Accessor for current frame focus. Will be false if no frame has focus.
     687     *
     688     * @return integer/string/boolean    Label if any, otherwise the position in the frameset or
     689     * false if none.
     690     */
     691    public function getFrameFocus()
     692    {
    664693        return $this->page->getFrameFocus();
    665694    }
    666695
    667696    /**
    668      *    Sets the focus by index. The integer index starts from 1.
    669      *    @param integer $choice    Chosen frame.
    670      *    @return boolean           True if frame exists.
    671      *    @access public
    672      */
    673     function setFrameFocusByIndex($choice) {
     697     * Sets the focus by index. The integer index starts from 1.
     698     *
     699     * @param int $choice    Chosen frame.
     700     *
     701     * @return bool           True if frame exists.
     702     */
     703    public function setFrameFocusByIndex($choice)
     704    {
    674705        return $this->page->setFrameFocusByIndex($choice);
    675706    }
    676707
    677708    /**
    678      *    Sets the focus by name.
    679      *    @param string $name    Chosen frame.
    680      *    @return boolean        True if frame exists.
    681      *    @access public
    682      */
    683     function setFrameFocus($name) {
     709     * Sets the focus by name.
     710     *
     711     * @param string $name    Chosen frame.
     712     *
     713     * @return bool        True if frame exists.
     714     */
     715    public function setFrameFocus($name)
     716    {
    684717        return $this->page->setFrameFocus($name);
    685718    }
    686719
    687720    /**
    688      *    Clears the frame focus. All frames will be searched
    689      *    for content.
    690      *    @access public
    691      */
    692     function clearFrameFocus() {
     721     * Clears the frame focus. All frames will be searched for content.
     722     */
     723    public function clearFrameFocus()
     724    {
    693725        return $this->page->clearFrameFocus();
    694726    }
    695727
    696728    /**
    697      *    Accessor for last error.
    698      *    @return string        Error from last response.
    699      *    @access public
    700      */
    701     function getTransportError() {
     729     * Accessor for last error.
     730     *
     731     * @return string        Error from last response.
     732     */
     733    public function getTransportError()
     734    {
    702735        return $this->page->getTransportError();
    703736    }
    704737
    705738    /**
    706      *    Accessor for current MIME type.
    707      *    @return string    MIME type as string; e.g. 'text/html'
    708      *    @access public
    709      */
    710     function getMimeType() {
     739     * Accessor for current MIME type.
     740     *
     741     * @return string    MIME type as string; e.g. 'text/html'
     742     */
     743    public function getMimeType()
     744    {
    711745        return $this->page->getMimeType();
    712746    }
    713747
    714748    /**
    715      *    Accessor for last response code.
    716      *    @return integer    Last HTTP response code received.
    717      *    @access public
    718      */
    719     function getResponseCode() {
     749     * Accessor for last response code.
     750     *
     751     * @return int    Last HTTP response code received.
     752     */
     753    public function getResponseCode()
     754    {
    720755        return $this->page->getResponseCode();
    721756    }
    722757
    723758    /**
    724      *    Accessor for last Authentication type. Only valid
    725      *    straight after a challenge (401).
    726      *    @return string    Description of challenge type.
    727      *    @access public
    728      */
    729     function getAuthentication() {
     759     * Accessor for last Authentication type. Only valid straight after a challenge (401).
     760     *
     761     * @return string    Description of challenge type.
     762     */
     763    public function getAuthentication()
     764    {
    730765        return $this->page->getAuthentication();
    731766    }
    732767
    733768    /**
    734      *    Accessor for last Authentication realm. Only valid
    735      *    straight after a challenge (401).
    736      *    @return string    Name of security realm.
    737      *    @access public
    738      */
    739     function getRealm() {
     769     * Accessor for last Authentication realm. Only valid straight after a challenge (401).
     770     *
     771     * @return string    Name of security realm.
     772     */
     773    public function getRealm()
     774    {
    740775        return $this->page->getRealm();
    741776    }
    742777
    743778    /**
    744      *    Accessor for current URL of page or frame if
    745      *    focused.
    746      *    @return string    Location of current page or frame as
    747      *                      a string.
    748      */
    749     function getUrl() {
     779     * Accessor for current URL of page or frame if focused.
     780     *
     781     * @return string    Location of current page or frame as a string.
     782     */
     783    public function getUrl()
     784    {
    750785        $url = $this->page->getUrl();
     786
    751787        return $url ? $url->asString() : false;
    752788    }
    753789
    754790    /**
    755      *    Accessor for base URL of page if set via BASE tag
    756      *    @return string    base URL
    757      */
    758     function getBaseUrl() {
     791     * Accessor for base URL of page if set via BASE tag
     792     *
     793     * @return string    base URL
     794     */
     795    public function getBaseUrl()
     796    {
    759797        $url = $this->page->getBaseUrl();
     798
    760799        return $url ? $url->asString() : false;
    761800    }
    762801
    763802    /**
    764      *    Accessor for raw bytes sent down the wire.
    765      *    @return string      Original text sent.
    766      *    @access public
    767      */
    768     function getRequest() {
     803     * Accessor for raw bytes sent down the wire.
     804     *
     805     * @return string      Original text sent.
     806     */
     807    public function getRequest()
     808    {
    769809        return $this->page->getRequest();
    770810    }
    771811
    772812    /**
    773      *    Accessor for raw header information.
    774      *    @return string      Header block.
    775      *    @access public
    776      */
    777     function getHeaders() {
     813     * Accessor for raw header information.
     814     *
     815     * @return string      Header block.
     816     */
     817    public function getHeaders()
     818    {
    778819        return $this->page->getHeaders();
    779820    }
    780821
    781822    /**
    782      *    Accessor for raw page information.
    783      *    @return string      Original text content of web page.
    784      *    @access public
    785      */
    786     function getContent() {
     823     * Accessor for raw page information.
     824     *
     825     * @return string      Original text content of web page.
     826     */
     827    public function getContent()
     828    {
    787829        return $this->page->getRaw();
    788830    }
    789831
    790832    /**
    791      *    Accessor for plain text version of the page.
    792      *    @return string      Normalised text representation.
    793      *    @access public
    794      */
    795     function getContentAsText() {
     833     * Accessor for plain text version of the page.
     834     *
     835     * @return string      Normalised text representation.
     836     */
     837    public function getContentAsText()
     838    {
    796839        return $this->page->getText();
    797840    }
    798841
    799842    /**
    800      *    Accessor for parsed title.
    801      *    @return string     Title or false if no title is present.
    802      *    @access public
    803      */
    804     function getTitle() {
     843     * Accessor for parsed title.
     844     *
     845     * @return string     Title or false if no title is present.
     846     */
     847    public function getTitle()
     848    {
    805849        return $this->page->getTitle();
    806850    }
    807851
    808852    /**
    809      *    Accessor for a list of all links in current page.
    810      *    @return array   List of urls with scheme of
    811      *                   http or https and hostname.
    812      *    @access public
    813      */
    814     function getUrls() {
     853     * Accessor for a list of all links in current page.
     854     *
     855     * @return array   List of urls with scheme of http or https and hostname.
     856     */
     857    public function getUrls()
     858    {
    815859        return $this->page->getUrls();
    816860    }
    817861
    818862    /**
    819      *    Sets all form fields with that name.
    820      *    @param string $label   Name or label of field in forms.
    821      *    @param string $value   New value of field.
    822      *    @return boolean        True if field exists, otherwise false.
    823      *    @access public
    824      */
    825     function setField($label, $value, $position=false) {
    826         return $this->page->setField(new SimpleByLabelOrName($label), $value, $position);
    827     }
    828 
    829     /**
    830      *    Sets all form fields with that name. Will use label if
    831      *    one is available (not yet implemented).
    832      *    @param string $name    Name of field in forms.
    833      *    @param string $value   New value of field.
    834      *    @return boolean        True if field exists, otherwise false.
    835      *    @access public
    836      */
    837     function setFieldByName($name, $value, $position=false) {
    838         return $this->page->setField(new SimpleByName($name), $value, $position);
    839     }
    840 
    841     /**
    842      *    Sets all form fields with that id attribute.
    843      *    @param string/integer $id   Id of field in forms.
    844      *    @param string $value        New value of field.
    845      *    @return boolean             True if field exists, otherwise false.
    846      *    @access public
    847      */
    848     function setFieldById($id, $value) {
    849         return $this->page->setField(new SimpleById($id), $value);
    850     }
    851 
    852     /**
    853      *    Accessor for a form element value within the page.
    854      *    Finds the first match.
    855      *    @param string $label       Field label.
    856      *    @return string/boolean     A value if the field is
    857      *                               present, false if unchecked
    858      *                               and null if missing.
    859      *    @access public
    860      */
    861     function getField($label) {
    862         return $this->page->getField(new SimpleByLabelOrName($label));
    863     }
    864 
    865     /**
    866      *    Accessor for a form element value within the page.
    867      *    Finds the first match.
    868      *    @param string $name        Field name.
    869      *    @return string/boolean     A string if the field is
    870      *                               present, false if unchecked
    871      *                               and null if missing.
    872      *    @access public
    873      */
    874     function getFieldByName($name) {
    875         return $this->page->getField(new SimpleByName($name));
    876     }
    877 
    878     /**
    879      *    Accessor for a form element value within the page.
    880      *    @param string/integer $id  Id of field in forms.
    881      *    @return string/boolean     A string if the field is
    882      *                               present, false if unchecked
    883      *                               and null if missing.
    884      *    @access public
    885      */
    886     function getFieldById($id) {
    887         return $this->page->getField(new SimpleById($id));
    888     }
    889 
    890     /**
    891      *    Clicks the submit button by label. The owning
    892      *    form will be submitted by this.
    893      *    @param string $label    Button label. An unlabeled
    894      *                            button can be triggered by 'Submit'.
    895      *    @param hash $additional Additional form data.
    896      *    @return string/boolean  Page on success.
    897      *    @access public
    898      */
    899     function clickSubmit($label = 'Submit', $additional = false) {
    900         if (! ($form = $this->page->getFormBySubmit(new SimpleByLabel($label)))) {
     863     * Sets all form fields with that name.
     864     *
     865     * @param string $label   Name or label of field in forms.
     866     * @param string $value   New value of field.
     867     *
     868     * @return bool        True if field exists, otherwise false.
     869     */
     870    public function setField($label, $value, $position=false)
     871    {
     872        return $this->page->setField(new SelectByLabelOrName($label), $value, $position);
     873    }
     874
     875    /**
     876     * Sets all form fields with that name. Will use label if one is available (not yet
     877     * implemented).
     878     *
     879     * @param string $name    Name of field in forms.
     880     * @param string $value   New value of field.
     881     *
     882     * @return bool        True if field exists, otherwise false.
     883     */
     884    public function setFieldByName($name, $value, $position=false)
     885    {
     886        return $this->page->setField(new SelectByName($name), $value, $position);
     887    }
     888
     889    /**
     890     * Sets all form fields with that id attribute.
     891     *
     892     * @param string/integer $id   Id of field in forms.
     893     * @param string $value        New value of field.
     894     *
     895     * @return bool             True if field exists, otherwise false.
     896     */
     897    public function setFieldById($id, $value)
     898    {
     899        return $this->page->setField(new SelectById($id), $value);
     900    }
     901
     902    /**
     903     * Accessor for a form element value within the page.
     904     * Finds the first match.
     905     *
     906     * @param string $label       Field label.
     907     *
     908     * @return string/boolean     A value if the field is present, false if unchecked and null if
     909     * missing.
     910     */
     911    public function getField($label)
     912    {
     913        return $this->page->getField(new SelectByLabelOrName($label));
     914    }
     915
     916    /**
     917     * Accessor for a form element value within the page. Finds the first match.
     918     *
     919     * @param string $name        Field name.
     920     *
     921     * @return string/boolean     A string if the field is present, false if unchecked and null if
     922     * missing.
     923     */
     924    public function getFieldByName($name)
     925    {
     926        return $this->page->getField(new SelectByName($name));
     927    }
     928
     929    /**
     930     * Accessor for a form element value within the page.
     931     *
     932     * @param string/integer $id  Id of field in forms.
     933     *
     934     * @return string/boolean     A string if the field is present, false if unchecked and null if
     935     * missing.
     936     */
     937    public function getFieldById($id)
     938    {
     939        return $this->page->getField(new SelectById($id));
     940    }
     941
     942    /**
     943     * Clicks the submit button by label. The owning form will be submitted by this.
     944     *
     945     * @param string $label    Button label. An unlabeled button can be triggered by 'Submit'.
     946     * @param hash $additional Additional form data.
     947     *
     948     * @return string/boolean  Page on success.
     949     */
     950    public function clickSubmit($label = 'Submit', $additional = false)
     951    {
     952        if (! ($form = $this->page->getFormBySubmit(new SelectByLabel($label)))) {
    901953            return false;
    902954        }
    903955        $success = $this->load(
    904956                $form->getAction(),
    905                 $form->submitButton(new SimpleByLabel($label), $additional));
     957                $form->submitButton(new SelectByLabel($label), $additional));
     958
    906959        return ($success ? $this->getContent() : $success);
    907960    }
    908961
    909962    /**
    910      *    Clicks the submit button by name attribute. The owning
    911      *    form will be submitted by this.
    912      *    @param string $name     Button name.
    913      *    @param hash $additional Additional form data.
    914      *    @return string/boolean  Page on success.
    915      *    @access public
    916      */
    917     function clickSubmitByName($name, $additional = false) {
    918         if (! ($form = $this->page->getFormBySubmit(new SimpleByName($name)))) {
     963     * Clicks the submit button by name attribute. The owning form will be submitted by this.
     964     *
     965     * @param string $name     Button name.
     966     * @param hash $additional Additional form data.
     967     *
     968     * @return string/boolean  Page on success.
     969     */
     970    public function clickSubmitByName($name, $additional = false)
     971    {
     972        if (! ($form = $this->page->getFormBySubmit(new SelectByName($name)))) {
    919973            return false;
    920974        }
    921975        $success = $this->load(
    922976                $form->getAction(),
    923                 $form->submitButton(new SimpleByName($name), $additional));
     977                $form->submitButton(new SelectByName($name), $additional));
     978
    924979        return ($success ? $this->getContent() : $success);
    925980    }
    926981
    927982    /**
    928      *    Clicks the submit button by ID attribute of the button
    929      *    itself. The owning form will be submitted by this.
    930      *    @param string $id       Button ID.
    931      *    @param hash $additional Additional form data.
    932      *    @return string/boolean  Page on success.
    933      *    @access public
    934      */
    935     function clickSubmitById($id, $additional = false) {
    936         if (! ($form = $this->page->getFormBySubmit(new SimpleById($id)))) {
     983     * Clicks the submit button by ID attribute of the button itself. The owning form will be
     984     * submitted by this.
     985     *
     986     * @param string $id       Button ID.
     987     * @param hash $additional Additional form data.
     988     *
     989     * @return string/boolean  Page on success.
     990     */
     991    public function clickSubmitById($id, $additional = false)
     992    {
     993        if (! ($form = $this->page->getFormBySubmit(new SelectById($id)))) {
    937994            return false;
    938995        }
    939996        $success = $this->load(
    940997                $form->getAction(),
    941                 $form->submitButton(new SimpleById($id), $additional));
     998                $form->submitButton(new SelectById($id), $additional));
     999
    9421000        return ($success ? $this->getContent() : $success);
    9431001    }
    9441002
    9451003    /**
    946      *    Tests to see if a submit button exists with this
    947      *    label.
    948      *    @param string $label    Button label.
    949      *    @return boolean         True if present.
    950      *    @access public
    951      */
    952     function isSubmit($label) {
    953         return (boolean)$this->page->getFormBySubmit(new SimpleByLabel($label));
    954     }
    955 
    956     /**
    957      *    Clicks the submit image by some kind of label. Usually
    958      *    the alt tag or the nearest equivalent. The owning
    959      *    form will be submitted by this. Clicking outside of
    960      *    the boundary of the coordinates will result in
    961      *    a failure.
    962      *    @param string $label    ID attribute of button.
    963      *    @param integer $x       X-coordinate of imaginary click.
    964      *    @param integer $y       Y-coordinate of imaginary click.
    965      *    @param hash $additional Additional form data.
    966      *    @return string/boolean  Page on success.
    967      *    @access public
    968      */
    969     function clickImage($label, $x = 1, $y = 1, $additional = false) {
    970         if (! ($form = $this->page->getFormByImage(new SimpleByLabel($label)))) {
     1004     * Tests to see if a submit button exists with this label.
     1005     *
     1006     * @param string $label    Button label.
     1007     *
     1008     * @return bool         True if present.
     1009     */
     1010    public function isSubmit($label)
     1011    {
     1012        return (boolean) $this->page->getFormBySubmit(new SelectByLabel($label));
     1013    }
     1014
     1015    /**
     1016     * Clicks the submit image by some kind of label.
     1017     * Usually the alt tag or the nearest equivalent.
     1018     * The owning form will be submitted by this.
     1019     * Clicking outside of the boundary of the coordinates will result in a failure.
     1020     *
     1021     * @param string $label    ID attribute of button.
     1022     * @param int $x       X-coordinate of imaginary click.
     1023     * @param int $y       Y-coordinate of imaginary click.
     1024     * @param hash $additional Additional form data.
     1025     *
     1026     * @return string/boolean  Page on success.
     1027     */
     1028    public function clickImage($label, $x = 1, $y = 1, $additional = false)
     1029    {
     1030        if (! ($form = $this->page->getFormByImage(new SelectByLabel($label)))) {
    9711031            return false;
    9721032        }
    9731033        $success = $this->load(
    9741034                $form->getAction(),
    975                 $form->submitImage(new SimpleByLabel($label), $x, $y, $additional));
     1035                $form->submitImage(new SelectByLabel($label), $x, $y, $additional));
     1036
    9761037        return ($success ? $this->getContent() : $success);
    9771038    }
    9781039
    9791040    /**
    980      *    Clicks the submit image by the name. Usually
    981      *    the alt tag or the nearest equivalent. The owning
    982      *    form will be submitted by this. Clicking outside of
    983      *    the boundary of the coordinates will result in
    984      *    a failure.
    985      *    @param string $name     Name attribute of button.
    986      *    @param integer $x       X-coordinate of imaginary click.
    987      *    @param integer $y       Y-coordinate of imaginary click.
    988      *    @param hash $additional Additional form data.
    989      *    @return string/boolean  Page on success.
    990      *    @access public
    991      */
    992     function clickImageByName($name, $x = 1, $y = 1, $additional = false) {
    993         if (! ($form = $this->page->getFormByImage(new SimpleByName($name)))) {
     1041     * Clicks the submit image by the name.
     1042     * Usually the alt tag or the nearest equivalent.
     1043     * The owning form will be submitted by this.
     1044     * Clicking outside of the boundary of the coordinates will result in a failure.
     1045     *
     1046     * @param string $name     Name attribute of button.
     1047     * @param int $x       X-coordinate of imaginary click.
     1048     * @param int $y       Y-coordinate of imaginary click.
     1049     * @param hash $additional Additional form data.
     1050     *
     1051     * @return string/boolean  Page on success.
     1052     */
     1053    public function clickImageByName($name, $x = 1, $y = 1, $additional = false)
     1054    {
     1055        if (! ($form = $this->page->getFormByImage(new SelectByName($name)))) {
    9941056            return false;
    9951057        }
    9961058        $success = $this->load(
    9971059                $form->getAction(),
    998                 $form->submitImage(new SimpleByName($name), $x, $y, $additional));
     1060                $form->submitImage(new SelectByName($name), $x, $y, $additional));
     1061
    9991062        return ($success ? $this->getContent() : $success);
    10001063    }
    10011064
    10021065    /**
    1003      *    Clicks the submit image by ID attribute. The owning
    1004      *    form will be submitted by this. Clicking outside of
    1005      *    the boundary of the coordinates will result in
    1006      *    a failure.
    1007      *    @param integer/string $id    ID attribute of button.
    1008      *    @param integer $x            X-coordinate of imaginary click.
    1009      *    @param integer $y            Y-coordinate of imaginary click.
    1010      *    @param hash $additional      Additional form data.
    1011      *    @return string/boolean       Page on success.
    1012      *    @access public
    1013      */
    1014     function clickImageById($id, $x = 1, $y = 1, $additional = false) {
    1015         if (! ($form = $this->page->getFormByImage(new SimpleById($id)))) {
     1066     * Clicks the submit image by ID attribute.
     1067     * The owning form will be submitted by this.
     1068     * Clicking outside of the boundary of the coordinates will result in a failure.
     1069     *
     1070     * @param integer/string $id    ID attribute of button.
     1071     * @param int $x            X-coordinate of imaginary click.
     1072     * @param int $y            Y-coordinate of imaginary click.
     1073     * @param hash $additional      Additional form data.
     1074     *
     1075     * @return string/boolean       Page on success.
     1076     */
     1077    public function clickImageById($id, $x = 1, $y = 1, $additional = false)
     1078    {
     1079        if (! ($form = $this->page->getFormByImage(new SelectById($id)))) {
    10161080            return false;
    10171081        }
    10181082        $success = $this->load(
    10191083                $form->getAction(),
    1020                 $form->submitImage(new SimpleById($id), $x, $y, $additional));
     1084                $form->submitImage(new SelectById($id), $x, $y, $additional));
     1085
    10211086        return ($success ? $this->getContent() : $success);
    10221087    }
    10231088
    10241089    /**
    1025      *    Tests to see if an image exists with this
    1026      *    title or alt text.
    1027      *    @param string $label    Image text.
    1028      *    @return boolean         True if present.
    1029      *    @access public
    1030      */
    1031     function isImage($label) {
    1032         return (boolean)$this->page->getFormByImage(new SimpleByLabel($label));
    1033     }
    1034 
    1035     /**
    1036      *    Submits a form by the ID.
    1037      *    @param string $id       The form ID. No submit button value
    1038      *                            will be sent.
    1039      *    @return string/boolean  Page on success.
    1040      *    @access public
    1041      */
    1042     function submitFormById($id, $additional = false) {
     1090     * Tests to see if an image exists with this title or alt text.
     1091     *
     1092     * @param string $label    Image text.
     1093     *
     1094     * @return bool         True if present.
     1095     */
     1096    public function isImage($label)
     1097    {
     1098        return (boolean) $this->page->getFormByImage(new SelectByLabel($label));
     1099    }
     1100
     1101    /**
     1102     * Submits a form by the ID.
     1103     *
     1104     * @param string $id       The form ID. No submit button value will be sent.
     1105     *
     1106     * @return string/boolean  Page on success.
     1107     */
     1108    public function submitFormById($id, $additional = false)
     1109    {
    10431110        if (! ($form = $this->page->getFormById($id))) {
    10441111            return false;
     
    10471114                $form->getAction(),
    10481115                $form->submit($additional));
     1116
    10491117        return ($success ? $this->getContent() : $success);
    10501118    }
    10511119
    10521120    /**
    1053      *    Finds a URL by label. Will find the first link
    1054      *    found with this link text by default, or a later
    1055      *    one if an index is given. The match ignores case and
    1056      *    white space issues.
    1057      *    @param string $label     Text between the anchor tags.
    1058      *    @param integer $index    Link position counting from zero.
    1059      *    @return string/boolean   URL on success.
    1060      *    @access public
    1061      */
    1062     function getLink($label, $index = 0) {
     1121     * Finds a URL by label. Will find the first link found with this link text by default,
     1122     * or a later one if an index is given. The match ignores case and white space issues.
     1123     *
     1124     * @param string $label     Text between the anchor tags.
     1125     * @param int $index    Link position counting from zero.
     1126     *
     1127     * @return string/boolean   URL on success.
     1128     */
     1129    public function getLink($label, $index = 0)
     1130    {
    10631131        $urls = $this->page->getUrlsByLabel($label);
    10641132        if (count($urls) == 0) {
     
    10681136            return false;
    10691137        }
     1138
    10701139        return $urls[$index];
    10711140    }
    10721141
    10731142    /**
    1074      *    Follows a link by label. Will click the first link
    1075      *    found with this link text by default, or a later
    1076      *    one if an index is given. The match ignores case and
    1077      *    white space issues.
    1078      *    @param string $label     Text between the anchor tags.
    1079      *    @param integer $index    Link position counting from zero.
    1080      *    @return string/boolean   Page on success.
    1081      *    @access public
    1082      */
    1083     function clickLink($label, $index = 0) {
     1143     * Follows a link by label.
     1144     * Will click the first link found with this link text by default,
     1145     * or a later one, if an index is given.
     1146     * The match ignores case and white space issues.
     1147     *
     1148     * @param string $label     Text between the anchor tags.
     1149     * @param int $index    Link position counting from zero.
     1150     *
     1151     * @return boolean   True on success.
     1152     */
     1153    public function clickLink($label, $index = 0)
     1154    {
    10841155        $url = $this->getLink($label, $index);
    10851156        if ($url === false) {
    10861157            return false;
    10871158        }
     1159
    10881160        $this->load($url, new SimpleGetEncoding());
     1161
     1162        return (bool) $this->getContent();
     1163    }
     1164
     1165    /**
     1166     * Finds a link by id attribute.
     1167     *
     1168     * @param string $id        ID attribute value.
     1169     *
     1170     * @return string/boolean   URL on success.
     1171     */
     1172    public function getLinkById($id)
     1173    {
     1174        return $this->page->getUrlById($id);
     1175    }
     1176
     1177    /**
     1178     * Follows a link by id attribute.
     1179     *
     1180     * @param string $id        ID attribute value.
     1181     *
     1182     * @return string/boolean   Page on success.
     1183     */
     1184    public function clickLinkById($id)
     1185    {
     1186        if (! ($url = $this->getLinkById($id))) {
     1187            return false;
     1188        }
     1189        $this->load($url, new SimpleGetEncoding());
     1190
    10891191        return $this->getContent();
    10901192    }
    10911193
    10921194    /**
    1093      *    Finds a link by id attribute.
    1094      *    @param string $id        ID attribute value.
    1095      *    @return string/boolean   URL on success.
    1096      *    @access public
    1097      */
    1098     function getLinkById($id) {
    1099         return $this->page->getUrlById($id);
    1100     }
    1101 
    1102     /**
    1103      *    Follows a link by id attribute.
    1104      *    @param string $id        ID attribute value.
    1105      *    @return string/boolean   Page on success.
    1106      *    @access public
    1107      */
    1108     function clickLinkById($id) {
    1109         if (! ($url = $this->getLinkById($id))) {
    1110             return false;
    1111         }
    1112         $this->load($url, new SimpleGetEncoding());
    1113         return $this->getContent();
    1114     }
    1115 
    1116     /**
    1117      *    Clicks a visible text item. Will first try buttons,
    1118      *    then links and then images.
    1119      *    @param string $label        Visible text or alt text.
    1120      *    @return string/boolean      Raw page or false.
    1121      *    @access public
    1122      */
    1123     function click($label) {
     1195     * Clicks a visible text item. Will first try buttons, then links and then images.
     1196     *
     1197     * @param string $label        Visible text or alt text.
     1198     *
     1199     * @return string/boolean      Raw page or false.
     1200     */
     1201    public function click($label)
     1202    {
    11241203        $raw = $this->clickSubmit($label);
    11251204        if (! $raw) {
     
    11291208            $raw = $this->clickImage($label);
    11301209        }
     1210
    11311211        return $raw;
    11321212    }
    11331213
    11341214    /**
    1135      *    Tests to see if a click target exists.
    1136      *    @param string $label    Visible text or alt text.
    1137      *    @return boolean         True if target present.
    1138      *    @access public
    1139      */
    1140     function isClickable($label) {
     1215     * Tests to see if a click target exists.
     1216     *
     1217     * @param string $label    Visible text or alt text.
     1218     *
     1219     * @return bool         True if target present.
     1220     */
     1221    public function isClickable($label)
     1222    {
    11411223        return $this->isSubmit($label) || ($this->getLink($label) !== false) || $this->isImage($label);
    11421224    }
    11431225}
    1144 ?>
  • _core_/tests/simpletest/collector.php

    r80772 r100149  
    55 *
    66 * @author Travis Swicegood <development@domain51.com>
    7  * @package SimpleTest
    8  * @subpackage UnitTester
    9  * @version $Id: collector.php 2011 2011-04-29 08:22:48Z pp11 $
    107 */
    118
     
    1411 *
    1512 * @see collect(), GroupTest::collect()
    16  * @package SimpleTest
    17  * @subpackage UnitTester
    1813 */
    19 class SimpleCollector {
    20 
     14class SimpleCollector
     15{
    2116    /**
    2217     * Strips off any kind of slash at the end so as to normalise the path.
    23      * @param string $path    Path to normalise.
    24      * @return string         Path without trailing slash.
     18     *
     19     * @param string $path Path to normalise.
     20     *
     21     * @return string Path without trailing slash.
    2522     */
    26     protected function removeTrailingSlash($path) {
     23    protected function removeTrailingSlash($path)
     24    {
    2725        if (substr($path, -1) == DIRECTORY_SEPARATOR) {
    2826            return substr($path, 0, -1);
     
    3634    /**
    3735     * Scans the directory and adds what it can.
    38      * @param object $test    Group test with {@link GroupTest::addTestFile()} method.
    39      * @param string $path    Directory to scan.
     36     *
     37     * @param object $test Group test with {@link GroupTest::addFile)} method.
     38     * @param string $path Directory to scan.
     39     *
    4040     * @see _attemptToAdd()
    4141     */
    42     function collect(&$test, $path) {
     42    public function collect(&$test, $path)
     43    {
    4344        $path = $this->removeTrailingSlash($path);
    4445        if ($handle = opendir($path)) {
     
    5556    /**
    5657     * This method determines what should be done with a given file and adds
    57      * it via {@link GroupTest::addTestFile()} if necessary.
     58     * it via {@link GroupTest::addFile)} if necessary.
    5859     *
    5960     * This method should be overriden to provide custom matching criteria,
     
    6162     * {@link SimplePatternCollector::_handle()}.
    6263     *
    63      * @param object $test      Group test with {@link GroupTest::addTestFile()} method.
    64      * @param string $filename  A filename as generated by {@link collect()}
     64     * @param object $test     Group test with {@link GroupTest::addFile)} method.
     65     * @param string $filename A filename as generated by {@link collect()}
     66     *
    6567     * @see collect()
    66      * @access protected
    6768     */
    68     protected function handle(&$test, $file) {
     69    protected function handle(&$test, $file)
     70    {
    6971        if (is_dir($file)) {
    7072            return;
     
    7476
    7577    /**
    76      *  Tests for hidden files so as to skip them. Currently
    77      *  only tests for Unix hidden files.
    78      *  @param string $filename        Plain filename.
    79      *  @return boolean                True if hidden file.
    80      *  @access private
     78     * Tests for hidden files so as to skip them.
     79     * Currently only tests for Unix hidden files.
     80     *
     81     * @param string $filename        Plain filename.
     82     *
     83     * @return bool                True if hidden file.
    8184     */
    82     protected function isHidden($filename) {
     85    protected function isHidden($filename)
     86    {
    8387        return strncmp($filename, '.', 1) == 0;
    8488    }
     
    8690
    8791/**
    88  * An extension to {@link SimpleCollector} that only adds files matching a
    89  * given pattern.
     92 * An extension to {@link SimpleCollector} that only adds files matching a given pattern.
    9093 *
    91  * @package SimpleTest
    92  * @subpackage UnitTester
     94 * See {@link http://php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE}
     95 * for documentation of valid patterns.
     96 *
    9397 * @see SimpleCollector
    9498 */
    95 class SimplePatternCollector extends SimpleCollector {
     99class SimplePatternCollector extends SimpleCollector
     100{
    96101    private $pattern;
    97102
    98103    /**
    99      *
    100      * @param string $pattern   Perl compatible regex to test name against
    101      *  See {@link http://us4.php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE}
    102      *  for full documentation of valid pattern.s
     104     * @param string $pattern Perl compatible regex to test name against
    103105     */
    104     function __construct($pattern = '/php$/i') {
     106    public function __construct($pattern = '/php$/i')
     107    {
    105108        $this->pattern = $pattern;
    106109    }
     
    110113     *
    111114     * @see SimpleCollector::_handle()
    112      * @param object $test    Group test with {@link GroupTest::addTestFile()} method.
    113      * @param string $path    Directory to scan.
    114      * @access protected
     115     *
     116     * @param object $test Group test with {@link GroupTest::addFile)} method.
     117     * @param string $path Directory to scan.
    115118     */
    116     protected function handle(&$test, $filename) {
     119    protected function handle(&$test, $filename)
     120    {
    117121        if (preg_match($this->pattern, $filename)) {
    118122            parent::handle($test, $filename);
     
    120124    }
    121125}
    122 ?>
  • _core_/tests/simpletest/compatibility.php

    r80772 r100149  
    11<?php
    22/**
    3  *  base include file for SimpleTest
    4  *  @package    SimpleTest
    5  *  @version    $Id: compatibility.php 1900 2009-07-29 11:44:37Z lastcraft $
     3 * Static methods for compatibility between different PHP versions.
    64 */
    7 
    8 /**
    9  *  Static methods for compatibility between different
    10  *  PHP versions.
    11  *  @package    SimpleTest
    12  */
    13 class SimpleTestCompatibility {
    14 
     5class SimpleTestCompatibility
     6{
    157    /**
    16      *    Creates a copy whether in PHP5 or PHP4.
    17      *    @param object $object     Thing to copy.
    18      *    @return object            A copy.
    19      *    @access public
     8     * Recursive type test.
     9     *
     10     * @param mixed $first    Test subject.
     11     * @param mixed $second   Comparison object.
     12     *
     13     * @return bool        True if same type.
    2014     */
    21     static function copy($object) {
    22         if (version_compare(phpversion(), '5') >= 0) {
    23             eval('$copy = clone $object;');
    24             return $copy;
    25         }
    26         return $object;
    27     }
    28 
    29     /**
    30      *    Identity test. Drops back to equality + types for PHP5
    31      *    objects as the === operator counts as the
    32      *    stronger reference constraint.
    33      *    @param mixed $first    Test subject.
    34      *    @param mixed $second   Comparison object.
    35      *    @return boolean        True if identical.
    36      *    @access public
    37      */
    38     static function isIdentical($first, $second) {
    39         if (version_compare(phpversion(), '5') >= 0) {
    40             return SimpleTestCompatibility::isIdenticalType($first, $second);
    41         }
    42         if ($first != $second) {
    43             return false;
    44         }
    45         return ($first === $second);
    46     }
    47 
    48     /**
    49      *    Recursive type test.
    50      *    @param mixed $first    Test subject.
    51      *    @param mixed $second   Comparison object.
    52      *    @return boolean        True if same type.
    53      *    @access private
    54      */
    55     protected static function isIdenticalType($first, $second) {
     15    public static function isIdentical($first, $second)
     16    {
    5617        if (gettype($first) != gettype($second)) {
    5718            return false;
     
    6122                return false;
    6223            }
    63             return SimpleTestCompatibility::isArrayOfIdenticalTypes(
     24
     25            return self::isArrayOfIdenticalTypes(
    6426                    (array) $first,
    6527                    (array) $second);
    6628        }
    6729        if (is_array($first) && is_array($second)) {
    68             return SimpleTestCompatibility::isArrayOfIdenticalTypes($first, $second);
     30            return self::isArrayOfIdenticalTypes($first, $second);
    6931        }
    7032        if ($first !== $second) {
    7133            return false;
    7234        }
     35
    7336        return true;
    7437    }
    7538
    7639    /**
    77      *    Recursive type test for each element of an array.
    78      *    @param mixed $first    Test subject.
    79      *    @param mixed $second   Comparison object.
    80      *    @return boolean        True if identical.
    81      *    @access private
     40     * Recursive type test for each element of an array.
     41     *
     42     * @param mixed $first    Test subject.
     43     * @param mixed $second   Comparison object.
     44     *
     45     * @return bool        True if identical.
    8246     */
    83     protected static function isArrayOfIdenticalTypes($first, $second) {
     47    protected static function isArrayOfIdenticalTypes($first, $second)
     48    {
    8449        if (array_keys($first) != array_keys($second)) {
    8550            return false;
    8651        }
    8752        foreach (array_keys($first) as $key) {
    88             $is_identical = SimpleTestCompatibility::isIdenticalType(
     53            $is_identical = self::isIdentical(
    8954                    $first[$key],
    9055                    $second[$key]);
     
    9358            }
    9459        }
     60
    9561        return true;
    9662    }
    9763
    9864    /**
    99      *    Test for two variables being aliases.
    100      *    @param mixed $first    Test subject.
    101      *    @param mixed $second   Comparison object.
    102      *    @return boolean        True if same.
    103      *    @access public
     65     * Test for two variables being aliases.
     66     *
     67     * @param mixed $first    Test subject.
     68     * @param mixed $second   Comparison object.
     69     *
     70     * @return bool        True if same.
    10471     */
    105     static function isReference(&$first, &$second) {
    106         if (version_compare(phpversion(), '5', '>=') && is_object($first)) {
     72    public static function isReference(&$first, &$second)
     73    {
     74        if (is_object($first)) {
    10775            return ($first === $second);
    10876        }
    10977        if (is_object($first) && is_object($second)) {
    110             $id = uniqid("test");
     78            $id         = uniqid(mt_rand());
    11179            $first->$id = true;
    112             $is_ref = isset($second->$id);
     80            $is_ref     = isset($second->$id);
    11381            unset($first->$id);
     82
    11483            return $is_ref;
    11584        }
    116         $temp = $first;
    117         $first = uniqid("test");
     85        $temp   = $first;
     86        $first  = uniqid(mt_rand());
    11887        $is_ref = ($first === $second);
    119         $first = $temp;
     88        $first  = $temp;
     89
    12090        return $is_ref;
    12191    }
    122 
    123     /**
    124      *    Test to see if an object is a member of a
    125      *    class hiearchy.
    126      *    @param object $object    Object to test.
    127      *    @param string $class     Root name of hiearchy.
    128      *    @return boolean         True if class in hiearchy.
    129      *    @access public
    130      */
    131     static function isA($object, $class) {
    132         if (version_compare(phpversion(), '5') >= 0) {
    133             if (! class_exists($class, false)) {
    134                 if (function_exists('interface_exists')) {
    135                     if (! interface_exists($class, false))  {
    136                         return false;
    137                     }
    138                 }
    139             }
    140             eval("\$is_a = \$object instanceof $class;");
    141             return $is_a;
    142         }
    143         if (function_exists('is_a')) {
    144             return is_a($object, $class);
    145         }
    146         return ((strtolower($class) == get_class($object))
    147                 or (is_subclass_of($object, $class)));
    148     }
    149 
    150     /**
    151      *    Sets a socket timeout for each chunk.
    152      *    @param resource $handle    Socket handle.
    153      *    @param integer $timeout    Limit in seconds.
    154      *    @access public
    155      */
    156     static function setTimeout($handle, $timeout) {
    157         if (function_exists('stream_set_timeout')) {
    158             stream_set_timeout($handle, $timeout, 0);
    159         } elseif (function_exists('socket_set_timeout')) {
    160             socket_set_timeout($handle, $timeout, 0);
    161         } elseif (function_exists('set_socket_timeout')) {
    162             set_socket_timeout($handle, $timeout, 0);
    163         }
    164     }
    16592}
    166 ?>
  • _core_/tests/simpletest/cookies.php

    r80772 r100149  
    11<?php
     2
     3require_once dirname(__FILE__) . '/url.php';
     4
    25/**
    3  *  Base include file for SimpleTest
    4  *  @package    SimpleTest
    5  *  @subpackage WebTester
    6  *  @version    $Id: cookies.php 2011 2011-04-29 08:22:48Z pp11 $
     6 * Cookie data holder.
     7 * Cookie rules are full of pretty arbitary stuff
     8 * I have used: http://www.cookiecentral.com/faq/
    79 */
    8 
    9 /**#@+
    10  *  include other SimpleTest class files
    11  */
    12 require_once(dirname(__FILE__) . '/url.php');
    13 /**#@-*/
    14 
    15 /**
    16  *    Cookie data holder. Cookie rules are full of pretty
    17  *    arbitary stuff. I have used...
    18  *    http://wp.netscape.com/newsref/std/cookie_spec.html
    19  *    http://www.cookiecentral.com/faq/
    20  *    @package SimpleTest
    21  *    @subpackage WebTester
    22  */
    23 class SimpleCookie {
     10class SimpleCookie
     11{
     12    private $expiry;
    2413    private $host;
     14    private $is_secure;
    2515    private $name;
     16    private $path;
    2617    private $value;
    27     private $path;
    28     private $expiry;
    29     private $is_secure;
    30 
    31     /**
    32      *    Constructor. Sets the stored values.
    33      *    @param string $name            Cookie key.
    34      *    @param string $value           Value of cookie.
    35      *    @param string $path            Cookie path if not host wide.
    36      *    @param string $expiry          Expiry date as string.
    37      *    @param boolean $is_secure      Currently ignored.
    38      */
    39     function __construct($name, $value = false, $path = false, $expiry = false, $is_secure = false) {
    40         $this->host = false;
    41         $this->name = $name;
    42         $this->value = $value;
    43         $this->path = ($path ? $this->fixPath($path) : "/");
     18
     19    /**
     20     * Constructor. Sets the stored values.
     21     *
     22     * @param string $name      Cookie key.
     23     * @param string $value     Value of cookie.
     24     * @param string $path      Cookie path if not host wide.
     25     * @param string $expiry    Expiry date as string.
     26     * @param bool   $is_secure Currently ignored.
     27     */
     28    public function __construct($name, $value = false, $path = false, $expiry = false, $is_secure = false)
     29    {
     30        $this->host   = false;
     31        $this->name   = $name;
     32        $this->value  = $value;
     33        $this->path   = ($path ? $this->fixPath($path) : '/');
    4434        $this->expiry = false;
    4535        if (is_string($expiry)) {
     
    5242
    5343    /**
    54      *    Sets the host. The cookie rules determine
    55      *    that the first two parts are taken for
    56      *    certain TLDs and three for others. If the
    57      *    new host does not match these rules then the
    58      *    call will fail.
    59      *    @param string $host       New hostname.
    60      *    @return boolean          True if hostname is valid.
    61      *    @access public
    62      */
    63     function setHost($host) {
     44     * Sets the host. The cookie rules determine that
     45     * the first two parts are taken for certain TLDs and three for others.
     46     * If the new host does not match these rules then the call will fail.
     47     *
     48     * @param string $host New hostname.
     49     *
     50     * @return bool True if hostname is valid.
     51     */
     52    public function setHost($host)
     53    {
    6454        if ($host = $this->truncateHost($host)) {
    6555            $this->host = $host;
     56
    6657            return true;
    6758        }
     59
    6860        return false;
    6961    }
    7062
    7163    /**
    72      *    Accessor for the truncated host to which this
    73      *    cookie applies.
    74      *    @return string      Truncated hostname.
    75      *    @access public
    76      */
    77     function getHost() {
     64     * Accessor for the truncated host to which this cookie applies.
     65     *
     66     * @return string Truncated hostname.
     67     */
     68    public function getHost()
     69    {
    7870        return $this->host;
    7971    }
    8072
    8173    /**
    82      *    Test for a cookie being valid for a host name.
    83      *    @param string $host    Host to test against.
    84      *    @return boolean        True if the cookie would be valid
    85      *                           here.
    86      */
    87     function isValidHost($host) {
     74     * Test for a cookie being valid for a host name.
     75     *
     76     * @param string $host Host to test against.
     77     *
     78     * @return bool True if the cookie would be valid here.
     79     */
     80    public function isValidHost($host)
     81    {
    8882        return ($this->truncateHost($host) === $this->getHost());
    8983    }
    9084
    9185    /**
    92      *    Extracts just the domain part that determines a
    93      *    cookie's host validity.
    94      *    @param string $host    Host name to truncate.
    95      *    @return string        Domain or false on a bad host.
    96      *    @access private
    97      */
    98     protected function truncateHost($host) {
     86     * Extracts just the domain part that determines a cookie's host validity.
     87     *
     88     * @param string $host Host name to truncate.
     89     *
     90     * @return string Domain or false on a bad host.
     91     */
     92    protected function truncateHost($host)
     93    {
    9994        $tlds = SimpleUrl::getAllTopLevelDomains();
    10095        if (preg_match('/[a-z\-]+\.(' . $tlds . ')$/i', $host, $matches)) {
     
    10398            return $matches[0];
    10499        }
     100
    105101        return false;
    106102    }
    107103
    108104    /**
    109      *    Accessor for name.
    110      *    @return string       Cookie key.
    111      *    @access public
    112      */
    113     function getName() {
     105     * Accessor for name.
     106     *
     107     * @return string Cookie key.
     108     */
     109    public function getName()
     110    {
    114111        return $this->name;
    115112    }
    116113
    117114    /**
    118      *    Accessor for value. A deleted cookie will
    119      *    have an empty string for this.
    120      *    @return string      Cookie value.
    121      *    @access public
    122      */
    123     function getValue() {
     115     * Accessor for value. A deleted cookie will have an empty string for this.
     116     *
     117     * @return string Cookie value.
     118     */
     119    public function getValue()
     120    {
    124121        return $this->value;
    125122    }
    126123
    127124    /**
    128      *    Accessor for path.
    129      *    @return string       Valid cookie path.
    130      *    @access public
    131      */
    132     function getPath() {
     125     * Accessor for path.
     126     *
     127     * @return string Valid cookie path.
     128     */
     129    public function getPath()
     130    {
    133131        return $this->path;
    134132    }
    135133
    136134    /**
    137      *    Tests a path to see if the cookie applies
    138      *    there. The test path must be longer or
    139      *    equal to the cookie path.
    140      *    @param string $path       Path to test against.
    141      *    @return boolean           True if cookie valid here.
    142      *    @access public
    143      */
    144     function isValidPath($path) {
    145         return (strncmp(
    146                 $this->fixPath($path),
    147                 $this->getPath(),
    148                 strlen($this->getPath())) == 0);
    149     }
    150 
    151     /**
    152      *    Accessor for expiry.
    153      *    @return string       Expiry string.
    154      *    @access public
    155      */
    156     function getExpiry() {
     135     * Tests a path to see if the cookie applies there.
     136     * The test path must be longer or equal to the cookie path.
     137     *
     138     * @param string $path Path to test against.
     139     *
     140     * @return bool True if cookie valid here.
     141     */
     142    public function isValidPath($path)
     143    {
     144        return (strncmp($this->fixPath($path), $this->getPath(), strlen($this->getPath())) == 0);
     145    }
     146
     147    /**
     148     * Accessor for expiry.
     149     *
     150     * @return string Expiry string.
     151     */
     152    public function getExpiry()
     153    {
    157154        if (! $this->expiry) {
    158155            return false;
    159156        }
    160         return gmdate("D, d M Y H:i:s", $this->expiry) . " GMT";
    161     }
    162 
    163     /**
    164      *    Test to see if cookie is expired against
    165      *    the cookie format time or timestamp.
    166      *    Will give true for a session cookie.
    167      *    @param integer/string $now  Time to test against. Result
    168      *                                will be false if this time
    169      *                                is later than the cookie expiry.
    170      *                                Can be either a timestamp integer
    171      *                                or a cookie format date.
    172      *    @access public
    173      */
    174     function isExpired($now) {
     157
     158        return gmdate('D, d M Y H:i:s', $this->expiry) . ' GMT';
     159    }
     160
     161    /**
     162     * Test to see if cookie is expired against the cookie format time or timestamp.
     163     * Will give true for a session cookie.
     164     *
     165     * @param integer/string $now Time to test against. Result will be false if this time
     166     *                            is later than the cookie expiry. Can be either a timestamp
     167     *                            integer or a cookie format date.
     168     */
     169    public function isExpired($now)
     170    {
    175171        if (! $this->expiry) {
    176172            return true;
     
    179175            $now = strtotime($now);
    180176        }
     177
    181178        return ($this->expiry < $now);
    182179    }
    183180
    184181    /**
    185      *    Ages the cookie by the specified number of
    186      *    seconds.
    187      *    @param integer $interval  In seconds.
    188      *    @public
    189      */
    190     function agePrematurely($interval) {
     182     * Ages the cookie by the specified number of seconds.
     183     *
     184     * @param int $interval In seconds.
     185     */
     186    public function agePrematurely($interval)
     187    {
    191188        if ($this->expiry) {
    192189            $this->expiry -= $interval;
     
    195192
    196193    /**
    197      *    Accessor for the secure flag.
    198      *    @return boolean       True if cookie needs SSL.
    199      *    @access public
    200      */
    201     function isSecure() {
     194     * Accessor for the secure flag.
     195     *
     196     * @return bool True if cookie needs SSL.
     197     */
     198    public function isSecure()
     199    {
    202200        return $this->is_secure;
    203201    }
    204202
    205203    /**
    206      *    Adds a trailing and leading slash to the path
    207      *    if missing.
    208      *    @param string $path            Path to fix.
    209      *    @access private
    210      */
    211     protected function fixPath($path) {
     204     * Adds a trailing and leading slash to the path if missing.
     205     *
     206     * @param string $path Path to fix.
     207     */
     208    protected function fixPath($path)
     209    {
    212210        if (substr($path, 0, 1) != '/') {
    213211            $path = '/' . $path;
     
    216214            $path .= '/';
    217215        }
     216
    218217        return $path;
    219218    }
     
    221220
    222221/**
    223  *    Repository for cookies. This stuff is a
    224  *    tiny bit browser dependent.
    225  *    @package SimpleTest
    226  *    @subpackage WebTester
     222 * Repository for cookies. This stuff is a tiny bit browser dependent.
    227223 */
    228 class SimpleCookieJar {
     224class SimpleCookieJar
     225{
    229226    private $cookies;
    230227
    231228    /**
    232      *    Constructor. Jar starts empty.
    233      *    @access public
    234      */
    235     function __construct() {
     229     * Constructor. Jar starts empty.
     230     */
     231    public function __construct()
     232    {
    236233        $this->cookies = array();
    237234    }
    238235
    239236    /**
    240      *    Removes expired and temporary cookies as if
    241      *    the browser was closed and re-opened.
    242      *    @param string/integer $now  Time to test expiry against.
    243      *    @access public
    244      */
    245     function restartSession($date = false) {
     237     * Removes expired and temporary cookies as if the browser was closed and re-opened.
     238     *
     239     * @param string/integer $date Time to test expiry against.
     240     */
     241    public function restartSession($date = false)
     242    {
    246243        $surviving_cookies = array();
    247244        for ($i = 0; $i < count($this->cookies); $i++) {
     
    261258
    262259    /**
    263      *    Ages all cookies in the cookie jar.
    264      *    @param integer $interval     The old session is moved
    265      *                                 into the past by this number
    266      *                                 of seconds. Cookies now over
    267      *                                 age will be removed.
    268      *    @access public
    269      */
    270     function agePrematurely($interval) {
     260     * Ages all cookies in the cookie jar.
     261     *
     262     * @param int $interval The old session is moved into the past by this number
     263     *                      of seconds. Cookies now over age will be removed.
     264     */
     265    public function agePrematurely($interval)
     266    {
    271267        for ($i = 0; $i < count($this->cookies); $i++) {
    272268            $this->cookies[$i]->agePrematurely($interval);
     
    275271
    276272    /**
    277      *    Sets an additional cookie. If a cookie has
    278      *    the same name and path it is replaced.
    279      *    @param string $name       Cookie key.
    280      *    @param string $value      Value of cookie.
    281      *    @param string $host       Host upon which the cookie is valid.
    282      *    @param string $path       Cookie path if not host wide.
    283      *    @param string $expiry    Expiry date.
    284      *    @access public
    285      */
    286     function setCookie($name, $value, $host = false, $path = '/', $expiry = false) {
     273     * Sets an additional cookie. If a cookie has the same name and path it is replaced.
     274     *
     275     * @param string $name   Cookie key.
     276     * @param string $value  Value of cookie.
     277     * @param string $host   Host upon which the cookie is valid.
     278     * @param string $path   Cookie path if not host wide.
     279     * @param string $expiry Expiry date.
     280     */
     281    public function setCookie($name, $value, $host = false, $path = '/', $expiry = false)
     282    {
    287283        $cookie = new SimpleCookie($name, $value, $path, $expiry);
    288284        if ($host) {
     
    293289
    294290    /**
    295      *    Finds a matching cookie to write over or the
    296      *    first empty slot if none.
    297      *    @param SimpleCookie $cookie    Cookie to write into jar.
    298      *    @return integer                Available slot.
    299      *    @access private
    300      */
    301     protected function findFirstMatch($cookie) {
     291     * Finds a matching cookie to write over or the first empty slot if none.
     292     *
     293     * @param SimpleCookie $cookie Cookie to write into jar.
     294     *
     295     * @return int Available slot.
     296     */
     297    protected function findFirstMatch($cookie)
     298    {
    302299        for ($i = 0; $i < count($this->cookies); $i++) {
    303300            $is_match = $this->isMatch(
     
    310307            }
    311308        }
     309
    312310        return count($this->cookies);
    313311    }
    314312
    315313    /**
    316      *    Reads the most specific cookie value from the
    317      *    browser cookies. Looks for the longest path that
    318      *    matches.
    319      *    @param string $host        Host to search.
    320      *    @param string $path        Applicable path.
    321      *    @param string $name        Name of cookie to read.
    322      *    @return string             False if not present, else the
    323      *                               value as a string.
    324      *    @access public
    325      */
    326     function getCookieValue($host, $path, $name) {
     314     * Reads the most specific cookie value from the browser cookies.
     315     * Looks for the longest path that matches.
     316     *
     317     * @param string $host Host to search.
     318     * @param string $path Applicable path.
     319     * @param string $name Name of cookie to read.
     320     *
     321     * @return string False if not present, else the value as a string.
     322     */
     323    public function getCookieValue($host, $path, $name)
     324    {
    327325        $longest_path = '';
    328326        foreach ($this->cookies as $cookie) {
    329327            if ($this->isMatch($cookie, $host, $path, $name)) {
    330328                if (strlen($cookie->getPath()) > strlen($longest_path)) {
    331                     $value = $cookie->getValue();
     329                    $value        = $cookie->getValue();
    332330                    $longest_path = $cookie->getPath();
    333331                }
    334332            }
    335333        }
     334
    336335        return (isset($value) ? $value : false);
    337336    }
    338337
    339338    /**
    340      *    Tests cookie for matching against search
    341      *    criteria.
    342      *    @param SimpleTest $cookie    Cookie to test.
    343      *    @param string $host          Host must match.
    344      *    @param string $path          Cookie path must be shorter than
    345      *                                 this path.
    346      *    @param string $name          Name must match.
    347      *    @return boolean              True if matched.
    348      *    @access private
    349      */
    350     protected function isMatch($cookie, $host, $path, $name) {
     339     * Tests cookie for matching against search criteria.
     340     *
     341     * @param SimpleTest $cookie Cookie to test.
     342     * @param string     $host   Host must match.
     343     * @param string     $path   Cookie path must be shorter than this path.
     344     * @param string     $name   Name must match.
     345     *
     346     * @return bool True if matched.
     347     */
     348    protected function isMatch($cookie, $host, $path, $name)
     349    {
    351350        if ($cookie->getName() != $name) {
    352351            return false;
     
    358357            return false;
    359358        }
     359
    360360        return true;
    361361    }
    362362
    363363    /**
    364      *    Uses a URL to sift relevant cookies by host and
    365      *    path. Results are list of strings of form "name=value".
    366      *    @param SimpleUrl $url       Url to select by.
    367      *    @return array               Valid name and value pairs.
    368      *    @access public
    369      */
    370     function selectAsPairs($url) {
     364     * Uses a URL to sift relevant cookies by host and path.
     365     * Results are list of strings of form "name=value".
     366     *
     367     * @param SimpleUrl $url Url to select by.
     368     *
     369     * @return array Valid name and value pairs.
     370     */
     371    public function selectAsPairs($url)
     372    {
    371373        $pairs = array();
    372374        foreach ($this->cookies as $cookie) {
     
    375377            }
    376378        }
     379
    377380        return $pairs;
    378381    }
    379382}
    380 ?>
  • _core_/tests/simpletest/default_reporter.php

    r80772 r100149  
    11<?php
     2
     3require_once dirname(__FILE__) . '/simpletest.php';
     4require_once dirname(__FILE__) . '/scorer.php';
     5require_once dirname(__FILE__) . '/reporter.php';
     6require_once dirname(__FILE__) . '/xml.php';
     7
    28/**
    3  *  Optional include file for SimpleTest
    4  *  @package    SimpleTest
    5  *  @subpackage UnitTester
    6  *  @version    $Id: default_reporter.php 2011 2011-04-29 08:22:48Z pp11 $
     9 * Parser for command line arguments.
     10 * Extracts the a specific test to run and engages XML reporting when necessary.
    711 */
    8 
    9 /**#@+
    10  *  include other SimpleTest class files
    11  */
    12 require_once(dirname(__FILE__) . '/simpletest.php');
    13 require_once(dirname(__FILE__) . '/scorer.php');
    14 require_once(dirname(__FILE__) . '/reporter.php');
    15 require_once(dirname(__FILE__) . '/xml.php');
    16 /**#@-*/
    17 
    18 /**
    19  *    Parser for command line arguments. Extracts
    20  *    the a specific test to run and engages XML
    21  *    reporting when necessary.
    22  *    @package SimpleTest
    23  *    @subpackage UnitTester
    24  */
    25 class SimpleCommandLineParser {
     12class SimpleCommandLineParser
     13{
    2614    private $to_property = array(
    2715            'case' => 'case', 'c' => 'case',
    2816            'test' => 'test', 't' => 'test',
    2917    );
    30     private $case = '';
    31     private $test = '';
    32     private $xml = false;
    33     private $help = false;
    34     private $no_skips = false;
    35 
    36     /**
    37      *    Parses raw command line arguments into object properties.
    38      *    @param string $arguments        Raw commend line arguments.
    39      */
    40     function __construct($arguments) {
     18    private $case           = '';
     19    private $test           = '';
     20    private $xml            = false;
     21    private $junit          = false;
     22    private $help           = false;
     23    private $no_skips       = false;   
     24    private $excludes       = array();
     25    private $doCodeCoverage = false;
     26
     27    /**
     28     * Parses raw command line arguments into object properties.
     29     *
     30     * @param string $arguments        Raw commend line arguments.
     31     */
     32    public function __construct($arguments)
     33    {
    4134        if (! is_array($arguments)) {
    4235            return;
     
    4437        foreach ($arguments as $i => $argument) {
    4538            if (preg_match('/^--?(test|case|t|c)=(.+)$/', $argument, $matches)) {
    46                 $property = $this->to_property[$matches[1]];
     39                $property        = $this->to_property[$matches[1]];
    4740                $this->$property = $matches[2];
    4841            } elseif (preg_match('/^--?(test|case|t|c)$/', $argument, $matches)) {
     
    5144                    $this->$property = $arguments[$i + 1];
    5245                }
     46            } elseif (preg_match('/^--?(cx)=(.+)$/', $argument, $matches)) {
     47//                 $property = $this->to_property[$matches[1]];
     48                $this->excludes[] = $matches[2];
     49            } elseif (preg_match('/^--?(cx)$/', $argument, $matches)) {
     50//                 $property = $this->to_property[$matches[1]];
     51                if (isset($arguments[$i + 1])) {
     52                    $this->excludes[] = $arguments[$i + 1];
     53                }
    5354            } elseif (preg_match('/^--?(xml|x)$/', $argument)) {
    5455                $this->xml = true;
     56            } elseif (preg_match('/^--?(junit|j)$/', $argument)) {
     57                $this->junit = true;
     58            } elseif (preg_match('/^--?(codecoverage|cc)$/', $argument)) {
     59                $this->doCodeCoverage = true;
    5560            } elseif (preg_match('/^--?(no-skip|no-skips|s)$/', $argument)) {
    5661                $this->no_skips = true;
     
    6267
    6368    /**
    64      *    Run only this test.
    65      *    @return string        Test name to run.
    66      */
    67     function getTest() {
     69     * Run only this test.
     70     *
     71     * @return string        Test name to run.
     72     */
     73    public function getTest()
     74    {
    6875        return $this->test;
    6976    }
    7077
    7178    /**
    72      *    Run only this test suite.
    73      *    @return string        Test class name to run.
    74      */
    75     function getTestCase() {
     79     * Run only this test suite.
     80     *
     81     * @return string        Test class name to run.
     82     */
     83    public function getTestCase()
     84    {
    7685        return $this->case;
    7786    }
    7887
    7988    /**
    80      *    Output should be XML or not.
    81      *    @return boolean        True if XML desired.
    82      */
    83     function isXml() {
     89     * Output should be XML or not.
     90     *
     91     * @return bool        True if XML desired.
     92     */
     93    public function isXml()
     94    {
    8495        return $this->xml;
    8596    }
    8697
    8798    /**
    88      *    Output should suppress skip messages.
    89      *    @return boolean        True for no skips.
    90      */
    91     function noSkips() {
     99     * Output should be JUnit or not.
     100     *
     101     * @return boolean True if JUnit desired.
     102     */
     103    public function isJUnit()
     104    {
     105        return $this->junit;
     106    }
     107
     108    /**
     109     *    Should code coverage be run or not.
     110     *    @return boolean        True if code coverage should be run.
     111     */
     112    public function doCodeCoverage()
     113    {
     114        return $this->doCodeCoverage;
     115    }
     116
     117    /**
     118     *    Array of excluded folders.
     119     *    @return array        Array of strings to exclude from code coverage.
     120     */
     121    public function getExcludes()
     122    {
     123        return $this->excludes;
     124    }
     125
     126    /**
     127     * Output should suppress skip messages.
     128     *
     129     * @return bool        True for no skips.
     130     */
     131    public function noSkips()
     132    {
    92133        return $this->no_skips;
    93134    }
    94135
    95136    /**
    96      *    Output should be a help message. Disabled during XML mode.
    97      *    @return boolean        True if help message desired.
    98      */
    99     function help() {
    100         return $this->help && ! $this->xml;
    101     }
    102 
    103     /**
    104      *    Returns plain-text help message for command line runner.
    105      *    @return string         String help message
    106      */
    107     function getHelpText() {
     137     * Output should be a help message. Disabled during XML mode.
     138     *
     139     * @return bool        True if help message desired.
     140     */
     141    public function help()
     142    {
     143        return $this->help && ! ($this->xml || $this->junit);
     144    }
     145
     146    /**
     147     * Returns plain-text help message for command line runner.
     148     *
     149     * @return string         String help message
     150     */
     151    public function getHelpText()
     152    {
    108153        return <<<HELP
    109154SimpleTest command line default reporter (autorun)
     
    114159    -s              Suppress skip messages
    115160    -x              Return test results in XML
     161    -j              Return test results in JUnit format
     162    -cc             Generate code coverage reports
     163    -cx             Code coverage exclude folder (may have multiple)
    116164    -h              Display this help message
    117165
    118166HELP;
    119167    }
    120 
    121168}
    122169
    123170/**
    124  *    The default reporter used by SimpleTest's autorun
    125  *    feature. The actual reporters used are dependency
    126  *    injected and can be overridden.
    127  *    @package SimpleTest
    128  *    @subpackage UnitTester
     171 * The default reporter used by SimpleTest's autorun feature.
     172 * The actual reporters used are dependency injected and can be overridden.
    129173 */
    130 class DefaultReporter extends SimpleReporterDecorator {
    131 
    132     /**
    133      *  Assembles the appropriate reporter for the environment.
    134      */
    135     function __construct() {
     174class DefaultReporter extends SimpleReporterDecorator
     175{
     176    public $doCodeCoverage = false;
     177    public $excludes;
     178
     179    /**
     180     * Assembles the appropriate reporter for the environment.
     181     */
     182    public function __construct()
     183    {
    136184        if (SimpleReporter::inCli()) {
    137             $parser = new SimpleCommandLineParser($_SERVER['argv']);
    138             $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter');
     185            $parser     = new SimpleCommandLineParser($_SERVER['argv']);
     186            $this->doCodeCoverage = $parser->doCodeCoverage();
     187            $this->excludes = $parser->getExcludes();
     188            if ($parser->isXml()) {
     189                $interfaces = array('XmlReporter');
     190            } else if ($parser->isJUnit()) {
     191                $interfaces = array('JUnitXmlReporter');
     192            } else {
     193                $interfaces = array('TextReporter');
     194            }
    139195            if ($parser->help()) {
    140                 // I'm not sure if we should do the echo'ing here -- ezyang
    141196                echo $parser->getHelpText();
    142197                exit(1);
    143198            }
     199
    144200            $reporter = new SelectiveReporter(
    145                     SimpleTest::preferred($interfaces),
    146                     $parser->getTestCase(),
    147                     $parser->getTest());
     201                SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest()
     202            );
     203
    148204            if ($parser->noSkips()) {
    149205                $reporter = new NoSkipsReporter($reporter);
     
    151207        } else {
    152208            $reporter = new SelectiveReporter(
    153                     SimpleTest::preferred('HtmlReporter'),
    154                     @$_GET['c'],
    155                     @$_GET['t']);
    156             if (@$_GET['skips'] == 'no' || @$_GET['show-skips'] == 'no') {
     209                    SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']);
     210            if (@$_GET['skips'] === 'no' || @$_GET['show-skips'] === 'no') {
    157211                $reporter = new NoSkipsReporter($reporter);
    158212            }
     
    161215    }
    162216}
    163 ?>
  • _core_/tests/simpletest/detached.php

    r80772 r100149  
    11<?php
    2 /**
    3  *  base include file for SimpleTest
    4  *  @package    SimpleTest
    5  *  @subpackage UnitTester
    6  *  @version    $Id: detached.php 1784 2008-04-26 13:07:14Z pp11 $
    7  */
    82
    9 /**#@+
    10  *  include other SimpleTest class files
    11  */
    12 require_once(dirname(__FILE__) . '/xml.php');
    13 require_once(dirname(__FILE__) . '/shell_tester.php');
    14 /**#@-*/
     3require_once dirname(__FILE__) . '/xml.php';
     4require_once dirname(__FILE__) . '/shell_tester.php';
    155
    166/**
    17  *    Runs an XML formated test in a separate process.
    18  *    @package SimpleTest
    19  *    @subpackage UnitTester
     7 * Runs an XML formated test in a separate process.
    208 */
    21 class DetachedTestCase {
     9class DetachedTestCase
     10{
    2211    private $command;
    2312    private $dry_command;
     
    2514
    2615    /**
    27      *    Sets the location of the remote test.
    28      *    @param string $command       Test script.
    29      *    @param string $dry_command   Script for dry run.
    30      *    @access public
     16     * Sets the location of the remote test.
     17     *
     18     * @param string $command       Test script.
     19     * @param string $dry_command   Script for dry run.
    3120     */
    32     function __construct($command, $dry_command = false) {
    33         $this->command = $command;
     21    public function __construct($command, $dry_command = false)
     22    {
     23        $this->command     = $command;
    3424        $this->dry_command = $dry_command ? $dry_command : $command;
    35         $this->size = false;
     25        $this->size        = false;
    3626    }
    3727
    3828    /**
    39      *    Accessor for the test name for subclasses.
    40      *    @return string       Name of the test.
    41      *    @access public
     29     * Accessor for the test name for subclasses.
     30     *
     31     * @return string       Name of the test.
    4232     */
    43     function getLabel() {
     33    public function getLabel()
     34    {
    4435        return $this->command;
    4536    }
    4637
    4738    /**
    48      *    Runs the top level test for this class. Currently
    49      *    reads the data as a single chunk. I'll fix this
    50      *    once I have added iteration to the browser.
    51      *    @param SimpleReporter $reporter    Target of test results.
    52      *    @returns boolean                   True if no failures.
    53      *    @access public
     39     * Runs the top level test for this class.
     40     * Currently reads the data as a single chunk.
     41     * I'll fix this once I have added iteration to the browser.
     42     *
     43     * @param SimpleReporter $reporter    Target of test results.
     44     *
     45     * @returns boolean                   True if no failures.
    5446     */
    55     function run(&$reporter) {
    56         $shell = &new SimpleShell();
     47    public function run(&$reporter)
     48    {
     49        $shell = new SimpleShell();
    5750        $shell->execute($this->command);
    58         $parser = &$this->createParser($reporter);
     51        $parser = $this->createParser($reporter);
    5952        if (! $parser->parse($shell->getOutput())) {
    6053            trigger_error('Cannot parse incoming XML from [' . $this->command . ']');
     54
    6155            return false;
    6256        }
     57
    6358        return true;
    6459    }
    6560
    6661    /**
    67      *    Accessor for the number of subtests.
    68      *    @return integer       Number of test cases.
    69      *    @access public
     62     * Accessor for the number of subtests.
     63     *
     64     * @return int       Number of test cases.
    7065     */
    71     function getSize() {
     66    public function getSize()
     67    {
    7268        if ($this->size === false) {
    73             $shell = &new SimpleShell();
     69            $shell = new SimpleShell();
    7470            $shell->execute($this->dry_command);
    75             $reporter = &new SimpleReporter();
    76             $parser = &$this->createParser($reporter);
     71            $reporter = new SimpleReporter();
     72            $parser   = $this->createParser($reporter);
    7773            if (! $parser->parse($shell->getOutput())) {
    7874                trigger_error('Cannot parse incoming XML from [' . $this->dry_command . ']');
     75
    7976                return false;
    8077            }
    8178            $this->size = $reporter->getTestCaseCount();
    8279        }
     80
    8381        return $this->size;
    8482    }
    8583
    8684    /**
    87      *    Creates the XML parser.
    88      *    @param SimpleReporter $reporter    Target of test results.
    89      *    @return SimpleTestXmlListener      XML reader.
    90      *    @access protected
     85     * Creates the XML parser.
     86     *
     87     * @param SimpleReporter $reporter    Target of test results.
     88     *
     89     * @return SimpleTestXmlListener      XML reader.
    9190     */
    92     protected function &createParser(&$reporter) {
     91    protected function createParser(&$reporter)
     92    {
    9393        return new SimpleTestXmlParser($reporter);
    9494    }
    9595}
    96 ?>
  • _core_/tests/simpletest/dumper.php

    r80772 r100149  
    11<?php
    2 /**
    3  *  base include file for SimpleTest
    4  *  @package    SimpleTest
    5  *  @subpackage UnitTester
    6  *  @version    $Id: dumper.php 1909 2009-07-29 15:58:11Z dgheath $
    7  */
     2
    83/**
    94 * does type matter
     
    149
    1510/**
    16  *    Displays variables as text and does diffs.
    17  *    @package  SimpleTest
    18  *    @subpackage   UnitTester
     11 * Displays variables as text and does diffs.
    1912 */
    20 class SimpleDumper {
    21 
    22     /**
    23      *    Renders a variable in a shorter form than print_r().
    24      *    @param mixed $value      Variable to render as a string.
    25      *    @return string           Human readable string form.
    26      *    @access public
    27      */
    28     function describeValue($value) {
     13class SimpleDumper
     14{
     15    /**
     16     * Renders a variable in a shorter form than print_r().
     17     *
     18     * @param mixed $value      Variable to render as a string.
     19     *
     20     * @return string           Human readable string form.
     21     */
     22    public function describeValue($value)
     23    {
    2924        $type = $this->getType($value);
    30         switch($type) {
    31             case "Null":
    32                 return "NULL";
    33             case "Boolean":
    34                 return "Boolean: " . ($value ? "true" : "false");
    35             case "Array":
    36                 return "Array: " . count($value) . " items";
    37             case "Object":
    38                 return "Object: of " . get_class($value);
    39             case "String":
    40                 return "String: " . $this->clipString($value, 200);
     25        switch ($type) {
     26            case 'Null':
     27                return 'NULL';
     28            case 'Boolean':
     29                return 'Boolean: ' . ($value ? 'true' : 'false');
     30            case 'Array':
     31                return 'Array: ' . count($value) . ' items';
     32            case 'Object':
     33                return 'Object: of ' . get_class($value);
     34            case 'String':
     35                return 'String: ' . $this->clipString($value, 200);
    4136            default:
    42                 return "$type: $value";
    43         }
    44         return "Unknown";
    45     }
    46 
    47     /**
    48      *    Gets the string representation of a type.
    49      *    @param mixed $value    Variable to check against.
    50      *    @return string         Type.
    51      *    @access public
    52      */
    53     function getType($value) {
     37                return $type . ': ' . $value;
     38        }
     39    }
     40
     41    /**
     42     * Gets the string representation of a type.
     43     *
     44     * @param mixed $value    Variable to check against.
     45     *
     46     * @return string         Type.
     47     */
     48    public function getType($value)
     49    {
    5450        if (! isset($value)) {
    55             return "Null";
     51            return 'Null';
    5652        } elseif (is_bool($value)) {
    57             return "Boolean";
     53            return 'Boolean';
    5854        } elseif (is_string($value)) {
    59             return "String";
     55            return 'String';
    6056        } elseif (is_integer($value)) {
    61             return "Integer";
     57            return 'Integer';
    6258        } elseif (is_float($value)) {
    63             return "Float";
     59            return 'Float';
    6460        } elseif (is_array($value)) {
    65             return "Array";
     61            return 'Array';
    6662        } elseif (is_resource($value)) {
    67             return "Resource";
     63            return 'Resource';
    6864        } elseif (is_object($value)) {
    69             return "Object";
    70         }
    71         return "Unknown";
    72     }
    73 
    74     /**
    75      *    Creates a human readable description of the
    76      *    difference between two variables. Uses a
    77      *    dynamic call.
    78      *    @param mixed $first        First variable.
    79      *    @param mixed $second       Value to compare with.
    80      *    @param boolean $identical  If true then type anomolies count.
    81      *    @return string             Description of difference.
    82      *    @access public
    83      */
    84     function describeDifference($first, $second, $identical = false) {
     65            return 'Object';
     66        }
     67
     68        return 'Unknown';
     69    }
     70
     71    /**
     72     * Creates a human readable description of the difference between two variables.
     73     * Uses a dynamic call.
     74     *
     75     * @param mixed $first        First variable.
     76     * @param mixed $second       Value to compare with.
     77     * @param bool $identical  If true then type anomolies count.
     78     *
     79     * @return string             Description of difference.
     80     */
     81    public function describeDifference($first, $second, $identical = false)
     82    {
    8583        if ($identical) {
    8684            if (! $this->isTypeMatch($first, $second)) {
    87                 return "with type mismatch as [" . $this->describeValue($first) .
    88                     "] does not match [" . $this->describeValue($second) . "]";
     85                return sprintf(
     86                    'with type mismatch as [%s] does not match [%s]',
     87                    $this->describeValue($first),
     88                    $this->describeValue($second)
     89                );
    8990            }
    9091        }
    9192        $type = $this->getType($first);
    92         if ($type == "Unknown") {
    93             return "with unknown type";
     93        if ($type === 'Unknown') {
     94            return 'with unknown type';
    9495        }
    9596        $method = 'describe' . $type . 'Difference';
     97
    9698        return $this->$method($first, $second, $identical);
    9799    }
    98100
    99101    /**
    100      *    Tests to see if types match.
    101      *    @param mixed $first        First variable.
    102      *    @param mixed $second       Value to compare with.
    103      *    @return boolean            True if matches.
    104      *    @access private
    105      */
    106     protected function isTypeMatch($first, $second) {
     102     * Tests to see if types match.
     103     *
     104     * @param mixed $first        First variable.
     105     * @param mixed $second       Value to compare with.
     106     *
     107     * @return bool            True if matches.
     108     */
     109    protected function isTypeMatch($first, $second)
     110    {
    107111        return ($this->getType($first) == $this->getType($second));
    108112    }
    109113
    110114    /**
    111      *    Clips a string to a maximum length.
    112      *    @param string $value         String to truncate.
    113      *    @param integer $size         Minimum string size to show.
    114      *    @param integer $position     Centre of string section.
    115      *    @return string               Shortened version.
    116      *    @access public
    117      */
    118     function clipString($value, $size, $position = 0) {
     115     * Clips a string to a maximum length.
     116     *
     117     * @param string $value         String to truncate.
     118     * @param int $size         Minimum string size to show.
     119     * @param int $position     Centre of string section.
     120     *
     121     * @return string               Shortened version.
     122     */
     123    public function clipString($value, $size, $position = 0)
     124    {
    119125        $length = strlen($value);
    120126        if ($length <= $size) {
     
    122128        }
    123129        $position = min($position, $length);
    124         $start = ($size/2 > $position ? 0 : $position - $size/2);
     130        $start    = ($size/2 > $position ? 0 : $position - $size/2);
    125131        if ($start + $size > $length) {
    126132            $start = $length - $size;
    127133        }
    128134        $value = substr($value, $start, $size);
    129         return ($start > 0 ? "..." : "") . $value . ($start + $size < $length ? "..." : "");
    130     }
    131 
    132     /**
    133      *    Creates a human readable description of the
    134      *    difference between two variables. The minimal
    135      *    version.
    136      *    @param null $first          First value.
    137      *    @param mixed $second        Value to compare with.
    138      *    @return string              Human readable description.
    139      *    @access private
    140      */
    141     protected function describeGenericDifference($first, $second) {
    142         return "as [" . $this->describeValue($first) .
    143                 "] does not match [" .
    144                 $this->describeValue($second) . "]";
    145     }
    146 
    147     /**
    148      *    Creates a human readable description of the
    149      *    difference between a null and another variable.
    150      *    @param null $first          First null.
    151      *    @param mixed $second        Null to compare with.
    152      *    @param boolean $identical   If true then type anomolies count.
    153      *    @return string              Human readable description.
    154      *    @access private
    155      */
    156     protected function describeNullDifference($first, $second, $identical) {
     135
     136        return ($start > 0 ? '...' : '') . $value . ($start + $size < $length ? '...' : '');
     137    }
     138
     139    /**
     140     * Creates a human readable description of the difference between two variables.
     141     * The minimal version.
     142     *
     143     * @param null $first          First value.
     144     * @param mixed $second        Value to compare with.
     145     *
     146     * @return string              Human readable description.
     147     */
     148    protected function describeGenericDifference($first, $second)
     149    {
     150        return sprintf(
     151            'as [%s] does not match [%s]', $this->describeValue($first), $this->describeValue($second)
     152        );
     153    }
     154
     155    /**
     156     * Creates a human readable description of the difference between a null and another variable.
     157     *
     158     * @param null $first          First null.
     159     * @param mixed $second        Null to compare with.
     160     * @param bool $identical   If true then type anomolies count.
     161     *
     162     * @return string              Human readable description.
     163     */
     164    protected function describeNullDifference($first, $second, $identical)
     165    {
    157166        return $this->describeGenericDifference($first, $second);
    158167    }
    159168
    160169    /**
    161      *    Creates a human readable description of the
    162      *    difference between a boolean and another variable.
    163      *    @param boolean $first       First boolean.
    164      *    @param mixed $second        Boolean to compare with.
    165      *    @param boolean $identical   If true then type anomolies count.
    166      *    @return string              Human readable description.
    167      *    @access private
    168      */
    169     protected function describeBooleanDifference($first, $second, $identical) {
     170     * Creates a human readable description of the difference between a boolean and another
     171     * variable.
     172     *
     173     * @param bool $first       First boolean.
     174     * @param mixed $second        Boolean to compare with.
     175     * @param bool $identical   If true then type anomolies count.
     176     *
     177     * @return string              Human readable description.
     178     */
     179    protected function describeBooleanDifference($first, $second, $identical)
     180    {
    170181        return $this->describeGenericDifference($first, $second);
    171182    }
    172183
    173184    /**
    174      *    Creates a human readable description of the
    175      *    difference between a string and another variable.
    176      *    @param string $first        First string.
    177      *    @param mixed $second        String to compare with.
    178      *    @param boolean $identical   If true then type anomolies count.
    179      *    @return string              Human readable description.
    180      *    @access private
    181      */
    182     protected function describeStringDifference($first, $second, $identical) {
     185     * Creates a human readable description of the difference between
     186     * a string and another variable.
     187     *
     188     * @param string $first        First string.
     189     * @param mixed $second        String to compare with.
     190     * @param bool $identical   If true then type anomolies count.
     191     *
     192     * @return string              Human readable description.
     193     */
     194    protected function describeStringDifference($first, $second, $identical)
     195    {
    183196        if (is_object($second) || is_array($second)) {
    184197            return $this->describeGenericDifference($first, $second);
    185198        }
    186199        $position = $this->stringDiffersAt($first, $second);
    187         $message = "at character $position";
    188         $message .= " with [" .
    189                 $this->clipString($first, 200, $position) . "] and [" .
    190                 $this->clipString($second, 200, $position) . "]";
    191         return $message;
    192     }
    193 
    194     /**
    195      *    Creates a human readable description of the
    196      *    difference between an integer and another variable.
    197      *    @param integer $first       First number.
    198      *    @param mixed $second        Number to compare with.
    199      *    @param boolean $identical   If true then type anomolies count.
    200      *    @return string              Human readable description.
    201      *    @access private
    202      */
    203     protected function describeIntegerDifference($first, $second, $identical) {
     200
     201        return sprintf(
     202            'at character %s with [%s] and [%s]',
     203            $position,
     204            $this->clipString($first, 200, $position),
     205            $this->clipString($second, 200, $position)
     206        );
     207    }
     208
     209    /**
     210     * Creates a human readable description of the difference between
     211     * an integer and another variable.
     212     *
     213     * @param int $first       First number.
     214     * @param mixed $second        Number to compare with.
     215     * @param bool $identical   If true then type anomolies count.
     216     *
     217     * @return string              Human readable description.
     218     */
     219    protected function describeIntegerDifference($first, $second, $identical)
     220    {
    204221        if (is_object($second) || is_array($second)) {
    205222            return $this->describeGenericDifference($first, $second);
    206223        }
    207         return "because [" . $this->describeValue($first) .
    208                 "] differs from [" .
    209                 $this->describeValue($second) . "] by " .
    210                 abs($first - $second);
    211     }
    212 
    213     /**
    214      *    Creates a human readable description of the
    215      *    difference between two floating point numbers.
    216      *    @param float $first         First float.
    217      *    @param mixed $second        Float to compare with.
    218      *    @param boolean $identical   If true then type anomolies count.
    219      *    @return string              Human readable description.
    220      *    @access private
    221      */
    222     protected function describeFloatDifference($first, $second, $identical) {
     224
     225        return sprintf(
     226            'because [%s] differs from [%s] by %s',
     227            $this->describeValue($first),
     228            $this->describeValue($second),
     229            abs($first - $second)
     230        );
     231    }
     232
     233    /**
     234     * Creates a human readable description of the difference between
     235     * two floating point numbers.
     236     *
     237     * @param float $first         First float.
     238     * @param mixed $second        Float to compare with.
     239     * @param bool $identical   If true then type anomolies count.
     240     *
     241     * @return string              Human readable description.
     242     */
     243    protected function describeFloatDifference($first, $second, $identical)
     244    {
    223245        if (is_object($second) || is_array($second)) {
    224246            return $this->describeGenericDifference($first, $second);
    225247        }
    226         return "because [" . $this->describeValue($first) .
    227                 "] differs from [" .
    228                 $this->describeValue($second) . "] by " .
    229                 abs($first - $second);
    230     }
    231 
    232     /**
    233      *    Creates a human readable description of the
    234      *    difference between two arrays.
    235      *    @param array $first         First array.
    236      *    @param mixed $second        Array to compare with.
    237      *    @param boolean $identical   If true then type anomolies count.
    238      *    @return string              Human readable description.
    239      *    @access private
    240      */
    241     protected function describeArrayDifference($first, $second, $identical) {
     248
     249        return sprintf(
     250            'because [%s] differs from [%s] by %s',
     251            $this->describeValue($first),
     252            $this->describeValue($second),
     253            abs($first - $second)
     254        );
     255    }
     256
     257    /**
     258     * Creates a human readable description of the difference between two arrays.
     259     *
     260     * @param array $first         First array.
     261     * @param mixed $second        Array to compare with.
     262     * @param bool $identical   If true then type anomolies count.
     263     *
     264     * @return string              Human readable description.
     265     */
     266    protected function describeArrayDifference($first, $second, $identical)
     267    {
    242268        if (! is_array($second)) {
    243269            return $this->describeGenericDifference($first, $second);
    244270        }
    245271        if (! $this->isMatchingKeys($first, $second, $identical)) {
    246             return "as key list [" .
    247                     implode(", ", array_keys($first)) . "] does not match key list [" .
    248                     implode(", ", array_keys($second)) . "]";
     272            return sprintf(
     273                'as key list [%s] does not match key list [%s]',
     274                implode(', ', array_keys($first)),
     275                implode(', ', array_keys($second))
     276            );
    249277        }
    250278        foreach (array_keys($first) as $key) {
     
    255283                continue;
    256284            }
    257             return "with member [$key] " . $this->describeDifference(
    258                     $first[$key],
    259                     $second[$key],
    260                     $identical);
    261         }
    262         return "";
    263     }
    264 
    265     /**
    266      *    Compares two arrays to see if their key lists match.
    267      *    For an identical match, the ordering and types of the keys
    268      *    is significant.
    269      *    @param array $first         First array.
    270      *    @param array $second        Array to compare with.
    271      *    @param boolean $identical   If true then type anomolies count.
    272      *    @return boolean             True if matching.
    273      *    @access private
    274      */
    275     protected function isMatchingKeys($first, $second, $identical) {
    276         $first_keys = array_keys($first);
     285
     286            return sprintf(
     287                'with member [%s] %s',
     288                $key,
     289                $this->describeDifference($first[$key], $second[$key], $identical)
     290            );
     291        }
     292
     293        return '';
     294    }
     295
     296    /**
     297     * Compares two arrays to see if their key lists match.
     298     * For an identical match, the ordering and types of the keys is significant.
     299     *
     300     * @param array $first         First array.
     301     * @param array $second        Array to compare with.
     302     * @param bool $identical   If true then type anomolies count.
     303     *
     304     * @return bool             True if matching.
     305     */
     306    protected function isMatchingKeys($first, $second, $identical)
     307    {
     308        $first_keys  = array_keys($first);
    277309        $second_keys = array_keys($second);
    278310        if ($identical) {
     
    281313        sort($first_keys);
    282314        sort($second_keys);
     315
    283316        return ($first_keys == $second_keys);
    284317    }
    285318
    286319    /**
    287      *    Creates a human readable description of the
    288      *    difference between a resource and another variable.
    289      *    @param resource $first       First resource.
    290      *    @param mixed $second         Resource to compare with.
    291      *    @param boolean $identical    If true then type anomolies count.
    292      *    @return string              Human readable description.
    293      *    @access private
    294      */
    295     protected function describeResourceDifference($first, $second, $identical) {
     320     * Creates a human readable description of the difference between
     321     * a resource and another variable.
     322     *
     323     * @param resource $first       First resource.
     324     * @param mixed $second         Resource to compare with.
     325     * @param bool $identical    If true then type anomolies count.
     326     *
     327     * @return string              Human readable description.
     328     */
     329    protected function describeResourceDifference($first, $second, $identical)
     330    {
    296331        return $this->describeGenericDifference($first, $second);
    297332    }
    298333
    299334    /**
    300      *    Creates a human readable description of the
    301      *    difference between two objects.
    302      *    @param object $first        First object.
    303      *    @param mixed $second        Object to compare with.
    304      *    @param boolean $identical   If true then type anomolies count.
    305      *    @return string              Human readable description.
    306      */
    307     protected function describeObjectDifference($first, $second, $identical) {
     335     * Creates a human readable description of the difference between two objects.
     336     *
     337     * @param object $first        First object.
     338     * @param mixed $second        Object to compare with.
     339     * @param bool $identical   If true then type anomolies count.
     340     *
     341     * @return string              Human readable description.
     342     */
     343    protected function describeObjectDifference($first, $second, $identical)
     344    {
    308345        if (! is_object($second)) {
    309346            return $this->describeGenericDifference($first, $second);
    310347        }
     348
    311349        return $this->describeArrayDifference(
    312350                $this->getMembers($first),
     
    316354
    317355    /**
    318      *    Get all members of an object including private and protected ones.
    319      *    A safer form of casting to an array.
    320      *    @param object $object     Object to list members of,
    321      *                              including private ones.
    322      *    @return array             Names and values in the object.
    323      */
    324     protected function getMembers($object) {
     356     * Get all members of an object including private and protected ones.
     357     * A safer form of casting to an array.
     358     *
     359     * @param object $object     Object to list members of, including private ones.
     360     *
     361     * @return array             Names and values in the object.
     362     */
     363    protected function getMembers($object)
     364    {
    325365        $reflection = new ReflectionObject($object);
    326         $members = array();
     366        $members    = array();
    327367        foreach ($reflection->getProperties() as $property) {
    328368            if (method_exists($property, 'setAccessible')) {
     
    336376            }
    337377        }
     378
    338379        return $members;
    339380    }
    340381
    341382    /**
    342      *    Extracts a private member's value when reflection won't play ball.
    343      *    @param string $name        Property name.
    344      *    @param object $object      Object to read.
    345      *    @return mixed              Value of property.
    346      */
    347     private function getPrivatePropertyNoMatterWhat($name, $object) {
    348         foreach ((array)$object as $mangled_name => $value) {
     383     * Extracts a private member's value when reflection won't play ball.
     384     *
     385     * @param string $name        Property name.
     386     * @param object $object      Object to read.
     387     *
     388     * @return mixed              Value of property.
     389     */
     390    private function getPrivatePropertyNoMatterWhat($name, $object)
     391    {
     392        foreach ((array) $object as $mangled_name => $value) {
    349393            if ($this->unmangle($mangled_name) == $name) {
    350394                return $value;
     
    354398
    355399    /**
    356      *    Removes crud from property name after it's been converted
    357      *    to an array.
    358      *    @param string $mangled     Name from array cast.
    359      *    @return string             Cleaned up name.
    360      */
    361     function unmangle($mangled) {
     400     * Removes crud from property name after it's been converted to an array.
     401     *
     402     * @param string $mangled     Name from array cast.
     403     *
     404     * @return string             Cleaned up name.
     405     */
     406    public function unmangle($mangled)
     407    {
    362408        $parts = preg_split('/[^a-zA-Z0-9_\x7f-\xff]+/', $mangled);
     409
    363410        return array_pop($parts);
    364411    }
    365412
    366413    /**
    367      *    Find the first character position that differs
    368      *    in two strings by binary chop.
    369      *    @param string $first        First string.
    370      *    @param string $second       String to compare with.
    371      *    @return integer             Position of first differing
    372      *                               character.
    373      *    @access private
    374      */
    375     protected function stringDiffersAt($first, $second) {
     414     * Find the first character position that differs in two strings by binary chop.
     415     *
     416     * @param string $first        First string.
     417     * @param string $second       String to compare with.
     418     *
     419     * @return int             Position of first differing character.
     420     */
     421    protected function stringDiffersAt($first, $second)
     422    {
    376423        if (! $first || ! $second) {
    377424            return 0;
     
    381428        }
    382429        $position = 0;
    383         $step = strlen($first);
     430        $step     = strlen($first);
    384431        while ($step > 1) {
    385             $step = (integer)(($step + 1) / 2);
     432            $step = (integer) (($step + 1) / 2);
    386433            if (strncmp($first, $second, $position + $step) == 0) {
    387434                $position += $step;
    388435            }
    389436        }
     437
    390438        return $position;
    391439    }
    392440
    393441    /**
    394      *    Sends a formatted dump of a variable to a string.
    395      *    @param mixed $variable    Variable to display.
    396      *    @return string            Output from print_r().
    397      *    @access public
    398      */
    399     function dump($variable) {
     442     * Sends a formatted dump of a variable to a string.
     443     *
     444     * @param mixed $variable    Variable to display.
     445     *
     446     * @return string            Output from print_r().
     447     */
     448    public function dump($variable)
     449    {
    400450        ob_start();
    401451        print_r($variable);
    402452        $formatted = ob_get_contents();
    403453        ob_end_clean();
     454
    404455        return $formatted;
    405456    }
    406457}
    407 ?>
  • _core_/tests/simpletest/eclipse.php

    r80772 r100149  
    11<?php
     2
     3require_once 'unit_tester.php';
     4require_once 'test_case.php';
     5require_once 'invoker.php';
     6require_once 'socket.php';
     7require_once 'mock_objects.php';
     8
    29/**
    3  *  base include file for eclipse plugin
    4  *  @package    SimpleTest
    5  *  @subpackage Eclipse
    6  *  @version    $Id: eclipse.php 2011 2011-04-29 08:22:48Z pp11 $
     10 * base reported class for eclipse plugin
    711 */
    8 /**#@+
    9  * simpletest include files
    10  */
    11 include_once 'unit_tester.php';
    12 include_once 'test_case.php';
    13 include_once 'invoker.php';
    14 include_once 'socket.php';
    15 include_once 'mock_objects.php';
    16 /**#@-*/
    17 
    18 /**
    19  *  base reported class for eclipse plugin
    20  *  @package    SimpleTest
    21  *  @subpackage Eclipse
    22  */
    23 class EclipseReporter extends SimpleScorer {
    24 
    25     /**
    26      *    Reporter to be run inside of Eclipse interface.
    27      *    @param object $listener   Eclipse listener (?).
    28      *    @param boolean $cc        Whether to include test coverage.
    29      */
    30     function __construct(&$listener, $cc=false){
    31         $this->listener = &$listener;
     12class EclipseReporter extends SimpleScorer
     13{
     14    /**
     15     * Reporter to be run inside of Eclipse interface.
     16     *
     17     * @param object $listener   Eclipse listener (?).
     18     * @param bool $cc        Whether to include test coverage.
     19     */
     20    public function __construct(&$listener, $cc=false)
     21    {
     22        $this->listener = $listener;
    3223        $this->SimpleScorer();
    33         $this->case = "";
    34         $this->group = "";
    35         $this->method = "";
    36         $this->cc = $cc;
    37         $this->error = false;
    38         $this->fail = false;
    39     }
    40 
    41     /**
    42      *    Means to display human readable object comparisons.
    43      *    @return SimpleDumper        Visual comparer.
    44      */
    45     function getDumper() {
     24        $this->case   = '';
     25        $this->group  = '';
     26        $this->method = '';
     27        $this->cc     = $cc;
     28        $this->error  = false;
     29        $this->fail   = false;
     30    }
     31
     32    /**
     33     * Means to display human readable object comparisons.
     34     *
     35     * @return SimpleDumper        Visual comparer.
     36     */
     37    public function getDumper()
     38    {
    4639        return new SimpleDumper();
    4740    }
    4841
    4942    /**
    50      *    Localhost connection from Eclipse.
    51      *    @param integer $port      Port to connect to Eclipse.
    52      *    @param string $host       Normally localhost.
    53      *    @return SimpleSocket      Connection to Eclipse.
    54      */
    55     function &createListener($port, $host="127.0.0.1"){
    56         $tmplistener = &new SimpleSocket($host, $port, 5);
     43     * Localhost connection from Eclipse.
     44     *
     45     * @param int $port      Port to connect to Eclipse.
     46     * @param string $host       Normally localhost.
     47     *
     48     * @return SimpleSocket      Connection to Eclipse.
     49     */
     50    public function createListener($port, $host='127.0.0.1')
     51    {
     52        $tmplistener = new SimpleSocket($host, $port, 5);
     53
    5754        return $tmplistener;
    5855    }
    5956
    6057    /**
    61      *    Wraps the test in an output buffer.
    62      *    @param SimpleInvoker $invoker     Current test runner.
    63      *    @return EclipseInvoker            Decorator with output buffering.
    64      *    @access public
    65      */
    66     function &createInvoker(&$invoker){
    67         $eclinvoker = &new EclipseInvoker($invoker, $this->listener);
     58     * Wraps the test in an output buffer.
     59     *
     60     * @param SimpleInvoker $invoker     Current test runner.
     61     *
     62     * @return EclipseInvoker            Decorator with output buffering.
     63     */
     64    public function createInvoker(&$invoker)
     65    {
     66        $eclinvoker = new EclipseInvoker($invoker, $this->listener);
     67
    6868        return $eclinvoker;
    6969    }
    7070
    7171    /**
    72      *    C style escaping.
    73      *    @param string $raw    String with backslashes, quotes and whitespace.
    74      *    @return string        Replaced with C backslashed tokens.
    75      */
    76     function escapeVal($raw){
    77         $needle = array("\\","\"","/","\b","\f","\n","\r","\t");
     72     * C style escaping.
     73     *
     74     * @param string $raw    String with backslashes, quotes and whitespace.
     75     *
     76     * @return string        Replaced with C backslashed tokens.
     77     */
     78    public static function escapeVal($raw)
     79    {
     80        $needle  = array('\\','"','/',"\b","\f","\n","\r","\t");
    7881        $replace = array('\\\\','\"','\/','\b','\f','\n','\r','\t');
     82
    7983        return str_replace($needle, $replace, $raw);
    8084    }
    8185
    8286    /**
    83      *    Stash the first passing item. Clicking the test
    84      *    item goes to first pass.
    85      *    @param string $message    Test message, but we only wnat the first.
    86      *    @access public
    87      */
    88     function paintPass($message){
    89         if (! $this->pass){
    90             $this->message = $this->escapeVal($message);
     87     * Stash the first passing item. Clicking the test item goes to first pass.
     88     *
     89     * @param string $message    Test message, but we only wnat the first.
     90     */
     91    public function paintPass($message)
     92    {
     93        if (! $this->pass) {
     94            $this->message = self::escapeVal($message);
    9195        }
    9296        $this->pass = true;
     
    9498
    9599    /**
    96      *    Stash the first failing item. Clicking the test
    97      *    item goes to first fail.
    98      *    @param string $message    Test message, but we only wnat the first.
    99      *    @access public
    100      */
    101     function paintFail($message){
     100     * Stash the first failing item. Clicking the test item goes to first fail.
     101     *
     102     * @param string $message    Test message, but we only wnat the first.
     103     */
     104    public function paintFail($message)
     105    {
    102106        //only get the first failure or error
    103         if (! $this->fail && ! $this->error){
    104             $this->fail = true;
    105             $this->message = $this->escapeVal($message);
    106             $this->listener->write('{status:"fail",message:"'.$this->message.'",group:"'.$this->group.'",case:"'.$this->case.'",method:"'.$this->method.'"}');
    107         }
    108     }
    109 
    110     /**
    111      *    Stash the first error. Clicking the test
    112      *    item goes to first error.
    113      *    @param string $message    Test message, but we only wnat the first.
    114      *    @access public
    115      */
    116     function paintError($message){
    117         if (! $this->fail && ! $this->error){
     107        if (! $this->fail && ! $this->error) {
     108            $this->fail    = true;
     109            $this->message = self::escapeVal($message);
     110            $this->listener->write(
     111                '{status:"fail",message:"' . $this->message . '",group:"' . $this->group .
     112                '",case:"' . $this->case . '",method:"' . $this->method . '"}'
     113            );
     114        }
     115    }
     116
     117    /**
     118     * Stash the first error. Clicking the test item goes to first error.
     119     *
     120     * @param string $message    Test message, but we only wnat the first.
     121     */
     122    public function paintError($message)
     123    {
     124        if (! $this->fail && ! $this->error) {
     125            $this->error   = true;
     126            $this->message = self::escapeVal($message);
     127            $this->listener->write(
     128                '{status:"error",message:"' . $this->message . '",group:"' . $this->group .
     129                '",case:"' . $this->case . '",method:"' . $this->method . '"}'
     130            );
     131        }
     132    }
     133
     134    /**
     135     * Stash the first exception. Clicking the test item goes to first message.
     136     *
     137     * @param string $message    Test message, but we only wnat the first.
     138     */
     139    public function paintException($exception)
     140    {
     141        if (! $this->fail && ! $this->error) {
    118142            $this->error = true;
    119             $this->message = $this->escapeVal($message);
    120             $this->listener->write('{status:"error",message:"'.$this->message.'",group:"'.$this->group.'",case:"'.$this->case.'",method:"'.$this->method.'"}');
    121         }
    122     }
    123 
    124 
    125     /**
    126      *    Stash the first exception. Clicking the test
    127      *    item goes to first message.
    128      *    @param string $message    Test message, but we only wnat the first.
    129      *    @access public
    130      */
    131     function paintException($exception){
    132         if (! $this->fail && ! $this->error){
    133             $this->error = true;
    134             $message = 'Unexpected exception of type[' . get_class($exception) .
     143            $message     = 'Unexpected exception of type[' . get_class($exception) .
    135144                    '] with message [' . $exception->getMessage() . '] in [' .
    136                     $exception->getFile() .' line '. $exception->getLine() . ']';
    137             $this->message = $this->escapeVal($message);
     145                    $exception->getFile() . ' line ' . $exception->getLine() . ']';
     146            $this->message = self::escapeVal($message);
    138147            $this->listener->write(
    139                     '{status:"error",message:"' . $this->message . '",group:"' .
    140                     $this->group . '",case:"' . $this->case . '",method:"' . $this->method
    141                     . '"}');
    142         }
    143     }
    144 
    145 
    146     /**
    147      *    We don't display any special header.
    148      *    @param string $test_name     First test top level
    149      *                                 to start.
    150      *    @access public
    151      */
    152     function paintHeader($test_name) {
    153     }
    154 
    155     /**
    156      *    We don't display any special footer.
    157      *    @param string $test_name        The top level test.
    158      *    @access public
    159      */
    160     function paintFooter($test_name) {
    161     }
    162 
    163     /**
    164      *    Paints nothing at the start of a test method, but stash
    165      *    the method name for later.
    166      *    @param string $test_name   Name of test that is starting.
    167      *    @access public
    168      */
    169     function paintMethodStart($method) {
    170         $this->pass = false;
    171         $this->fail = false;
    172         $this->error = false;
    173         $this->method = $this->escapeVal($method);
    174     }
    175 
    176     /**
    177      *    Only send one message if the test passes, after that
    178      *    suppress the message.
    179      *    @param string $test_name   Name of test that is ending.
    180      *    @access public
    181      */
    182     function paintMethodEnd($method){
    183         if ($this->fail || $this->error || ! $this->pass){
     148                    '{status:"error",message:"' . $this->message . '",group:"' . $this->group .
     149                    '",case:"' . $this->case . '",method:"' . $this->method. '"}'
     150            );
     151        }
     152    }
     153
     154    /**
     155     * We don't display any special header.
     156     *
     157     * @param string $test_name     First test top level to start.
     158     */
     159    public function paintHeader($test_name)
     160    {
     161    }
     162
     163    /**
     164     * We don't display any special footer.
     165     *
     166     * @param string $test_name        The top level test.
     167     */
     168    public function paintFooter($test_name)
     169    {
     170    }
     171
     172    /**
     173     * Paints nothing at the start of a test method, but stash the method name for later.
     174     *
     175     * @param string $test_name   Name of test that is starting.
     176     */
     177    public function paintMethodStart($method)
     178    {
     179        $this->pass   = false;
     180        $this->fail   = false;
     181        $this->error  = false;
     182        $this->method = self::escapeVal($method);
     183    }
     184
     185    /**
     186     * Only send one message if the test passes, after that suppress the message.
     187     *
     188     * @param string $test_name   Name of test that is ending.
     189     */
     190    public function paintMethodEnd($method)
     191    {
     192        if ($this->fail || $this->error || ! $this->pass) {
    184193        } else {
    185194            $this->listener->write(
     
    191200
    192201    /**
    193      *    Stashes the test case name for the later failure message.
    194      *    @param string $test_name     Name of test or other label.
    195      *    @access public
    196      */
    197     function paintCaseStart($case){
    198         $this->case = $this->escapeVal($case);
    199     }
    200 
    201     /**
    202      *    Drops the name.
    203      *    @param string $test_name     Name of test or other label.
    204      *    @access public
    205      */
    206     function paintCaseEnd($case){
    207         $this->case = "";
    208     }
    209 
    210     /**
    211      *    Stashes the name of the test suite. Starts test coverage
    212      *    if enabled.
    213      *    @param string $group     Name of test or other label.
    214      *    @param integer $size     Number of test cases starting.
    215      *    @access public
    216      */
    217     function paintGroupStart($group, $size){
    218         $this->group = $this->escapeVal($group);
    219         if ($this->cc){
    220             if (extension_loaded('xdebug')){
     202     * Stashes the test case name for the later failure message.
     203     *
     204     * @param string $test_name     Name of test or other label.
     205     */
     206    public function paintCaseStart($case)
     207    {
     208        $this->case = self::escapeVal($case);
     209    }
     210
     211    /**
     212     * Drops the name.
     213     *
     214     * @param string $test_name     Name of test or other label.
     215     */
     216    public function paintCaseEnd($case)
     217    {
     218        $this->case = '';
     219    }
     220
     221    /**
     222     * Stashes the name of the test suite. Starts test coverage if enabled.
     223     *
     224     * @param string $group     Name of test or other label.
     225     * @param int $size     Number of test cases starting.
     226     */
     227    public function paintGroupStart($group, $size)
     228    {
     229        $this->group = self::escapeVal($group);
     230        if ($this->cc) {
     231            if (extension_loaded('xdebug')) {
    221232                xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
    222233            }
     
    225236
    226237    /**
    227      *    Paints coverage report if enabled.
    228      *    @param string $group     Name of test or other label.
    229      *    @access public
    230      */
    231     function paintGroupEnd($group){
    232         $this->group = "";
    233         $cc = "";
    234         if ($this->cc){
    235             if (extension_loaded('xdebug')){
     238     * Paints coverage report if enabled.
     239     *
     240     * @param string $group     Name of test or other label.
     241     */
     242    public function paintGroupEnd($group)
     243    {
     244        $this->group = '';
     245        $cc          = '';
     246        if ($this->cc) {
     247            if (extension_loaded('xdebug')) {
    236248                $arrfiles = xdebug_get_code_coverage();
    237249                xdebug_stop_code_coverage();
    238                 $thisdir = dirname(__FILE__);
     250                $thisdir    = dirname(__FILE__);
    239251                $thisdirlen = strlen($thisdir);
    240                 foreach ($arrfiles as $index=>$file){
    241                     if (substr($index, 0, $thisdirlen)===$thisdir){
     252                foreach ($arrfiles as $index=>$file) {
     253                    if (substr($index, 0, $thisdirlen)===$thisdir) {
    242254                        continue;
    243255                    }
    244256                    $lcnt = 0;
    245257                    $ccnt = 0;
    246                     foreach ($file as $line){
    247                         if ($line == -2){
     258                    foreach ($file as $line) {
     259                        if ($line == -2) {
    248260                            continue;
    249261                        }
    250262                        $lcnt++;
    251                         if ($line==1){
     263                        if ($line==1) {
    252264                            $ccnt++;
    253265                        }
    254266                    }
    255                     if ($lcnt > 0){
     267                    if ($lcnt > 0) {
    256268                        $cc .= round(($ccnt/$lcnt) * 100, 2) . '%';
    257                     }else{
    258                         $cc .= "0.00%";
     269                    } else {
     270                        $cc .= '0.00%';
    259271                    }
    260                     $cc.= "\t". $index . "\n";
     272                    $cc.= "\t" . $index . "\n";
    261273                }
    262274            }
    263275        }
    264         $this->listener->write('{status:"coverage",message:"' .
    265                                 EclipseReporter::escapeVal($cc) . '"}');
     276
     277        $this->listener->write(
     278            '{status:"coverage",message:"' . self::escapeVal($cc) . '"}'
     279        );
    266280    }
    267281}
    268282
    269283/**
    270  *  Invoker decorator for Eclipse. Captures output until
    271  *  the end of the test.
    272  *  @package    SimpleTest
    273  *  @subpackage Eclipse
     284 * Invoker decorator for Eclipse. Captures output until the end of the test.
    274285 */
    275 class EclipseInvoker extends SimpleInvokerDecorator{
    276     function __construct(&$invoker, &$listener) {
    277         $this->listener = &$listener;
     286class EclipseInvoker extends SimpleInvokerDecorator
     287{
     288    public function __construct(&$invoker, &$listener)
     289