WordPress.org

Make WordPress Core

Ticket #38433: 38433.2.diff

File 38433.2.diff, 3.1 KB (added by santilinwp, 10 months ago)

An extended patch which demostrates the duplicating of tests (multisite and not multisite)

  • tests/phpunit/tests/user/capabilities.php

    diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php
    index 86d70c3ea2..b1d2ff66f9 100644
    a b class Tests_User_Capabilities extends WP_UnitTestCase { 
    15081508
    15091509                $this->assertTrue( current_user_can_for_blog( get_current_blog_id(), 'edit_posts' ) );
    15101510                $this->assertFalse( current_user_can_for_blog( get_current_blog_id(), 'foo_the_bar' ) );
    1511                 if ( ! is_multisite() ) {
    1512                         $this->assertTrue( current_user_can_for_blog( 12345, 'edit_posts' ) );
    1513                         return;
    1514                 }
     1511                $this->assertTrue( current_user_can_for_blog( 12345, 'edit_posts' ) );
     1512
     1513                wp_set_current_user( $old_uid );
     1514        }
     1515
     1516        /**
     1517         * @group ms-required
     1518         */
     1519        function test_multisite_current_user_can_for_blog() {
     1520                global $wpdb;
     1521
     1522                $user    = self::$users['administrator'];
     1523                $old_uid = get_current_user_id();
     1524                wp_set_current_user( $user->ID );
     1525
     1526                $this->assertTrue( current_user_can_for_blog( get_current_blog_id(), 'edit_posts' ) );
     1527                $this->assertFalse( current_user_can_for_blog( get_current_blog_id(), 'foo_the_bar' ) );
    15151528
    15161529                $suppress = $wpdb->suppress_errors();
    15171530                $this->assertFalse( current_user_can_for_blog( 12345, 'edit_posts' ) );
    class Tests_User_Capabilities extends WP_UnitTestCase { 
    15241537                wp_set_current_user( $old_uid );
    15251538        }
    15261539
     1540
    15271541        /**
    15281542         * @group ms-required
    15291543         */
    class Tests_User_Capabilities extends WP_UnitTestCase { 
    15721586                $user->remove_cap( 'publish_posts' );
    15731587                $this->assertFalse( $user->has_cap( 'publish_posts' ) );
    15741588        }
    1575 
     1589        /**
     1590         * @group santilin
     1591         */
    15761592        function test_subscriber_cant_edit_posts() {
    15771593                $user = self::$users['subscriber'];
    15781594                wp_set_current_user( $user->ID );
    class Tests_User_Capabilities extends WP_UnitTestCase { 
    15801596                $post = self::factory()->post->create( array( 'post_author' => 1 ) );
    15811597
    15821598                $this->assertFalse( current_user_can( 'edit_post', $post ) );
     1599                $this->assertFalse( current_user_can_for_blog( get_current_blog_id(), 'edit_post', $post ) );
     1600                $this->assertFalse( current_user_can( 'edit_post', $post + 1 ) );
     1601                $this->assertFalse( current_user_can_for_blog( get_current_blog_id(), 'edit_post', $post + 1 ) );
     1602        }
     1603
     1604        /**
     1605         * @group santilin
     1606         */
     1607        function test_editor_can_edit_posts() {
     1608                $user = self::$users['editor'];
     1609                wp_set_current_user( $user->ID );
     1610
     1611                $post = self::factory()->post->create( array( 'post_author' => $user->ID ) );
     1612
     1613                $this->assertTrue( current_user_can( 'edit_post', $post ) );
    15831614                $this->assertFalse( current_user_can( 'edit_post', $post + 1 ) );
     1615                $this->assertTrue( current_user_can_for_blog( get_current_blog_id(), 'edit_post', $post ) );
     1616                $this->assertFalse( current_user_can_for_blog( get_current_blog_id(), 'edit_post', $post + 1 ) );
     1617                if ( is_multisite() ) {
     1618                        $this->assertFalse( current_user_can_for_blog( 12345, 'edit_post', $post ) );
     1619                        $this->assertFalse( current_user_can_for_blog( 12345, 'edit_post', $post + 1 ) );
     1620                } else {
     1621                        $this->assertTrue( current_user_can_for_blog( 12345, 'edit_post', $post ) );
     1622                        $this->assertFalse( current_user_can_for_blog( 12345, 'edit_post', $post + 1 ) );
     1623                }
    15841624        }
    15851625
    15861626        /**