mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
[https://github.com/sebastianbergmann/phpunit/blob/9.6/ChangeLog-9.6.md#961---2023-02-03 PHPUnit 9.6.1] deprecated the `assertObjectHasAttribute()` and `assertObjectNotHasAttribute()` methods, leading to deprecation notices in a number of tests. [https://github.com/sebastianbergmann/phpunit/blob/10.1.3/ChangeLog-10.1.md#1010---2023-04-14 PHPUnit 10.1.0] brought the methods back by popular request, though renamed as `assertObjectHasProperty()` and `assertObjectNotHasProperty()`, to prevent confusion with PHP 8.0 attributes. This meant that users which cannot (yet) upgrade to PHPUnit 10.1+ would always have deprecation notices for these methods without recourse. So, after much discussion, the new methods have been backported to [https://github.com/sebastianbergmann/phpunit/blob/9.6/ChangeLog-9.6.md#9611---2023-08-19 PHPUnit 9.6.11], leaving just the 10.0.x series with a deprecation notice and no recourse. What does this mean for WordPress? WordPress uses the [https://github.com/Yoast/PHPUnit-Polyfills PHPUnit Polyfills] to be able to write tests for the most recent versions of PHPUnit, with the Polyfills taking care of polyfilling any new PHPUnit methods on older PHPUnit versions. * The PHPUnit Polyfills 1.x series supports PHPUnit 4.x to 9.x. * The PHPUnit Polyfills 2.x series supports PHPUnit 5.x to 10.x. WordPress currently runs against PHPUnit 6.x to 9.x with PHPUnit Polyfills 1.x, while the new methods were previously only included in PHPUnit Polyfills 2.0.0+, as they were introduced in PHPUnit 10.x. Since the `assertObjectHasProperty()` and `assertObjectNotHasProperty()` methods have been backported to PHPUnit 9.x, the PHPUnit Polyfills will now include these methods in the 1.x series as well. By upgrading to the latest [https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/1.1.0 PHPUnit Polyfills 1.1.0] release, we can get rid of the deprecation notices related to the use of the `assertObjectHasAttribute()` and `assertObjectNotHasAttribute()` methods. This could have implications for plugins or themes running integration tests with WordPress if they have set their PHPUnit Polyfills dependency to a fixed version or have a too strict version constraint (limiting the PHPUnit Polyfills to the 1.0.x series). The solution for those plugins or themes is to update their version constraints for the PHPUnit Polyfills to allow for the 1.1.x series. Follow-up to [51559], [51598]. Props jrf, ayeshrajans. Fixes #59150. git-svn-id: https://develop.svn.wordpress.org/trunk@56421 602fd350-edb4-49c9-b593-d223f7449a82
142 lines
2.9 KiB
PHP
142 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Test `update_post_cache()`.
|
|
*
|
|
* @package WordPress
|
|
*/
|
|
|
|
/**
|
|
* Test class for `update_post_cache()`.
|
|
*
|
|
* @group post
|
|
* @group query
|
|
*
|
|
* @covers ::update_post_cache
|
|
*/
|
|
class Tests_Post_UpdatePostCache extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Post IDs from the shared fixture.
|
|
*
|
|
* @var int[]
|
|
*/
|
|
public static $post_ids;
|
|
|
|
/**
|
|
* Set up test resources before the class.
|
|
*
|
|
* @param WP_UnitTest_Factory $factory The unit test factory.
|
|
*/
|
|
public static function wpSetupBeforeClass( WP_UnitTest_Factory $factory ) {
|
|
self::$post_ids = $factory->post->create_many( 1 );
|
|
}
|
|
|
|
/**
|
|
* Ensure that `update_post_cache()` returns `null` when
|
|
* `$posts` is empty.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_should_return_null_with_an_empty_array() {
|
|
$posts = array();
|
|
$this->assertNull( update_post_cache( $posts ) );
|
|
}
|
|
|
|
/**
|
|
* Ensure filter = raw is always set via Query.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_query_caches_post_filter() {
|
|
$post_id = self::$post_ids[0];
|
|
$this->go_to( '/' );
|
|
|
|
$cached_post = wp_cache_get( $post_id, 'posts' );
|
|
$this->assertIsObject(
|
|
$cached_post,
|
|
'The cached post is not an object'
|
|
);
|
|
|
|
$this->assertObjectHasProperty(
|
|
'filter',
|
|
$cached_post,
|
|
'The cached post does not have a "filter" property'
|
|
);
|
|
|
|
$this->assertSame(
|
|
'raw',
|
|
$cached_post->filter,
|
|
'The filter is not set to "raw"'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure filter = raw is always set via get_post.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_get_post_caches_post_filter() {
|
|
$post_id = self::$post_ids[0];
|
|
get_post( $post_id );
|
|
|
|
$cached_post = wp_cache_get( $post_id, 'posts' );
|
|
$this->assertSame( 'raw', $cached_post->filter );
|
|
}
|
|
|
|
/**
|
|
* Ensure filter = raw is always set via get_post called with a different filter setting.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_get_post_caches_post_filter_is_always_raw() {
|
|
$post_id = self::$post_ids[0];
|
|
get_post( $post_id, OBJECT, 'display' );
|
|
|
|
$cached_post = wp_cache_get( $post_id, 'posts' );
|
|
$this->assertIsObject(
|
|
$cached_post,
|
|
'The cached post is not an object'
|
|
);
|
|
|
|
$this->assertObjectHasProperty(
|
|
'filter',
|
|
$cached_post,
|
|
'The cached post does not have a "filter" property'
|
|
);
|
|
|
|
$this->assertSame(
|
|
'raw',
|
|
$cached_post->filter,
|
|
'The filter is not set to "raw"'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure filter = raw is always set via get_posts.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_get_posts_caches_post_filter_is_always_raw() {
|
|
$post_id = self::$post_ids[0];
|
|
get_posts( array( 'includes' => $post_id ) );
|
|
|
|
$cached_post = wp_cache_get( $post_id, 'posts' );
|
|
$this->assertIsObject(
|
|
$cached_post,
|
|
'The cached post is not an object'
|
|
);
|
|
|
|
$this->assertObjectHasProperty(
|
|
'filter',
|
|
$cached_post,
|
|
'The cached post does not have a "filter" property'
|
|
);
|
|
|
|
$this->assertSame(
|
|
'raw',
|
|
$cached_post->filter,
|
|
'The filter is not set to "raw"'
|
|
);
|
|
}
|
|
}
|