Ticket #30883: 30883.2.diff
File 30883.2.diff, 8.2 KB (added by , 10 years ago) |
---|
-
src/wp-includes/post-template.php
471 471 continue; 472 472 } 473 473 474 $term_class = sanitize_html_class( $term->slug, $term->term_id ); 475 if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) { 476 $term_class = $term->term_id; 477 } 478 474 479 // 'post_tag' uses the 'tag' prefix for backward compatibility. 475 480 if ( 'post_tag' == $taxonomy ) { 476 $classes[] = 'tag-' . sanitize_html_class( $term->slug, $term->term_id );481 $classes[] = 'tag-' . $term_class; 477 482 } else { 478 $classes[] = sanitize_html_class( $taxonomy . '-' . $term ->slug, $taxonomy . '-' . $term->term_id );483 $classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id ); 479 484 } 480 485 } 481 486 } … … 588 593 $cat = $wp_query->get_queried_object(); 589 594 $classes[] = 'category'; 590 595 if ( isset( $cat->term_id ) ) { 591 $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id ); 596 $cat_class = sanitize_html_class( $cat->slug, $cat->term_id ); 597 if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) { 598 $cat_class = $cat->term_id; 599 } 600 601 $classes[] = 'category-' . $cat_class; 592 602 $classes[] = 'category-' . $cat->term_id; 593 603 } 594 604 } elseif ( is_tag() ) { 595 $tag s= $wp_query->get_queried_object();605 $tag = $wp_query->get_queried_object(); 596 606 $classes[] = 'tag'; 597 if ( isset( $tags->term_id ) ) { 598 $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id ); 599 $classes[] = 'tag-' . $tags->term_id; 607 if ( isset( $tag->term_id ) ) { 608 $tag_class = sanitize_html_class( $tag->slug, $tag->term_id ); 609 if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) { 610 $tag_class = $tag->term_id; 611 } 612 613 $classes[] = 'tag-' . $tag_class; 614 $classes[] = 'tag-' . $tag->term_id; 600 615 } 601 616 } elseif ( is_tax() ) { 602 617 $term = $wp_query->get_queried_object(); 603 618 if ( isset( $term->term_id ) ) { 619 $term_class = sanitize_html_class( $term->slug, $term->term_id ); 620 if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) { 621 $term_class = $term->term_id; 622 } 623 604 624 $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy ); 605 $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );625 $classes[] = 'term-' . $term_class; 606 626 $classes[] = 'term-' . $term->term_id; 607 627 } 608 628 } -
tests/phpunit/tests/post/getBodyClass.php
1 <?php 2 3 /** 4 * @group post 5 * @covers ::get_body_class 6 */ 7 class Tests_Post_GetBodyClass extends WP_UnitTestCase { 8 protected $post_id; 9 10 public function setUp() { 11 parent::setUp(); 12 $this->post_id = $this->factory->post->create(); 13 } 14 15 /** 16 * @ticket 30883 17 */ 18 public function test_with_utf8_category_slugs() { 19 $cat_id1 = $this->factory->category->create( array( 'name' => 'Первая рубрика' ) ); 20 $cat_id2 = $this->factory->category->create( array( 'name' => 'Вторая рубрика' ) ); 21 $cat_id3 = $this->factory->category->create( array( 'name' => '25кадр' ) ); 22 wp_set_post_terms( $this->post_id, array( $cat_id1, $cat_id2, $cat_id3 ), 'category' ); 23 24 $this->go_to( home_url( "?cat=$cat_id1" ) ); 25 $this->assertContains( "category-$cat_id1", get_body_class() ); 26 27 $this->go_to( home_url( "?cat=$cat_id2" ) ); 28 $this->assertContains( "category-$cat_id2", get_body_class() ); 29 30 $this->go_to( home_url( "?cat=$cat_id3" ) ); 31 $this->assertContains( "category-$cat_id3", get_body_class() ); 32 } 33 34 /** 35 * @ticket 30883 36 */ 37 public function test_with_utf8_tag_slugs() { 38 $tag_id1 = $this->factory->tag->create( array( 'name' => 'Первая метка' ) ); 39 $tag_id2 = $this->factory->tag->create( array( 'name' => 'Вторая метка' ) ); 40 $tag_id3 = $this->factory->tag->create( array( 'name' => '25кадр' ) ); 41 wp_set_post_terms( $this->post_id, array( $tag_id1, $tag_id2, $tag_id3 ), 'post_tag' ); 42 43 $tag1 = get_term( $tag_id1, 'post_tag' ); 44 $tag2 = get_term( $tag_id2, 'post_tag' ); 45 $tag3 = get_term( $tag_id3, 'post_tag' ); 46 47 $this->go_to( home_url( "?tag={$tag1->slug}" ) ); 48 $this->assertContains( "tag-$tag_id1", get_body_class() ); 49 50 $this->go_to( home_url( "?tag={$tag2->slug}" ) ); 51 $this->assertContains( "tag-$tag_id2", get_body_class() ); 52 53 $this->go_to( home_url( "?tag={$tag3->slug}" ) ); 54 $this->assertContains( "tag-$tag_id3", get_body_class() ); 55 } 56 57 /** 58 * @ticket 30883 59 */ 60 public function test_with_utf8_term_slugs() { 61 register_taxonomy( 'wptests_tax', 'post' ); 62 $term_id1 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Первая метка' ) ); 63 $term_id2 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => 'Вторая метка' ) ); 64 $term_id3 = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax', 'name' => '25кадр' ) ); 65 wp_set_post_terms( $this->post_id, array( $term_id1, $term_id2, $term_id3 ), 'wptests_tax' ); 66 67 $term1 = get_term( $term_id1, 'wptests_tax' ); 68 $term2 = get_term( $term_id2, 'wptests_tax' ); 69 $term3 = get_term( $term_id3, 'wptests_tax' ); 70 71 $this->go_to( home_url( "?wptests_tax={$term1->slug}" ) ); 72 $this->assertContains( "term-$term_id1", get_body_class() ); 73 74 $this->go_to( home_url( "?wptests_tax={$term2->slug}" ) ); 75 $this->assertContains( "term-$term_id2", get_body_class() ); 76 77 $this->go_to( home_url( "?wptests_tax={$term3->slug}" ) ); 78 $this->assertContains( "term-$term_id3", get_body_class() ); 79 } 80 81 } -
tests/phpunit/tests/post/getPostClass.php
54 54 } 55 55 56 56 /** 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 /** 57 106 * @group cache 58 107 */ 59 108 public function test_taxonomy_classes_hit_cache() {