Make WordPress Core

Changeset 32604


Ignore:
Timestamp:
05/26/2015 06:07:17 PM (11 years ago)
Author:
boonebgorges
Message:

Improve unit tests for wp_unique_post_slug().

See #5305.

Location:
trunk/tests/phpunit/tests
Files:
1 added
1 edited

Legend:

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

    r31940 r32604  
    471471
    472472        /**
    473          * @ticket 21013
    474          */
    475         function test_wp_unique_post_slug_with_non_latin_slugs() {
    476                 $inputs = array(
    477                         'Αρνάκι άσπρο και παχύ της μάνας του καμάρι, και άλλα τραγούδια',
    478                         'Предлагаем супер металлообрабатывающее оборудование',
    479                 );
    480 
    481                 $outputs = array(
    482                         'αρνάκι-άσπρο-και-παχύ-της-μάνας-του-κα-2',
    483                         'предлагаем-супер-металлообрабатыва-2',
    484                 );
    485 
    486                 foreach ( $inputs as $k => $post_title ) {
    487                         for ( $i = 0; $i < 2; $i++ ) {
    488                                 $post = array(
    489                                         'post_author' => $this->author_id,
    490                                         'post_status' => 'publish',
    491                                         'post_content' => rand_str(),
    492                                         'post_title' => $post_title,
    493                                 );
    494 
    495                                 $id = $this->post_ids[] = wp_insert_post( $post );
    496                         }
    497 
    498                         $post = get_post( $id );
    499                         $this->assertEquals( $outputs[$k], urldecode( $post->post_name ) );
    500                 }
    501         }
    502 
    503         /**
    504473         * @ticket 15665
    505474         */
     
    947916
    948917        /**
    949          * @ticket 18962
    950          */
    951         function test_wp_unique_post_slug_with_multiple_hierarchies() {
    952                 register_post_type( 'post-type-1', array( 'hierarchical' => true ) );
    953                 register_post_type( 'post-type-2', array( 'hierarchical' => true ) );
    954 
    955                 $args = array(
    956                         'post_type' => 'post-type-1',
    957                         'post_name' => 'some-slug',
    958                         'post_status' => 'publish',
    959                 );
    960                 $one = $this->factory->post->create( $args );
    961                 $args['post_type'] = 'post-type-2';
    962                 $two = $this->factory->post->create( $args );
    963 
    964                 $this->assertEquals( 'some-slug', get_post( $one )->post_name );
    965                 $this->assertEquals( 'some-slug', get_post( $two )->post_name );
    966 
    967                 $this->assertEquals( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-1', 0 ) );
    968                 $this->assertEquals( 'some-other-slug', wp_unique_post_slug( 'some-other-slug', $one, 'publish', 'post-type-2', 0 ) );
    969 
    970                 _unregister_post_type( 'post-type-1' );
    971                 _unregister_post_type( 'post-type-2' );
    972         }
    973 
    974         /**
    975          * @ticket 30339
    976          */
    977         function test_wp_unique_post_slug_with_hierarchy() {
    978                 register_post_type( 'post-type-1', array( 'hierarchical' => true ) );
    979 
    980                 $args = array(
    981                         'post_type' => 'post-type-1',
    982                         'post_name' => 'some-slug',
    983                         'post_status' => 'publish',
    984                 );
    985                 $one = $this->factory->post->create( $args );
    986                 $args['post_name'] = 'some-slug-2';
    987                 $two = $this->factory->post->create( $args );
    988 
    989                 $this->assertEquals( 'some-slug', get_post( $one )->post_name );
    990                 $this->assertEquals( 'some-slug-2', get_post( $two )->post_name );
    991 
    992                 $this->assertEquals( 'some-slug-3', wp_unique_post_slug( 'some-slug', 0, 'publish', 'post-type-1', 0 ) );
    993 
    994                 _unregister_post_type( 'post-type-1' );
    995         }
    996 
    997         /**
    998          * @ticket 18962
    999          */
    1000         function test_wp_unique_post_slug_with_hierarchy_and_attachments() {
    1001                 register_post_type( 'post-type-1', array( 'hierarchical' => true ) );
    1002 
    1003                 $args = array(
    1004                         'post_type' => 'post-type-1',
    1005                         'post_name' => 'some-slug',
    1006                         'post_status' => 'publish',
    1007                 );
    1008                 $one = $this->factory->post->create( $args );
    1009 
    1010                 $args = array(
    1011                         'post_mime_type' => 'image/jpeg',
    1012                         'post_type' => 'attachment',
    1013                         'post_name' => 'image'
    1014                 );
    1015                 $attachment = $this->factory->attachment->create_object( 'image.jpg', $one, $args );
    1016 
    1017                 $args = array(
    1018                         'post_type' => 'post-type-1',
    1019                         'post_name' => 'image',
    1020                         'post_status' => 'publish',
    1021                         'post_parent' => $one
    1022                 );
    1023                 $two = $this->factory->post->create( $args );
    1024 
    1025                 $this->assertEquals( 'some-slug', get_post( $one )->post_name );
    1026                 $this->assertEquals( 'image', get_post( $attachment )->post_name );
    1027                 $this->assertEquals( 'image-2', get_post( $two )->post_name );
    1028 
    1029                 // 'image' can be a child of image-2
    1030                 $this->assertEquals( 'image', wp_unique_post_slug( 'image', 0, 'publish', 'post-type-1', $two ) );
    1031 
    1032                 _unregister_post_type( 'post-type-1' );
    1033         }
    1034 
    1035         /**
    1036918         * @ticket 21212
    1037919         */
Note: See TracChangeset for help on using the changeset viewer.