diff --git a/tests/phpunit/tests/functions/getNumQueries.php b/tests/phpunit/tests/functions/getNumQueries.php new file mode 100644 index 0000000000000..c23a525141eae --- /dev/null +++ b/tests/phpunit/tests/functions/getNumQueries.php @@ -0,0 +1,28 @@ +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.' ); + } +} diff --git a/tests/phpunit/tests/functions/wpGetNocacheHeaders.php b/tests/phpunit/tests/functions/wpGetNocacheHeaders.php new file mode 100644 index 0000000000000..0f2b5eb4fa202 --- /dev/null +++ b/tests/phpunit/tests/functions/wpGetNocacheHeaders.php @@ -0,0 +1,82 @@ +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() + ); + } +}