mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646], [51650], [51651], [51860], [52264], [52265], [53489], [53863]. See #56793. git-svn-id: https://develop.svn.wordpress.org/trunk@54704 602fd350-edb4-49c9-b593-d223f7449a82
66 lines
1.3 KiB
PHP
66 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group comment
|
|
*
|
|
* @covers WP_Comment::get_instance
|
|
*/
|
|
class Tests_Comment_WpComment extends WP_UnitTestCase {
|
|
protected static $comment_id;
|
|
|
|
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
|
|
global $wpdb;
|
|
|
|
// Ensure that there is a comment with ID 1.
|
|
$comment_1 = WP_Comment::get_instance( 1 );
|
|
if ( ! $comment_1 ) {
|
|
$wpdb->insert(
|
|
$wpdb->comments,
|
|
array(
|
|
'comment_ID' => 1,
|
|
)
|
|
);
|
|
|
|
clean_comment_cache( 1 );
|
|
}
|
|
|
|
self::$comment_id = $factory->comment->create();
|
|
}
|
|
|
|
/**
|
|
* @ticket 37738
|
|
*/
|
|
public function test_get_instance_should_work_for_numeric_string() {
|
|
$found = WP_Comment::get_instance( (string) self::$comment_id );
|
|
|
|
$this->assertEquals( self::$comment_id, $found->comment_ID );
|
|
}
|
|
|
|
/**
|
|
* @ticket 37738
|
|
*/
|
|
public function test_get_instance_should_fail_for_negative_number() {
|
|
$found = WP_Comment::get_instance( -self::$comment_id );
|
|
|
|
$this->assertFalse( $found );
|
|
}
|
|
|
|
/**
|
|
* @ticket 37738
|
|
*/
|
|
public function test_get_instance_should_fail_for_non_numeric_string() {
|
|
$found = WP_Comment::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_Comment::get_instance( 1.0 );
|
|
|
|
$this->assertEquals( 1, $found->comment_ID );
|
|
}
|
|
}
|