Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
04d4330
added test for get_num_queries and wp_get_nocache_headers
pbearne Nov 23, 2021
796b742
fixed phpcs
pbearne Nov 23, 2021
61849ab
phpcs
pbearne Nov 23, 2021
51ab9bd
Update tests/phpunit/tests/functions/get_num_queries.php
pbearne Nov 23, 2021
ceb912b
Update tests/phpunit/tests/functions/get_num_queries.php
pbearne Nov 23, 2021
b3bb21b
Update tests/phpunit/tests/functions/get_num_queries.php
pbearne Nov 23, 2021
a18b3bd
Update tests/phpunit/tests/functions/wp_get_nocache_headers.php
pbearne Nov 23, 2021
1cb9b3e
Update tests/phpunit/tests/functions/get_num_queries.php
pbearne Nov 23, 2021
d30ee68
Update tests/phpunit/tests/functions/wp_get_nocache_headers.php
pbearne Nov 23, 2021
ee4959d
Merge branch 'WordPress:trunk' into wp_get_nocache_headers
pbearne Nov 26, 2021
767b0da
Merge branch 'trunk' into wp_get_nocache_headers
peterwilsoncc Nov 5, 2023
561b2ba
Rename file.
peterwilsoncc Nov 5, 2023
6534d17
Various changes to get_num_queries test.
peterwilsoncc Nov 5, 2023
a9389e3
Add to wpdb group as it ensures wpdb->num_queries increases.
peterwilsoncc Nov 5, 2023
10b76cc
Rename file.
peterwilsoncc Nov 5, 2023
3400bd1
Various test changes.
peterwilsoncc Nov 5, 2023
61509cd
CS: Remove excessive line break.
peterwilsoncc Nov 5, 2023
d3f563e
Apply suggestions from code review
peterwilsoncc Nov 5, 2023
17f3d1f
Descriptions I somehow missed out committing earliuer.
peterwilsoncc Nov 6, 2023
0bc93d3
Merge branch 'trunk' into wp_get_nocache_headers
pbearne Jun 26, 2026
7ed0a59
Update `wp_get_nocache_headers` test to reflect added `no-store, priv…
Jun 26, 2026
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
28 changes: 28 additions & 0 deletions tests/phpunit/tests/functions/getNumQueries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Tests for get_num_queries().
*
* @group functions
* @group wpdb
*
* @covers ::get_num_queries
*/
class Tests_Functions_getNumQueries extends WP_UnitTestCase {
/**
* Tests that making a database query increases the number of queries.
*
* @ticket 54490
*/
public function test_get_num_queries() {
global $wpdb;

$current_count = get_num_queries();
$this->assertIsInt( $current_count, 'get_num_queries() did not return an integer.' );

// Do a single database query.
$wpdb->query( 'SELECT NOW();' );

// Check the count increased by one.
$this->assertSame( $current_count + 1, get_num_queries(), 'The number of queries did not increase by one.' );
}
}
82 changes: 82 additions & 0 deletions tests/phpunit/tests/functions/wpGetNocacheHeaders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* Tests for wp_get_nocache_headers().
*
* @group functions
*
* @covers ::wp_get_nocache_headers
*/
class Tests_Functions_wpGetNocacheHeaders extends WP_UnitTestCase {
/**
* User ID.
*
* @var int
*/
public static $user_id;

/**
* Creates a user account for tests.
*
* @param WP_UnitTest_Factory $factory
*/
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$user_id = $factory->user->create();
}

/**
* Tests nocache headers are as expected for a logged out user.
*
* @ticket 54490
*/
public function test_wp_get_nocache_headers_for_logged_out_user() {
$this->assertSameSetsWithIndex(
array(
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
'Cache-Control' => 'no-cache, must-revalidate, max-age=0, no-store, private',
'Last-Modified' => false,
),
wp_get_nocache_headers()
);
}

/**
* Tests nocache headers are as expected for a logged in user.
*
* @ticket 21938
* @ticket 54490
*/
public function test_wp_get_nocache_headers_for_logged_in_user() {
wp_set_current_user( self::$user_id );

$this->assertSameSetsWithIndex(
array(
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
'Cache-Control' => 'no-cache, must-revalidate, max-age=0, no-store, private',
'Last-Modified' => false,
),
wp_get_nocache_headers()
);
}

/**
* Tests the `nocache_headers` filter fires and filters the headers.
*
* @ticket 54490
*/
public function test_filter_nocache_headers() {
add_filter(
'nocache_headers',
static function () {
return array( 'filter_name' => 'nocache_headers' );
}
);

$this->assertSameSetsWithIndex(
array(
'filter_name' => 'nocache_headers',
'Last-Modified' => false,
),
wp_get_nocache_headers()
);
}
}
Loading