Make WordPress Core

Changeset 35 in tests for wp-testlib/utils.php


Ignore:
Timestamp:
09/25/2007 07:49:25 AM (18 years ago)
Author:
tellyworth
Message:

add gen_tests_array

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testlib/utils.php

    r25 r35  
    4848        $this->events[] = array('action' => __FUNCTION__, 'tag'=>$current_action, 'args'=>$args);
    4949    }
    50    
     50
    5151    // return a list of all the actions, tags and args
    5252    function get_events() {
     
    213213}
    214214
     215// recursively generate some quick assertEquals tests based on an array
     216function gen_tests_array($name, $array) {
     217    $out = array();
     218    foreach ($array as $k=>$v) {
     219        if (is_numeric($k))
     220            $index = strval($k);
     221        else
     222            $index = "'".addcslashes($k, "\n\r\t'\\")."'";
     223
     224        if (is_string($v)) {
     225            $out[] = '$this->assertEquals( \'' . addcslashes($v, "\n\r\t'\\") . '\', $'.$name.'['.$index.'] );';
     226        }
     227        elseif (is_numeric($v)) {
     228            $out[] = '$this->assertEquals( ' . $v . ', $'.$name.'['.$index.'] );';
     229        }
     230        elseif (is_array($v)) {
     231            $out[] = gen_tests_array("{$name}[{$index}]", $v);
     232        }
     233    }
     234    return join("\n", $out)."\n";
     235}
     236
    215237?>
Note: See TracChangeset for help on using the changeset viewer.