Make WordPress Core

Ticket #29589: 29589.unit-tests.diff

File 29589.unit-tests.diff, 1.9 KB (added by georgestephanis, 10 years ago)
  • tests/phpunit/tests/taxonomy.php

     
    296296                $term20 = $this->factory->tag->create( array( 'name' => 'A--' ) );
    297297                $this->assertFalse( is_wp_error( $term20 ) );
    298298        }
     299
     300        function test_term_exists_that_sanitizes_to_empty() {   
     301                wp_insert_term( '//', 'category' );
     302                $this->assertTrue( term_exists( '//' ) );
     303                $this->assertTrue( term_exists( '//', 'category' ) );
     304        }
     305
     306        /**
     307         * Unfinished at the moment, but you should be able to see where it's going.
     308         * Currently, first iteration works, second iteration breaks, due to
     309         *  failure of test_term_exists_that_sanitizes_to_empty
     310         */
     311        function test_insert_terms_that_sanitize_to_empty() {
     312                $post_one = $this->factory->post->create_and_get();
     313                $post_two = $this->factory->post->create_and_get();
     314
     315                $this->assertEquals( 0, term_exists( '>>' ) );
     316                $this->assertEquals( 0, term_exists( '//' ) );
     317
     318                $terms = wp_set_object_terms( $post_one->ID, array( '>>', '//' ), 'category' );
     319
     320                $this->assertEquals( 2, sizeof( $terms ) );
     321                $this->assertEquals( $terms, array_map( 'intval', $terms ) );
     322                $this->assertNotEquals( 0, term_exists( '>>' ), "term_exists( '>>' ) has not found existence of the queried term." );
     323                $this->assertNotEquals( 0, term_exists( '//' ), "term_exists( '//' ) has not found existence of the queried term." );
     324
     325                $terms = wp_set_object_terms( $post_two->ID, array( '>>', '//' ), 'category' );
     326
     327                $this->assertEquals( 2, sizeof( $terms ) );
     328                $this->assertEquals( $terms, array_map( 'intval', $terms ) );
     329                $this->assertNotEquals( 0, term_exists( '>>' ), "term_exists( '>>' ) has not found existence of the queried term." );
     330                $this->assertNotEquals( 0, term_exists( '//' ), "term_exists( '//' ) has not found existence of the queried term." );
     331        }
    299332}