Make WordPress Core

Changeset 44943


Ignore:
Timestamp:
03/20/2019 05:40:17 PM (7 years ago)
Author:
desrosj
Message:

Tests: Fix failing tests for privacy export/erase requests when running the ajax group for multisite.

Props davidbinda, garrett-eclipse.
Fixes #43438.

Location:
trunk/tests/phpunit/tests/ajax
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/PrivacyErasePersonalData.php

    r44909 r44943  
    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
     
    149153                remove_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_custom_personal_data_eraser' ) );
    150154                $this->new_callback_value = '';
     155
     156                if ( is_multisite() ) {
     157                        revoke_super_admin( get_current_user_id() );
     158                }
    151159
    152160                parent::tearDown();
     
    295303                $this->assertFalse( current_user_can( 'erase_others_personal_data' ) );
    296304                $this->assertFalse( current_user_can( 'delete_users' ) );
     305
     306                $this->_make_ajax_call();
     307
     308                $this->assertFalse( $this->_last_response_parsed['success'] );
     309                $this->assertSame( 'Sorry, you are not allowed to perform this action.', $this->_last_response_parsed['data'] );
     310        }
     311
     312        /**
     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() );
    297325
    298326                $this->_make_ajax_call();
  • trunk/tests/phpunit/tests/ajax/PrivacyExportPersonalData.php

    r44909 r44943  
    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
     
    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        }
     
    261268                $this->assertFalse( $this->_last_response_parsed['success'] );
    262269                $this->assertFalse( current_user_can( 'export_others_personal_data' ) );
     270                $this->assertSame( 'Sorry, you are not allowed to perform this action.', $this->_last_response_parsed['data'] );
     271        }
     272
     273        /**
     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'] );
    263290                $this->assertSame( 'Sorry, you are not allowed to perform this action.', $this->_last_response_parsed['data'] );
    264291        }
Note: See TracChangeset for help on using the changeset viewer.