| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * @group post
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | class 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 = new stdClass();;
|
|---|
| 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 | $numericstring = '1.4';
|
|---|
| 51 | $post = WP_Post::get_instance($numericstring);
|
|---|
| 52 | $this->assertTrue($post instanceof WP_Post);
|
|---|
| 53 |
|
|---|
| 54 | $post = WP_Post::get_instance(NULL);
|
|---|
| 55 | $this->assertFalse($post);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | ?>
|
|---|