WordPress.org

Make WordPress Core

Ticket #22023: 22023.term_exists-tests.diff

File 22023.term_exists-tests.diff, 1.9 KB (added by simonwheatley, 7 years ago)

Beef up tests for term_exists

  • tests/phpunit/tests/term.php

     
    5555
    5656        function test_term_exists_known() {
    5757                // insert a term
    58                 $term = rand_str();
    59                 $t = wp_insert_term( $term, $this->taxonomy );
    60                 $this->assertInternalType( 'array', $t );
    61                 $this->assertEquals( $t['term_id'], term_exists($t['term_id']) );
    62                 $this->assertEquals( $t['term_id'], term_exists($term) );
     58                $term_k_name = 'kierkegaard';
     59                $term_k = wp_insert_term( 'kierkegaard', $this->taxonomy );
     60                $this->assertInternalType( 'array', $term_k );
     61                $this->assertEquals( $term_k['term_id'], term_exists($term_k['term_id']) );
     62                $this->assertEquals( $term_k['term_id'], term_exists($term_k_name) );
     63                $term_k_in_tax = term_exists( $term_k['term_id'], $this->taxonomy );
     64                $this->assertEquals( $term_k['term_id'], $term_k_in_tax['term_id'] );
    6365
     66                $term_s = wp_insert_term( 'satre', $this->taxonomy, array( 'parent' => $term_k['term_id'] ) );
     67                $this->assertFalse( is_wp_error( $term_s ) );
     68                $this->assertEquals( $term_s['term_id'], term_exists($term_s['term_id']) );
     69                $term_s_in_tax_with_parent = term_exists( $term_s['term_id'], $this->taxonomy, $term_k['term_id'] );
     70                $this->assertEquals( $term_s['term_id'], $term_s_in_tax_with_parent['term_id'] );
     71
    6472                // clean up
    65                 $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );
     73                wp_delete_term($term_k['term_id'], $this->taxonomy);
     74                wp_delete_term($term_s['term_id'], $this->taxonomy);
    6675        }
    6776
    6877        function test_term_exists_unknown() {
    69                 $this->assertNull( term_exists(rand_str()) );
     78                $this->assertNull( term_exists('nothing') );
    7079                $this->assertEquals( 0, term_exists(0) );
     80                $this->assertEquals( 0, term_exists(99999) );
    7181                $this->assertEquals( 0, term_exists('') );
    7282                $this->assertEquals( 0, term_exists(NULL) );
    7383        }