Changeset 1326 in tests
- Timestamp:
- 07/28/2013 11:22:34 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/post.php
r1323 r1326 20 20 parent::tearDown(); 21 21 } 22 22 23 23 // helper function: return the timestamp(s) of cron jobs for the specified hook and post 24 24 function _next_schedule_for_post($hook, $id) { 25 25 return wp_next_scheduled('publish_future_post', array(0=>intval($id))); 26 26 } 27 27 28 // helper function, unsets current user globally 29 function _unset_current_user() { 30 global $current_user, $user_ID; 31 32 $current_user = $user_ID = null; 33 } 34 28 35 // test simple valid behavior: insert and get a post 29 36 function test_vb_insert_get_delete() { … … 694 701 $this->assertEquals( 1, $numpages ); 695 702 $this->assertEquals( array( 'Page 0' ), $pages ); 703 } 704 705 /** 706 * @ticket 19373 707 */ 708 function test_insert_programmatic_sanitized() { 709 $this->_unset_current_user(); 710 711 register_taxonomy( 'test_tax', 'post' ); 712 713 $title = rand_str(); 714 $post_data = array( 715 'post_author' => $this->author_id, 716 'post_status' => 'public', 717 'post_content' => rand_str(), 718 'post_title' => $title, 719 'tax_input' => array( 720 'test_tax' => array( 'term', 'term2', 'term3' ) 721 ) 722 ); 723 $insert_post_id = wp_insert_post( $post_data, true, true ); 724 $this->assertTrue( ( is_int($insert_post_id) && $insert_post_id > 0 ) ); 725 726 $post = get_post( $insert_post_id ); 727 $this->assertEquals( $post->post_author, $this->author_id ); 728 $this->assertEquals( $post->post_title, $title ); 729 } 730 731 /** 732 * @ticket 19373 733 */ 734 function test_insert_programmatic_without_current_user_success() { 735 $this->_unset_current_user(); 736 737 register_taxonomy( 'test_tax', 'post' ); 738 739 $title = rand_str(); 740 $post_data = array( 741 'post_author' => $this->author_id, 742 'post_status' => 'public', 743 'post_content' => rand_str(), 744 'post_title' => $title, 745 'tax_input' => array( 746 'test_tax' => array( 'term', 'term2', 'term3' ) 747 ) 748 ); 749 // with sanitize set to false 750 $insert_post_id = wp_insert_post( $post_data, true, false ); 751 752 $post = get_post( $insert_post_id ); 753 $this->assertEquals( $post->post_author, $this->author_id ); 754 $this->assertEquals( $post->post_title, $title ); 755 756 $terms = wp_get_object_terms( $insert_post_id, 'test_tax' ); 757 $this->assertTrue( ( is_array( $terms ) && count( $terms ) == 3 ) ); 758 } 759 760 /** 761 * @ticket 19373 762 */ 763 function test_insert_programmatic_without_current_user_fail() { 764 $this->_unset_current_user(); 765 766 register_taxonomy( 'test_tax', 'post' ); 767 768 $title = rand_str(); 769 $post_data = array( 770 // post_author not set 771 'post_status' => 'public', 772 'post_content' => rand_str(), 773 'post_title' => $title, 774 'tax_input' => array( 775 'test_tax' => array( 'term', 'term2', 'term3' ) 776 ) 777 ); 778 // with sanitize set to false 779 $insert_post_id = wp_insert_post( $post_data, true, false ); 780 781 // should error because no default user exists and no post author is passed in 782 $this->assertInstanceOf( 'WP_Error', $insert_post_id ); 783 $this->assertEquals( 'empty_author', $insert_post_id->get_error_code() ); 696 784 } 697 785
Note: See TracChangeset
for help on using the changeset viewer.