Code is Poetry.

WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2017-11-30 23:09:33 +00:00
parent ec6a089f98
commit 8f95800d52
1103 changed files with 105978 additions and 78184 deletions
+119 -87
View File
@@ -25,17 +25,17 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
foreach ( $inputs as $k => $post_title ) {
for ( $i = 0; $i < 2; $i++ ) {
$post = array(
'post_author' => $author_id,
'post_status' => 'publish',
'post_author' => $author_id,
'post_status' => 'publish',
'post_content' => 'Post content',
'post_title' => $post_title,
'post_title' => $post_title,
);
$id = $this->post_ids[] = self::factory()->post->create( $post );
}
$post = get_post( $id );
$this->assertEquals( $outputs[$k], urldecode( $post->post_name ) );
$this->assertEquals( $outputs[ $k ], urldecode( $post->post_name ) );
}
}
@@ -46,14 +46,14 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
register_post_type( 'post-type-1', array( 'hierarchical' => true ) );
register_post_type( 'post-type-2', array( 'hierarchical' => true ) );
$args = array(
'post_type' => 'post-type-1',
'post_name' => 'some-slug',
$args = array(
'post_type' => 'post-type-1',
'post_name' => 'some-slug',
'post_status' => 'publish',
);
$one = self::factory()->post->create( $args );
$one = self::factory()->post->create( $args );
$args['post_type'] = 'post-type-2';
$two = self::factory()->post->create( $args );
$two = self::factory()->post->create( $args );
$this->assertEquals( 'some-slug', get_post( $one )->post_name );
$this->assertEquals( 'some-slug', get_post( $two )->post_name );
@@ -71,14 +71,14 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_with_hierarchy() {
register_post_type( 'post-type-1', array( 'hierarchical' => true ) );
$args = array(
'post_type' => 'post-type-1',
'post_name' => 'some-slug',
$args = array(
'post_type' => 'post-type-1',
'post_name' => 'some-slug',
'post_status' => 'publish',
);
$one = self::factory()->post->create( $args );
$one = self::factory()->post->create( $args );
$args['post_name'] = 'some-slug-2';
$two = self::factory()->post->create( $args );
$two = self::factory()->post->create( $args );
$this->assertEquals( 'some-slug', get_post( $one )->post_name );
$this->assertEquals( 'some-slug-2', get_post( $two )->post_name );
@@ -95,26 +95,26 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
register_post_type( 'post-type-1', array( 'hierarchical' => true ) );
$args = array(
'post_type' => 'post-type-1',
'post_name' => 'some-slug',
'post_type' => 'post-type-1',
'post_name' => 'some-slug',
'post_status' => 'publish',
);
$one = self::factory()->post->create( $args );
$one = self::factory()->post->create( $args );
$args = array(
$args = array(
'post_mime_type' => 'image/jpeg',
'post_type' => 'attachment',
'post_name' => 'image'
'post_type' => 'attachment',
'post_name' => 'image',
);
$attachment = self::factory()->attachment->create_object( 'image.jpg', $one, $args );
$args = array(
'post_type' => 'post-type-1',
'post_name' => 'image',
'post_type' => 'post-type-1',
'post_name' => 'image',
'post_status' => 'publish',
'post_parent' => $one
'post_parent' => $one,
);
$two = self::factory()->post->create( $args );
$two = self::factory()->post->create( $args );
$this->assertEquals( 'some-slug', get_post( $one )->post_name );
$this->assertEquals( 'image', get_post( $attachment )->post_name );
@@ -130,14 +130,18 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
* @dataProvider whitelist_post_statuses
*/
public function test_whitelisted_post_statuses_should_not_be_forced_to_be_unique( $status ) {
$p1 = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p1 = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$p2 = self::factory()->post->create( array(
'post_type' => 'post',
) );
$p2 = self::factory()->post->create(
array(
'post_type' => 'post',
)
);
$actual = wp_unique_post_slug( 'foo', $p2, $status, 'post', 0 );
@@ -153,14 +157,18 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
}
public function test_revisions_should_not_be_forced_to_be_unique() {
$p1 = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p1 = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$p2 = self::factory()->post->create( array(
'post_type' => 'post',
) );
$p2 = self::factory()->post->create(
array(
'post_type' => 'post',
)
);
$actual = wp_unique_post_slug( 'foo', $p2, 'inherit', 'revision', 0 );
@@ -173,10 +181,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_be_suffixed() {
$this->set_permalink_structure( '/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
$this->assertEquals( '2015-2', $found );
@@ -188,11 +198,13 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_not_be_suffixed_for_already_published_posts() {
$this->set_permalink_structure( '/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
'post_status' => 'publish',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
'post_status' => 'publish',
)
);
$found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
$this->assertEquals( '2015-2', $found );
@@ -204,10 +216,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_yearlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_year_archives() {
$this->set_permalink_structure( '/%year%/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
$this->assertEquals( '2015', $found );
@@ -219,10 +233,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_slugs_resulting_in_permalinks_that_resemble_month_archives_should_be_suffixed() {
$this->set_permalink_structure( '/%year%/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
$this->assertEquals( '11-2', $found );
@@ -234,10 +250,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_monthlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_month_archives() {
$this->set_permalink_structure( '/%year%/foo/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
$this->assertEquals( '11', $found );
@@ -249,10 +267,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_monthlike_slugs_should_not_be_suffixed_for_invalid_month_numbers() {
$this->set_permalink_structure( '/%year%/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$found = wp_unique_post_slug( '13', $p, 'publish', 'post', 0 );
$this->assertEquals( '13', $found );
@@ -264,10 +284,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_slugs_resulting_in_permalinks_that_resemble_day_archives_should_be_suffixed() {
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
$this->assertEquals( '30-2', $found );
@@ -279,10 +301,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_daylike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_day_archives() {
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
$this->assertEquals( '30', $found );
@@ -294,10 +318,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_daylike_slugs_should_not_be_suffixed_for_invalid_day_numbers() {
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'foo',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'foo',
)
);
$found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 );
$this->assertEquals( '32', $found );
@@ -309,10 +335,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_embed_slug_should_be_suffixed_for_posts() {
$this->set_permalink_structure( '/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'post',
'post_name' => 'embed',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'post',
'post_name' => 'embed',
)
);
$found = wp_unique_post_slug( 'embed', $p, 'publish', 'post', 0 );
$this->assertSame( 'embed-2', $found );
@@ -324,10 +352,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_embed_slug_should_be_suffixed_for_pages() {
$this->set_permalink_structure( '/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'page',
'post_name' => 'embed',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'page',
'post_name' => 'embed',
)
);
$found = wp_unique_post_slug( 'embed', $p, 'publish', 'paage', 0 );
$this->assertSame( 'embed-2', $found );
@@ -339,10 +369,12 @@ class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase {
public function test_embed_slug_should_be_suffixed_for_attachments() {
$this->set_permalink_structure( '/%postname%/' );
$p = self::factory()->post->create( array(
'post_type' => 'attachment',
'post_name' => 'embed',
) );
$p = self::factory()->post->create(
array(
'post_type' => 'attachment',
'post_name' => 'embed',
)
);
$found = wp_unique_post_slug( 'embed', $p, 'publish', 'attachment', 0 );
$this->assertSame( 'embed-2', $found );