WordPress.org

Make WordPress Core

Changeset 375 in tests


Ignore:
Timestamp:
07/18/11 17:11:51 (3 years ago)
Author:
ryan
Message:

create_post_meta, edit_post_meta, and delete_post_meta cap tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_user_capabilities.php

    r366 r375  
    2828        unset($GLOBALS['wp_user_roles']); 
    2929        #$GLOBALS['wp_roles'] = new WP_Roles(); 
     30    } 
     31 
     32    function _meta_yes_you_can( $key, $post_id, $user_id, $cap ) { 
     33        return true; 
     34    } 
     35 
     36    function _meta_no_you_cant( $key, $post_id, $user_id, $cap ) { 
     37        return false; 
    3038    } 
    3139 
     
    446454        $this->assertFalse($author_2->has_cap('delete_post', $post)); 
    447455        $this->assertFalse($contributor->has_cap('delete_post', $post)); 
     456 
     457        // Test meta authorization callbacks 
     458        if ( function_exists( 'register_meta') ) { 
     459            $this->assertTrue( $admin->has_cap('edit_post_meta',  $post) ); 
     460            $this->assertTrue( $admin->has_cap('create_post_meta',  $post) ); 
     461            $this->assertTrue( $admin->has_cap('delete_post_meta',  $post) ); 
     462 
     463            $this->assertFalse( $admin->has_cap('edit_post_meta', $post, '_protected') ); 
     464            $this->assertFalse( $admin->has_cap('create_post_meta', $post, '_protected') ); 
     465            $this->assertFalse( $admin->has_cap('delete_post_meta', $post, '_protected') ); 
     466 
     467            register_meta( '_protected', 'post', array( 'auth_callback' => array( &$this, '_meta_yes_you_can' ) ) ); 
     468            $this->assertTrue( $admin->has_cap('edit_post_meta',  $post, '_protected') ); 
     469            $this->assertTrue( $admin->has_cap('create_post_meta',  $post, '_protected') ); 
     470            $this->assertTrue( $admin->has_cap('delete_post_meta',  $post, '_protected') ); 
     471 
     472            $this->assertTrue( $admin->has_cap('edit_post_meta', $post, 'not_protected') ); 
     473            $this->assertTrue( $admin->has_cap('create_post_meta', $post, 'not_protected') ); 
     474            $this->assertTrue( $admin->has_cap('delete_post_meta', $post, 'not_protected') ); 
     475 
     476            register_meta( 'not_protected', 'post', array( 'auth_callback' => array( &$this, '_meta_no_you_cant') ) ); 
     477            $this->assertFalse( $admin->has_cap('edit_post_meta',  $post, 'not_protected') ); 
     478            $this->assertFalse( $admin->has_cap('create_post_meta',  $post, 'not_protected') ); 
     479            $this->assertFalse( $admin->has_cap('delete_post_meta',  $post, 'not_protected') ); 
     480        } 
    448481    } 
    449482 
Note: See TracChangeset for help on using the changeset viewer.