Skip to content

Commit 392e2a3

Browse files
committed
Tests: Add a test for wp_ajax_logged_in().
Check that the handler responds with `1` for a logged-in user. Developed in: #11836 Props pbearne. Fixes #65242. git-svn-id: https://develop.svn.wordpress.org/trunk@65291 602fd350-edb4-49c9-b593-d223f7449a82
1 parent cfdb7a1 commit 392e2a3

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Testing wp_ajax_logged_in() functionality.
4+
*
5+
* @package WordPress
6+
* @subpackage UnitTests
7+
* @since 6.8.0
8+
*/
9+
10+
/**
11+
* Admin Ajax functions to be tested.
12+
*/
13+
require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
14+
15+
/**
16+
* Testing wp_ajax_logged_in() functionality.
17+
*
18+
* @group ajax
19+
*
20+
* @covers ::wp_ajax_logged_in
21+
*/
22+
class Tests_Ajax_WpAjaxLoggedIn extends WP_Ajax_UnitTestCase {
23+
24+
/**
25+
* Tests the logged-in AJAX action.
26+
*
27+
* @ticket 65242
28+
*/
29+
public function test_wp_ajax_logged_in() {
30+
// Become a subscriber.
31+
$this->_setRole( 'subscriber' );
32+
33+
// Set up the request.
34+
$_REQUEST['action'] = 'logged-in';
35+
36+
// Make the request.
37+
try {
38+
$this->_handleAjax( 'logged-in' );
39+
} catch ( WPAjaxDieContinueException $e ) {
40+
// Expected exception.
41+
unset( $e );
42+
} catch ( WPAjaxDieStopException $e ) {
43+
$this->_last_response = $e->getMessage();
44+
}
45+
46+
// The response should be 1.
47+
$this->assertSame( '1', $this->_last_response, 'The response should be 1 for logged-in users' );
48+
}
49+
}

0 commit comments

Comments
 (0)