mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
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
This commit is contained in:
33
tests/phpunit/tests/post/wpCountAttachments.php
Normal file
33
tests/phpunit/tests/post/wpCountAttachments.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user