Make WordPress Core

Changeset 81 in tests


Ignore:
Timestamp:
11/11/2007 10:38:57 PM (17 years ago)
Author:
tellyworth
Message:

add mask_input_value() util function

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_meta.php

    r39 r81  
    5353
    5454    }
     55   
     56    function test_mask_input_value() {
     57        $in = <<<EOF
     58<h2>Assign Authors</h2>
     59<p>To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.</p>
     60<p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
     61        <ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="855ae98911" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user  <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
     62EOF;
     63        // _wpnonce value should be replaced with 'xxx'
     64        $expected = <<<EOF
     65<h2>Assign Authors</h2>
     66<p>To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.</p>
     67<p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
     68        <ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="***" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user  <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
     69EOF;
     70        $this->assertEquals($expected, mask_input_value($in));
     71    }
    5572}
    5673
  • wp-testlib/utils.php

    • Property svn:eol-style set to native
    r70 r81  
    7171        $this->events[] = array('filter' => __FUNCTION__, 'tag'=>$this->current_filter(), 'args'=>$args);
    7272        return $arg;
     73    }
     74
     75    function filterall($tag, $arg) {
     76    // this one doesn't return the result, so it's safe to use with the new 'all' filter
     77if ($this->debug) dmp(__FUNCTION__, $this->current_filter());
     78
     79        $args = func_get_args();
     80        $this->events[] = array('filter' => __FUNCTION__, 'tag'=>$tag, 'args'=>array_slice($args, 1));
    7381    }
    7482
     
    289297}
    290298
     299// mask out any input fields matching the given name
     300function mask_input_value($in, $name='_wpnonce') {
     301    return preg_replace('@<input([^>]*) name="'.preg_quote($name).'"([^>]*) value="[^>]*" />@', '<input$1 name="'.preg_quote($name).'"$2 value="***" />', $in);
     302}
     303
    291304?>
Note: See TracChangeset for help on using the changeset viewer.