Make WordPress Core

Ticket #19373: 19373-unittests.diff

File 19373-unittests.diff, 1.9 KB (added by boonebgorges, 10 years ago)

See #30284.

  • tests/phpunit/tests/post.php

    diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
    index cab19d8..0962f92 100644
    class Tests_Post extends WP_UnitTestCase { 
    738738        }
    739739
    740740        /**
     741         * @ticket 19373
     742         */
     743        function test_insert_programmatic_without_current_user_success() {
     744                $this->_unset_current_user();
     745
     746                register_taxonomy( 'test_tax', 'post' );
     747
     748                $title = rand_str();
     749                $post_data = array(
     750                        'post_author' => $this->author_id,
     751                        'post_status' => 'public',
     752                        'post_content' => rand_str(),
     753                        'post_title' => $title,
     754                        'tax_input' => array(
     755                                'test_tax' => array( 'term', 'term2', 'term3' )
     756                        )
     757                );
     758                // with sanitize set to false
     759                $insert_post_id = wp_insert_post( $post_data, true, false );
     760
     761                $post = get_post( $insert_post_id );
     762                $this->assertEquals( $post->post_author, $this->author_id );
     763                $this->assertEquals( $post->post_title, $title );
     764
     765                $terms = wp_get_object_terms( $insert_post_id, 'test_tax' );
     766                $this->assertTrue( ( is_array( $terms ) && count( $terms ) == 3 ) );
     767        }
     768
     769        /**
     770         * @ticket 19373
     771         */
     772        function test_insert_programmatic_without_current_user_fail() {
     773                $this->_unset_current_user();
     774
     775                register_taxonomy( 'test_tax', 'post' );
     776
     777                $title = rand_str();
     778                $post_data = array(
     779                        // post_author not set
     780                        'post_status' => 'public',
     781                        'post_content' => rand_str(),
     782                        'post_title' => $title,
     783                        'tax_input' => array(
     784                                'test_tax' => array( 'term', 'term2', 'term3' )
     785                        )
     786                );
     787                // with sanitize set to false
     788                $insert_post_id = wp_insert_post( $post_data, true, false );
     789
     790                // should error because no default user exists and no post author is passed in
     791                $this->assertInstanceOf( 'WP_Error', $insert_post_id );
     792                $this->assertEquals( 'empty_author', $insert_post_id->get_error_code() );
     793        }
     794
     795        /**
    741796         * @ticket 24803
    742797         */
    743798        function test_wp_count_posts() {