Make WordPress Core

Ticket #37738: class-wp-post.php

File class-wp-post.php, 1.3 KB (added by deeptiboddapati, 8 years ago)

Test class for WP_Post:get_instance showing where it fails.

Line 
1<?php 
2/**
3 * @group post
4*/
5
6class Tests_WP_Post extends WP_UnitTestCase {
7
8        public function test_get_instance(){
9                global $wpdb;
10
11                // Gather post data.
12                $this->assertNull(get_post(1));
13                $my_post = array(
14                        'ID' => 1,
15                        'post_title'    => 'My post',
16                        'post_content'  => 'This is my post.',
17                        'post_status'   => 'publish',
18                        'post_author'   => 1,
19                        );
20
21                // Insert the post into the database.
22                // using $wpdb-> insert because wp_insert_post doesn't start at id = 1
23                $wpdb->insert( $wpdb->prefix.'posts',$my_post);
24                $this->assertTrue(get_post(1) instanceof WP_Post);
25               
26                $arr =array(1,4,5);
27                $post = WP_Post::get_instance($arr);
28                $this->assertFalse($post);
29
30                $obj = (object) array(1,4,5);
31                $post = WP_Post::get_instance($obj);
32                $this->assertFalse($post);
33
34                $bool = (bool) 1;
35                $post = WP_Post::get_instance($bool);
36                $this->assertTrue($post instanceof WP_Post);
37
38                $int = (int) 1;
39                $post = WP_Post::get_instance($int);
40                $this->assertTrue($post instanceof WP_Post);
41
42                $float = 1.4;
43                $post = WP_Post::get_instance($float);
44                $this->assertTrue($post instanceof WP_Post);
45
46                $string = "Winter is Coming";
47                $post = WP_Post::get_instance($string);
48                $this->assertFalse($post);
49
50
51                $post = WP_Post::get_instance(NULL);
52                $this->assertFalse($post);
53        }
54       
55
56}
57
58
59
60
61
62
63
64
65?>