mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
This brings consistency to this often-used method, and allows IDEs to provide help to developers when using its `$factory` parameter. See #51344 git-svn-id: https://develop.svn.wordpress.org/trunk@49603 602fd350-edb4-49c9-b593-d223f7449a82
62 lines
1.2 KiB
PHP
62 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group post
|
|
*/
|
|
class Tests_Post_wpPost extends WP_UnitTestCase {
|
|
protected static $post_id;
|
|
|
|
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
|
|
global $wpdb;
|
|
|
|
// Ensure that there is a post with ID 1.
|
|
if ( ! get_post( 1 ) ) {
|
|
$wpdb->insert(
|
|
$wpdb->posts,
|
|
array(
|
|
'ID' => 1,
|
|
'post_title' => 'Post 1',
|
|
)
|
|
);
|
|
}
|
|
|
|
self::$post_id = $factory->post->create();
|
|
}
|
|
|
|
/**
|
|
* @ticket 37738
|
|
*/
|
|
public function test_get_instance_should_work_for_numeric_string() {
|
|
$found = WP_Post::get_instance( (string) self::$post_id );
|
|
|
|
$this->assertSame( self::$post_id, $found->ID );
|
|
}
|
|
|
|
/**
|
|
* @ticket 37738
|
|
*/
|
|
public function test_get_instance_should_fail_for_negative_number() {
|
|
$found = WP_Post::get_instance( -self::$post_id );
|
|
|
|
$this->assertFalse( $found );
|
|
}
|
|
|
|
/**
|
|
* @ticket 37738
|
|
*/
|
|
public function test_get_instance_should_fail_for_non_numeric_string() {
|
|
$found = WP_Post::get_instance( 'abc' );
|
|
|
|
$this->assertFalse( $found );
|
|
}
|
|
|
|
/**
|
|
* @ticket 37738
|
|
*/
|
|
public function test_get_instance_should_succeed_for_float_that_is_equal_to_post_id() {
|
|
$found = WP_Post::get_instance( 1.0 );
|
|
|
|
$this->assertSame( 1, $found->ID );
|
|
}
|
|
}
|