Make WordPress Core

Changeset 1158 in tests for trunk/tests/term.php


Ignore:
Timestamp:
11/27/2012 07:30:41 PM (14 years ago)
Author:
ryan
Message:

Test invalidation of object term relationship cache. see #WP22560

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/term.php

    r1048 r1158  
    175175                $this->assertEquals( $tt_1[1], $tt_2[0] );
    176176
     177        }
     178
     179        /**
     180         * @ticket 22560
     181         */
     182        function test_object_term_cache() {
     183                $post_id = $this->factory->post->create();
     184
     185                $terms_1 = array('foo', 'bar', 'baz');
     186                $terms_2 = array('bar', 'bing');
     187
     188                // Cache should be empty after a set.
     189                $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
     190                $this->assertEquals( 3, count($tt_1) );
     191                $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships') );
     192
     193                // wp_get_object_terms() does not prime the cache.
     194                wp_get_object_terms( $post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id') );
     195                $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships') );
     196
     197                // get_the_terms() does prime the cache.
     198                $terms = get_the_terms( $post_id, $this->taxonomy );
     199                $cache = wp_cache_get( $post_id, $this->taxonomy . '_relationships');
     200                $this->assertInternalType( 'array', $cache );
     201
     202                // Cache should be empty after a set.
     203                $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
     204                $this->assertEquals( 2, count($tt_2) );
     205                $this->assertFalse( wp_cache_get( $post_id, $this->taxonomy . '_relationships') );
    177206        }
    178207
Note: See TracChangeset for help on using the changeset viewer.