wordpress-develop/tests/phpunit/tests/post/wpCountAttachments.php
Jb Audras 0cfcb3e272 Media: Add caching to wp_count_attachments().
This changeset adds caching to `wp_count_attachments()`, for better consistency with `wp_count_posts()`.

Props jeherve, antpb, mukesh27, robinwpdeveloper, costdev.
Fixes #55227.


git-svn-id: https://develop.svn.wordpress.org/trunk@54255 602fd350-edb4-49c9-b593-d223f7449a82
2022-09-20 14:20:57 +00:00

34 lines
665 B
PHP

<?php
/**
* @group post
* @group media
* @group upload
*
* @covers ::wp_count_attachments
*/
class Tests_Post_wpCountAttachments extends WP_UnitTestCase {
/**
* Tests that the result is cached.
*
* @ticket 55227
*/
public function test_wp_count_attachments_should_cache_the_result() {
$mime_type = 'image/jpeg';
$cache_key = 'attachments:image_jpeg';
self::factory()->post->create_many(
3,
array(
'post_type' => 'attachment',
'post_mime_type' => $mime_type,
)
);
$expected = wp_count_attachments( $mime_type );
$actual = wp_cache_get( $cache_key, 'counts' );
$this->assertEquals( $expected, $actual );
}
}