Skip to content

Commit 2c414d6

Browse files
committed
More tests
1 parent 2a66931 commit 2c414d6

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

projects/packages/forms/tests/php/contact-form/Contact_Form_Endpoint_Test.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public function test_get_forms_config_returns_401_for_unauthorized() {
463463
}
464464

465465
/**
466-
* Test GET feedback/config unauthorized access.
466+
* Test GET feedback/export unauthorized access.
467467
*/
468468
public function test_get_forms_export_returns_401_for_unauthorized() {
469469
wp_set_current_user( 0 );
@@ -473,7 +473,30 @@ public function test_get_forms_export_returns_401_for_unauthorized() {
473473
}
474474

475475
/**
476-
* Test GET feedback/config unauthorized access.
476+
* Test GET feedback/export unauthorized access.
477+
*/
478+
public function test_get_forms_export_returns_401_for_user_without_export_permission() {
479+
480+
$user_id = wp_insert_user(
481+
array(
482+
'user_login' => 'test_author',
483+
'user_pass' => '123',
484+
'role' => 'author',
485+
)
486+
);
487+
488+
wp_set_current_user( $user_id );
489+
$request = new WP_REST_Request( 'POST', '/wp/v2/feedback/export' );
490+
$request->set_param( 'selected', array( 123 ) );
491+
492+
add_filter( 'wordbless_wpdb_query_results', array( $this, 'get_posts_return_feedback' ), 10, 2 );
493+
$response = $this->server->dispatch( $request );
494+
remove_filter( 'wordbless_wpdb_query_results', array( $this, 'get_posts_return_feedback' ), 10 );
495+
$this->assertEquals( 403, $response->get_status() );
496+
}
497+
498+
/**
499+
* Test GET feedback/export empty authorized access.
477500
*/
478501
public function test_get_forms_export_returns_404_for_authorized_but_empty() {
479502
$request = new WP_REST_Request( 'POST', '/wp/v2/feedback/export' );
@@ -494,7 +517,7 @@ public function get_posts_return_feedback( $results, $query ) {
494517
}
495518

496519
/**
497-
* Test GET feedback/config unauthorized access.
520+
* Test GET feedback/export authorized access.
498521
*/
499522
public function test_get_forms_export_returns_200_for_authorized() {
500523
$request = new WP_REST_Request( 'POST', '/wp/v2/feedback/export' );

0 commit comments

Comments
 (0)