WordPress.org

Make WordPress Core

Changeset 1159 in tests


Ignore:
Timestamp:
11/29/12 15:59:16 (17 months ago)
Author:
nacin
Message:

Update capabilities test to reflect that create_posts is not a real cap, but rather an alias on the post type object. see #WP16714.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/user/capabilities.php

    r1117 r1159  
    487487        $this->assertFalse($contributor->has_cap('publish_post', $post)); 
    488488 
    489         // administrators, editors, and authors can create posts 
    490         $this->assertTrue($admin->has_cap('create_posts', 'post')); 
    491         $this->assertTrue($author->has_cap('create_posts', 'post')); 
    492         $this->assertTrue($editor->has_cap('create_posts', 'post')); 
    493         $this->assertTrue($author_2->has_cap('create_posts', 'post')); 
    494         $this->assertTrue($contributor->has_cap('create_posts', 'post')); 
    495  
    496         // Defaults to post_type of post 
    497         $this->assertTrue($admin->has_cap('create_posts')); 
    498         $this->assertTrue($author->has_cap('create_posts')); 
    499         $this->assertTrue($editor->has_cap('create_posts')); 
    500         $this->assertTrue($author_2->has_cap('create_posts')); 
    501         $this->assertTrue($contributor->has_cap('create_posts')); 
    502  
    503         // Dummy post type 
    504         $this->assertFalse($admin->has_cap('create_posts', 'foobar')); 
    505         $this->assertFalse($author->has_cap('create_posts', 'foobar')); 
    506         $this->assertFalse($editor->has_cap('create_posts', 'foobar')); 
    507         $this->assertFalse($author_2->has_cap('create_posts', 'foobar')); 
    508         $this->assertFalse($contributor->has_cap('create_posts', 'foobar')); 
    509  
    510         // No longer a dummy type. Maps to primitive capability edit_posts. 
    511         register_post_type( 'foobar' ); 
    512         $this->assertTrue($admin->has_cap('create_posts', 'foobar')); 
    513         $this->assertTrue($author->has_cap('create_posts', 'foobar')); 
    514         $this->assertTrue($editor->has_cap('create_posts', 'foobar')); 
    515         $this->assertTrue($author_2->has_cap('create_posts', 'foobar')); 
    516         $this->assertTrue($contributor->has_cap('create_posts', 'foobar')); 
    517  
    518         // Primitive capability edit_foobars is not assigned to any users. 
    519         register_post_type( 'foobar', array( 'capability_type' => array( 'foobar', 'foobars' ) ) ); 
    520         $this->assertFalse($admin->has_cap('create_posts', 'foobar')); 
    521         $this->assertFalse($author->has_cap('create_posts', 'foobar')); 
    522         $this->assertFalse($editor->has_cap('create_posts', 'foobar')); 
    523         $this->assertFalse($author_2->has_cap('create_posts', 'foobar')); 
    524         $this->assertFalse($contributor->has_cap('create_posts', 'foobar')); 
    525  
    526         // Add edit_foobars primitive cap to a user. 
    527         $admin->add_cap( 'edit_foobars', true ); 
    528         $admin = new WP_User( $admin->ID ); 
    529         $this->assertTrue($admin->has_cap('create_posts', 'foobar')); 
    530         $this->assertFalse($author->has_cap('create_posts', 'foobar')); 
    531         $this->assertFalse($editor->has_cap('create_posts', 'foobar')); 
    532         $this->assertFalse($author_2->has_cap('create_posts', 'foobar')); 
    533         $this->assertFalse($contributor->has_cap('create_posts', 'foobar')); 
    534  
    535         _unregister_post_type( 'foobar' ); 
    536  
    537489        register_post_type( 'something', array( 'capabilities' => array( 'edit_posts' => 'draw_somethings' ) ) ); 
    538490        $something = get_post_type_object( 'something' ); 
     
    571523            $this->assertFalse( $admin->has_cap('delete_post_meta',  $post, 'not_protected') ); 
    572524        } 
     525    } 
     526 
     527    /** 
     528     * @ticket 16714 
     529     */ 
     530    function test_create_posts_caps() { 
     531        $author = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) ); 
     532        $admin = new WP_User( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); 
     533        $author_2 = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) ); 
     534        $editor = new WP_User( $this->factory->user->create( array( 'role' => 'editor' ) ) ); 
     535        $contributor = new WP_User( $this->factory->user->create( array( 'role' => 'contributor' ) ) ); 
     536 
     537        // create_posts isn't a real cap. 
     538        $this->assertFalse($admin->has_cap('create_posts')); 
     539        $this->assertFalse($author->has_cap('create_posts')); 
     540        $this->assertFalse($editor->has_cap('create_posts')); 
     541        $this->assertFalse($author_2->has_cap('create_posts')); 
     542        $this->assertFalse($contributor->has_cap('create_posts')); 
     543 
     544        register_post_type( 'foobar' ); 
     545        $cap = get_post_type_object( 'foobar' )->cap; 
     546 
     547        $this->assertEquals( 'edit_posts', $cap->create_posts ); 
     548 
     549        $this->assertTrue($admin->has_cap( $cap->create_posts )); 
     550 
     551        $this->assertTrue($admin->has_cap( $cap->create_posts )); 
     552        $this->assertTrue($author->has_cap( $cap->create_posts )); 
     553        $this->assertTrue($editor->has_cap( $cap->create_posts )); 
     554        $this->assertTrue($author_2->has_cap( $cap->create_posts )); 
     555        $this->assertTrue($contributor->has_cap( $cap->create_posts )); 
     556 
     557        _unregister_post_type( 'foobar' ); 
     558 
     559        // Primitive capability edit_foobars is not assigned to any users. 
     560        register_post_type( 'foobar', array( 'capability_type' => array( 'foobar', 'foobars' ) ) ); 
     561        $cap = get_post_type_object( 'foobar' )->cap; 
     562 
     563        $this->assertFalse($admin->has_cap( $cap->create_posts )); 
     564        $this->assertFalse($author->has_cap( $cap->create_posts )); 
     565        $this->assertFalse($editor->has_cap( $cap->create_posts )); 
     566        $this->assertFalse($author_2->has_cap( $cap->create_posts )); 
     567        $this->assertFalse($contributor->has_cap( $cap->create_posts )); 
     568 
     569        // Add edit_foobars primitive cap to a user. 
     570        $admin->add_cap( 'edit_foobars', true ); 
     571        $admin = new WP_User( $admin->ID ); 
     572        $this->assertTrue($admin->has_cap( $cap->create_posts )); 
     573        $this->assertFalse($author->has_cap( $cap->create_posts )); 
     574        $this->assertFalse($editor->has_cap( $cap->create_posts )); 
     575        $this->assertFalse($author_2->has_cap( $cap->create_posts )); 
     576        $this->assertFalse($contributor->has_cap( $cap->create_posts )); 
     577 
     578        _unregister_post_type( 'foobar' ); 
    573579    } 
    574580 
Note: See TracChangeset for help on using the changeset viewer.