Make WordPress Core

Changeset 21 in tests


Ignore:
Timestamp:
09/22/2007 02:44:11 AM (19 years ago)
Author:
tellyworth
Message:

add test_wp_dropdown_users

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_user.php

    r20 r21  
    88
    99        function setUp() {
     10                parent::setUp();
    1011                // keep track of users we create
    1112                $user_ids = array();
     
    1314
    1415        function tearDown() {
     16                parent::tearDown();
    1517                // delete any users that were created during tests
    1618                foreach ($this->user_ids as $id)
     
    120122                // get the complete usermeta array
    121123                $out = get_usermeta($user_id);
    122                
     124
    123125                // for reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere.
    124126                // so we'll just check to make sure our values are included somewhere.
     
    138140                }
    139141        }
     142
     143        // simple test for user dropdown
     144        function test_wp_dropdown_users() {
     145                // add some users
     146                foreach (array('administrator', 'editor', 'author', 'contributor', 'subscriber') as $role) {
     147                        $id = $this->_make_user($role, "test-{$role}");
     148                        $user[] = $id;
     149                }
     150
     151                $expected = <<<EOF
     152<select name='user' id='user' class=''>
     153<option value='1'>{$this->author->display_name}</option>
     154<option value='{$user[0]}'>test-administrator</option>
     155<option value='{$user[1]}'>test-editor</option>
     156<option value='{$user[2]}'>test-author</option>
     157<option value='{$user[3]}'>test-contributor</option>
     158<option value='{$user[4]}'>test-subscriber</option>
     159</select>
     160EOF;
     161
     162                $out = wp_dropdown_users('echo=0&orderby=ID');
     163
     164                $this->assertEquals(strip_ws($expected), strip_ws($out));
     165        }
    140166}
    141167
  • wp-testlib/utils.php

    r11 r21  
    55function rand_str($len=32) {
    66        return substr(md5(uniqid(rand())), 0, $len);
     7}
     8
     9// strip leading and trailing whitespace from each line in the string
     10function strip_ws($txt) {
     11        $lines = explode("\n", $txt);
     12        $result = array();
     13        foreach ($lines as $line)
     14                if (trim($line))
     15                        $result[] = trim($line);
     16
     17        return trim(join("\n", $result));
    718}
    819
Note: See TracChangeset for help on using the changeset viewer.