WordPress.org

Make WordPress Core

Changeset 445 in tests


Ignore:
Timestamp:
09/29/11 06:42:41 (3 years ago)
Author:
nacin
Message:

Add metadata testcases for double-stripslashing when update_metadata() calls add_metadata(). see #17343.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_meta.php

    r428 r445  
    102102        $this->assertFalse( metadata_exists( 'user',  1234567890, 'meta_key' ) ); 
    103103    } 
     104 
     105    function test_metadata_slashes() { 
     106        $key = rand_str(); 
     107        $value = 'Test\\singleslash'; 
     108        $expected = 'Testsingleslash'; 
     109        $value2 = 'Test\\\\doubleslash'; 
     110        $expected2 = 'Test\\doubleslash'; 
     111        $this->assertFalse( metadata_exists( 'user', $this->author->ID, $key ) ); 
     112        $this->assertFalse( delete_metadata( 'user', $this->author->ID, $key ) ); 
     113        $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) ); 
     114        $this->assertInternalType( 'int', add_metadata( 'user', $this->author->ID, $key, $value ) ); 
     115        $this->assertEquals( $expected, get_metadata( 'user', $this->author->ID, $key, true ) ); 
     116        $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) ); 
     117        $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) ); 
     118        $this->assertInternalType( 'int', update_metadata( 'user', $this->author->ID, $key, $value ) ); 
     119        $this->assertEquals( $expected, get_metadata( 'user', $this->author->ID, $key, true ) ); 
     120        $this->assertTrue( update_metadata( 'user', $this->author->ID, $key, 'blah' ) ); 
     121        $this->assertEquals( 'blah', get_metadata( 'user', $this->author->ID, $key, true ) ); 
     122        $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) ); 
     123        $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) ); 
     124        $this->assertFalse( metadata_exists( 'user', $this->author->ID, $key ) ); 
     125 
     126        // Test overslashing 
     127        $this->assertInternalType( 'int', add_metadata( 'user', $this->author->ID, $key, $value2 ) ); 
     128        $this->assertEquals( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) ); 
     129        $this->assertTrue( delete_metadata( 'user', $this->author->ID, $key ) ); 
     130        $this->assertSame( '', get_metadata( 'user', $this->author->ID, $key, true ) ); 
     131        $this->assertInternalType( 'int', update_metadata( 'user', $this->author->ID, $key, $value2 ) ); 
     132        $this->assertEquals( $expected2, get_metadata( 'user', $this->author->ID, $key, true ) ); 
     133    } 
    104134} 
Note: See TracChangeset for help on using the changeset viewer.