Make WordPress Core

Changeset 38382


Ignore:
Timestamp:
08/26/2016 08:21:30 PM (9 years ago)
Author:
johnbillion
Message:

Build/Test Tools: Remove many unnecessary calls to rand_str() which can, in theory, fail at random. Static strings are much more appropriate.

See #37371

Location:
trunk/tests/phpunit/tests
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/actions.php

    r38251 r38382  
    145145
    146146    function test_did_action() {
    147         $tag1 = rand_str();
    148         $tag2 = rand_str();
     147        $tag1 = 'action1';
     148        $tag2 = 'action2';
    149149
    150150        // do action tag1 but not tag2
  • trunk/tests/phpunit/tests/admin/includesScreen.php

    r36089 r38382  
    187187     */
    188188    function test_help_tabs_priority() {
    189         $tab_1      = rand_str();
     189        $tab_1      = 'tab1';
    190190        $tab_1_args = array(
    191191            'title'    => 'Help!',
     
    196196        );
    197197
    198         $tab_2      = rand_str();
     198        $tab_2      = 'tab2';
    199199        $tab_2_args = array(
    200200            'title'    => 'Help!',
     
    204204            'priority' => 2,
    205205        );
    206         $tab_3      = rand_str();
     206        $tab_3      = 'tab3';
    207207        $tab_3_args = array(
    208208            'title'    => 'help!',
     
    212212            'priority' => 40,
    213213        );
    214         $tab_4      = rand_str();
     214        $tab_4      = 'tab4';
    215215        $tab_4_args = array(
    216216            'title'    => 'help!',
  • trunk/tests/phpunit/tests/cron.php

    r31622 r38382  
    4040    function test_schedule_event_single_args() {
    4141        // schedule an event with arguments and make sure it's returned by wp_next_scheduled
    42         $hook = rand_str();
    43         $timestamp = strtotime('+1 hour');
    44         $args = array(rand_str());
     42        $hook = 'event';
     43        $timestamp = strtotime('+1 hour');
     44        $args = array('foo');
    4545
    4646        wp_schedule_single_event( $timestamp, $hook, $args );
     
    4949        // these don't match so return nothing
    5050        $this->assertEquals( false, wp_next_scheduled($hook) );
    51         $this->assertEquals( false, wp_next_scheduled($hook, array(rand_str())) );
     51        $this->assertEquals( false, wp_next_scheduled($hook, array('bar')) );
    5252
    5353        // it's a non recurring event
     
    7070    function test_schedule_event_args() {
    7171        // schedule an event and make sure it's returned by wp_next_scheduled
    72         $hook = rand_str();
     72        $hook = 'event';
    7373        $timestamp = strtotime('+1 hour');
    7474        $recur = 'hourly';
    75         $args = array(rand_str());
     75        $args = array('foo');
    7676
    7777        wp_schedule_event( $timestamp, 'hourly', $hook, $args );
     
    8080        // these don't match so return nothing
    8181        $this->assertEquals( false, wp_next_scheduled($hook) );
    82         $this->assertEquals( false, wp_next_scheduled($hook, array(rand_str())) );
     82        $this->assertEquals( false, wp_next_scheduled($hook, array('bar')) );
    8383
    8484        $this->assertEquals( $recur, wp_get_schedule($hook, $args) );
  • trunk/tests/phpunit/tests/db/charset.php

    r37320 r38382  
    544544
    545545        $vars = array();
    546         foreach( $this->table_and_column_defs as $value ) {
    547             $this_table_name = $table_name . '_' . rand_str( 5 );
     546        foreach( $this->table_and_column_defs as $i => $value ) {
     547            $this_table_name = $table_name . '_' . $i;
    548548            $drop = "DROP TABLE IF EXISTS $this_table_name";
    549549            $create = "CREATE TABLE $this_table_name {$value['definition']}";
     
    584584
    585585        $vars = array();
    586         foreach( $this->table_and_column_defs as $value ) {
    587             $this_table_name = $table_name . '_' . rand_str( 5 );
     586        foreach( $this->table_and_column_defs as $i => $value ) {
     587            $this_table_name = $table_name . '_' . $i;
    588588            $drop = "DROP TABLE IF EXISTS $this_table_name";
    589589            $create = "CREATE TABLE $this_table_name {$value['definition']}";
     
    688688        );
    689689
    690         foreach( $data as &$value ) {
    691             $this_table_name = $table_name . '_' . rand_str( 5 );
     690        foreach( $data as $i => &$value ) {
     691            $this_table_name = $table_name . '_' . $i;
    692692
    693693            $value[0] = "CREATE TABLE $this_table_name {$value[0]}";
     
    802802        );
    803803
    804         foreach( $data as &$value ) {
    805             $this_table_name = $table_name . '_' . rand_str( 5 );
     804        foreach( $data as $i => &$value ) {
     805            $this_table_name = $table_name . '_' . $i;
    806806
    807807            $value[0] = "CREATE TABLE $this_table_name {$value[0]}";
  • trunk/tests/phpunit/tests/option/option.php

    r31640 r38382  
    1111
    1212    function test_the_basics() {
    13         $key = rand_str();
    14         $key2 = rand_str();
    15         $value = rand_str();
    16         $value2 = rand_str();
     13        $key = 'key1';
     14        $key2 = 'key2';
     15        $value = 'value1';
     16        $value2 = 'value2';
    1717
    1818        $this->assertFalse( get_option( 'doesnotexist' ) );
     
    3636
    3737    function test_default_filter() {
    38         $random = rand_str();
     38        $value = 'value';
    3939
    4040        $this->assertFalse( get_option( 'doesnotexist' ) );
     
    4949
    5050        // Once the option exists, the $default arg and the default filter are ignored.
    51         add_option( 'doesnotexist', $random );
    52         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
     51        add_option( 'doesnotexist', $value );
     52        $this->assertEquals( $value, get_option( 'doesnotexist', 'foo' ) );
    5353        add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    54         $this->assertEquals( $random, get_option( 'doesnotexist', 'foo' ) );
     54        $this->assertEquals( $value, get_option( 'doesnotexist', 'foo' ) );
    5555        remove_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) );
    5656
  • trunk/tests/phpunit/tests/option/siteOption.php

    r34766 r38382  
    9393
    9494    function test_update_site_option_returns_true_for_new_value() {
    95         $key = rand_str();
    96         $value = rand_str();
    97         $new_value = rand_str();
     95        $key = 'key';
     96        $value = 'value1';
     97        $new_value = 'value2';
    9898        add_site_option( $key, $value );
    9999        $this->assertTrue( update_site_option( $key, $new_value ) );
  • trunk/tests/phpunit/tests/option/siteTransient.php

    r37223 r38382  
    1515
    1616    function test_the_basics() {
    17         $key = rand_str();
    18         $value = rand_str();
    19         $value2 = rand_str();
     17        $key = 'key1';
     18        $value = 'value1';
     19        $value2 = 'value2';
    2020
    2121        $this->assertFalse( get_site_transient( 'doesnotexist' ) );
  • trunk/tests/phpunit/tests/option/transient.php

    r34828 r38382  
    1515
    1616    function test_the_basics() {
    17         $key = rand_str();
    18         $value = rand_str();
    19         $value2 = rand_str();
     17        $key = 'key1';
     18        $value = 'value1';
     19        $value2 = 'value2';
    2020
    2121        $this->assertFalse( get_transient( 'doesnotexist' ) );
  • trunk/tests/phpunit/tests/query/results.php

    r36138 r38382  
    457457     */
    458458    function test_query_author_vars() {
    459         $author_1 = self::factory()->user->create( array( 'user_login' => 'admin1', 'user_pass' => rand_str(), 'role' => 'author' ) );
    460         $post_1 = self::factory()->post->create( array( 'post_title' => rand_str(), 'post_author' => $author_1, 'post_date' => '2007-01-01 00:00:00' ) );
    461 
    462         $author_2 = self::factory()->user->create( array( 'user_login' => rand_str(), 'user_pass' => rand_str(), 'role' => 'author' ) );
    463         $post_2 = self::factory()->post->create( array( 'post_title' => rand_str(), 'post_author' => $author_2, 'post_date' => '2007-01-01 00:00:00' ) );
    464 
    465         $author_3 = self::factory()->user->create( array( 'user_login' => rand_str(), 'user_pass' => rand_str(), 'role' => 'author' ) );
    466         $post_3 = self::factory()->post->create( array( 'post_title' => rand_str(), 'post_author' => $author_3, 'post_date' => '2007-01-01 00:00:00' ) );
    467 
    468         $author_4 = self::factory()->user->create( array( 'user_login' => rand_str(), 'user_pass' => rand_str(), 'role' => 'author' ) );
    469         $post_4 = self::factory()->post->create( array( 'post_title' => rand_str(), 'post_author' => $author_4, 'post_date' => '2007-01-01 00:00:00' ) );
     459        $author_1 = self::factory()->user->create( array( 'user_login' => 'author1', 'role' => 'author' ) );
     460        $post_1 = self::factory()->post->create( array( 'post_title' => 'Post 1', 'post_author' => $author_1, 'post_date' => '2007-01-01 00:00:00' ) );
     461
     462        $author_2 = self::factory()->user->create( array( 'user_login' => 'author2', 'role' => 'author' ) );
     463        $post_2 = self::factory()->post->create( array( 'post_title' => 'Post 2', 'post_author' => $author_2, 'post_date' => '2007-01-01 00:00:00' ) );
     464
     465        $author_3 = self::factory()->user->create( array( 'user_login' => 'author3', 'role' => 'author' ) );
     466        $post_3 = self::factory()->post->create( array( 'post_title' => 'Post 3', 'post_author' => $author_3, 'post_date' => '2007-01-01 00:00:00' ) );
     467
     468        $author_4 = self::factory()->user->create( array( 'user_login' => 'author4', 'role' => 'author' ) );
     469        $post_4 = self::factory()->post->create( array( 'post_title' => 'Post 4', 'post_author' => $author_4, 'post_date' => '2007-01-01 00:00:00' ) );
    470470
    471471        $posts = $this->q->query( array(
     
    550550
    551551        $posts = $this->q->query( array(
    552             'author_name' => 'admin1',
     552            'author_name' => 'author1',
    553553            'post__in' => array( $post_1, $post_2, $post_3, $post_4 )
    554554        ) );
  • trunk/tests/phpunit/tests/term/getTerms.php

    r38337 r38382  
    23152315    protected function set_up_three_posts_and_tags() {
    23162316        $posts = self::factory()->post->create_many( 3, array( 'post_type' => 'post' ) );
    2317         foreach ( $posts as $post ) {
    2318             wp_set_object_terms( $post, rand_str(), 'post_tag' );
     2317        foreach ( $posts as $i => $post ) {
     2318            wp_set_object_terms( $post, "term_{$i}", 'post_tag' );
    23192319        }
    23202320
  • trunk/tests/phpunit/tests/term/wpInsertTerm.php

    r37641 r38382  
    1111        // insert one term into every post taxonomy
    1212        // otherwise term_ids and term_taxonomy_ids might be identical, which could mask bugs
    13         $term = rand_str();
     13        $term = 'seed_term';
    1414        foreach(get_object_taxonomies('post') as $tax)
    1515            wp_insert_term( $term, $tax );
     
    2121
    2222        // a new unused term
    23         $term = rand_str();
     23        $term = 'term';
    2424        $this->assertNull( term_exists($term) );
    2525
  • trunk/tests/phpunit/tests/term/wpSetObjectTerms.php

    r37649 r38382  
    111111        $terms = array();
    112112        for ($i=0; $i<3; $i++ ) {
    113             $term = rand_str();
     113            $term = "term_{$i}";
    114114            $result = wp_insert_term( $term, $this->taxonomy );
    115115            $this->assertInternalType( 'array', $result );
     
    246246        $terms_1 = array();
    247247        for ($i=0; $i<3; $i++ ) {
    248             $term = rand_str();
     248            $term = "term_{$i}";
    249249            $result = wp_insert_term( $term, $this->taxonomy );
    250250            $this->assertInternalType( 'array', $result );
     
    256256        $terms_2[0] = $terms_1[1];
    257257
    258         $term = rand_str();
     258        $term = 'term';
    259259        $result = wp_insert_term( $term, $this->taxonomy );
    260260        $terms_2[1] = $result['term_id'];
  • trunk/tests/phpunit/tests/user.php

    r38278 r38382  
    104104    // simple tests for usermeta functions
    105105    function test_usermeta() {
    106         $key = rand_str();
    107         $val = rand_str();
     106        $key = 'key';
     107        $val = 'value1';
    108108
    109109        // get a meta key that doesn't exist
     
    115115
    116116        // change and get again
    117         $val2 = rand_str();
     117        $val2 = 'value2';
    118118        update_user_meta( self::$author_id, $key, $val2 );
    119119        $this->assertEquals( $val2, get_user_meta( self::$author_id, $key, true ) );
     
    582582    function test_user_update_email_error() {
    583583        $id1 = wp_insert_user( array(
    584             'user_login' => rand_str(),
     584            'user_login' => 'blackburn',
    585585            'user_pass'  => 'password',
    586586            'user_email' => 'blackburn@battlefield4.com',
     
    589589
    590590        $id2 = wp_insert_user( array(
    591             'user_login' => rand_str(),
     591            'user_login' => 'miller',
    592592            'user_pass'  => 'password',
    593593            'user_email' => 'miller@battlefield4.com',
  • trunk/tests/phpunit/tests/xmlrpc/wp/getPosts.php

    r35242 r38382  
    137137        $this->make_user_by_role( 'editor' );
    138138
    139         $post_ids[] = self::factory()->post->create( array( 'post_title' => 'First: ' . rand_str() ) );
    140         $post_ids[] = self::factory()->post->create( array( 'post_title' => 'Second: ' . rand_str() ) );
     139        $post_ids[] = self::factory()->post->create( array( 'post_title' => 'First: Hello, World!' ) );
     140        $post_ids[] = self::factory()->post->create( array( 'post_title' => 'Second: Hello, World!' ) );
    141141
    142142        // Search for none of them
    143         $filter = array( 's' => rand_str() );
     143        $filter = array( 's' => 'Third' );
    144144        $results = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
    145145        $this->assertNotInstanceOf( 'IXR_Error', $results );
  • trunk/tests/phpunit/tests/xmlrpc/wp/getTerms.php

    r38078 r38382  
    6767        register_taxonomy( $tax_name, 'post' );
    6868        for( $i = 0; $i < $num_terms; $i++ )
    69             wp_insert_term( rand_str( 10 ), $tax_name );
     69            wp_insert_term( "term_{$i}", $tax_name );
    7070
    7171
  • trunk/tests/phpunit/tests/xmlrpc/wp/newPost.php

    r36163 r38382  
    234234        $this->make_user_by_role( 'editor' );
    235235
    236         $tag1 = wp_create_tag ( rand_str( 30 ) );
     236        $tag1 = wp_create_tag( 'tag1' );
    237237        $this->assertInternalType( 'array', $tag1 );
    238         $tag2 = wp_create_tag ( rand_str( 30 ) );
     238        $tag2 = wp_create_tag( 'tag2' );
    239239        $this->assertInternalType( 'array', $tag2 );
    240         $tag3 = wp_create_tag ( rand_str( 30 ) );
     240        $tag3 = wp_create_tag( 'tag3' );
    241241        $this->assertInternalType( 'array', $tag3 );
    242242
     
    259259        $this->make_user_by_role( 'editor' );
    260260
    261         $ambiguous_name = rand_str( 30 );
     261        $ambiguous_name = 'foo';
    262262        $parent_cat = wp_create_category( $ambiguous_name );
    263263        $child_cat = wp_create_category( $ambiguous_name, $parent_cat );
    264264
    265         $cat1_name = rand_str( 30 );
     265        $cat1_name = 'cat1';
    266266        $cat1 = wp_create_category( $cat1_name, $parent_cat );
    267         $cat2_name = rand_str( 30 );
     267        $cat2_name = 'cat2';
    268268
    269269        // first a post with valid categories; one that already exists and one to be created
Note: See TracChangeset for help on using the changeset viewer.