WordPress.org

Make WordPress Core

Changeset 30480


Ignore:
Timestamp:
11/20/2014 04:45:48 PM (7 years ago)
Author:
johnbillion
Message:

Correct an SQL syntax error introduced in r30158. Adds tests.

Fixes #30339
See #18962
Props julien731

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r30287 r30480  
    37213721            do {
    37223722                $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
    3723                 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) );
     3723                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) ); 
    37243724                $suffix++;
    37253725            } while ( $post_name_check );
  • trunk/tests/phpunit/tests/post.php

    r30346 r30480  
    10191019
    10201020    /**
     1021     * @ticket 30339
     1022     */
     1023    function test_wp_unique_post_slug_with_hierarchy() {
     1024        register_post_type( 'post-type-1', array( 'hierarchical' => true ) );
     1025
     1026        $args = array(
     1027            'post_type' => 'post-type-1',
     1028            'post_name' => 'some-slug',
     1029            'post_status' => 'publish',
     1030        );
     1031        $one = $this->factory->post->create( $args );
     1032        $args['post_name'] = 'some-slug-2';
     1033        $two = $this->factory->post->create( $args );
     1034
     1035        $this->assertEquals( 'some-slug', get_post( $one )->post_name );
     1036        $this->assertEquals( 'some-slug-2', get_post( $two )->post_name );
     1037
     1038        $this->assertEquals( 'some-slug-3', wp_unique_post_slug( 'some-slug', 0, 'publish', 'post-type-1', 0 ) );
     1039
     1040        _unregister_post_type( 'post-type-1' );
     1041    }
     1042
     1043    /**
     1044     * @ticket 18962
     1045     */
     1046    function test_wp_unique_post_slug_with_hierarchy_and_attachments() {
     1047        register_post_type( 'post-type-1', array( 'hierarchical' => true ) );
     1048
     1049        $args = array(
     1050            'post_type' => 'post-type-1',
     1051            'post_name' => 'some-slug',
     1052            'post_status' => 'publish',
     1053        );
     1054        $one = $this->factory->post->create( $args );
     1055
     1056        $args = array(
     1057            'post_mime_type' => 'image/jpeg',
     1058            'post_type' => 'attachment',
     1059            'post_name' => 'image'
     1060        );
     1061        $attachment = $this->factory->attachment->create_object( 'image.jpg', $one, $args );
     1062
     1063        $args = array(
     1064            'post_type' => 'post-type-1',
     1065            'post_name' => 'image',
     1066            'post_status' => 'publish',
     1067            'post_parent' => $one
     1068        );
     1069        $two = $this->factory->post->create( $args );
     1070
     1071        $this->assertEquals( 'some-slug', get_post( $one )->post_name );
     1072        $this->assertEquals( 'image', get_post( $attachment )->post_name );
     1073        $this->assertEquals( 'image-2', get_post( $two )->post_name );
     1074
     1075        // 'image' can be a child of image-2
     1076        $this->assertEquals( 'image', wp_unique_post_slug( 'image', 0, 'publish', 'post-type-1', $two ) );
     1077
     1078        _unregister_post_type( 'post-type-1' );
     1079    }
     1080
     1081    /**
    10211082     * @ticket 21212
    10221083     */
Note: See TracChangeset for help on using the changeset viewer.