| | 1847 | |
| | 1848 | /** |
| | 1849 | * Ensure updated post have a different slug then already publish post with same name. |
| | 1850 | * |
| | 1851 | * @ticket 50447 |
| | 1852 | * @covers ::wp_publish_post |
| | 1853 | */ |
| | 1854 | public function test_updated_draft_post_have_unique_slug_from_publish_post_with_same_title() { |
| | 1855 | |
| | 1856 | // Publish post metainfo. |
| | 1857 | $post = array( |
| | 1858 | 'post_name' => 'test', |
| | 1859 | 'post_title' => 'test', |
| | 1860 | 'post_status' => 'publish', |
| | 1861 | ); |
| | 1862 | |
| | 1863 | // Add post. |
| | 1864 | $post_id = self::factory()->post->create( $post ); |
| | 1865 | |
| | 1866 | // Testcase for publish post with $post_id |
| | 1867 | $post_object = get_post( $post_id ); |
| | 1868 | $this->assertSame( 'test', $post_object->post_title ); |
| | 1869 | $this->assertSame( 'test', $post_object->post_name ); |
| | 1870 | |
| | 1871 | // Draft post metainfo. |
| | 1872 | $draft_post = array( |
| | 1873 | 'post_title' => 'test', |
| | 1874 | 'post_status' => 'draft', |
| | 1875 | 'post_name' => 'test' |
| | 1876 | ); |
| | 1877 | |
| | 1878 | // Add draft post. |
| | 1879 | $draft_post_id = self::factory()->post->create( $draft_post ); |
| | 1880 | |
| | 1881 | // Testcase for draft post with $draft_post_id. |
| | 1882 | $post_object = get_post( $draft_post_id ); |
| | 1883 | $this->assertSame( 'test', $post_object->post_title ); |
| | 1884 | $this->assertSame( 'draft', $post_object->post_status ); |
| | 1885 | |
| | 1886 | // Update draft post. |
| | 1887 | wp_publish_post( $draft_post_id ); |
| | 1888 | |
| | 1889 | // Testcase for updated draft post. |
| | 1890 | $post_object = get_post( $draft_post_id ); |
| | 1891 | $this->assertSame( 'test', $post_object->post_title ); |
| | 1892 | $this->assertSame( 'publish', $post_object->post_status ); |
| | 1893 | $this->assertNotSame( 'test', $post_object->post_name ); |
| | 1894 | $this->assertSame( wp_unique_post_slug($post_object->post_name, $post_object->ID, $post_object->post_status, $post_object->post_type, $post_object->post_parent), $post_object->post_name ); |
| | 1895 | } |