wordpress-develop/tests/phpunit/tests/post/wpPost.php
Gary Pendergast a75d153eee Coding Standards: Upgrade WPCS to 1.0.0
WPCS 1.0.0 includes a bunch of new auto-fixers, which drops the number of coding standards issues across WordPress significantly. Prior to running the auto-fixers, there were 15,312 issues detected. With this commit, we now drop to 4,769 issues.

This change includes three notable additions:
- Multiline function calls must now put each parameter on a new line.
- Auto-formatting files is now part of the `grunt precommit` script. 
- Auto-fixable coding standards issues will now cause Travis failures.

Fixes #44600.



git-svn-id: https://develop.svn.wordpress.org/trunk@43571 602fd350-edb4-49c9-b593-d223f7449a82
2018-08-17 01:50:26 +00:00

62 lines
1.2 KiB
PHP

<?php
/**
* @group post
*/
class Tests_Post_WpPost extends WP_UnitTestCase {
protected static $post_id;
public static function wpSetUpBeforeClass( $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 = self::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 );
}
}