Changeset 50265 for trunk/tests/phpunit/includes/utils.php
- Timestamp:
- 02/09/2021 01:22:47 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/utils.php
r49193 r50265 3 3 // Misc help functions and utilities. 4 4 5 /** 6 * Returns a string of the required length containing random characters. Note that 7 * the maximum possible string length is 32. 8 * 9 * @param int $len Optional. The required length. Default 32. 10 * @return string The string. 11 */ 5 12 function rand_str( $len = 32 ) { 6 13 return substr( md5( uniqid( rand() ) ), 0, $len ); 7 14 } 8 15 16 /** 17 * Returns a string of the required length containing random characters. 18 * 19 * @param int $len The required length. 20 * @return string The string. 21 */ 9 22 function rand_long_str( $length ) { 10 23 $chars = 'abcdefghijklmnopqrstuvwxyz'; … … 19 32 } 20 33 21 // Strip leading and trailing whitespace from each line in the string. 34 /** 35 * Strips leading and trailing whitespace from each line in the string. 36 * 37 * @param string $txt The text. 38 * @return string Text with line-leading and line-trailing whitespace stripped. 39 */ 22 40 function strip_ws( $txt ) { 23 41 $lines = explode( "\n", $txt ); … … 34 52 /* 35 53 * Helper class for testing code that involves actions and filters. 54 * 36 55 * Typical use: 37 * $ma = new MockAction(); 38 * add_action( 'foo', array( &$ma, 'action' ) ); 56 * 57 * $ma = new MockAction(); 58 * add_action( 'foo', array( &$ma, 'action' ) ); 39 59 */ 40 60 class MockAction { … … 241 261 } 242 262 263 /** 264 * Converts an XML string into an array tree structure. 265 * 266 * The output of this function can be passed to xml_find() to find nodes by their path. 267 * 268 * @param string $in The XML string. 269 * @return array XML as an array. 270 */ 243 271 function xml_to_array( $in ) { 244 272 $p = new TestXMLParser( $in ); … … 246 274 } 247 275 276 /** 277 * Finds XML nodes by a given "path". 278 * 279 * Example usage: 280 * 281 * $tree = xml_to_array( $rss ); 282 * $items = xml_find( $tree, 'rss', 'channel', 'item' ); 283 * 284 * @param array $tree An array tree structure of XML, typically from xml_to_array(). 285 * @param string ...$elements Names of XML nodes to create a "path" to find within the XML. 286 * @return array Array of matching XML node information. 287 */ 248 288 function xml_find( $tree, ...$elements ) { 249 289 $n = count( $elements );
Note: See TracChangeset
for help on using the changeset viewer.