WordPress.org

Make WordPress Core

Changeset 1054 in tests


Ignore:
Timestamp:
09/27/12 15:33:54 (19 months ago)
Author:
ryan
Message:

Tests for create_posts capability. see #WP16714

File:
1 edited

Legend:

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

    r1053 r1054  
    486486        // contributors can't 
    487487        $this->assertFalse($contributor->has_cap('publish_post', $post)); 
     488 
     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' ); 
    488536 
    489537        // Test meta authorization callbacks 
Note: See TracChangeset for help on using the changeset viewer.