Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom capability for managing ElasticPress #3313

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unit tests for the new methods
  • Loading branch information
felipeelia committed Feb 15, 2023
commit b33249778a546a035449d43ba29823875f88de01
59 changes: 59 additions & 0 deletions tests/php/TestUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,63 @@ public function testGenerateRequestId() {
add_filter( 'ep_request_id', $custom_request_id );
$this->assertEquals( 'totally-new-request-id', Utils\generate_request_id() );
}

/**
* Test the `get_capability` function
*
* @since 4.5.0
*/
public function testGetCapability() {
$this->assertSame( 'manage_elasticpress', Utils\get_capability() );

/**
* Test the `ep_capability` filter.
*/
$change_cap_name = function( $cap ) {
$this->assertSame( 'manage_elasticpress', $cap );
return 'custom_manage_ep';
};
add_filter( 'ep_capability', $change_cap_name );

$this->assertSame( 'custom_manage_ep', Utils\get_capability() );
}

/**
* Test the `get_network_capability` function
*
* @since 4.5.0
*/
public function testGetNetworkCapability() {
$this->assertSame( 'manage_network_elasticpress', Utils\get_network_capability() );

/**
* Test the `ep_network_capability` filter.
*/
$change_cap_name = function( $cap ) {
$this->assertSame( 'manage_network_elasticpress', $cap );
return 'custom_manage_network_ep';
};
add_filter( 'ep_network_capability', $change_cap_name );

$this->assertSame( 'custom_manage_network_ep', Utils\get_network_capability() );
}

/**
* Test the `get_post_map_capabilities` function
*
* @since 4.5.0
*/
public function testGetPostMapCapabilities() {
$expected = [
'edit_post' => 'manage_elasticpress',
'edit_posts' => 'manage_elasticpress',
'edit_others_posts' => 'manage_elasticpress',
'publish_posts' => 'manage_elasticpress',
'read_post' => 'manage_elasticpress',
'read_private_posts' => 'manage_elasticpress',
'delete_post' => 'manage_elasticpress',
];

$this->assertSame( $expected, Utils\get_post_map_capabilities() );
}
}