Make WordPress Core


Ignore:
Timestamp:
04/02/2015 01:04:22 AM (11 years ago)
Author:
SergeyBiryukov
Message:

Avoid duplicate classes for different terms with UTF-8 slugs in post_class() and body_class().

Fall back to term ID if the sanitized slug is numeric or only contains hyphens.

props SergeyBiryukov, A5hleyRich, sgrant, davideugenepratt.
fixes #30883.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/getPostClass.php

    r31408 r31979  
    5555
    5656        /**
     57         * @ticket 30883
     58         */
     59        public function test_with_utf8_category_slugs() {
     60                $cat_id1 = $this->factory->category->create( array( 'name' => 'Первая рубрика' ) );
     61                $cat_id2 = $this->factory->category->create( array( 'name' => 'Вторая рубрика' ) );
     62                $cat_id3 = $this->factory->category->create( array( 'name' => '25кадр' ) );
     63                wp_set_post_terms( $this->post_id, array( $cat_id1, $cat_id2, $cat_id3 ), 'category' );
     64
     65                $found = get_post_class( '', $this->post_id );
     66
     67                $this->assertContains( "category-$cat_id1", $found );
     68                $this->assertContains( "category-$cat_id2", $found );
     69                $this->assertContains( "category-$cat_id3", $found );
     70        }
     71
     72        /**
     73         * @ticket 30883
     74         */
     75        public function test_with_utf8_tag_slugs() {
     76                $tag_id1 = $this->factory->tag->create( array( 'name' => 'Первая метка' ) );
     77                $tag_id2 = $this->factory->tag->create( array( 'name' => 'Вторая метка' ) );
     78                $tag_id3 = $this->factory->tag->create( array( 'name' => '25кадр' ) );
     79                wp_set_post_terms( $this->post_id, array( $tag_id1, $tag_id2, $tag_id3 ), 'post_tag' );
     80
     81                $found = get_post_class( '', $this->post_id );
     82
     83                $this->assertContains( "tag-$tag_id1", $found );
     84                $this->assertContains( "tag-$tag_id2", $found );
     85                $this->assertContains( "tag-$tag_id3", $found );
     86        }
     87
     88        /**
     89         * @ticket 30883
     90         */
     91        public function test_with_utf8_term_slugs() {
     92                register_taxonomy( 'wptests_tax', 'post' );
     93                $term_id1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Первая метка' ) );
     94                $term_id2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Вторая метка' ) );
     95                $term_id3 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => '25кадр' ) );
     96                wp_set_post_terms( $this->post_id, array( $term_id1, $term_id2, $term_id3 ), 'wptests_tax' );
     97
     98                $found = get_post_class( '', $this->post_id );
     99
     100                $this->assertContains( "wptests_tax-$term_id1", $found );
     101                $this->assertContains( "wptests_tax-$term_id2", $found );
     102                $this->assertContains( "wptests_tax-$term_id3", $found );
     103        }
     104
     105        /**
    57106         * @group cache
    58107         */
Note: See TracChangeset for help on using the changeset viewer.