Make WordPress Core

Ticket #43438: 43438.22.diff

File 43438.22.diff, 3.3 KB (added by desrosj, 6 years ago)
  • tests/phpunit/tests/ajax/PrivacyErasePersonalData.php

     
    140140                add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_custom_personal_data_eraser' ) );
    141141
    142142                $this->_setRole( 'administrator' );
     143                // erase_others_personal_data meta cap in Multisite installation is only granted to those with `manage_network` capability.
     144                if ( is_multisite() ) {
     145                        grant_super_admin( get_current_user_id() );
     146                }
    143147        }
    144148
    145149        /**
     
    149153                remove_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_custom_personal_data_eraser' ) );
    150154                $this->new_callback_value = '';
    151155
     156                if ( is_multisite() ) {
     157                        revoke_super_admin( get_current_user_id() );
     158                }
     159
    152160                parent::tearDown();
    153161        }
    154162
     
    302310        }
    303311
    304312        /**
     313         * Test requests do not succeed on multisite when the current user is not a network admin.
     314         *
     315         * @group multisite
     316         *
     317         * @ticket 43438
     318         */
     319        public function test_error_when_current_user_missing_required_capabilities_multisite() {
     320                if ( ! is_multisite() ) {
     321                        $this->markTestSkipped( 'This test only runs on multisite.' );
     322                }
     323
     324                revoke_super_admin( get_current_user_id() );
     325
     326                $this->_make_ajax_call();
     327
     328                $this->assertFalse( $this->_last_response_parsed['success'] );
     329                $this->assertSame( 'Sorry, you are not allowed to perform this action.', $this->_last_response_parsed['data'] );
     330        }
     331
     332        /**
    305333         * The function should send an error when the nonce does not validate.
    306334         *
    307335         * @since 5.2.0
  • tests/phpunit/tests/ajax/PrivacyExportPersonalData.php

     
    154154                add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'filter_register_custom_personal_data_exporter' ) );
    155155
    156156                $this->_setRole( 'administrator' );
     157                // export_others_personal_data meta cap in Multisite installation is only granted to those with `manage_network` capability.
     158                if ( is_multisite() ) {
     159                        grant_super_admin( get_current_user_id() );
     160                }
    157161        }
    158162
    159163        /**
     
    162166        public function tearDown() {
    163167                remove_filter( 'wp_privacy_personal_data_exporters', array( $this, 'filter_register_custom_personal_data_exporter' ) );
    164168
     169                if ( is_multisite() ) {
     170                        revoke_super_admin( get_current_user_id() );
     171                }
    165172                parent::tearDown();
    166173        }
    167174
     
    264271        }
    265272
    266273        /**
     274         * Test requests do not succeed on multisite when the current user is not a network admin.
     275         *
     276         * @group multisite
     277         *
     278         * @ticket 43438
     279         */
     280        public function test_error_when_current_user_missing_required_capability_multisite() {
     281                if ( ! is_multisite() ) {
     282                        $this->markTestSkipped( 'This test only runs on multisite.' );
     283                }
     284
     285                revoke_super_admin( get_current_user_id() );
     286
     287                $this->_make_ajax_call();
     288
     289                $this->assertFalse( $this->_last_response_parsed['success'] );
     290                $this->assertSame( 'Sorry, you are not allowed to perform this action.', $this->_last_response_parsed['data'] );
     291        }
     292
     293        /**
    267294         * The function should send an error when the nonce does not validate.
    268295         *
    269296         * @since 5.2.0