Make WordPress Core


Ignore:
Timestamp:
02/06/2014 05:19:05 AM (11 years ago)
Author:
wonderboymusic
Message:

Move some cache related tests to the new term/cache.php from [27103].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/cache.php

    r27103 r27104  
    2828
    2929        $this->assertEquals( array( $term_id1 => array( $term_id1_child ), $term_id2 => array( $term_id2_child ) ), $hierarchy );
     30    }
    3031
     32    /**
     33     * @ticket 22526
     34     */
     35    function test_get_taxonomy_last_changed() {
     36        $last_changed = get_taxonomy_last_changed( 'category' );
     37        $last_changed_cache = wp_cache_get( 'last_changed', 'category' );
     38        $this->assertEquals( $last_changed, $last_changed_cache );
     39        wp_cache_delete( 'last_changed', 'category' );
     40        $this->assertEquals( $last_changed, $last_changed_cache );
     41        $last_changed = get_taxonomy_last_changed( 'category' );
     42        $this->assertNotEquals( $last_changed, $last_changed_cache );
     43
     44        $last_changed2 = get_taxonomy_last_changed( 'category' );
     45        $this->factory->category->create();
     46        $last_changed3 = get_taxonomy_last_changed( 'category' );
     47        $this->assertNotEquals( $last_changed2, $last_changed3 );
     48    }
     49
     50    /**
     51     * @ticket 22526
     52     */
     53    function test_set_taxonomy_last_changed() {
     54        $last_changed1 = set_taxonomy_last_changed( 'category' );
     55        $last_changed2 = set_taxonomy_last_changed( 'category' );
     56        $this->assertNotEquals( $last_changed1, $last_changed2 );
     57
     58        $last_changed3 = set_taxonomy_last_changed( 'category' );
     59        $last_changed4 = get_taxonomy_last_changed( 'category' );
     60        $this->assertEquals( $last_changed3, $last_changed4 );
     61    }
     62
     63    /**
     64     * @ticket 22526
     65     */
     66    function test_post_taxonomy_is_fresh() {
     67        $post_id = $this->factory->post->create();
     68        $term_id = $this->factory->category->create( array( 'name' => 'Foo' ) );
     69        wp_set_post_categories( $post_id, $term_id );
     70
     71        $this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) );
     72        $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) );
     73        $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) );
     74
     75        wp_update_term( $term_id, 'category', array( 'name' => 'Bar' ) );
     76
     77        $this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) );
     78        get_the_category( $post_id );
     79        $this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) );
     80    }
     81
     82    /**
     83     * @ticket 22526
     84     */
     85    function test_category_name_change() {
     86        $term = $this->factory->category->create_and_get( array( 'name' => 'Foo' ) );
     87        $post_id = $this->factory->post->create();
     88        wp_set_post_categories( $post_id, $term->term_id );
     89
     90        $post = get_post( $post_id );
     91        $cats1 = get_the_category( $post->ID );
     92        $this->assertEquals( $term->name, reset( $cats1 )->name );
     93
     94        wp_update_term( $term->term_id, 'category', array( 'name' => 'Bar' ) );
     95        $cats2 = get_the_category( $post->ID );
     96        $this->assertNotEquals( $term->name, reset( $cats2 )->name );
     97    }
     98
     99    function test_hierachy_invalidation() {
     100        $tax = 'burrito';
     101        register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) );
     102        $this->assertTrue( get_taxonomy( $tax )->hierarchical );
     103
     104        $step = 1;
     105        $parent_id = 0;
     106        $children = 0;
     107
     108        foreach ( range( 1, 99 ) as $i ) {
     109            switch ( $step ) {
     110            case 1:
     111                $parent = wp_insert_term( 'Parent' . $i, $tax );
     112                $parent_id = $parent['term_id'];
     113                break;
     114            case 2:
     115                $parent = wp_insert_term( 'Child' . $i, $tax, array( 'parent' => $parent_id ) );
     116                $parent_id = $parent['term_id'];
     117                $children++;
     118                break;
     119            case 3:
     120                wp_insert_term( 'Grandchild' . $i, $tax, array( 'parent' => $parent_id ) );
     121                $parent_id = 0;
     122                $children++;
     123                break;
     124            }
     125
     126            $terms = get_terms( $tax, array( 'hide_empty' => false ) );
     127            $this->assertEquals( $i, count( $terms ) );
     128            if ( 1 < $i ) {
     129                $hierarchy = _get_term_hierarchy( $tax );
     130                $this->assertNotEmpty( $hierarchy );
     131                $this->assertEquals( $children, count( $hierarchy, COUNT_RECURSIVE ) - count( $hierarchy ) );
     132            }
     133
     134            if ( $i % 3 === 0 ) {
     135                $step = 1;
     136            } else {
     137                $step++;
     138            }
     139        }
     140
     141        _unregister_taxonomy( $tax );
    31142    }
    32143}
Note: See TracChangeset for help on using the changeset viewer.