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

Props davidbinda, garrett-eclipse.
Fixes #43438.

git-svn-id: https://develop.svn.wordpress.org/trunk@44943 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2019-03-20 17:40:17 +00:00
parent 7834856fcb
commit 34251aa2ab
2 changed files with 55 additions and 0 deletions

View File

@ -140,6 +140,10 @@ class Tests_Ajax_PrivacyErasePersonalData extends WP_Ajax_UnitTestCase {
add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_custom_personal_data_eraser' ) );
$this->_setRole( 'administrator' );
// erase_others_personal_data meta cap in Multisite installation is only granted to those with `manage_network` capability.
if ( is_multisite() ) {
grant_super_admin( get_current_user_id() );
}
}
/**
@ -149,6 +153,10 @@ class Tests_Ajax_PrivacyErasePersonalData extends WP_Ajax_UnitTestCase {
remove_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_custom_personal_data_eraser' ) );
$this->new_callback_value = '';
if ( is_multisite() ) {
revoke_super_admin( get_current_user_id() );
}
parent::tearDown();
}
@ -301,6 +309,26 @@ class Tests_Ajax_PrivacyErasePersonalData extends WP_Ajax_UnitTestCase {
$this->assertSame( 'Sorry, you are not allowed to perform this action.', $this->_last_response_parsed['data'] );
}
/**
* Test requests do not succeed on multisite when the current user is not a network admin.
*
* @group multisite
*
* @ticket 43438
*/
public function test_error_when_current_user_missing_required_capabilities_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test only runs on multisite.' );
}
revoke_super_admin( get_current_user_id() );
$this->_make_ajax_call();
$this->assertFalse( $this->_last_response_parsed['success'] );
$this->assertSame( 'Sorry, you are not allowed to perform this action.', $this->_last_response_parsed['data'] );
}
/**
* The function should send an error when the nonce does not validate.
*

View File

@ -154,6 +154,10 @@ class Tests_Ajax_PrivacyExportPersonalData extends WP_Ajax_UnitTestCase {
add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'filter_register_custom_personal_data_exporter' ) );
$this->_setRole( 'administrator' );
// export_others_personal_data meta cap in Multisite installation is only granted to those with `manage_network` capability.
if ( is_multisite() ) {
grant_super_admin( get_current_user_id() );
}
}
/**
@ -162,6 +166,9 @@ class Tests_Ajax_PrivacyExportPersonalData extends WP_Ajax_UnitTestCase {
public function tearDown() {
remove_filter( 'wp_privacy_personal_data_exporters', array( $this, 'filter_register_custom_personal_data_exporter' ) );
if ( is_multisite() ) {
revoke_super_admin( get_current_user_id() );
}
parent::tearDown();
}
@ -263,6 +270,26 @@ class Tests_Ajax_PrivacyExportPersonalData extends WP_Ajax_UnitTestCase {
$this->assertSame( 'Sorry, you are not allowed to perform this action.', $this->_last_response_parsed['data'] );
}
/**
* Test requests do not succeed on multisite when the current user is not a network admin.
*
* @group multisite
*
* @ticket 43438
*/
public function test_error_when_current_user_missing_required_capability_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test only runs on multisite.' );
}
revoke_super_admin( get_current_user_id() );
$this->_make_ajax_call();
$this->assertFalse( $this->_last_response_parsed['success'] );
$this->assertSame( 'Sorry, you are not allowed to perform this action.', $this->_last_response_parsed['data'] );
}
/**
* The function should send an error when the nonce does not validate.
*